1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2009 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 #define CONFIG_RDN "cn=config"
41 #define SCHEMA_RDN "cn=schema"
43 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
44 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
46 extern int slap_DN_strict; /* dn.c */
49 typedef struct modpath_s {
50 struct modpath_s *mp_next;
51 struct berval mp_path;
55 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 typedef struct ConfigFile {
59 struct ConfigFile *c_sibs;
60 struct ConfigFile *c_kids;
62 AttributeType *c_at_head, *c_at_tail;
63 ContentRule *c_cr_head, *c_cr_tail;
64 ObjectClass *c_oc_head, *c_oc_tail;
65 OidMacro *c_om_head, *c_om_tail;
66 Syntax *c_syn_head, *c_syn_tail;
71 ConfigFile *cb_config;
73 BackendDB cb_db; /* underlying database */
78 static CfBackInfo cfBackInfo;
80 static char *passwd_salt;
82 static char *logfileName;
83 #ifdef SLAP_AUTH_REWRITE
84 static BerVarray authz_rewrites;
87 static struct berval cfdir;
90 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
91 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
93 static ConfigFile *cfn;
95 static Avlnode *CfOcTree;
97 /* System schema state */
98 extern AttributeType *at_sys_tail; /* at.c */
99 extern ObjectClass *oc_sys_tail; /* oc.c */
100 extern OidMacro *om_sys_tail; /* oidm.c */
101 extern Syntax *syn_sys_tail; /* syntax.c */
102 static AttributeType *cf_at_tail;
103 static ObjectClass *cf_oc_tail;
104 static OidMacro *cf_om_tail;
105 static Syntax *cf_syn_tail;
107 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
108 SlapReply *rs, int *renumber, Operation *op );
110 static int config_check_schema( Operation *op, CfBackInfo *cfb );
112 static ConfigDriver config_fname;
113 static ConfigDriver config_cfdir;
114 static ConfigDriver config_generic;
115 static ConfigDriver config_search_base;
116 static ConfigDriver config_passwd_hash;
117 static ConfigDriver config_schema_dn;
118 static ConfigDriver config_sizelimit;
119 static ConfigDriver config_timelimit;
120 static ConfigDriver config_overlay;
121 static ConfigDriver config_subordinate;
122 static ConfigDriver config_suffix;
123 static ConfigDriver config_rootdn;
124 static ConfigDriver config_rootpw;
125 static ConfigDriver config_restrict;
126 static ConfigDriver config_allows;
127 static ConfigDriver config_disallows;
128 static ConfigDriver config_requires;
129 static ConfigDriver config_security;
130 static ConfigDriver config_referral;
131 static ConfigDriver config_loglevel;
132 static ConfigDriver config_updatedn;
133 static ConfigDriver config_updateref;
134 static ConfigDriver config_include;
135 static ConfigDriver config_obsolete;
137 static ConfigDriver config_tls_option;
138 static ConfigDriver config_tls_config;
140 extern ConfigDriver syncrepl_config;
148 CFG_TLS_PROTOCOL_MIN,
197 static OidRec OidMacros[] = {
198 /* OpenLDAProot:1.12.2 */
199 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
200 { "OLcfgAt", "OLcfg:3" },
201 { "OLcfgGlAt", "OLcfgAt:0" },
202 { "OLcfgBkAt", "OLcfgAt:1" },
203 { "OLcfgDbAt", "OLcfgAt:2" },
204 { "OLcfgOvAt", "OLcfgAt:3" },
205 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
206 { "OLcfgOc", "OLcfg:4" },
207 { "OLcfgGlOc", "OLcfgOc:0" },
208 { "OLcfgBkOc", "OLcfgOc:1" },
209 { "OLcfgDbOc", "OLcfgOc:2" },
210 { "OLcfgOvOc", "OLcfgOc:3" },
211 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
213 /* Syntaxes. We should just start using the standard names and
214 * document that they are predefined and available for users
215 * to reference in their own schema. Defining schema without
216 * OID macros is for masochists...
218 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
219 { "OMsBoolean", "OMsyn:7" },
220 { "OMsDN", "OMsyn:12" },
221 { "OMsDirectoryString", "OMsyn:15" },
222 { "OMsIA5String", "OMsyn:26" },
223 { "OMsInteger", "OMsyn:27" },
224 { "OMsOID", "OMsyn:38" },
225 { "OMsOctetString", "OMsyn:40" },
230 * Backend/Database registry
232 * OLcfg{Bk|Db}{Oc|At}:0 -> common
233 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
234 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
235 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
236 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
237 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
238 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
239 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
245 * OLcfgOv{Oc|At}:1 -> syncprov
246 * OLcfgOv{Oc|At}:2 -> pcache
247 * OLcfgOv{Oc|At}:3 -> chain
248 * OLcfgOv{Oc|At}:4 -> accesslog
249 * OLcfgOv{Oc|At}:5 -> valsort
250 * OLcfgOv{Oc|At}:7 -> distproc
251 * OLcfgOv{Oc|At}:8 -> dynlist
252 * OLcfgOv{Oc|At}:9 -> dds
253 * OLcfgOv{Oc|At}:10 -> unique
254 * OLcfgOv{Oc|At}:11 -> refint
255 * OLcfgOv{Oc|At}:12 -> ppolicy
256 * OLcfgOv{Oc|At}:13 -> constraint
257 * OLcfgOv{Oc|At}:14 -> translucent
258 * OLcfgOv{Oc|At}:15 -> auditlog
259 * OLcfgOv{Oc|At}:16 -> rwm
260 * OLcfgOv{Oc|At}:17 -> dyngroup
261 * OLcfgOv{Oc|At}:18 -> memberof
262 * OLcfgOv{Oc|At}:19 -> collect
263 * OLcfgOv{Oc|At}:20 -> retcode
266 /* alphabetical ordering */
268 static ConfigTable config_back_cf_table[] = {
269 /* This attr is read-only */
270 { "", "", 0, 0, 0, ARG_MAGIC,
271 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
272 "DESC 'File for slapd configuration directives' "
273 "EQUALITY caseIgnoreMatch "
274 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
275 { "", "", 0, 0, 0, ARG_MAGIC,
276 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
277 "DESC 'Directory for slapd configuration backend' "
278 "EQUALITY caseIgnoreMatch "
279 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
280 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
281 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
282 "DESC 'Access Control List' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
285 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
286 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
287 "DESC 'Check ACLs against content of Add ops' "
288 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
289 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
290 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
291 "DESC 'Allowed set of deprecated features' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString )", NULL, NULL },
294 { "argsfile", "file", 2, 2, 0, ARG_STRING,
295 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
296 "DESC 'File for slapd command line options' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
299 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
300 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString )", NULL, NULL },
303 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
304 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
305 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
306 "DESC 'OpenLDAP attributeTypes' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
310 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
311 #ifdef SLAP_AUTH_REWRITE
312 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
316 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
317 "EQUALITY caseIgnoreMatch "
318 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
319 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
320 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
321 "EQUALITY caseIgnoreMatch "
322 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
323 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
324 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
325 "EQUALITY caseIgnoreMatch "
326 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
327 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
328 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
329 "DESC 'A type of backend' "
330 "EQUALITY caseIgnoreMatch "
331 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
333 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
334 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
335 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
336 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
337 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
338 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
339 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
340 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
341 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
342 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
343 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
344 "DESC 'The backend type for a database instance' "
345 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
346 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
347 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
348 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
349 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
350 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
351 "EQUALITY caseIgnoreMatch "
352 "SYNTAX OMsDirectoryString )", NULL, NULL },
353 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
354 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
355 "DESC 'OpenLDAP DIT content rules' "
356 "EQUALITY caseIgnoreMatch "
357 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
359 { "gentlehup", "on|off", 2, 2, 0,
361 ARG_ON_OFF, &global_gentlehup,
365 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
366 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
367 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
368 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
369 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
370 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
371 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
372 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
373 { "include", "file", 2, 2, 0, ARG_MAGIC,
374 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
375 "SUP labeledURI )", NULL, NULL },
376 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
377 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
378 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
379 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
380 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
381 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
382 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
383 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
384 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
385 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
386 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
387 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
388 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
389 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
390 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
391 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
392 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
393 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
394 { "ldapsyntax", "syntax", 2, 0, 0,
395 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
396 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
397 "DESC 'OpenLDAP ldapSyntax' "
398 "EQUALITY caseIgnoreMatch "
399 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
401 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
402 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
403 "EQUALITY caseIgnoreMatch "
404 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
405 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
406 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
407 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
408 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
409 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
410 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
411 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
412 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
413 "EQUALITY caseIgnoreMatch "
414 "SYNTAX OMsDirectoryString )", NULL, NULL },
415 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
416 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
417 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
418 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
419 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
420 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
421 { "moduleload", "file", 2, 0, 0,
423 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
427 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
428 "EQUALITY caseIgnoreMatch "
429 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
430 { "modulepath", "path", 2, 2, 0,
432 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
436 "( OLcfgGlAt:31 NAME 'olcModulePath' "
437 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
438 { "monitoring", "TRUE|FALSE", 2, 2, 0,
439 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
440 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
441 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
442 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
443 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
444 "DESC 'OpenLDAP object classes' "
445 "EQUALITY caseIgnoreMatch "
446 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
448 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
449 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
450 "EQUALITY caseIgnoreMatch "
451 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
452 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
453 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
454 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
455 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
456 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
457 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
458 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
459 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
460 "EQUALITY caseIgnoreMatch "
461 "SYNTAX OMsDirectoryString )", NULL, NULL },
462 { "pidfile", "file", 2, 2, 0, ARG_STRING,
463 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
464 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
465 { "plugin", NULL, 0, 0, 0,
467 ARG_MAGIC|CFG_PLUGIN, &config_generic,
471 "( OLcfgGlAt:38 NAME 'olcPlugin' "
472 "EQUALITY caseIgnoreMatch "
473 "SYNTAX OMsDirectoryString )", NULL, NULL },
474 { "pluginlog", "filename", 2, 2, 0,
476 ARG_STRING, &slapi_log_file,
480 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
481 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
482 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
483 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
484 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
485 { "referral", "url", 2, 2, 0, ARG_MAGIC,
486 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
487 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
488 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
489 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
490 "EQUALITY caseIgnoreMatch "
491 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
492 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
493 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
494 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
495 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
496 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
497 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
498 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
499 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
500 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
501 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
502 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
503 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
504 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
505 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
506 "EQUALITY caseIgnoreMatch "
507 "SYNTAX OMsDirectoryString )", NULL, NULL },
508 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
509 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
510 "EQUALITY caseIgnoreMatch "
511 "SYNTAX OMsDirectoryString )", NULL, NULL },
512 { "reverse-lookup", "on|off", 2, 2, 0,
513 #ifdef SLAPD_RLOOKUPS
514 ARG_ON_OFF, &use_reverse_lookup,
518 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
519 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
520 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
521 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
522 "EQUALITY distinguishedNameMatch "
523 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
524 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
525 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
526 "EQUALITY caseIgnoreMatch "
527 "SYNTAX OMsDirectoryString )", NULL, NULL },
528 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
529 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
530 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
531 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
532 &config_generic, NULL, NULL, NULL },
533 { "sasl-host", "host", 2, 2, 0,
534 #ifdef HAVE_CYRUS_SASL
535 ARG_STRING|ARG_UNIQUE, &sasl_host,
539 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "sasl-realm", "realm", 2, 2, 0,
542 #ifdef HAVE_CYRUS_SASL
543 ARG_STRING|ARG_UNIQUE, &global_realm,
547 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
548 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
549 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
550 &config_generic, NULL, NULL, NULL },
551 { "sasl-secprops", "properties", 2, 2, 0,
552 #ifdef HAVE_CYRUS_SASL
553 ARG_MAGIC|CFG_SASLSECP, &config_generic,
557 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
558 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
559 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
560 &config_generic, NULL, NULL, NULL },
561 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
562 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
563 "EQUALITY distinguishedNameMatch "
564 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
565 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
566 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
567 "EQUALITY caseIgnoreMatch "
568 "SYNTAX OMsDirectoryString )", NULL, NULL },
569 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
570 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
571 "EQUALITY caseIgnoreMatch "
572 "SYNTAX OMsDirectoryString )", NULL, NULL },
573 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
574 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
575 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
576 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
577 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
578 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
579 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
580 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
581 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
582 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
583 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
584 "DESC 'Attributes whose values will always be sorted' "
585 "EQUALITY caseIgnoreMatch "
586 "SYNTAX OMsDirectoryString )", NULL, NULL },
587 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
588 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
589 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
590 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
591 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
592 "EQUALITY distinguishedNameMatch "
593 "SYNTAX OMsDN )", NULL, NULL },
594 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
595 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
596 "EQUALITY caseIgnoreMatch "
597 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
598 { "threads", "count", 2, 2, 0,
602 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
604 "( OLcfgGlAt:66 NAME 'olcThreads' "
605 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
606 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
607 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
608 "SYNTAX OMsDirectoryString )", NULL, NULL },
609 { "TLSCACertificateFile", NULL, 0, 0, 0,
611 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
615 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
616 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
617 { "TLSCACertificatePath", NULL, 0, 0, 0,
619 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
623 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
624 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
625 { "TLSCertificateFile", NULL, 0, 0, 0,
627 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
631 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
632 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
633 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
635 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
639 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
640 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
641 { "TLSCipherSuite", NULL, 0, 0, 0,
643 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
647 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
648 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
649 { "TLSCRLCheck", NULL, 0, 0, 0,
650 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
651 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
655 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
656 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
657 { "TLSCRLFile", NULL, 0, 0, 0,
658 #if defined(HAVE_GNUTLS)
659 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
663 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
664 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
665 { "TLSRandFile", NULL, 0, 0, 0,
667 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
671 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
672 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
673 { "TLSVerifyClient", NULL, 0, 0, 0,
675 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
679 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
680 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
681 { "TLSDHParamFile", NULL, 0, 0, 0,
683 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
687 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
688 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
689 { "TLSProtocolMin", NULL, 0, 0, 0,
691 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
695 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
696 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
697 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
698 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
699 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
700 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
701 NULL, NULL, NULL, NULL },
702 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
703 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
704 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
705 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
706 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
707 "EQUALITY caseIgnoreMatch "
708 "SUP labeledURI )", NULL, NULL },
709 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
710 NULL, NULL, NULL, NULL }
713 /* Need to no-op this keyword for dynamic config */
714 ConfigTable olcDatabaseDummy[] = {
715 { "", "", 0, 0, 0, ARG_IGNORED,
716 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
717 "DESC 'The backend type for a database instance' "
718 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
719 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
722 /* Routines to check if a child can be added to this type */
723 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
724 cfAddBackend, cfAddModule, cfAddOverlay;
726 /* NOTE: be careful when defining array members
727 * that can be conditionally compiled */
728 #define CFOC_GLOBAL cf_ocs[1]
729 #define CFOC_SCHEMA cf_ocs[2]
730 #define CFOC_BACKEND cf_ocs[3]
731 #define CFOC_DATABASE cf_ocs[4]
732 #define CFOC_OVERLAY cf_ocs[5]
733 #define CFOC_INCLUDE cf_ocs[6]
734 #define CFOC_FRONTEND cf_ocs[7]
736 #define CFOC_MODULE cf_ocs[8]
737 #endif /* SLAPD_MODULES */
739 static ConfigOCs cf_ocs[] = {
742 "DESC 'OpenLDAP configuration object' "
743 "ABSTRACT SUP top )", Cft_Abstract, NULL },
746 "DESC 'OpenLDAP Global configuration options' "
747 "SUP olcConfig STRUCTURAL "
748 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
749 "olcAttributeOptions $ olcAuthIDRewrite $ "
750 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
751 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
752 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
753 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
754 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
755 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
756 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
757 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
758 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
760 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
761 "olcSecurity $ olcServerID $ olcSizeLimit $ "
762 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
763 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
764 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
765 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
766 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
767 "olcTLSCRLFile $ olcToolThreads $ "
768 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
769 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
771 "NAME 'olcSchemaConfig' "
772 "DESC 'OpenLDAP schema object' "
773 "SUP olcConfig STRUCTURAL "
774 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
775 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
776 Cft_Schema, NULL, cfAddSchema },
778 "NAME 'olcBackendConfig' "
779 "DESC 'OpenLDAP Backend-specific options' "
780 "SUP olcConfig STRUCTURAL "
781 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
783 "NAME 'olcDatabaseConfig' "
784 "DESC 'OpenLDAP Database-specific options' "
785 "SUP olcConfig STRUCTURAL "
787 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
788 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
789 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
790 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
791 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
792 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
793 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
795 Cft_Database, NULL, cfAddDatabase },
797 "NAME 'olcOverlayConfig' "
798 "DESC 'OpenLDAP Overlay-specific options' "
799 "SUP olcConfig STRUCTURAL "
800 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
802 "NAME 'olcIncludeFile' "
803 "DESC 'OpenLDAP configuration include file' "
804 "SUP olcConfig STRUCTURAL "
806 "MAY ( cn $ olcRootDSE ) )",
807 /* Used to be Cft_Include, that def has been removed */
808 Cft_Abstract, NULL, cfAddInclude },
809 /* This should be STRUCTURAL like all the other database classes, but
810 * that would mean inheriting all of the olcDatabaseConfig attributes,
811 * which causes them to be merged twice in config_build_entry.
814 "NAME 'olcFrontendConfig' "
815 "DESC 'OpenLDAP frontend configuration' "
817 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
818 Cft_Database, NULL, NULL },
821 "NAME 'olcModuleList' "
822 "DESC 'OpenLDAP dynamic module info' "
823 "SUP olcConfig STRUCTURAL "
824 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
825 Cft_Module, NULL, cfAddModule },
830 typedef struct ServerID {
831 struct ServerID *si_next;
832 struct berval si_url;
836 static ServerID *sid_list;
838 typedef struct voidList {
839 struct voidList *vl_next;
843 typedef struct ADlist {
844 struct ADlist *al_next;
845 AttributeDescription *al_desc;
848 static ADlist *sortVals;
851 config_generic(ConfigArgs *c) {
854 if ( c->op == SLAP_CONFIG_EMIT ) {
858 c->value_int = ldap_pvt_thread_get_concurrency();
861 c->value_int = connection_pool_max;
864 c->value_int = slap_tool_thread_max;
868 c->value_string = ch_strdup( passwd_salt );
873 if ( c->be->be_limits ) {
877 for ( i=0; c->be->be_limits[i]; i++ ) {
878 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
879 if ( bv.bv_len >= sizeof( buf ) ) {
880 ber_bvarray_free_x( c->rvalue_vals, NULL );
881 c->rvalue_vals = NULL;
885 bv.bv_val = buf + bv.bv_len;
886 limits_unparse( c->be->be_limits[i], &bv,
887 sizeof( buf ) - ( bv.bv_val - buf ) );
888 bv.bv_len += bv.bv_val - buf;
890 value_add_one( &c->rvalue_vals, &bv );
893 if ( !c->rvalue_vals ) rc = 1;
896 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
899 c->value_string = ch_strdup( slap_sasl_getpolicy());
902 slap_sasl_regexp_unparse( &c->rvalue_vals );
903 if ( !c->rvalue_vals ) rc = 1;
905 #ifdef HAVE_CYRUS_SASL
907 struct berval bv = BER_BVNULL;
908 slap_sasl_secprops_unparse( &bv );
909 if ( !BER_BVISNULL( &bv )) {
910 ber_bvarray_add( &c->rvalue_vals, &bv );
918 c->value_int = c->be->be_max_deref_depth;
921 if ( SLAP_DBHIDDEN( c->be )) {
928 ConfigFile *cf = c->ca_private;
930 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
931 else if ( cf->c_om_head )
932 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
934 if ( !c->rvalue_vals )
939 ad_unparse_options( &c->rvalue_vals );
942 ConfigFile *cf = c->ca_private;
944 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
945 else if ( cf->c_oc_head )
946 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
948 if ( !c->rvalue_vals )
953 ConfigFile *cf = c->ca_private;
955 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
956 else if ( cf->c_at_head )
957 at_unparse( &c->rvalue_vals, cf->c_at_head,
959 if ( !c->rvalue_vals )
964 ConfigFile *cf = c->ca_private;
966 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
967 else if ( cf->c_syn_head )
968 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
970 if ( !c->rvalue_vals )
975 ConfigFile *cf = c->ca_private;
977 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
978 else if ( cf->c_cr_head )
979 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
981 if ( !c->rvalue_vals )
988 char *src, *dst, ibuf[11];
989 struct berval bv, abv;
990 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
991 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
992 if ( abv.bv_len >= sizeof( ibuf ) ) {
993 ber_bvarray_free_x( c->rvalue_vals, NULL );
994 c->rvalue_vals = NULL;
998 acl_unparse( a, &bv );
999 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1000 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1001 /* Turn TAB / EOL into plain space */
1002 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1003 if (isspace((unsigned char)*src)) *dst++ = ' ';
1007 if (dst[-1] == ' ') {
1011 abv.bv_len = dst - abv.bv_val;
1012 ber_bvarray_add( &c->rvalue_vals, &abv );
1018 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1021 ConfigFile *cf = c->ca_private;
1022 if ( cf->c_dseFiles ) {
1023 value_add( &c->rvalue_vals, cf->c_dseFiles );
1034 for ( si = sid_list; si; si=si->si_next ) {
1035 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1036 if ( !BER_BVISEMPTY( &si->si_url )) {
1037 bv.bv_len = si->si_url.bv_len + 6;
1038 bv.bv_val = ch_malloc( bv.bv_len );
1039 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1040 si->si_url.bv_val );
1041 ber_bvarray_add( &c->rvalue_vals, &bv );
1045 bv.bv_len = sprintf( buf, "%d", si->si_num );
1046 value_add_one( &c->rvalue_vals, &bv );
1055 c->value_string = ch_strdup( logfileName );
1060 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1062 case CFG_MIRRORMODE:
1063 if ( SLAP_SHADOW(c->be))
1064 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1068 case CFG_MONITORING:
1069 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1071 case CFG_SSTR_IF_MAX:
1072 c->value_int = index_substr_if_maxlen;
1074 case CFG_SSTR_IF_MIN:
1075 c->value_int = index_substr_if_minlen;
1078 c->value_int = index_intlen;
1080 case CFG_SORTVALS: {
1083 for ( sv = sortVals; sv; sv = sv->al_next ) {
1084 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1088 #ifdef SLAPD_MODULES
1090 ModPaths *mp = c->ca_private;
1093 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1096 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1097 SLAP_X_ORDERED_FMT "%s", i,
1098 mp->mp_loads[i].bv_val );
1099 if ( bv.bv_len >= sizeof( c->log ) ) {
1100 ber_bvarray_free_x( c->rvalue_vals, NULL );
1101 c->rvalue_vals = NULL;
1104 value_add_one( &c->rvalue_vals, &bv );
1108 rc = c->rvalue_vals ? 0 : 1;
1112 ModPaths *mp = c->ca_private;
1113 if ( !BER_BVISNULL( &mp->mp_path ))
1114 value_add_one( &c->rvalue_vals, &mp->mp_path );
1116 rc = c->rvalue_vals ? 0 : 1;
1122 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1123 if ( !c->rvalue_vals ) rc = 1;
1126 #ifdef SLAP_AUTH_REWRITE
1128 if ( authz_rewrites ) {
1129 struct berval bv, idx;
1134 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1135 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1136 if ( idx.bv_len >= sizeof( ibuf ) ) {
1137 ber_bvarray_free_x( c->rvalue_vals, NULL );
1138 c->rvalue_vals = NULL;
1141 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1142 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1143 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1144 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1145 authz_rewrites[i].bv_val,
1146 authz_rewrites[i].bv_len + 1 );
1147 ber_bvarray_add( &c->rvalue_vals, &bv );
1150 if ( !c->rvalue_vals ) rc = 1;
1157 } else if ( c->op == LDAP_MOD_DELETE ) {
1160 /* single-valued attrs, no-ops */
1168 case CFG_MIRRORMODE:
1169 case CFG_MONITORING:
1171 case CFG_SSTR_IF_MAX:
1172 case CFG_SSTR_IF_MIN:
1176 /* no-ops, requires slapd restart */
1181 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1185 ch_free( passwd_salt );
1190 ch_free( logfileName );
1198 case CFG_SERVERID: {
1199 ServerID *si, **sip;
1201 for ( i=0, si = sid_list, sip = &sid_list;
1202 si; si = *sip, i++ ) {
1203 if ( c->valx == -1 || i == c->valx ) {
1215 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1219 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1220 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1221 SLAP_INDEX_INTLEN_DEFAULT );
1225 if ( c->valx < 0 ) {
1226 acl_destroy( c->be->be_acl );
1227 c->be->be_acl = NULL;
1230 AccessControl **prev, *a;
1232 for (i=0, prev = &c->be->be_acl; i < c->valx;
1235 prev = &a->acl_next;
1238 *prev = a->acl_next;
1245 /* Can be NULL when undoing a failed add */
1246 if ( c->ca_entry ) {
1247 ce = c->ca_entry->e_private;
1248 /* can't modify the hardcoded schema */
1249 if ( ce->ce_parent->ce_type == Cft_Global )
1253 cfn = c->ca_private;
1254 if ( c->valx < 0 ) {
1257 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1259 if ( oc == cfn->c_oc_tail )
1262 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1264 ObjectClass *oc, *prev = NULL;
1266 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1271 if ( cfn->c_oc_tail == oc ) {
1272 cfn->c_oc_tail = prev;
1274 if ( cfn->c_oc_head == oc ) {
1276 cfn->c_oc_head = oc;
1283 /* Can be NULL when undoing a failed add */
1284 if ( c->ca_entry ) {
1285 ce = c->ca_entry->e_private;
1286 /* can't modify the hardcoded schema */
1287 if ( ce->ce_parent->ce_type == Cft_Global )
1291 cfn = c->ca_private;
1292 if ( c->valx < 0 ) {
1295 for( at = cfn->c_at_head; at; at_next( &at )) {
1297 if ( at == cfn->c_at_tail )
1300 cfn->c_at_head = cfn->c_at_tail = NULL;
1302 AttributeType *at, *prev = NULL;
1304 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1309 if ( cfn->c_at_tail == at ) {
1310 cfn->c_at_tail = prev;
1312 if ( cfn->c_at_head == at ) {
1314 cfn->c_at_head = at;
1321 /* Can be NULL when undoing a failed add */
1322 if ( c->ca_entry ) {
1323 ce = c->ca_entry->e_private;
1324 /* can't modify the hardcoded schema */
1325 if ( ce->ce_parent->ce_type == Cft_Global )
1329 cfn = c->ca_private;
1330 if ( c->valx < 0 ) {
1333 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1335 if ( syn == cfn->c_syn_tail )
1338 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1340 Syntax *syn, *prev = NULL;
1342 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1347 if ( cfn->c_syn_tail == syn ) {
1348 cfn->c_syn_tail = prev;
1350 if ( cfn->c_syn_head == syn ) {
1352 cfn->c_syn_head = syn;
1357 if ( c->valx < 0 ) {
1359 for ( sv = sortVals; sv; sv = sortVals ) {
1360 sortVals = sv->al_next;
1361 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1368 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1369 prev = &sv->al_next;
1372 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1373 *prev = sv->al_next;
1379 /* FIXME: there is no limits_free function */
1381 /* FIXME: there is no ad_option_free function */
1383 /* FIXME: there is no way to remove attributes added by
1397 if(!(c->bi = backend_info(c->argv[1]))) {
1398 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1399 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1400 c->log, c->cr_msg, c->argv[1] );
1407 /* NOTE: config is always the first backend!
1409 if ( !strcasecmp( c->argv[1], "config" )) {
1410 c->be = LDAP_STAILQ_FIRST(&backendDB);
1411 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1414 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1416 if ( c->cr_msg[0] == 0 )
1417 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1418 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1425 ldap_pvt_thread_set_concurrency(c->value_int);
1429 if ( c->value_int < 2 ) {
1430 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1431 "threads=%d smaller than minimum value 2",
1433 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1434 c->log, c->cr_msg, 0 );
1437 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1438 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1439 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1440 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1441 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1442 c->log, c->cr_msg, 0 );
1444 if ( slapMode & SLAP_SERVER_MODE )
1445 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1446 connection_pool_max = c->value_int; /* save for reference */
1450 if ( slapMode & SLAP_TOOL_MODE )
1451 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1452 slap_tool_thread_max = c->value_int; /* save for reference */
1456 if ( passwd_salt ) ch_free( passwd_salt );
1457 passwd_salt = c->value_string;
1458 lutil_salt_format(passwd_salt);
1462 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1468 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1470 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1474 ch_free(c->value_string);
1475 if (slap_sasl_setpolicy( c->argv[1] )) {
1476 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1477 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1478 c->log, c->cr_msg, c->argv[1] );
1484 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1488 #ifdef HAVE_CYRUS_SASL
1491 char *txt = slap_sasl_secprops( c->argv[1] );
1493 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1495 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1503 c->be->be_max_deref_depth = c->value_int;
1509 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1510 cfn = c->ca_private;
1511 if(parse_oidm(c, 1, &om))
1513 if (!cfn->c_om_head) cfn->c_om_head = om;
1514 cfn->c_om_tail = om;
1519 ObjectClass *oc, *prev;
1521 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1522 cfn = c->ca_private;
1523 if ( c->valx < 0 ) {
1524 prev = cfn->c_oc_tail;
1527 /* If adding anything after the first, prev is easy */
1530 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1535 /* If adding the first, and head exists, find its prev */
1536 if (cfn->c_oc_head) {
1537 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1542 /* else prev is NULL, append to end of global list */
1544 if(parse_oc(c, &oc, prev)) return(1);
1545 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1546 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1551 AttributeType *at, *prev;
1553 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1554 cfn = c->ca_private;
1555 if ( c->valx < 0 ) {
1556 prev = cfn->c_at_tail;
1559 /* If adding anything after the first, prev is easy */
1562 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1567 /* If adding the first, and head exists, find its prev */
1568 if (cfn->c_at_head) {
1569 for ( at_start( &at ); at != cfn->c_at_head; ) {
1574 /* else prev is NULL, append to end of global list */
1576 if(parse_at(c, &at, prev)) return(1);
1577 if (!cfn->c_at_head) cfn->c_at_head = at;
1578 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1585 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1586 cfn = c->ca_private;
1587 if ( c->valx < 0 ) {
1588 prev = cfn->c_syn_tail;
1591 /* If adding anything after the first, prev is easy */
1594 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1599 /* If adding the first, and head exists, find its prev */
1600 if (cfn->c_syn_head) {
1601 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1606 /* else prev is NULL, append to end of global list */
1608 if ( parse_syn( c, &syn, prev ) ) return(1);
1609 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1610 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1617 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1618 cfn = c->ca_private;
1619 if(parse_cr(c, &cr)) return(1);
1620 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1621 cfn->c_cr_tail = cr;
1626 ad_define_option(NULL, NULL, 0);
1627 for(i = 1; i < c->argc; i++)
1628 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1633 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1634 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1635 else if ( c->value_int > 255 )
1637 index_intlen = c->value_int;
1638 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1642 case CFG_SORTVALS: {
1643 ADlist *svnew = NULL, *svtail, *sv;
1645 for ( i = 1; i < c->argc; i++ ) {
1646 AttributeDescription *ad = NULL;
1650 rc = slap_str2ad( c->argv[i], &ad, &text );
1652 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1655 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1656 c->log, c->cr_msg, c->argv[i] );
1657 for ( sv = svnew; sv; sv = svnew ) {
1658 svnew = sv->al_next;
1663 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1664 ad->ad_type->sat_single_value ) {
1665 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1667 goto sortval_reject;
1669 sv = ch_malloc( sizeof( ADlist ));
1674 svtail->al_next = sv;
1679 for ( sv = svnew; sv; sv = sv->al_next )
1680 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1681 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1683 sv->al_next = svnew;
1690 /* Don't append to the global ACL if we're on a specific DB */
1692 if ( c->valx == -1 ) {
1695 for ( a=c->be->be_acl; a; a = a->acl_next )
1698 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1705 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1707 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1711 if(root_dse_read_file(c->argv[1])) {
1712 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1713 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1714 c->log, c->cr_msg, c->argv[1] );
1719 ber_str2bv( c->argv[1], 0, 1, &bv );
1720 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1721 cfn = c->ca_private;
1722 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1728 ServerID *si, **sip;
1731 if ( lutil_atoi( &num, c->argv[1] ) ||
1732 num < 0 || num > SLAP_SYNC_SID_MAX )
1734 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1735 "<%s> illegal server ID", c->argv[0] );
1736 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1737 c->log, c->cr_msg, c->argv[1] );
1740 /* only one value allowed if no URL is given */
1741 if ( c->argc > 2 ) {
1744 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1745 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1746 "<%s> only one server ID allowed now", c->argv[0] );
1747 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1748 c->log, c->cr_msg, c->argv[1] );
1752 if ( ldap_url_parse( c->argv[2], &lud )) {
1753 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1754 "<%s> invalid URL", c->argv[0] );
1755 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1756 c->log, c->cr_msg, c->argv[2] );
1759 len = strlen( c->argv[2] );
1760 si = ch_malloc( sizeof(ServerID) + len + 1 );
1761 si->si_url.bv_val = (char *)(si+1);
1762 si->si_url.bv_len = len;
1763 strcpy( si->si_url.bv_val, c->argv[2] );
1766 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1767 "<%s> unqualified server ID not allowed now", c->argv[0] );
1768 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1769 c->log, c->cr_msg, c->argv[1] );
1772 si = ch_malloc( sizeof(ServerID) );
1773 BER_BVZERO( &si->si_url );
1774 slap_serverID = num;
1775 Debug( LDAP_DEBUG_CONFIG,
1777 c->log, slap_serverID, 0 );
1781 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1784 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1785 Listener **l = slapd_get_listeners();
1788 /* Try a straight compare with Listener strings */
1789 for ( i=0; l && l[i]; i++ ) {
1790 if ( !strcasecmp( c->argv[2], l[i]->sl_url.bv_val )) {
1796 /* If hostname is empty, or is localhost, or matches
1797 * our hostname, this serverID refers to this host.
1798 * Compare it against listeners and ports.
1800 if ( !isMe && ( !lud->lud_host || !lud->lud_host[0] ||
1801 !strncasecmp("localhost", lud->lud_host,
1802 STRLENOF("localhost")) ||
1803 !strcasecmp( global_host, lud->lud_host ))) {
1805 for ( i=0; l && l[i]; i++ ) {
1807 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1809 if ( strcasecmp( lud->lud_scheme,
1812 if ( lud->lud_port != lu2->lud_port )
1814 /* Listener on ANY address */
1815 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1819 /* URL on ANY address */
1820 if ( !lud->lud_host || !lud->lud_host[0] ) {
1824 /* Listener has specific host, must
1827 if ( !strcasecmp( lud->lud_host,
1833 ldap_free_urldesc( lu2 );
1840 slap_serverID = si->si_num;
1841 Debug( LDAP_DEBUG_CONFIG,
1842 "%s: SID=%d (listener=%s)\n",
1843 c->log, slap_serverID,
1844 l[i]->sl_url.bv_val );
1848 ldap_free_urldesc( lud );
1852 if ( logfileName ) ch_free( logfileName );
1853 logfileName = c->value_string;
1854 logfile = fopen(logfileName, "w");
1855 if(logfile) lutil_debug_file(logfile);
1859 if(SLAP_NOLASTMODCMD(c->be)) {
1860 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1861 c->argv[0], c->be->bd_info->bi_type );
1862 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1863 c->log, c->cr_msg, 0 );
1867 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1869 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1872 case CFG_MIRRORMODE:
1873 if(!SLAP_SHADOW(c->be)) {
1874 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1876 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1877 c->log, c->cr_msg, 0 );
1881 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1883 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1886 case CFG_MONITORING:
1888 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1890 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1895 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1897 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1900 case CFG_SSTR_IF_MAX:
1901 if (c->value_int < index_substr_if_minlen) {
1902 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1903 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1904 c->log, c->cr_msg, c->value_int );
1907 index_substr_if_maxlen = c->value_int;
1910 case CFG_SSTR_IF_MIN:
1911 if (c->value_int > index_substr_if_maxlen) {
1912 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1913 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1914 c->log, c->cr_msg, c->value_int );
1917 index_substr_if_minlen = c->value_int;
1920 #ifdef SLAPD_MODULES
1922 /* If we're just adding a module on an existing modpath,
1923 * make sure we've selected the current path.
1925 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1926 modcur = c->ca_private;
1927 /* This should never fail */
1928 if ( module_path( modcur->mp_path.bv_val )) {
1929 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1931 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1932 c->log, c->cr_msg, modcur->mp_path.bv_val );
1936 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1938 /* Record this load on the current path */
1942 if ( c->op == SLAP_CONFIG_ADD ) {
1943 ptr = c->line + STRLENOF("moduleload");
1944 while (!isspace((unsigned char) *ptr)) ptr++;
1945 while (isspace((unsigned char) *ptr)) ptr++;
1949 ber_str2bv(ptr, 0, 1, &bv);
1950 ber_bvarray_add( &modcur->mp_loads, &bv );
1952 /* Check for any new hardcoded schema */
1953 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1954 config_check_schema( NULL, &cfBackInfo );
1959 if(module_path(c->argv[1])) return(1);
1960 /* Record which path was used with each module */
1964 if (!modpaths.mp_loads) {
1967 mp = ch_malloc( sizeof( ModPaths ));
1968 modlast->mp_next = mp;
1970 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1972 mp->mp_loads = NULL;
1983 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1985 slapi_plugins_used++;
1989 #ifdef SLAP_AUTH_REWRITE
1994 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1997 if ( c->argc > 1 ) {
2000 /* quote all args but the first */
2001 line = ldap_charray2str( c->argv, "\" \"" );
2002 ber_str2bv( line, 0, 0, &bv );
2003 s = ber_bvchr( &bv, '"' );
2004 assert( s != NULL );
2005 /* move the trailing quote of argv[0] to the end */
2006 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2007 bv.bv_val[ bv.bv_len - 1 ] = '"';
2010 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2013 ber_bvarray_add( &authz_rewrites, &bv );
2020 Debug( LDAP_DEBUG_ANY,
2021 "%s: unknown CFG_TYPE %d.\n",
2022 c->log, c->type, 0 );
2031 config_fname(ConfigArgs *c) {
2032 if(c->op == SLAP_CONFIG_EMIT) {
2033 if (c->ca_private) {
2034 ConfigFile *cf = c->ca_private;
2035 value_add_one( &c->rvalue_vals, &cf->c_file );
2044 config_cfdir(ConfigArgs *c) {
2045 if(c->op == SLAP_CONFIG_EMIT) {
2046 if ( !BER_BVISEMPTY( &cfdir )) {
2047 value_add_one( &c->rvalue_vals, &cfdir );
2056 config_search_base(ConfigArgs *c) {
2057 if(c->op == SLAP_CONFIG_EMIT) {
2059 if (!BER_BVISEMPTY(&default_search_base)) {
2060 value_add_one(&c->rvalue_vals, &default_search_base);
2061 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2065 } else if( c->op == LDAP_MOD_DELETE ) {
2066 ch_free( default_search_base.bv_val );
2067 ch_free( default_search_nbase.bv_val );
2068 BER_BVZERO( &default_search_base );
2069 BER_BVZERO( &default_search_nbase );
2073 if(c->bi || c->be != frontendDB) {
2074 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2075 "prior to any backend or database definition\n",
2080 if(default_search_nbase.bv_len) {
2081 free(default_search_base.bv_val);
2082 free(default_search_nbase.bv_val);
2085 default_search_base = c->value_dn;
2086 default_search_nbase = c->value_ndn;
2090 /* For RE23 compatibility we allow this in the global entry
2091 * but we now defer it to the frontend entry to allow modules
2092 * to load new hash types.
2095 config_passwd_hash(ConfigArgs *c) {
2097 if (c->op == SLAP_CONFIG_EMIT) {
2099 /* Don't generate it in the global entry */
2100 if ( c->table == Cft_Global )
2102 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2103 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2104 value_add_one(&c->rvalue_vals, &bv);
2107 } else if ( c->op == LDAP_MOD_DELETE ) {
2108 /* Deleting from global is a no-op, only the frontendDB entry matters */
2109 if ( c->table == Cft_Global )
2111 if ( c->valx < 0 ) {
2112 ldap_charray_free( default_passwd_hash );
2113 default_passwd_hash = NULL;
2116 ch_free( default_passwd_hash[i] );
2117 for (; default_passwd_hash[i]; i++ )
2118 default_passwd_hash[i] = default_passwd_hash[i+1];
2122 for(i = 1; i < c->argc; i++) {
2123 if(!lutil_passwd_scheme(c->argv[i])) {
2124 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2125 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2126 c->log, c->cr_msg, c->argv[i]);
2128 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2131 if(!default_passwd_hash) {
2132 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2133 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2134 c->log, c->cr_msg, 0 );
2141 config_schema_dn(ConfigArgs *c) {
2142 if ( c->op == SLAP_CONFIG_EMIT ) {
2144 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2145 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2146 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2150 } else if ( c->op == LDAP_MOD_DELETE ) {
2151 ch_free( c->be->be_schemadn.bv_val );
2152 ch_free( c->be->be_schemandn.bv_val );
2153 BER_BVZERO( &c->be->be_schemadn );
2154 BER_BVZERO( &c->be->be_schemandn );
2157 ch_free( c->be->be_schemadn.bv_val );
2158 ch_free( c->be->be_schemandn.bv_val );
2159 c->be->be_schemadn = c->value_dn;
2160 c->be->be_schemandn = c->value_ndn;
2165 config_sizelimit(ConfigArgs *c) {
2167 struct slap_limits_set *lim = &c->be->be_def_limit;
2168 if (c->op == SLAP_CONFIG_EMIT) {
2173 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2174 if ( !BER_BVISEMPTY( &bv ))
2175 value_add_one( &c->rvalue_vals, &bv );
2179 } else if ( c->op == LDAP_MOD_DELETE ) {
2180 /* Reset to defaults */
2181 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2182 lim->lms_s_hard = 0;
2183 lim->lms_s_unchecked = -1;
2185 lim->lms_s_pr_hide = 0;
2186 lim->lms_s_pr_total = 0;
2189 for(i = 1; i < c->argc; i++) {
2190 if(!strncasecmp(c->argv[i], "size", 4)) {
2191 rc = limits_parse_one(c->argv[i], lim);
2193 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2194 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2195 c->log, c->cr_msg, c->argv[i]);
2199 if(!strcasecmp(c->argv[i], "unlimited")) {
2200 lim->lms_s_soft = -1;
2202 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2203 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2204 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2205 c->log, c->cr_msg, c->argv[i]);
2209 lim->lms_s_hard = 0;
2216 config_timelimit(ConfigArgs *c) {
2218 struct slap_limits_set *lim = &c->be->be_def_limit;
2219 if (c->op == SLAP_CONFIG_EMIT) {
2224 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2225 if ( !BER_BVISEMPTY( &bv ))
2226 value_add_one( &c->rvalue_vals, &bv );
2230 } else if ( c->op == LDAP_MOD_DELETE ) {
2231 /* Reset to defaults */
2232 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2233 lim->lms_t_hard = 0;
2236 for(i = 1; i < c->argc; i++) {
2237 if(!strncasecmp(c->argv[i], "time", 4)) {
2238 rc = limits_parse_one(c->argv[i], lim);
2240 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2241 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2242 c->log, c->cr_msg, c->argv[i]);
2246 if(!strcasecmp(c->argv[i], "unlimited")) {
2247 lim->lms_t_soft = -1;
2249 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2250 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2251 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2252 c->log, c->cr_msg, c->argv[i]);
2256 lim->lms_t_hard = 0;
2263 config_overlay(ConfigArgs *c) {
2264 if (c->op == SLAP_CONFIG_EMIT) {
2266 } else if ( c->op == LDAP_MOD_DELETE ) {
2269 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2270 c->valx, &c->bi, &c->reply)) {
2272 Debug( LDAP_DEBUG_ANY,
2273 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2274 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2276 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2283 config_subordinate(ConfigArgs *c)
2289 case SLAP_CONFIG_EMIT:
2290 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2293 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2294 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2297 value_add_one( &c->rvalue_vals, &bv );
2301 case LDAP_MOD_DELETE:
2302 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2303 glue_sub_del( c->be );
2305 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2310 case SLAP_CONFIG_ADD:
2311 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2312 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2319 config_suffix(ConfigArgs *c)
2322 struct berval pdn, ndn;
2323 char *notallowed = NULL;
2325 if ( c->be == frontendDB ) {
2326 notallowed = "frontend";
2328 } else if ( SLAP_MONITOR(c->be) ) {
2329 notallowed = "monitor";
2331 } else if ( SLAP_CONFIG(c->be) ) {
2332 notallowed = "config";
2335 if ( notallowed != NULL ) {
2336 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2340 case LDAP_MOD_DELETE:
2341 case LDAP_MOD_REPLACE:
2342 case LDAP_MOD_INCREMENT:
2343 case SLAP_CONFIG_ADD:
2344 if ( !BER_BVISNULL( &c->value_dn ) ) {
2345 snprintf( buf, sizeof( buf ), "<%s> ",
2346 c->value_dn.bv_val );
2349 Debug(LDAP_DEBUG_ANY,
2350 "%s: suffix %snot allowed in %s database.\n",
2351 c->log, buf, notallowed );
2354 case SLAP_CONFIG_EMIT:
2355 /* don't complain when emitting... */
2359 /* FIXME: don't know what values may be valid;
2360 * please remove assertion, or add legal values
2361 * to either block */
2369 if (c->op == SLAP_CONFIG_EMIT) {
2370 if ( c->be->be_suffix == NULL
2371 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2375 value_add( &c->rvalue_vals, c->be->be_suffix );
2376 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2379 } else if ( c->op == LDAP_MOD_DELETE ) {
2380 if ( c->valx < 0 ) {
2381 ber_bvarray_free( c->be->be_suffix );
2382 ber_bvarray_free( c->be->be_nsuffix );
2383 c->be->be_suffix = NULL;
2384 c->be->be_nsuffix = NULL;
2387 ch_free( c->be->be_suffix[i].bv_val );
2388 ch_free( c->be->be_nsuffix[i].bv_val );
2390 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2391 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2393 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2398 #ifdef SLAPD_MONITOR_DN
2399 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2400 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2402 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2403 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2408 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2409 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2410 c->argv[0], c->be->bd_info->bi_type );
2411 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2412 c->log, c->cr_msg, 0);
2419 if (SLAP_DBHIDDEN( c->be ))
2422 tbe = select_backend(&ndn, 0);
2424 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2430 BackendDB *b2 = tbe;
2432 /* Does tbe precede be? */
2433 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2436 char *type = tbe->bd_info->bi_type;
2438 if ( overlay_is_over( tbe ) ) {
2439 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2440 type = oi->oi_orig->bi_type;
2443 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2444 "already served by a preceding %s database",
2445 c->argv[0], pdn.bv_val, type );
2446 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2447 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2453 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2454 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2455 "base provided \"%s\" (assuming okay)\n",
2456 c->log, default_search_base.bv_val, 0);
2458 ber_bvarray_add(&c->be->be_suffix, &pdn);
2459 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2464 config_rootdn(ConfigArgs *c) {
2465 if (c->op == SLAP_CONFIG_EMIT) {
2466 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2467 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2468 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2473 } else if ( c->op == LDAP_MOD_DELETE ) {
2474 ch_free( c->be->be_rootdn.bv_val );
2475 ch_free( c->be->be_rootndn.bv_val );
2476 BER_BVZERO( &c->be->be_rootdn );
2477 BER_BVZERO( &c->be->be_rootndn );
2480 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2481 ch_free( c->be->be_rootdn.bv_val );
2482 ch_free( c->be->be_rootndn.bv_val );
2484 c->be->be_rootdn = c->value_dn;
2485 c->be->be_rootndn = c->value_ndn;
2490 config_rootpw(ConfigArgs *c) {
2493 if (c->op == SLAP_CONFIG_EMIT) {
2494 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2495 /* don't copy, because "rootpw" is marked
2497 c->value_bv = c->be->be_rootpw;
2501 } else if ( c->op == LDAP_MOD_DELETE ) {
2502 ch_free( c->be->be_rootpw.bv_val );
2503 BER_BVZERO( &c->be->be_rootpw );
2507 tbe = select_backend(&c->be->be_rootndn, 0);
2509 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2511 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2512 c->log, c->cr_msg, 0);
2515 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2516 ch_free( c->be->be_rootpw.bv_val );
2517 c->be->be_rootpw = c->value_bv;
2522 config_restrict(ConfigArgs *c) {
2523 slap_mask_t restrictops = 0;
2525 slap_verbmasks restrictable_ops[] = {
2526 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2527 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2528 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2529 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2530 { BER_BVC("modrdn"), 0 },
2531 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2532 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2533 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2534 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2535 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2536 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2537 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2538 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2539 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2540 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2541 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2545 if (c->op == SLAP_CONFIG_EMIT) {
2546 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2548 } else if ( c->op == LDAP_MOD_DELETE ) {
2550 c->be->be_restrictops = 0;
2552 restrictops = verb_to_mask( c->line, restrictable_ops );
2553 c->be->be_restrictops ^= restrictops;
2557 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2559 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2560 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2561 c->log, c->cr_msg, c->argv[i]);
2564 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2565 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2566 c->be->be_restrictops |= restrictops;
2571 config_allows(ConfigArgs *c) {
2572 slap_mask_t allows = 0;
2574 slap_verbmasks allowable_ops[] = {
2575 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2576 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2577 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2578 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2579 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2582 if (c->op == SLAP_CONFIG_EMIT) {
2583 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2584 } else if ( c->op == LDAP_MOD_DELETE ) {
2588 allows = verb_to_mask( c->line, allowable_ops );
2589 global_allows ^= allows;
2593 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2595 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2596 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2597 c->log, c->cr_msg, c->argv[i]);
2600 global_allows |= allows;
2605 config_disallows(ConfigArgs *c) {
2606 slap_mask_t disallows = 0;
2608 slap_verbmasks disallowable_ops[] = {
2609 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2610 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2611 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2612 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2613 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
2614 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
2617 if (c->op == SLAP_CONFIG_EMIT) {
2618 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2619 } else if ( c->op == LDAP_MOD_DELETE ) {
2621 global_disallows = 0;
2623 disallows = verb_to_mask( c->line, disallowable_ops );
2624 global_disallows ^= disallows;
2628 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2630 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2631 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2632 c->log, c->cr_msg, c->argv[i]);
2635 global_disallows |= disallows;
2640 config_requires(ConfigArgs *c) {
2641 slap_mask_t requires = frontendDB->be_requires;
2642 int i, argc = c->argc;
2643 char **argv = c->argv;
2645 slap_verbmasks requires_ops[] = {
2646 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2647 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2648 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2649 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2650 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2653 if (c->op == SLAP_CONFIG_EMIT) {
2654 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2655 } else if ( c->op == LDAP_MOD_DELETE ) {
2657 c->be->be_requires = 0;
2659 requires = verb_to_mask( c->line, requires_ops );
2660 c->be->be_requires ^= requires;
2664 /* "none" can only be first, to wipe out default/global values */
2665 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2670 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2672 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2673 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2674 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2675 c->log, c->cr_msg, 0);
2677 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2678 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2679 c->log, c->cr_msg, c->argv[i]);
2683 c->be->be_requires = requires;
2687 static slap_verbmasks *loglevel_ops;
2690 loglevel_init( void )
2692 slap_verbmasks lo[] = {
2693 { BER_BVC("Any"), -1 },
2694 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2695 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2696 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2697 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2698 { BER_BVC("BER"), LDAP_DEBUG_BER },
2699 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2700 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2701 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2702 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2703 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2704 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2705 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2706 #if 0 /* no longer used (nor supported) */
2707 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2708 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2710 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2711 { BER_BVC("None"), LDAP_DEBUG_NONE },
2715 return slap_verbmasks_init( &loglevel_ops, lo );
2719 loglevel_destroy( void )
2721 if ( loglevel_ops ) {
2722 (void)slap_verbmasks_destroy( loglevel_ops );
2724 loglevel_ops = NULL;
2727 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2730 slap_loglevel_register( slap_mask_t m, struct berval *s )
2734 if ( loglevel_ops == NULL ) {
2738 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2741 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2749 slap_loglevel_get( struct berval *s, int *l )
2754 if ( loglevel_ops == NULL ) {
2758 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2759 m |= loglevel_ops[ i ].mask;
2762 for ( i = 1; m & i; i <<= 1 )
2769 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2772 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2783 str2loglevel( const char *s, int *l )
2787 if ( loglevel_ops == NULL ) {
2791 i = verb_to_mask( s, loglevel_ops );
2793 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2797 *l = loglevel_ops[ i ].mask;
2803 loglevel2str( int l )
2805 struct berval bv = BER_BVNULL;
2807 loglevel2bv( l, &bv );
2813 loglevel2bv( int l, struct berval *bv )
2815 if ( loglevel_ops == NULL ) {
2821 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2825 loglevel2bvarray( int l, BerVarray *bva )
2827 if ( loglevel_ops == NULL ) {
2831 return mask_to_verbs( loglevel_ops, l, bva );
2835 loglevel_print( FILE *out )
2839 if ( loglevel_ops == NULL ) {
2843 fprintf( out, "Installed log subsystems:\n\n" );
2844 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2845 fprintf( out, "\t%-30s (%lu)\n",
2846 loglevel_ops[ i ].word.bv_val,
2847 loglevel_ops[ i ].mask );
2850 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2851 "by specific code\n\n" );
2856 static int config_syslog;
2859 config_loglevel(ConfigArgs *c) {
2862 if ( loglevel_ops == NULL ) {
2866 if (c->op == SLAP_CONFIG_EMIT) {
2867 /* Get default or commandline slapd setting */
2868 if ( ldap_syslog && !config_syslog )
2869 config_syslog = ldap_syslog;
2870 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2872 } else if ( c->op == LDAP_MOD_DELETE ) {
2876 int level = verb_to_mask( c->line, loglevel_ops );
2877 config_syslog ^= level;
2879 if ( slapMode & SLAP_SERVER_MODE ) {
2880 ldap_syslog = config_syslog;
2885 for( i=1; i < c->argc; i++ ) {
2888 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2889 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2890 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2891 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2892 c->log, c->cr_msg, c->argv[i]);
2896 if ( str2loglevel( c->argv[i], &level ) ) {
2897 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2898 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2899 c->log, c->cr_msg, c->argv[i]);
2903 /* Explicitly setting a zero clears all the levels */
2905 config_syslog |= level;
2909 if ( slapMode & SLAP_SERVER_MODE ) {
2910 ldap_syslog = config_syslog;
2916 config_referral(ConfigArgs *c) {
2918 if (c->op == SLAP_CONFIG_EMIT) {
2919 if ( default_referral ) {
2920 value_add( &c->rvalue_vals, default_referral );
2925 } else if ( c->op == LDAP_MOD_DELETE ) {
2926 if ( c->valx < 0 ) {
2927 ber_bvarray_free( default_referral );
2928 default_referral = NULL;
2931 ch_free( default_referral[i].bv_val );
2932 for (; default_referral[i].bv_val; i++ )
2933 default_referral[i] = default_referral[i+1];
2937 if(validate_global_referral(c->argv[1])) {
2938 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2939 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2940 c->log, c->cr_msg, c->argv[1]);
2944 ber_str2bv(c->argv[1], 0, 0, &val);
2945 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2953 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2954 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2955 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2956 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2957 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2958 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2959 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2960 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2961 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2966 config_security(ConfigArgs *c) {
2967 slap_ssf_set_t *set = &c->be->be_ssf_set;
2970 if (c->op == SLAP_CONFIG_EMIT) {
2976 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2977 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2980 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2981 if ( bv.bv_len >= sizeof( numbuf ) ) {
2982 ber_bvarray_free_x( c->rvalue_vals, NULL );
2983 c->rvalue_vals = NULL;
2987 bv.bv_len += sec_keys[i].key.bv_len;
2988 bv.bv_val = ch_malloc( bv.bv_len + 1);
2989 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2990 strcpy( next, numbuf );
2991 ber_bvarray_add( &c->rvalue_vals, &bv );
2996 for(i = 1; i < c->argc; i++) {
2997 slap_ssf_t *tgt = NULL;
2999 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3000 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3001 sec_keys[j].key.bv_len)) {
3002 src = c->argv[i] + sec_keys[j].key.bv_len;
3003 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3008 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3009 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3010 c->log, c->cr_msg, c->argv[i]);
3014 if ( lutil_atou( tgt, src ) != 0 ) {
3015 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3016 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3017 c->log, c->cr_msg, c->argv[i]);
3025 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3029 for (; !BER_BVISNULL( &an->an_name ); an++) {
3030 /* if buflen == 0, assume the buffer size has been
3031 * already checked otherwise */
3032 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3033 if ( comma ) *ptr++ = ',';
3034 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3041 config_updatedn(ConfigArgs *c) {
3042 if (c->op == SLAP_CONFIG_EMIT) {
3043 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3044 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3045 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3049 } else if ( c->op == LDAP_MOD_DELETE ) {
3050 ch_free( c->be->be_update_ndn.bv_val );
3051 BER_BVZERO( &c->be->be_update_ndn );
3052 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3055 if(SLAP_SHADOW(c->be)) {
3056 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3057 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3058 c->log, c->cr_msg, 0);
3062 ber_memfree_x( c->value_dn.bv_val, NULL );
3063 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3064 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3066 c->be->be_update_ndn = c->value_ndn;
3067 BER_BVZERO( &c->value_dn );
3068 BER_BVZERO( &c->value_ndn );
3070 return config_slurp_shadow( c );
3074 config_shadow( ConfigArgs *c, int flag )
3076 char *notallowed = NULL;
3078 if ( c->be == frontendDB ) {
3079 notallowed = "frontend";
3081 } else if ( SLAP_MONITOR(c->be) ) {
3082 notallowed = "monitor";
3085 if ( notallowed != NULL ) {
3086 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3090 if ( SLAP_SHADOW(c->be) ) {
3091 /* if already shadow, only check consistency */
3092 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3093 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%x.\n", c->log, flag, 0 );
3098 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3105 config_updateref(ConfigArgs *c) {
3107 if (c->op == SLAP_CONFIG_EMIT) {
3108 if ( c->be->be_update_refs ) {
3109 value_add( &c->rvalue_vals, c->be->be_update_refs );
3114 } else if ( c->op == LDAP_MOD_DELETE ) {
3115 if ( c->valx < 0 ) {
3116 ber_bvarray_free( c->be->be_update_refs );
3117 c->be->be_update_refs = NULL;
3120 ch_free( c->be->be_update_refs[i].bv_val );
3121 for (; c->be->be_update_refs[i].bv_val; i++)
3122 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3126 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3127 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3129 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3130 c->log, c->cr_msg, 0);
3134 if(validate_global_referral(c->argv[1])) {
3135 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3136 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3137 c->log, c->cr_msg, c->argv[1]);
3140 ber_str2bv(c->argv[1], 0, 0, &val);
3141 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3146 config_obsolete(ConfigArgs *c) {
3147 if (c->op == SLAP_CONFIG_EMIT)
3150 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3152 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3157 config_include(ConfigArgs *c) {
3158 int savelineno = c->lineno;
3161 ConfigFile *cfsave = cfn;
3162 ConfigFile *cf2 = NULL;
3164 /* Leftover from RE23. No dynamic config for include files */
3165 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3168 cf = ch_calloc( 1, sizeof(ConfigFile));
3169 if ( cfn->c_kids ) {
3170 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3176 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3177 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3178 c->lineno = savelineno - 1;
3181 if ( cf2 ) cf2->c_sibs = NULL;
3182 else cfn->c_kids = NULL;
3183 ch_free( cf->c_file.bv_val );
3193 config_tls_cleanup(ConfigArgs *c) {
3196 if ( slap_tls_ld ) {
3199 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3201 /* Force new ctx to be created */
3202 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3204 /* The ctx's refcount is bumped up here */
3205 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3206 /* This is a no-op if it's already loaded */
3207 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3214 config_tls_option(ConfigArgs *c) {
3216 LDAP *ld = slap_tls_ld;
3218 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3219 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3220 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3221 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3222 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3223 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3224 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3226 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3228 default: Debug(LDAP_DEBUG_ANY, "%s: "
3229 "unknown tls_option <0x%x>\n",
3230 c->log, c->type, 0);
3233 if (c->op == SLAP_CONFIG_EMIT) {
3234 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3235 } else if ( c->op == LDAP_MOD_DELETE ) {
3236 c->cleanup = config_tls_cleanup;
3237 return ldap_pvt_tls_set_option( ld, flag, NULL );
3239 ch_free(c->value_string);
3240 c->cleanup = config_tls_cleanup;
3241 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3244 /* FIXME: this ought to be provided by libldap */
3246 config_tls_config(ConfigArgs *c) {
3249 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3250 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3251 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3253 Debug(LDAP_DEBUG_ANY, "%s: "
3254 "unknown tls_option <0x%x>\n",
3255 c->log, c->type, 0);
3258 if (c->op == SLAP_CONFIG_EMIT) {
3259 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3260 } else if ( c->op == LDAP_MOD_DELETE ) {
3262 c->cleanup = config_tls_cleanup;
3263 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3265 ch_free( c->value_string );
3266 c->cleanup = config_tls_cleanup;
3267 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3268 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3269 Debug(LDAP_DEBUG_ANY, "%s: "
3270 "unable to parse %s \"%s\"\n",
3271 c->log, c->argv[0], c->argv[1] );
3274 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3276 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3281 static CfEntryInfo *
3282 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3292 if ( dn_match( &root->ce_entry->e_nname, dn ))
3295 c = dn->bv_val+dn->bv_len;
3296 for (;*c != ',';c--);
3300 for (--c;c>dn->bv_val && *c != ',';c--);
3304 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3306 root = root->ce_kids;
3308 for (;root;root=root->ce_sibs) {
3309 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3310 if ( cdn.bv_val == dn->bv_val ) {
3320 typedef struct setup_cookie {
3330 config_ldif_resp( Operation *op, SlapReply *rs )
3332 if ( rs->sr_type == REP_SEARCH ) {
3333 setup_cookie *sc = op->o_callback->sc_private;
3336 sc->cfb->cb_got_ldif = 1;
3337 /* Does the frontend exist? */
3338 if ( !sc->got_frontend ) {
3339 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3340 "olcDatabase", STRLENOF( "olcDatabase" )))
3342 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3343 STRLENOF( "olcDatabase" ), "={-1}frontend",
3344 STRLENOF( "={-1}frontend" )))
3348 sc->ca->be = frontendDB;
3349 sc->ca->bi = frontendDB->bd_info;
3350 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3351 rdn.bv_val = sc->ca->log;
3352 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3353 "%s=" SLAP_X_ORDERED_FMT "%s",
3354 cfAd_database->ad_cname.bv_val, -1,
3355 sc->ca->bi->bi_type);
3357 sc->frontend = config_build_entry( op, rs,
3358 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3359 sc->ca->be->be_cf_ocs );
3369 dnParent( &rs->sr_entry->e_nname, &pdn );
3371 /* Does the configDB exist? */
3372 if ( sc->got_frontend && !sc->got_config &&
3373 !strncmp( rs->sr_entry->e_nname.bv_val,
3374 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3375 dn_match( &config_rdn, &pdn ) )
3377 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3378 STRLENOF( "olcDatabase" ), "={0}config",
3379 STRLENOF( "={0}config" )))
3383 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3384 sc->ca->bi = sc->ca->be->bd_info;
3385 rdn.bv_val = sc->ca->log;
3386 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3387 "%s=" SLAP_X_ORDERED_FMT "%s",
3388 cfAd_database->ad_cname.bv_val, 0,
3389 sc->ca->bi->bi_type);
3391 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3392 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3399 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3400 if ( rs->sr_err != LDAP_SUCCESS ) {
3401 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3402 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3408 /* Configure and read the underlying back-ldif store */
3410 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3411 CfBackInfo *cfb = be->be_private;
3417 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3418 Connection conn = {0};
3419 OperationBuffer opbuf;
3421 SlapReply rs = {REP_RESULT};
3422 Filter filter = { LDAP_FILTER_PRESENT };
3423 struct berval filterstr = BER_BVC("(objectclass=*)");
3426 /* Is the config directory available? */
3427 if ( stat( dir, &st ) < 0 ) {
3428 /* No, so don't bother using the backing store.
3429 * All changes will be in-memory only.
3434 cfb->cb_db.bd_info = backend_info( "ldif" );
3435 if ( !cfb->cb_db.bd_info )
3436 return 0; /* FIXME: eventually this will be a fatal error */
3438 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3441 cfb->cb_db.be_suffix = be->be_suffix;
3442 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3444 /* The suffix is always "cn=config". The underlying DB's rootdn
3445 * is always the same as the suffix.
3447 cfb->cb_db.be_rootdn = be->be_suffix[0];
3448 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3450 ber_str2bv( dir, 0, 1, &cfdir );
3455 argv[0] = "directory";
3456 argv[1] = (char *)dir;
3461 c.table = Cft_Database;
3463 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3467 if ( config_add_vals( ct, &c ))
3470 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3474 void *thrctx = ldap_pvt_thread_pool_context();
3477 connection_fake_init( &conn, &opbuf, thrctx );
3480 filter.f_desc = slap_schema.si_ad_objectClass;
3482 op->o_tag = LDAP_REQ_SEARCH;
3484 op->ors_filter = &filter;
3485 op->ors_filterstr = filterstr;
3486 op->ors_scope = LDAP_SCOPE_SUBTREE;
3488 op->o_dn = c.be->be_rootdn;
3489 op->o_ndn = c.be->be_rootndn;
3491 op->o_req_dn = be->be_suffix[0];
3492 op->o_req_ndn = be->be_nsuffix[0];
3494 op->ors_tlimit = SLAP_NO_LIMIT;
3495 op->ors_slimit = SLAP_NO_LIMIT;
3497 op->ors_attrs = slap_anlist_all_attributes;
3498 op->ors_attrsonly = 0;
3500 op->o_callback = &cb;
3503 cb.sc_private = ≻
3504 sc.got_frontend = 0;
3509 op->o_bd = &cfb->cb_db;
3511 /* Allow unknown attrs in DNs */
3512 prev_DN_strict = slap_DN_strict;
3515 rc = op->o_bd->be_search( op, &rs );
3517 /* Restore normal DN validation */
3518 slap_DN_strict = prev_DN_strict;
3520 op->o_tag = LDAP_REQ_ADD;
3521 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3522 op->ora_e = sc.frontend;
3523 rc = op->o_bd->be_add( op, &rs );
3525 if ( rc == LDAP_SUCCESS && sc.config ) {
3526 op->ora_e = sc.config;
3527 rc = op->o_bd->be_add( op, &rs );
3529 ldap_pvt_thread_pool_context_reset( thrctx );
3532 /* ITS#4194 - only use if it's present, or we're converting. */
3533 if ( !readit || rc == LDAP_SUCCESS )
3534 cfb->cb_use_ldif = 1;
3540 CfOc_cmp( const void *c1, const void *c2 ) {
3541 const ConfigOCs *co1 = c1;
3542 const ConfigOCs *co2 = c2;
3544 return ber_bvcmp( co1->co_name, co2->co_name );
3548 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3551 i = init_config_attrs( ct );
3554 /* set up the objectclasses */
3555 i = init_config_ocs( ocs );
3558 for (i=0; ocs[i].co_def; i++) {
3559 if ( ocs[i].co_oc ) {
3560 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3561 if ( !ocs[i].co_table )
3562 ocs[i].co_table = ct;
3563 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3570 read_config(const char *fname, const char *dir) {
3573 const char *cfdir, *cfname;
3576 /* Setup the config backend */
3577 be = backend_db_init( "config", NULL, 0, NULL );
3581 cfb = be->be_private;
3582 be->be_dfltaccess = ACL_NONE;
3584 /* If no .conf, or a dir was specified, setup the dir */
3585 if ( !fname || dir ) {
3587 /* If explicitly given, check for existence */
3590 if ( stat( dir, &st ) < 0 ) {
3591 Debug( LDAP_DEBUG_ANY,
3592 "invalid config directory %s, error %d\n",
3598 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3600 /* if fname is defaulted, try reading .d */
3601 rc = config_setup_ldif( be, cfdir, !fname );
3604 /* It may be OK if the base object doesn't exist yet. */
3605 if ( rc != LDAP_NO_SUCH_OBJECT )
3607 /* ITS#4194: But if dir was specified and no fname,
3608 * then we were supposed to read the dir. Unless we're
3609 * trying to slapadd the dir...
3611 if ( dir && !fname ) {
3612 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3614 /* Assume it's slapadd with a config dir, let it continue */
3616 cfb->cb_got_ldif = 1;
3617 cfb->cb_use_ldif = 1;
3622 /* If we read the config from back-ldif, nothing to do here */
3623 if ( cfb->cb_got_ldif ) {
3632 cfname = SLAPD_DEFAULT_CONFIGFILE;
3634 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3637 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3640 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3641 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3642 &frontendDB->be_schemadn );
3643 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3644 if ( rc != LDAP_SUCCESS ) {
3645 Debug(LDAP_DEBUG_ANY, "read_config: "
3646 "unable to normalize default schema DN \"%s\"\n",
3647 frontendDB->be_schemadn.bv_val, 0, 0 );
3648 /* must not happen */
3656 config_back_bind( Operation *op, SlapReply *rs )
3658 if ( be_isroot_pw( op ) ) {
3659 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3660 /* frontend sends result */
3661 return LDAP_SUCCESS;
3664 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3665 send_ldap_result( op, rs );
3671 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3675 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3677 rs->sr_attrs = op->ors_attrs;
3678 rs->sr_entry = ce->ce_entry;
3680 rc = send_search_entry( op, rs );
3681 if ( rc != LDAP_SUCCESS ) {
3685 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3686 if ( ce->ce_kids ) {
3687 rc = config_send( op, rs, ce->ce_kids, 1 );
3688 if ( rc ) return rc;
3691 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3692 rc = config_send( op, rs, ce, 0 );
3700 static ConfigTable *
3701 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3706 for (j=0; j<nocs; j++) {
3707 for (i=0; colst[j]->co_table[i].name; i++)
3708 if ( colst[j]->co_table[i].ad == ad ) {
3709 ca->table = colst[j]->co_type;
3710 return &colst[j]->co_table[i];
3716 /* Sort the attributes of the entry according to the order defined
3717 * in the objectclass, with required attributes occurring before
3718 * allowed attributes. For any attributes with sequencing dependencies
3719 * (e.g., rootDN must be defined after suffix) the objectclass must
3720 * list the attributes in the desired sequence.
3723 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3725 Attribute *a, *head = NULL, *tail = NULL, **prev;
3728 for (i=0; i<nocs; i++) {
3729 if ( colst[i]->co_oc->soc_required ) {
3730 AttributeType **at = colst[i]->co_oc->soc_required;
3731 for (j=0; at[j]; j++) {
3732 for (a=e->e_attrs, prev=&e->e_attrs; a;
3733 prev = &(*prev)->a_next, a=a->a_next) {
3734 if ( a->a_desc == at[j]->sat_ad ) {
3748 if ( colst[i]->co_oc->soc_allowed ) {
3749 AttributeType **at = colst[i]->co_oc->soc_allowed;
3750 for (j=0; at[j]; j++) {
3751 for (a=e->e_attrs, prev=&e->e_attrs; a;
3752 prev = &(*prev)->a_next, a=a->a_next) {
3753 if ( a->a_desc == at[j]->sat_ad ) {
3769 tail->a_next = e->e_attrs;
3775 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3777 Attribute *a = NULL;
3778 AttributeDescription *ad;
3788 Modifications *ml = ptr;
3790 vals = ml->sml_values;
3793 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3794 rc = ordered_value_sort( a, 1 );
3796 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3797 ad->ad_cname.bv_val );
3801 for ( i=0; vals[i].bv_val; i++ ) {
3802 ca->line = vals[i].bv_val;
3803 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3804 ca->line[0] == '{' ) {
3805 char *idx = strchr( ca->line, '}' );
3806 if ( idx ) ca->line = idx+1;
3808 rc = config_parse_vals( ct, ca, i );
3817 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3820 struct berval rtype, rval;
3822 AttributeDescription *ad = NULL;
3824 dnRdn( &e->e_name, rdn );
3825 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3826 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3827 rtype.bv_val = rdn->bv_val;
3828 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3831 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3832 a = attr_find( e->e_attrs, ad );
3833 if (!a ) return LDAP_NAMING_VIOLATION;
3840 config_rename_kids( CfEntryInfo *ce )
3843 struct berval rdn, nrdn;
3845 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3846 struct berval newdn, newndn;
3847 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3848 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3849 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
3850 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
3851 free( ce2->ce_entry->e_name.bv_val );
3852 free( ce2->ce_entry->e_nname.bv_val );
3853 ce2->ce_entry->e_name = newdn;
3854 ce2->ce_entry->e_nname = newndn;
3855 config_rename_kids( ce2 );
3860 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3861 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3862 struct berval *nnewrdn, int use_ldif )
3866 struct berval odn, ondn;
3870 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3871 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3874 free( a->a_vals[0].bv_val );
3875 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3876 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3877 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3878 strcpy( a->a_vals[0].bv_val, ptr1 );
3880 if ( a->a_nvals != a->a_vals ) {
3881 free( a->a_nvals[0].bv_val );
3882 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3883 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3884 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3885 strcpy( a->a_nvals[0].bv_val, ptr1 );
3888 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3889 BackendDB *be = op->o_bd;
3890 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3891 struct berval dn, ndn, xdn, xndn;
3893 op->o_bd = &cfb->cb_db;
3895 /* Save current rootdn; use the underlying DB's rootdn */
3899 xndn = op->o_req_ndn;
3900 op->o_dn = op->o_bd->be_rootdn;
3901 op->o_ndn = op->o_bd->be_rootndn;
3903 op->o_req_ndn = ondn;
3905 scp = op->o_callback;
3906 op->o_callback = ≻
3907 op->orr_newrdn = *newrdn;
3908 op->orr_nnewrdn = *nnewrdn;
3909 op->orr_newSup = NULL;
3910 op->orr_nnewSup = NULL;
3911 op->orr_deleteoldrdn = 1;
3912 op->orr_modlist = NULL;
3913 slap_modrdn2mods( op, rs );
3914 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3915 rc = op->o_bd->be_modrdn( op, rs );
3916 slap_mods_free( op->orr_modlist, 1 );
3919 op->o_callback = scp;
3923 op->o_req_ndn = xndn;
3926 free( ondn.bv_val );
3928 config_rename_kids( e->e_private );
3933 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3934 Entry *e, int idx, int tailindex, int use_ldif )
3936 struct berval ival, newrdn, nnewrdn;
3939 char ibuf[32], *ptr1, *ptr2 = NULL;
3942 rc = config_rename_attr( rs, e, &rdn, &a );
3943 if ( rc ) return rc;
3946 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3947 if ( ival.bv_len >= sizeof( ibuf ) ) {
3948 return LDAP_NAMING_VIOLATION;
3951 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3952 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3955 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3956 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3959 ptr2 = ber_bvchr( &rdn, '}' );
3963 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3965 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3966 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3967 a->a_desc->ad_cname.bv_len );
3969 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3970 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3974 /* Do the equivalent of ModRDN */
3975 /* Replace DN / NDN */
3976 newrdn.bv_len = ptr1 - newrdn.bv_val;
3977 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3978 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3980 free( nnewrdn.bv_val );
3981 free( newrdn.bv_val );
3986 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3987 SlapReply *rs, int *renum, int *ibase )
3990 int index = -1, gotindex = 0, nsibs, rc = 0;
3991 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3992 char *ptr1, *ptr2 = NULL;
3995 if ( renum ) *renum = 0;
3997 /* These entries don't get indexed/renumbered */
3998 if ( ce_type == Cft_Global ) return 0;
3999 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4001 if ( ce_type == Cft_Module )
4004 /* See if the rdn has an index already */
4005 dnRdn( &e->e_name, &rdn );
4006 if ( ce_type == Cft_Database ) {
4007 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4008 "frontend", STRLENOF("frontend") ))
4010 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4011 "config", STRLENOF("config") ))
4014 ptr1 = ber_bvchr( &e->e_name, '{' );
4015 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4017 ptr2 = strchr( ptr1, '}' );
4018 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4019 return LDAP_NAMING_VIOLATION;
4020 if ( ptr2-ptr1 == 1)
4021 return LDAP_NAMING_VIOLATION;
4023 index = strtol( ptr1 + 1, &next, 10 );
4024 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4025 return LDAP_NAMING_VIOLATION;
4028 /* Special case, we allow -1 for the frontendDB */
4029 if ( index != -1 || !isfrontend )
4030 return LDAP_NAMING_VIOLATION;
4032 if ( isconfig && index != 0 ){
4033 return LDAP_NAMING_VIOLATION;
4037 /* count related kids */
4038 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4039 if ( ce->ce_type == ce_type ) nsibs++;
4042 /* account for -1 frontend */
4043 if ( ce_type == Cft_Database )
4046 if ( index != nsibs ) {
4048 if ( index < nsibs ) {
4049 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4050 /* Siblings need to be renumbered */
4051 if ( index != -1 || !isfrontend )
4055 /* config DB is always "0" */
4056 if ( isconfig && index == -1 ) {
4059 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4063 /* just make index = nsibs */
4065 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4068 if ( ibase ) *ibase = index;
4069 if ( renum ) *renum = renumber;
4074 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4079 co.co_name = &oc->soc_cname;
4080 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4084 /* check for duplicates */
4085 for ( i = 0; i < *nocs; i++ ) {
4086 if ( *copp && (*copp)[i] == cop ) {
4092 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4093 if ( tmp == NULL ) {
4097 (*copp)[*nocs] = cop;
4102 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4103 if ( count_oc( *sups, copp, nocs ) ) {
4112 count_ocs( Attribute *oc_at, int *nocs )
4115 ConfigOCs **colst = NULL;
4119 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4123 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4125 assert( oc != NULL );
4126 if ( count_oc( oc, &colst, nocs ) ) {
4136 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4138 /* Leftover from RE23. Never parse this entry */
4139 return LDAP_COMPARE_TRUE;
4143 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4147 /* This entry is hardcoded, don't re-parse it */
4148 if ( p->ce_type == Cft_Global ) {
4149 cfn = p->ce_private;
4150 ca->ca_private = cfn;
4151 return LDAP_COMPARE_TRUE;
4153 if ( p->ce_type != Cft_Schema )
4154 return LDAP_CONSTRAINT_VIOLATION;
4156 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4157 ca->ca_private = cfn;
4158 cfo = p->ce_private;
4159 cfn->c_sibs = cfo->c_kids;
4161 return LDAP_SUCCESS;
4165 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4167 if ( p->ce_type != Cft_Global ) {
4168 return LDAP_CONSTRAINT_VIOLATION;
4170 /* config must be {0}, nothing else allowed */
4171 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4172 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4173 return LDAP_CONSTRAINT_VIOLATION;
4175 ca->be = frontendDB; /* just to get past check_vals */
4176 return LDAP_SUCCESS;
4180 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4182 if ( p->ce_type != Cft_Global ) {
4183 return LDAP_CONSTRAINT_VIOLATION;
4185 return LDAP_SUCCESS;
4189 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4191 if ( p->ce_type != Cft_Global ) {
4192 return LDAP_CONSTRAINT_VIOLATION;
4194 return LDAP_SUCCESS;
4198 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4200 if ( p->ce_type != Cft_Database ) {
4201 return LDAP_CONSTRAINT_VIOLATION;
4204 return LDAP_SUCCESS;
4208 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4213 AttributeDescription *ad;
4218 if ( cfn->c_cr_head ) {
4219 struct berval bv = BER_BVC("olcDitContentRules");
4221 slap_bv2ad( &bv, &ad, &text );
4222 ct = config_find_table( colst, nocs, ad, ca );
4223 config_del_vals( ct, ca );
4225 if ( cfn->c_oc_head ) {
4226 struct berval bv = BER_BVC("olcObjectClasses");
4228 slap_bv2ad( &bv, &ad, &text );
4229 ct = config_find_table( colst, nocs, ad, ca );
4230 config_del_vals( ct, ca );
4232 if ( cfn->c_at_head ) {
4233 struct berval bv = BER_BVC("olcAttributeTypes");
4235 slap_bv2ad( &bv, &ad, &text );
4236 ct = config_find_table( colst, nocs, ad, ca );
4237 config_del_vals( ct, ca );
4239 if ( cfn->c_syn_head ) {
4240 struct berval bv = BER_BVC("olcLdapSyntaxes");
4242 slap_bv2ad( &bv, &ad, &text );
4243 ct = config_find_table( colst, nocs, ad, ca );
4244 config_del_vals( ct, ca );
4246 if ( cfn->c_om_head ) {
4247 struct berval bv = BER_BVC("olcObjectIdentifier");
4249 slap_bv2ad( &bv, &ad, &text );
4250 ct = config_find_table( colst, nocs, ad, ca );
4251 config_del_vals( ct, ca );
4253 cfo = p->ce_private;
4254 cfo->c_kids = cfn->c_sibs;
4259 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4261 int rc = LDAP_CONSTRAINT_VIOLATION;
4264 if ( (*cop)->co_ldadd ) {
4265 rc = (*cop)->co_ldadd( last, e, ca );
4266 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4271 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4272 ConfigOCs co = { 0 };
4274 co.co_name = &(*ocp)->soc_cname;
4275 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4276 if ( *cop == NULL ) {
4280 rc = config_add_oc( cop, last, e, ca );
4281 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4289 /* Parse an LDAP entry into config directives */
4291 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4292 int *renum, Operation *op )
4294 CfEntryInfo *ce, *last = NULL;
4295 ConfigOCs co, *coptr, **colst;
4296 Attribute *a, *oc_at, *soc_at;
4297 int i, ibase = -1, nocs, rc = 0;
4300 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4302 memset( ca, 0, sizeof(ConfigArgs));
4304 /* Make sure parent exists and entry does not. But allow
4305 * Databases and Overlays to be inserted. Don't do any
4306 * auto-renumbering if manageDSAit control is present.
4308 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4310 if ( ( op && op->o_managedsait ) ||
4311 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4312 ce->ce_type != Cft_Module ) )
4314 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4315 "DN=\"%s\" already exists\n",
4316 log_prefix, e->e_name.bv_val, 0 );
4317 return LDAP_ALREADY_EXISTS;
4321 dnParent( &e->e_nname, &pdn );
4323 /* If last is NULL, the new entry is the root/suffix entry,
4324 * otherwise last should be the parent.
4326 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4328 rs->sr_matched = last->ce_entry->e_name.bv_val;
4330 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4331 "DN=\"%s\" not child of DN=\"%s\"\n",
4332 log_prefix, e->e_name.bv_val,
4333 last->ce_entry->e_name.bv_val );
4334 return LDAP_NO_SUCH_OBJECT;
4338 /* No parent, must be root. This will never happen... */
4339 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4340 return LDAP_NO_SUCH_OBJECT;
4343 if ( last && !access_allowed( op, last->ce_entry,
4344 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4346 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4347 "DN=\"%s\" no write access to \"children\" of parent\n",
4348 log_prefix, e->e_name.bv_val, 0 );
4349 return LDAP_INSUFFICIENT_ACCESS;
4353 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4355 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4356 "DN=\"%s\" no objectClass\n",
4357 log_prefix, e->e_name.bv_val, 0 );
4358 return LDAP_OBJECT_CLASS_VIOLATION;
4361 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4363 ObjectClass *soc = NULL;
4364 char textbuf[ SLAP_TEXT_BUFLEN ];
4365 const char *text = textbuf;
4367 /* FIXME: check result */
4368 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4369 &text, textbuf, sizeof(textbuf), NULL );
4370 if ( rc != LDAP_SUCCESS ) {
4371 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4372 "DN=\"%s\" no structural objectClass (%s)\n",
4373 log_prefix, e->e_name.bv_val, text );
4376 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4377 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4378 if ( soc_at == NULL ) {
4379 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4380 "DN=\"%s\" no structural objectClass; "
4381 "unable to merge computed class %s\n",
4382 log_prefix, e->e_name.bv_val,
4383 soc->soc_cname.bv_val );
4384 return LDAP_OBJECT_CLASS_VIOLATION;
4387 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4388 "DN=\"%s\" no structural objectClass; "
4389 "computed objectClass %s merged\n",
4390 log_prefix, e->e_name.bv_val,
4391 soc->soc_cname.bv_val );
4394 /* Fake the coordinates based on whether we're part of an
4395 * LDAP Add or if reading the config dir
4398 ca->fname = "slapd";
4401 ca->fname = cfdir.bv_val;
4406 co.co_name = &soc_at->a_nvals[0];
4407 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4408 if ( coptr == NULL ) {
4409 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4410 "DN=\"%s\" no structural objectClass in configuration table\n",
4411 log_prefix, e->e_name.bv_val, 0 );
4412 return LDAP_OBJECT_CLASS_VIOLATION;
4415 /* Only the root can be Cft_Global, everything else must
4416 * have a parent. Only limited nesting arrangements are allowed.
4418 rc = LDAP_CONSTRAINT_VIOLATION;
4419 if ( coptr->co_type == Cft_Global && !last ) {
4420 cfn = cfb->cb_config;
4421 ca->ca_private = cfn;
4422 ca->be = frontendDB; /* just to get past check_vals */
4426 colst = count_ocs( oc_at, &nocs );
4428 /* Check whether the Add is allowed by its parent, and do
4429 * any necessary arg setup
4432 rc = config_add_oc( &coptr, last, e, ca );
4433 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4434 for ( i = 0; i<nocs; i++ ) {
4435 /* Already checked these */
4436 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4438 if ( colst[i]->co_ldadd &&
4439 ( rc = colst[i]->co_ldadd( last, e, ca ))
4440 != LDAP_CONSTRAINT_VIOLATION ) {
4446 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4447 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4448 "DN=\"%s\" no structural objectClass add function\n",
4449 log_prefix, e->e_name.bv_val, 0 );
4450 return LDAP_OBJECT_CLASS_VIOLATION;
4454 /* Add the entry but don't parse it, we already have its contents */
4455 if ( rc == LDAP_COMPARE_TRUE ) {
4460 if ( rc != LDAP_SUCCESS )
4463 /* Parse all the values and check for simple syntax errors before
4464 * performing any set actions.
4466 * If doing an LDAPadd, check for indexed names and any necessary
4467 * renaming/renumbering. Entries that don't need indexed names are
4468 * ignored. Entries that need an indexed name and arrive without one
4469 * are assigned to the end. Entries that arrive with an index may
4470 * cause the following entries to be renumbered/bumped down.
4472 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4473 * don't allow Adding an entry with an index that's already in use.
4474 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4476 * These entries can have auto-assigned indexes (appended to the end)
4477 * but only the other types support auto-renumbering of siblings.
4480 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4485 if ( renum && *renum && coptr->co_type != Cft_Database &&
4486 coptr->co_type != Cft_Overlay )
4488 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4489 "operation requires sibling renumbering" );
4490 rc = LDAP_UNWILLING_TO_PERFORM;
4495 init_config_argv( ca );
4497 /* Make sure we process attrs in the required order */
4498 sort_attrs( e, colst, nocs );
4500 for ( a = e->e_attrs; a; a = a->a_next ) {
4501 if ( a == oc_at ) continue;
4502 ct = config_find_table( colst, nocs, a->a_desc, ca );
4503 if ( !ct ) continue; /* user data? */
4504 rc = check_vals( ct, ca, a, 1 );
4505 if ( rc ) goto done_noop;
4508 /* Basic syntax checks are OK. Do the actual settings. */
4509 for ( a=e->e_attrs; a; a=a->a_next ) {
4510 if ( a == oc_at ) continue;
4511 ct = config_find_table( colst, nocs, a->a_desc, ca );
4512 if ( !ct ) continue; /* user data? */
4513 for (i=0; a->a_vals[i].bv_val; i++) {
4516 ca->line = a->a_vals[i].bv_val;
4517 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4518 ptr = strchr( ca->line, '}' );
4520 iptr = strchr( ca->line, '{' );
4524 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4526 ca->valx = strtol( iptr+1, NULL, 0 );
4531 rc = config_parse_add( ct, ca, i );
4539 /* Newly added databases and overlays need to be started up */
4540 if ( CONFIG_ONLINE_ADD( ca )) {
4541 if ( colst[0]->co_type == Cft_Database ) {
4542 rc = backend_startup_one( ca->be, &ca->reply );
4544 } else if ( colst[0]->co_type == Cft_Overlay ) {
4545 if ( ca->bi->bi_db_open ) {
4546 BackendInfo *bi_orig = ca->be->bd_info;
4547 ca->be->bd_info = ca->bi;
4548 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4549 ca->be->bd_info = bi_orig;
4551 } else if ( ca->cleanup ) {
4552 rc = ca->cleanup( ca );
4555 if (ca->cr_msg[0] == '\0')
4556 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4558 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4559 ca->log, ca->cr_msg, ca->argv[1] );
4566 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4567 ce->ce_parent = last;
4568 ce->ce_entry = entry_dup( e );
4569 ce->ce_entry->e_private = ce;
4570 ce->ce_type = colst[0]->co_type;
4573 ce->ce_private = ca->ca_private;
4574 ca->ca_entry = ce->ce_entry;
4577 } else if ( last->ce_kids ) {
4578 CfEntryInfo *c2, **cprev;
4580 /* Advance to first of this type */
4581 cprev = &last->ce_kids;
4582 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4583 cprev = &c2->ce_sibs;
4586 /* Account for the (-1) frontendDB entry */
4587 if ( ce->ce_type == Cft_Database ) {
4588 if ( ca->be == frontendDB )
4590 else if ( ibase != -1 )
4595 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4596 cprev = &c2->ce_sibs;
4602 for ( i=0; i<ibase; i++ ) {
4604 cprev = &c2->ce_sibs;
4607 ce->ce_sibs = *cprev;
4615 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4616 if ( ca->be != frontendDB )
4617 backend_destroy_one( ca->be, 1 );
4618 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4619 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4620 } else if ( colst[0]->co_type == Cft_Schema ) {
4621 schema_destroy_one( ca, colst, nocs, last );
4626 ch_free( ca->argv );
4627 if ( colst ) ch_free( colst );
4631 #define BIGTMP 10000
4633 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4634 int base, int rebase, int max, int use_ldif )
4636 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4637 ConfigType etype = ce->ce_type;
4638 int count = 0, rc = 0;
4640 /* Reverse ce list */
4641 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4642 if (ce2->ce_type != etype) {
4647 ce2->ce_sibs = cetmp;
4650 if ( max && count >= max ) {
4656 /* Move original to a temp name until increments are done */
4658 ce->ce_entry->e_private = NULL;
4659 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4660 base+BIGTMP, 0, use_ldif );
4661 ce->ce_entry->e_private = ce;
4663 /* start incrementing */
4664 for (ce2=cetmp; ce2; ce2=ce3) {
4666 ce2->ce_sibs = cerem;
4669 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4670 count+base, 0, use_ldif );
4674 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4675 base, 0, use_ldif );
4680 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4681 CfEntryInfo *ce2, int old, int use_ldif )
4685 /* Renumber original to a temp value */
4686 ce->ce_entry->e_private = NULL;
4687 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4688 old+BIGTMP, 0, use_ldif );
4689 ce->ce_entry->e_private = ce;
4691 /* start decrementing */
4692 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4693 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4694 count+old, 0, use_ldif );
4697 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4698 count+old, 0, use_ldif );
4701 /* Parse an LDAP entry into config directives, then store in underlying
4705 config_back_add( Operation *op, SlapReply *rs )
4711 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4712 NULL, ACL_WADD, NULL )) {
4713 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4718 * Check for attribute ACL
4720 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
4721 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4722 rs->sr_text = "no write access to attribute";
4726 cfb = (CfBackInfo *)op->o_bd->be_private;
4728 /* add opattrs for syncprov */
4730 char textbuf[SLAP_TEXT_BUFLEN];
4731 size_t textlen = sizeof textbuf;
4732 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
4733 &rs->sr_text, textbuf, sizeof( textbuf ) );
4734 if ( rs->sr_err != LDAP_SUCCESS )
4736 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4737 if ( rs->sr_err != LDAP_SUCCESS ) {
4738 Debug( LDAP_DEBUG_TRACE,
4739 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4740 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4745 ldap_pvt_thread_pool_pause( &connection_pool );
4748 * 1) check for existence of entry
4749 * 2) check for sibling renumbering
4750 * 3) perform internal add
4751 * 4) perform any necessary renumbering
4752 * 5) store entry in underlying database
4754 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4755 if ( rs->sr_err != LDAP_SUCCESS ) {
4756 rs->sr_text = ca.cr_msg;
4761 CfEntryInfo *ce = ca.ca_entry->e_private;
4762 req_add_s addr = op->oq_add;
4763 op->o_tag = LDAP_REQ_MODRDN;
4764 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4765 op->o_tag = LDAP_REQ_ADD;
4767 if ( rs->sr_err != LDAP_SUCCESS ) {
4772 if ( cfb->cb_use_ldif ) {
4773 BackendDB *be = op->o_bd;
4774 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4775 struct berval dn, ndn;
4777 op->o_bd = &cfb->cb_db;
4779 /* Save current rootdn; use the underlying DB's rootdn */
4782 op->o_dn = op->o_bd->be_rootdn;
4783 op->o_ndn = op->o_bd->be_rootndn;
4785 scp = op->o_callback;
4786 op->o_callback = ≻
4787 op->o_bd->be_add( op, rs );
4789 op->o_callback = scp;
4795 ldap_pvt_thread_pool_resume( &connection_pool );
4798 send_ldap_result( op, rs );
4799 slap_graduate_commit_csn( op );
4803 typedef struct delrec {
4804 struct delrec *next;
4810 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4816 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4817 ca->line[0] == '{' )
4819 char *ptr = strchr( ca->line + 1, '}' );
4823 ca->valx = strtol( ca->line + 1, &next, 0 );
4824 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4830 rc = config_parse_add( ct, ca, i );
4838 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4841 int rc = LDAP_UNWILLING_TO_PERFORM;
4843 Entry *e = ce->ce_entry;
4844 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4849 delrec *dels = NULL, *deltail = NULL;
4851 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4852 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4854 colst = count_ocs( oc_at, &nocs );
4856 /* make sure add/del flags are clear; should always be true */
4857 for ( s = save_attrs; s; s = s->a_next ) {
4858 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4861 e->e_attrs = attrs_dup( e->e_attrs );
4863 init_config_argv( ca );
4866 ca->ca_private = ce->ce_private;
4868 ca->fname = "slapd";
4870 strcpy( ca->log, "back-config" );
4872 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4873 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4874 switch (ml->sml_op) {
4875 case LDAP_MOD_DELETE:
4876 case LDAP_MOD_REPLACE: {
4877 BerVarray vals = NULL, nvals = NULL;
4879 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4881 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4882 ml->sml_desc->ad_cname.bv_val );
4885 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4886 vals = ml->sml_values;
4887 nvals = ml->sml_nvalues;
4888 ml->sml_values = NULL;
4889 ml->sml_nvalues = NULL;
4891 /* If we're deleting by values, remember the indexes of the
4892 * values we deleted.
4894 if ( ct && ml->sml_values ) {
4896 i = ml->sml_numvals;
4897 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4908 rc = modify_delete_vindex(e, &ml->sml_mod,
4909 get_permissiveModify(op),
4910 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4911 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4912 ml->sml_values = vals;
4913 ml->sml_nvalues = nvals;
4918 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4921 case SLAP_MOD_SOFTADD: {
4922 int mop = ml->sml_op;
4924 ml->sml_op = LDAP_MOD_ADD;
4926 if ( ct->arg_type & ARG_NO_INSERT ) {
4927 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4929 navals = a->a_numvals;
4932 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4933 if ( ml->sml_values[i].bv_val[0] == '{' &&
4936 char *next, *val = ml->sml_values[i].bv_val + 1;
4939 j = strtol( val, &next, 0 );
4940 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4942 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4943 ml->sml_desc->ad_cname.bv_val );
4947 rc = check_vals( ct, ca, ml, 0 );
4948 if ( rc ) goto out_noop;
4951 rc = modify_add_values(e, &ml->sml_mod,
4952 get_permissiveModify(op),
4953 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4955 /* If value already exists, show success here
4956 * and ignore this operation down below.
4958 if ( mop == SLAP_MOD_SOFTADD ) {
4959 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4969 case LDAP_MOD_INCREMENT: /* FIXME */
4974 if(rc != LDAP_SUCCESS) break;
4977 if ( rc == LDAP_SUCCESS) {
4978 /* check that the entry still obeys the schema */
4979 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
4980 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4982 if ( rc ) goto out_noop;
4984 /* Basic syntax checks are OK. Do the actual settings. */
4985 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4986 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4987 if ( !ct ) continue;
4989 s = attr_find( save_attrs, ml->sml_desc );
4990 a = attr_find( e->e_attrs, ml->sml_desc );
4992 switch (ml->sml_op) {
4993 case LDAP_MOD_DELETE:
4994 case LDAP_MOD_REPLACE: {
4995 BerVarray vals = NULL, nvals = NULL;
4998 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4999 vals = ml->sml_values;
5000 nvals = ml->sml_nvalues;
5001 ml->sml_values = NULL;
5002 ml->sml_nvalues = NULL;
5005 if ( ml->sml_values )
5008 /* If we didn't delete the whole attribute */
5009 if ( ml->sml_values && a ) {
5010 struct berval *mvals;
5013 if ( ml->sml_nvalues )
5014 mvals = ml->sml_nvalues;
5016 mvals = ml->sml_values;
5018 /* use the indexes we saved up above */
5019 for (i=0; i < d->nidx; i++) {
5020 struct berval bv = *mvals++;
5021 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5022 bv.bv_val[0] == '{' ) {
5023 ptr = strchr( bv.bv_val, '}' ) + 1;
5024 bv.bv_len -= ptr - bv.bv_val;
5027 ca->line = bv.bv_val;
5028 ca->valx = d->idx[i];
5029 rc = config_del_vals( ct, ca );
5030 if ( rc != LDAP_SUCCESS ) break;
5032 s->a_flags |= SLAP_ATTR_IXDEL;
5033 for (j=i+1; j < d->nidx; j++)
5034 if ( d->idx[j] >d->idx[i] )
5040 rc = config_del_vals( ct, ca );
5041 if ( rc ) rc = LDAP_OTHER;
5043 s->a_flags |= SLAP_ATTR_IXDEL;
5045 if ( ml->sml_values ) {
5050 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5051 ml->sml_values = vals;
5052 ml->sml_nvalues = nvals;
5054 if ( !vals || rc != LDAP_SUCCESS )
5057 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5060 for (i=0; ml->sml_values[i].bv_val; i++) {
5061 ca->line = ml->sml_values[i].bv_val;
5063 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5066 a->a_flags |= SLAP_ATTR_IXADD;
5073 /* Undo for a failed operation */
5074 if ( rc != LDAP_SUCCESS ) {
5075 ConfigReply msg = ca->reply;
5076 for ( s = save_attrs; s; s = s->a_next ) {
5077 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5078 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5079 ct = config_find_table( colst, nocs, s->a_desc, ca );
5080 a = attr_find( e->e_attrs, s->a_desc );
5082 /* clear the flag so the add check below will skip it */
5083 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5086 config_del_vals( ct, ca );
5088 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5089 ca->line = s->a_vals[i].bv_val;
5091 config_modify_add( ct, ca, s->a_desc, i );
5095 for ( a = e->e_attrs; a; a = a->a_next ) {
5096 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5097 ct = config_find_table( colst, nocs, a->a_desc, ca );
5100 config_del_vals( ct, ca );
5101 s = attr_find( save_attrs, a->a_desc );
5103 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5104 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5105 ca->line = s->a_vals[i].bv_val;
5107 config_modify_add( ct, ca, s->a_desc, i );
5118 if ( rc == LDAP_SUCCESS ) {
5119 attrs_free( save_attrs );
5121 attrs_free( e->e_attrs );
5122 e->e_attrs = save_attrs;
5124 ch_free( ca->argv );
5125 if ( colst ) ch_free( colst );
5127 deltail = dels->next;
5136 config_back_modify( Operation *op, SlapReply *rs )
5139 CfEntryInfo *ce, *last;
5141 ConfigArgs ca = {0};
5144 AttributeDescription *rad = NULL;
5147 cfb = (CfBackInfo *)op->o_bd->be_private;
5149 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5152 rs->sr_matched = last->ce_entry->e_name.bv_val;
5153 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5157 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5158 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5162 /* Get type of RDN */
5163 rdn = ce->ce_entry->e_nname;
5164 ptr = strchr( rdn.bv_val, '=' );
5165 rdn.bv_len = ptr - rdn.bv_val;
5166 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5168 /* Some basic validation... */
5169 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5170 /* Don't allow Modify of RDN; must use ModRdn for that. */
5171 if ( ml->sml_desc == rad ) {
5172 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5173 rs->sr_text = "Use modrdn to change the entry name";
5176 /* Internal update of contextCSN? */
5177 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5183 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5186 ldap_pvt_thread_pool_pause( &connection_pool );
5189 * 1) perform the Modify on the cached Entry.
5190 * 2) verify that the Entry still satisfies the schema.
5191 * 3) perform the individual config operations.
5192 * 4) store Modified entry in underlying LDIF backend.
5194 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5196 rs->sr_text = ca.cr_msg;
5197 } else if ( cfb->cb_use_ldif ) {
5198 BackendDB *be = op->o_bd;
5199 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5200 struct berval dn, ndn;
5202 op->o_bd = &cfb->cb_db;
5206 op->o_dn = op->o_bd->be_rootdn;
5207 op->o_ndn = op->o_bd->be_rootndn;
5209 scp = op->o_callback;
5210 op->o_callback = ≻
5211 op->o_bd->be_modify( op, rs );
5213 op->o_callback = scp;
5219 ldap_pvt_thread_pool_resume( &connection_pool );
5221 send_ldap_result( op, rs );
5222 slap_graduate_commit_csn( op );
5227 config_back_modrdn( Operation *op, SlapReply *rs )
5230 CfEntryInfo *ce, *last;
5234 cfb = (CfBackInfo *)op->o_bd->be_private;
5236 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5239 rs->sr_matched = last->ce_entry->e_name.bv_val;
5240 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5243 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5244 NULL, ACL_WRITE, NULL )) {
5245 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5249 if ( ce->ce_parent )
5250 parent = ce->ce_parent->ce_entry;
5252 parent = (Entry *)&slap_entry_root;
5253 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5254 NULL, ACL_WRITE, NULL )) {
5255 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5260 /* We don't allow moving objects to new parents.
5261 * Generally we only allow reordering a set of ordered entries.
5263 if ( op->orr_newSup ) {
5264 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5268 /* If newRDN == oldRDN, quietly succeed */
5269 dnRdn( &op->o_req_ndn, &rdn );
5270 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5271 rs->sr_err = LDAP_SUCCESS;
5275 /* Current behavior, subject to change as needed:
5277 * For backends and overlays, we only allow renumbering.
5278 * For schema, we allow renaming with the same number.
5279 * Otherwise, the op is not allowed.
5282 if ( ce->ce_type == Cft_Schema ) {
5286 /* Can't alter the main cn=schema entry */
5287 if ( ce->ce_parent->ce_type == Cft_Global ) {
5288 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5289 rs->sr_text = "renaming not allowed for this entry";
5293 /* We could support this later if desired */
5294 ptr1 = ber_bvchr( &rdn, '}' );
5295 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5296 len = ptr1 - rdn.bv_val;
5297 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5298 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5299 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5300 rs->sr_text = "schema reordering not supported";
5303 } else if ( ce->ce_type == Cft_Database ||
5304 ce->ce_type == Cft_Overlay ) {
5305 char *ptr1, *ptr2, *iptr1, *iptr2;
5308 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5309 if ( *iptr2 != '{' ) {
5310 rs->sr_err = LDAP_NAMING_VIOLATION;
5311 rs->sr_text = "new ordering index is required";
5315 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5316 ptr1 = ber_bvchr( &rdn, '}' );
5317 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5319 rs->sr_err = LDAP_NAMING_VIOLATION;
5320 rs->sr_text = "new ordering index is required";
5324 len1 = ptr1 - rdn.bv_val;
5325 len2 = ptr2 - op->orr_newrdn.bv_val;
5327 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5328 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5329 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5330 rs->sr_text = "changing database/overlay type not allowed";
5333 ixold = strtol( iptr1, NULL, 0 );
5334 ixnew = strtol( iptr2, &ptr1, 0 );
5335 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5336 rs->sr_err = LDAP_NAMING_VIOLATION;
5339 /* config DB is always 0, cannot be changed */
5340 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5341 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5345 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5346 rs->sr_text = "renaming not supported for this entry";
5350 ldap_pvt_thread_pool_pause( &connection_pool );
5352 if ( ce->ce_type == Cft_Schema ) {
5353 req_modrdn_s modr = op->oq_modrdn;
5356 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5357 if ( rs->sr_err == LDAP_SUCCESS ) {
5358 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5359 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5362 op->oq_modrdn = modr;
5364 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5365 req_modrdn_s modr = op->oq_modrdn;
5368 /* Advance to first of this type */
5369 cprev = &ce->ce_parent->ce_kids;
5370 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5371 cprev = &ce2->ce_sibs;
5374 /* Skip the -1 entry */
5375 if ( ce->ce_type == Cft_Database ) {
5376 cprev = &ce2->ce_sibs;
5382 /* Remove from old slot */
5383 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5384 cprev = &ce2->ce_sibs;
5385 *cprev = ce->ce_sibs;
5386 ceold = ce->ce_sibs;
5388 /* Insert into new slot */
5390 for ( i=0; i<ixnew; i++ ) {
5394 cprev = &ce2->ce_sibs;
5396 ce->ce_sibs = *cprev;
5401 /* NOTE: These should be encoded in the OC tables, not inline here */
5402 if ( ce->ce_type == Cft_Database )
5403 backend_db_move( ce->ce_be, ixnew );
5404 else if ( ce->ce_type == Cft_Overlay )
5405 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5407 if ( ixold < ixnew ) {
5408 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5411 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5412 ixold - ixnew, cfb->cb_use_ldif );
5414 op->oq_modrdn = modr;
5417 ldap_pvt_thread_pool_resume( &connection_pool );
5419 send_ldap_result( op, rs );
5424 config_back_delete( Operation *op, SlapReply *rs )
5426 #ifdef SLAP_CONFIG_DELETE
5428 CfEntryInfo *ce, *last, *ce2;
5430 cfb = (CfBackInfo *)op->o_bd->be_private;
5432 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5435 rs->sr_matched = last->ce_entry->e_name.bv_val;
5436 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5437 } else if ( ce->ce_kids ) {
5438 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5439 } else if ( ce->ce_type == Cft_Overlay ){
5443 ldap_pvt_thread_pool_pause( &connection_pool );
5445 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5447 /* remove CfEntryInfo from the siblings list */
5448 if ( ce->ce_parent->ce_kids == ce ) {
5449 ce->ce_parent->ce_kids = ce->ce_sibs;
5451 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5452 if ( ce2->ce_sibs == ce ) {
5453 ce2->ce_sibs = ce->ce_sibs;
5459 /* remove from underlying database */
5460 if ( cfb->cb_use_ldif ) {
5461 BackendDB *be = op->o_bd;
5462 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5463 struct berval dn, ndn, req_dn, req_ndn;
5465 op->o_bd = &cfb->cb_db;
5469 req_dn = op->o_req_dn;
5470 req_ndn = op->o_req_ndn;
5472 op->o_dn = op->o_bd->be_rootdn;
5473 op->o_ndn = op->o_bd->be_rootndn;
5474 op->o_req_dn = ce->ce_entry->e_name;
5475 op->o_req_ndn = ce->ce_entry->e_nname;
5477 scp = op->o_callback;
5478 op->o_callback = ≻
5479 op->o_bd->be_delete( op, rs );
5481 op->o_callback = scp;
5484 op->o_req_dn = req_dn;
5485 op->o_req_ndn = req_ndn;
5488 /* renumber siblings */
5489 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5490 ixold = strtol( iptr, NULL, 0 );
5491 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5492 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5493 count+ixold, 0, cfb->cb_use_ldif );
5497 ce->ce_entry->e_private=NULL;
5498 entry_free(ce->ce_entry);
5500 ldap_pvt_thread_pool_resume( &connection_pool );
5502 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5505 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5506 #endif /* SLAP_CONFIG_DELETE */
5507 send_ldap_result( op, rs );
5512 config_back_search( Operation *op, SlapReply *rs )
5515 CfEntryInfo *ce, *last;
5518 cfb = (CfBackInfo *)op->o_bd->be_private;
5520 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5523 rs->sr_matched = last->ce_entry->e_name.bv_val;
5524 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5527 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5528 ACL_SEARCH, NULL, &mask ))
5530 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5531 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5533 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5537 switch ( op->ors_scope ) {
5538 case LDAP_SCOPE_BASE:
5539 case LDAP_SCOPE_SUBTREE:
5540 rs->sr_err = config_send( op, rs, ce, 0 );
5543 case LDAP_SCOPE_ONELEVEL:
5544 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5545 rs->sr_err = config_send( op, rs, ce, 1 );
5554 send_ldap_result( op, rs );
5558 /* no-op, we never free entries */
5559 int config_entry_release(
5564 if ( !e->e_private ) {
5567 return LDAP_SUCCESS;
5570 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5572 int config_back_entry_get(
5576 AttributeDescription *at,
5581 CfEntryInfo *ce, *last;
5582 int rc = LDAP_NO_SUCH_OBJECT;
5584 cfb = (CfBackInfo *)op->o_bd->be_private;
5586 ce = config_find_base( cfb->cb_root, ndn, &last );
5588 *ent = ce->ce_entry;
5591 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5592 rc = LDAP_NO_SUCH_ATTRIBUTE;
5602 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5603 ConfigTable *ct, ConfigArgs *c )
5607 for (; at && *at; at++) {
5608 /* Skip the naming attr */
5609 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5611 for (i=0;ct[i].name;i++) {
5612 if (ct[i].ad == (*at)->sat_ad) {
5613 rc = config_get_vals(&ct[i], c);
5614 /* NOTE: tolerate that config_get_vals()
5615 * returns success with no values */
5616 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5617 if ( c->rvalue_nvals )
5618 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
5621 slap_syntax_validate_func *validate =
5622 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
5625 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
5626 rc = ordered_value_validate( ct[i].ad,
5627 &c->rvalue_vals[j], LDAP_MOD_ADD );
5629 Debug( LDAP_DEBUG_ANY,
5630 "config_build_attrs: error %d on %s value #%d\n",
5631 rc, ct[i].ad->ad_cname.bv_val, j );
5637 rc = attr_merge_normalize(e, ct[i].ad,
5638 c->rvalue_vals, NULL);
5640 ber_bvarray_free( c->rvalue_nvals );
5641 ber_bvarray_free( c->rvalue_vals );
5643 Debug( LDAP_DEBUG_ANY,
5644 "config_build_attrs: error %d on %s\n",
5645 rc, ct[i].ad->ad_cname.bv_val, 0 );
5657 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5658 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5660 Entry *e = entry_alloc();
5661 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5663 struct berval ad_name;
5664 AttributeDescription *ad = NULL;
5667 const char *text = "";
5671 CfEntryInfo *ceprev = NULL;
5673 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5676 ce->ce_type = main->co_type;
5677 ce->ce_parent = parent;
5679 pdn = parent->ce_entry->e_nname;
5680 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5681 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5682 ceprev->ce_type <= ce->ce_type;
5683 ceprev = ceprev->ce_sibs );
5688 ce->ce_private = c->ca_private;
5692 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5693 ber_dupbv( &e->e_nname, &e->e_name );
5695 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5696 main->co_name, NULL );
5698 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5699 extra->co_name, NULL );
5700 ptr = strchr(rdn->bv_val, '=');
5701 ad_name.bv_val = rdn->bv_val;
5702 ad_name.bv_len = ptr - rdn->bv_val;
5703 rc = slap_bv2ad( &ad_name, &ad, &text );
5708 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5709 attr_merge_normalize_one(e, ad, &val, NULL );
5712 c->table = main->co_type;
5713 if ( oc->soc_required ) {
5714 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5715 if ( rc ) goto fail;
5718 if ( oc->soc_allowed ) {
5719 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5720 if ( rc ) goto fail;
5725 c->table = extra->co_type;
5726 if ( oc->soc_required ) {
5727 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5728 if ( rc ) goto fail;
5731 if ( oc->soc_allowed ) {
5732 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5733 if ( rc ) goto fail;
5737 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5738 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5739 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5740 if ( rc != LDAP_SUCCESS ) {
5742 Debug( LDAP_DEBUG_ANY,
5743 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5744 rdn->bv_val, text, 0);
5747 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5750 op->ora_modlist = NULL;
5751 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5752 if ( !op->o_noop ) {
5753 op->o_bd->be_add( op, rs );
5754 if ( ( rs->sr_err != LDAP_SUCCESS )
5755 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5761 ce->ce_sibs = ceprev->ce_sibs;
5762 ceprev->ce_sibs = ce;
5763 } else if ( parent ) {
5764 ce->ce_sibs = parent->ce_kids;
5765 parent->ce_kids = ce;
5772 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5773 Operation *op, SlapReply *rs )
5776 ConfigFile *cf = c->ca_private;
5778 struct berval bv, rdn;
5780 for (; cf; cf=cf->c_sibs, c->depth++) {
5781 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5782 !cf->c_om_head && !cf->c_syn_head ) continue;
5783 c->value_dn.bv_val = c->log;
5784 LUTIL_SLASHPATH( cf->c_file.bv_val );
5785 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5790 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5792 ptr = strchr( bv.bv_val, '.' );
5794 bv.bv_len = ptr - bv.bv_val;
5795 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5796 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5797 /* FIXME: how can indicate error? */
5800 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5802 c->value_dn.bv_len += bv.bv_len;
5803 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5807 e = config_build_entry( op, rs, ceparent, c, &rdn,
5808 &CFOC_SCHEMA, NULL );
5811 } else if ( e && cf->c_kids ) {
5812 c->ca_private = cf->c_kids;
5813 config_build_schema_inc( c, e->e_private, op, rs );
5819 #ifdef SLAPD_MODULES
5822 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5823 Operation *op, SlapReply *rs )
5828 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5829 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5831 c->value_dn.bv_val = c->log;
5832 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5833 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5834 /* FIXME: how can indicate error? */
5838 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5847 config_check_schema(Operation *op, CfBackInfo *cfb)
5849 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5851 CfEntryInfo *ce, *last;
5854 /* If there's no root entry, we must be in the midst of converting */
5855 if ( !cfb->cb_root )
5858 /* Make sure the main schema entry exists */
5859 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5866 /* Make sure it's up to date */
5867 if ( cf_om_tail != om_sys_tail ) {
5868 a = attr_find( e->e_attrs, cfAd_om );
5870 if ( a->a_nvals != a->a_vals )
5871 ber_bvarray_free( a->a_nvals );
5872 ber_bvarray_free( a->a_vals );
5877 oidm_unparse( &bv, NULL, NULL, 1 );
5878 attr_merge_normalize( e, cfAd_om, bv, NULL );
5879 ber_bvarray_free( bv );
5880 cf_om_tail = om_sys_tail;
5882 if ( cf_at_tail != at_sys_tail ) {
5883 a = attr_find( e->e_attrs, cfAd_attr );
5885 if ( a->a_nvals != a->a_vals )
5886 ber_bvarray_free( a->a_nvals );
5887 ber_bvarray_free( a->a_vals );
5892 at_unparse( &bv, NULL, NULL, 1 );
5893 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5894 ber_bvarray_free( bv );
5895 cf_at_tail = at_sys_tail;
5897 if ( cf_oc_tail != oc_sys_tail ) {
5898 a = attr_find( e->e_attrs, cfAd_oc );
5900 if ( a->a_nvals != a->a_vals )
5901 ber_bvarray_free( a->a_nvals );
5902 ber_bvarray_free( a->a_vals );
5907 oc_unparse( &bv, NULL, NULL, 1 );
5908 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5909 ber_bvarray_free( bv );
5910 cf_oc_tail = oc_sys_tail;
5912 if ( cf_syn_tail != syn_sys_tail ) {
5913 a = attr_find( e->e_attrs, cfAd_syntax );
5915 if ( a->a_nvals != a->a_vals )
5916 ber_bvarray_free( a->a_nvals );
5917 ber_bvarray_free( a->a_vals );
5922 syn_unparse( &bv, NULL, NULL, 1 );
5923 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
5924 ber_bvarray_free( bv );
5925 cf_syn_tail = syn_sys_tail;
5928 SlapReply rs = {REP_RESULT};
5929 c.ca_private = NULL;
5930 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5931 &CFOC_SCHEMA, NULL );
5936 ce->ce_private = cfb->cb_config;
5937 cf_at_tail = at_sys_tail;
5938 cf_oc_tail = oc_sys_tail;
5939 cf_om_tail = om_sys_tail;
5940 cf_syn_tail = syn_sys_tail;
5945 static const char *defacl[] = {
5946 NULL, "to", "*", "by", "*", "none", NULL
5950 config_back_db_open( BackendDB *be, ConfigReply *cr )
5952 CfBackInfo *cfb = be->be_private;
5955 CfEntryInfo *ce, *ceparent;
5959 Connection conn = {0};
5960 OperationBuffer opbuf;
5962 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5963 SlapReply rs = {REP_RESULT};
5964 void *thrctx = NULL;
5966 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5968 /* If we have no explicitly configured ACLs, don't just use
5969 * the global ACLs. Explicitly deny access to everything.
5971 if ( !be->be_acl ) {
5972 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5975 thrctx = ldap_pvt_thread_pool_context();
5976 connection_fake_init( &conn, &opbuf, thrctx );
5979 op->o_tag = LDAP_REQ_ADD;
5980 op->o_callback = &cb;
5981 op->o_bd = &cfb->cb_db;
5982 op->o_dn = op->o_bd->be_rootdn;
5983 op->o_ndn = op->o_bd->be_rootndn;
5985 if ( !cfb->cb_use_ldif ) {
5989 /* If we read the config from back-ldif, do some quick sanity checks */
5990 if ( cfb->cb_got_ldif ) {
5991 return config_check_schema( op, cfb );
5994 /* create root of tree */
5996 c.ca_private = cfb->cb_config;
5998 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6008 #ifdef SLAPD_MODULES
6009 /* Create Module nodes... */
6010 if ( modpaths.mp_loads ) {
6011 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6017 /* Create schema nodes... cn=schema will contain the hardcoded core
6018 * schema, read-only. Child objects will contain runtime loaded schema
6022 c.ca_private = NULL;
6023 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6028 ce->ce_private = cfb->cb_config;
6029 cf_at_tail = at_sys_tail;
6030 cf_oc_tail = oc_sys_tail;
6031 cf_om_tail = om_sys_tail;
6032 cf_syn_tail = syn_sys_tail;
6034 /* Create schema nodes for included schema... */
6035 if ( cfb->cb_config->c_kids ) {
6037 c.ca_private = cfb->cb_config->c_kids;
6038 if (config_build_schema_inc( &c, ce, op, &rs )) {
6043 /* Create backend nodes. Skip if they don't provide a cf_table.
6044 * There usually aren't any of these.
6048 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6049 if (!bi->bi_cf_ocs) {
6050 /* If it only supports the old config mech, complain. */
6051 if ( bi->bi_config ) {
6052 Debug( LDAP_DEBUG_ANY,
6053 "WARNING: No dynamic config support for backend %s.\n",
6054 bi->bi_type, 0, 0 );
6059 if (!bi->bi_private) continue;
6062 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6063 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6064 if ( rdn.bv_len >= sizeof( c.log ) ) {
6065 /* FIXME: holler ... */ ;
6068 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6075 /* Create database nodes... */
6076 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6077 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6078 for ( i = -1, be = frontendDB ; be;
6079 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6080 slap_overinfo *oi = NULL;
6082 if ( overlay_is_over( be )) {
6083 oi = be->bd_info->bi_private;
6089 /* If this backend supports the old config mechanism, but not
6090 * the new mech, complain.
6092 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6093 Debug( LDAP_DEBUG_ANY,
6094 "WARNING: No dynamic config support for database %s.\n",
6095 bi->bi_type, 0, 0 );
6099 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6100 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6102 if ( rdn.bv_len >= sizeof( c.log ) ) {
6103 /* FIXME: holler ... */ ;
6107 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6113 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6114 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6115 /* Iterate through overlays */
6120 voidList *vl, *v0 = NULL;
6122 /* overlays are in LIFO order, must reverse stack */
6123 for (on=oi->oi_list; on; on=on->on_next) {
6124 vl = ch_malloc( sizeof( voidList ));
6129 for (j=0; vl; j++,vl=v0) {
6133 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6134 Debug( LDAP_DEBUG_ANY,
6135 "WARNING: No dynamic config support for overlay %s.\n",
6136 on->on_bi.bi_type, 0, 0 );
6140 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6141 "%s=" SLAP_X_ORDERED_FMT "%s",
6142 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6143 if ( rdn.bv_len >= sizeof( c.log ) ) {
6144 /* FIXME: holler ... */ ;
6148 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6149 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6153 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6154 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6159 ldap_pvt_thread_pool_context_reset( thrctx );
6161 if ( unsupp && cfb->cb_use_ldif ) {
6162 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6163 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6170 cfb_free_cffile( ConfigFile *cf )
6174 for (; cf; cf=next) {
6177 cfb_free_cffile( cf->c_kids );
6178 ch_free( cf->c_file.bv_val );
6179 ber_bvarray_free( cf->c_dseFiles );
6185 cfb_free_entries( CfEntryInfo *ce )
6189 for (; ce; ce=next) {
6192 cfb_free_entries( ce->ce_kids );
6193 ce->ce_entry->e_private = NULL;
6194 entry_free( ce->ce_entry );
6200 config_back_db_close( BackendDB *be, ConfigReply *cr )
6202 CfBackInfo *cfb = be->be_private;
6204 cfb_free_entries( cfb->cb_root );
6205 cfb->cb_root = NULL;
6207 if ( cfb->cb_db.bd_info ) {
6208 backend_shutdown( &cfb->cb_db );
6215 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6217 CfBackInfo *cfb = be->be_private;
6219 cfb_free_cffile( cfb->cb_config );
6221 ch_free( cfdir.bv_val );
6223 avl_free( CfOcTree, NULL );
6225 if ( cfb->cb_db.bd_info ) {
6226 cfb->cb_db.be_suffix = NULL;
6227 cfb->cb_db.be_nsuffix = NULL;
6228 BER_BVZERO( &cfb->cb_db.be_rootdn );
6229 BER_BVZERO( &cfb->cb_db.be_rootndn );
6231 backend_destroy_one( &cfb->cb_db, 0 );
6240 config_back_db_init( BackendDB *be, ConfigReply* cr )
6246 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6247 cfn = cfb->cb_config;
6248 be->be_private = cfb;
6250 ber_dupbv( &be->be_rootdn, &config_rdn );
6251 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6252 ber_dupbv( &dn, &be->be_rootdn );
6253 ber_bvarray_add( &be->be_suffix, &dn );
6254 ber_dupbv( &dn, &be->be_rootdn );
6255 ber_bvarray_add( &be->be_nsuffix, &dn );
6257 /* Hide from namingContexts */
6258 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6260 /* Check ACLs on content of Adds by default */
6261 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6267 config_back_destroy( BackendInfo *bi )
6269 ldif_must_b64_encode_release();
6274 config_tool_entry_open( BackendDB *be, int mode )
6276 CfBackInfo *cfb = be->be_private;
6277 BackendInfo *bi = cfb->cb_db.bd_info;
6279 if ( bi && bi->bi_tool_entry_open )
6280 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6287 config_tool_entry_close( BackendDB *be )
6289 CfBackInfo *cfb = be->be_private;
6290 BackendInfo *bi = cfb->cb_db.bd_info;
6292 if ( bi && bi->bi_tool_entry_close )
6293 return bi->bi_tool_entry_close( &cfb->cb_db );
6299 config_tool_entry_first( BackendDB *be )
6301 CfBackInfo *cfb = be->be_private;
6302 BackendInfo *bi = cfb->cb_db.bd_info;
6304 if ( bi && bi->bi_tool_entry_first )
6305 return bi->bi_tool_entry_first( &cfb->cb_db );
6311 config_tool_entry_next( BackendDB *be )
6313 CfBackInfo *cfb = be->be_private;
6314 BackendInfo *bi = cfb->cb_db.bd_info;
6316 if ( bi && bi->bi_tool_entry_next )
6317 return bi->bi_tool_entry_next( &cfb->cb_db );
6323 config_tool_entry_get( BackendDB *be, ID id )
6325 CfBackInfo *cfb = be->be_private;
6326 BackendInfo *bi = cfb->cb_db.bd_info;
6328 if ( bi && bi->bi_tool_entry_get )
6329 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6334 static int entry_put_got_frontend=0;
6335 static int entry_put_got_config=0;
6337 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6339 CfBackInfo *cfb = be->be_private;
6340 BackendInfo *bi = cfb->cb_db.bd_info;
6342 struct berval rdn, vals[ 2 ];
6344 OperationBuffer opbuf;
6346 Connection conn = {0};
6347 Operation *op = NULL;
6351 /* Create entry for frontend database if it does not exist already */
6352 if ( !entry_put_got_frontend ) {
6353 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6354 STRLENOF( "olcDatabase" ))) {
6355 if ( strncmp( e->e_nname.bv_val +
6356 STRLENOF( "olcDatabase" ), "={-1}frontend",
6357 STRLENOF( "={-1}frontend" )) &&
6358 strncmp( e->e_nname.bv_val +
6359 STRLENOF( "olcDatabase" ), "=frontend",
6360 STRLENOF( "=frontend" ))) {
6362 vals[1].bv_val = NULL;
6363 memset( &ca, 0, sizeof(ConfigArgs));
6365 ca.bi = frontendDB->bd_info;
6366 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6367 rdn.bv_val = ca.log;
6368 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6369 "%s=" SLAP_X_ORDERED_FMT "%s",
6370 cfAd_database->ad_cname.bv_val, -1,
6372 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6373 &CFOC_DATABASE, ca.be->be_cf_ocs );
6374 thrctx = ldap_pvt_thread_pool_context();
6375 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6377 op->o_bd = &cfb->cb_db;
6378 op->o_tag = LDAP_REQ_ADD;
6380 op->o_dn = be->be_rootdn;
6381 op->o_ndn = be->be_rootndn;
6382 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6383 if ( rc != LDAP_SUCCESS ) {
6384 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6385 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6389 if ( ce && bi && bi->bi_tool_entry_put &&
6390 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6391 entry_put_got_frontend++;
6393 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6394 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6398 entry_put_got_frontend++;
6403 /* Create entry for config database if it does not exist already */
6404 if ( !entry_put_got_config && !isFrontend ) {
6405 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6406 STRLENOF( "olcDatabase" ))) {
6407 if ( strncmp( e->e_nname.bv_val +
6408 STRLENOF( "olcDatabase" ), "={0}config",
6409 STRLENOF( "={0}config" )) &&
6410 strncmp( e->e_nname.bv_val +
6411 STRLENOF( "olcDatabase" ), "=config",
6412 STRLENOF( "=config" )) ) {
6414 vals[1].bv_val = NULL;
6415 memset( &ca, 0, sizeof(ConfigArgs));
6416 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6417 ca.bi = ca.be->bd_info;
6418 rdn.bv_val = ca.log;
6419 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6420 "%s=" SLAP_X_ORDERED_FMT "%s",
6421 cfAd_database->ad_cname.bv_val, 0,
6423 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6426 thrctx = ldap_pvt_thread_pool_context();
6427 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6429 op->o_bd = &cfb->cb_db;
6430 op->o_tag = LDAP_REQ_ADD;
6431 op->o_dn = be->be_rootdn;
6432 op->o_ndn = be->be_rootndn;
6435 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6436 if ( rc != LDAP_SUCCESS ) {
6437 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6438 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6441 if (ce && bi && bi->bi_tool_entry_put &&
6442 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6443 entry_put_got_config++;
6445 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6446 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6450 entry_put_got_config++;
6454 if ( bi && bi->bi_tool_entry_put &&
6455 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6456 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6463 AttributeDescription **desc;
6465 { "attribute", &cfAd_attr },
6466 { "backend", &cfAd_backend },
6467 { "database", &cfAd_database },
6468 { "include", &cfAd_include },
6469 { "ldapsyntax", &cfAd_syntax },
6470 { "objectclass", &cfAd_oc },
6471 { "objectidentifier", &cfAd_om },
6472 { "overlay", &cfAd_overlay },
6477 * add / delete: all types that may be added or deleted must use an
6478 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6479 * should automatically renumber the index of any siblings as needed,
6480 * so that no gaps in the numbering sequence exist after the add/delete
6482 * What can be added:
6484 * backend objects for backend-specific config directives
6488 * delete: probably no support this time around.
6490 * modrdn: generally not done. Will be invoked automatically by add/
6491 * delete to update numbering sequence. Perform as an explicit operation
6492 * so that the renumbering effect may be replicated. Subtree rename must
6493 * be supported, since renumbering a database will affect all its child
6496 * modify: must be fully supported.
6500 config_back_initialize( BackendInfo *bi )
6502 ConfigTable *ct = config_back_cf_table;
6506 AttributeDescription *ad = NULL;
6508 static char *controls[] = {
6509 LDAP_CONTROL_MANAGEDSAIT,
6513 /* Make sure we don't exceed the bits reserved for userland */
6514 config_check_userland( CFG_LAST );
6516 bi->bi_controls = controls;
6521 bi->bi_destroy = config_back_destroy;
6523 bi->bi_db_init = config_back_db_init;
6524 bi->bi_db_config = 0;
6525 bi->bi_db_open = config_back_db_open;
6526 bi->bi_db_close = config_back_db_close;
6527 bi->bi_db_destroy = config_back_db_destroy;
6529 bi->bi_op_bind = config_back_bind;
6530 bi->bi_op_unbind = 0;
6531 bi->bi_op_search = config_back_search;
6532 bi->bi_op_compare = 0;
6533 bi->bi_op_modify = config_back_modify;
6534 bi->bi_op_modrdn = config_back_modrdn;
6535 bi->bi_op_add = config_back_add;
6536 bi->bi_op_delete = config_back_delete;
6537 bi->bi_op_abandon = 0;
6539 bi->bi_extended = 0;
6541 bi->bi_chk_referrals = 0;
6543 bi->bi_access_allowed = slap_access_allowed;
6545 bi->bi_connection_init = 0;
6546 bi->bi_connection_destroy = 0;
6548 bi->bi_entry_release_rw = config_entry_release;
6549 bi->bi_entry_get_rw = config_back_entry_get;
6551 bi->bi_tool_entry_open = config_tool_entry_open;
6552 bi->bi_tool_entry_close = config_tool_entry_close;
6553 bi->bi_tool_entry_first = config_tool_entry_first;
6554 bi->bi_tool_entry_next = config_tool_entry_next;
6555 bi->bi_tool_entry_get = config_tool_entry_get;
6556 bi->bi_tool_entry_put = config_tool_entry_put;
6559 argv[ 0 ] = "slapd";
6565 for (i=0; OidMacros[i].name; i++ ) {
6566 argv[1] = OidMacros[i].name;
6567 argv[2] = OidMacros[i].oid;
6568 parse_oidm( &ca, 0, NULL );
6571 bi->bi_cf_ocs = cf_ocs;
6573 i = config_register_schema( ct, cf_ocs );
6576 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6579 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6580 * basically, we don't care if it fails */
6581 i = slap_str2ad( "olcRootPW", &ad, &text );
6583 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6584 "warning, unable to get \"olcRootPW\" "
6585 "attribute description: %d: %s\n",
6588 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6589 ad->ad_type->sat_oid );
6592 /* set up the notable AttributeDescriptions */
6594 for (;ct->name;ct++) {
6595 if (strcmp(ct->name, ads[i].name)) continue;
6596 *ads[i].desc = ct->ad;
6598 if (!ads[i].name) break;