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_option(ConfigArgs *c) {
3195 LDAP *ld = slap_tls_ld;
3197 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3198 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3199 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3200 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3201 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3202 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3203 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3205 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3207 default: Debug(LDAP_DEBUG_ANY, "%s: "
3208 "unknown tls_option <0x%x>\n",
3209 c->log, c->type, 0);
3212 if (c->op == SLAP_CONFIG_EMIT) {
3213 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3214 } else if ( c->op == LDAP_MOD_DELETE ) {
3215 return ldap_pvt_tls_set_option( ld, flag, NULL );
3217 ch_free(c->value_string);
3218 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3221 /* FIXME: this ought to be provided by libldap */
3223 config_tls_config(ConfigArgs *c) {
3226 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3227 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3228 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3230 Debug(LDAP_DEBUG_ANY, "%s: "
3231 "unknown tls_option <0x%x>\n",
3232 c->log, c->type, 0);
3235 if (c->op == SLAP_CONFIG_EMIT) {
3236 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3237 } else if ( c->op == LDAP_MOD_DELETE ) {
3239 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3241 ch_free( c->value_string );
3242 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3243 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3244 Debug(LDAP_DEBUG_ANY, "%s: "
3245 "unable to parse %s \"%s\"\n",
3246 c->log, c->argv[0], c->argv[1] );
3249 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3251 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3256 static CfEntryInfo *
3257 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3267 if ( dn_match( &root->ce_entry->e_nname, dn ))
3270 c = dn->bv_val+dn->bv_len;
3271 for (;*c != ',';c--);
3275 for (--c;c>dn->bv_val && *c != ',';c--);
3279 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3281 root = root->ce_kids;
3283 for (;root;root=root->ce_sibs) {
3284 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3285 if ( cdn.bv_val == dn->bv_val ) {
3295 typedef struct setup_cookie {
3305 config_ldif_resp( Operation *op, SlapReply *rs )
3307 if ( rs->sr_type == REP_SEARCH ) {
3308 setup_cookie *sc = op->o_callback->sc_private;
3311 sc->cfb->cb_got_ldif = 1;
3312 /* Does the frontend exist? */
3313 if ( !sc->got_frontend ) {
3314 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3315 "olcDatabase", STRLENOF( "olcDatabase" )))
3317 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3318 STRLENOF( "olcDatabase" ), "={-1}frontend",
3319 STRLENOF( "={-1}frontend" )))
3323 sc->ca->be = frontendDB;
3324 sc->ca->bi = frontendDB->bd_info;
3325 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3326 rdn.bv_val = sc->ca->log;
3327 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3328 "%s=" SLAP_X_ORDERED_FMT "%s",
3329 cfAd_database->ad_cname.bv_val, -1,
3330 sc->ca->bi->bi_type);
3332 sc->frontend = config_build_entry( op, rs,
3333 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3334 sc->ca->be->be_cf_ocs );
3344 dnParent( &rs->sr_entry->e_nname, &pdn );
3346 /* Does the configDB exist? */
3347 if ( sc->got_frontend && !sc->got_config &&
3348 !strncmp( rs->sr_entry->e_nname.bv_val,
3349 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3350 dn_match( &config_rdn, &pdn ) )
3352 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3353 STRLENOF( "olcDatabase" ), "={0}config",
3354 STRLENOF( "={0}config" )))
3358 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3359 sc->ca->bi = sc->ca->be->bd_info;
3360 rdn.bv_val = sc->ca->log;
3361 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3362 "%s=" SLAP_X_ORDERED_FMT "%s",
3363 cfAd_database->ad_cname.bv_val, 0,
3364 sc->ca->bi->bi_type);
3366 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3367 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3374 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3375 if ( rs->sr_err != LDAP_SUCCESS ) {
3376 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3377 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3383 /* Configure and read the underlying back-ldif store */
3385 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3386 CfBackInfo *cfb = be->be_private;
3392 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3393 Connection conn = {0};
3394 OperationBuffer opbuf;
3396 SlapReply rs = {REP_RESULT};
3397 Filter filter = { LDAP_FILTER_PRESENT };
3398 struct berval filterstr = BER_BVC("(objectclass=*)");
3401 /* Is the config directory available? */
3402 if ( stat( dir, &st ) < 0 ) {
3403 /* No, so don't bother using the backing store.
3404 * All changes will be in-memory only.
3409 cfb->cb_db.bd_info = backend_info( "ldif" );
3410 if ( !cfb->cb_db.bd_info )
3411 return 0; /* FIXME: eventually this will be a fatal error */
3413 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3416 cfb->cb_db.be_suffix = be->be_suffix;
3417 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3419 /* The suffix is always "cn=config". The underlying DB's rootdn
3420 * is always the same as the suffix.
3422 cfb->cb_db.be_rootdn = be->be_suffix[0];
3423 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3425 ber_str2bv( dir, 0, 1, &cfdir );
3430 argv[0] = "directory";
3431 argv[1] = (char *)dir;
3436 c.table = Cft_Database;
3438 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3442 if ( config_add_vals( ct, &c ))
3445 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3449 void *thrctx = ldap_pvt_thread_pool_context();
3452 connection_fake_init( &conn, &opbuf, thrctx );
3455 filter.f_desc = slap_schema.si_ad_objectClass;
3457 op->o_tag = LDAP_REQ_SEARCH;
3459 op->ors_filter = &filter;
3460 op->ors_filterstr = filterstr;
3461 op->ors_scope = LDAP_SCOPE_SUBTREE;
3463 op->o_dn = c.be->be_rootdn;
3464 op->o_ndn = c.be->be_rootndn;
3466 op->o_req_dn = be->be_suffix[0];
3467 op->o_req_ndn = be->be_nsuffix[0];
3469 op->ors_tlimit = SLAP_NO_LIMIT;
3470 op->ors_slimit = SLAP_NO_LIMIT;
3472 op->ors_attrs = slap_anlist_all_attributes;
3473 op->ors_attrsonly = 0;
3475 op->o_callback = &cb;
3478 cb.sc_private = ≻
3479 sc.got_frontend = 0;
3484 op->o_bd = &cfb->cb_db;
3486 /* Allow unknown attrs in DNs */
3487 prev_DN_strict = slap_DN_strict;
3490 rc = op->o_bd->be_search( op, &rs );
3492 /* Restore normal DN validation */
3493 slap_DN_strict = prev_DN_strict;
3495 op->o_tag = LDAP_REQ_ADD;
3496 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3497 op->ora_e = sc.frontend;
3498 rc = op->o_bd->be_add( op, &rs );
3500 if ( rc == LDAP_SUCCESS && sc.config ) {
3501 op->ora_e = sc.config;
3502 rc = op->o_bd->be_add( op, &rs );
3504 ldap_pvt_thread_pool_context_reset( thrctx );
3507 /* ITS#4194 - only use if it's present, or we're converting. */
3508 if ( !readit || rc == LDAP_SUCCESS )
3509 cfb->cb_use_ldif = 1;
3515 CfOc_cmp( const void *c1, const void *c2 ) {
3516 const ConfigOCs *co1 = c1;
3517 const ConfigOCs *co2 = c2;
3519 return ber_bvcmp( co1->co_name, co2->co_name );
3523 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3526 i = init_config_attrs( ct );
3529 /* set up the objectclasses */
3530 i = init_config_ocs( ocs );
3533 for (i=0; ocs[i].co_def; i++) {
3534 if ( ocs[i].co_oc ) {
3535 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3536 if ( !ocs[i].co_table )
3537 ocs[i].co_table = ct;
3538 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3545 read_config(const char *fname, const char *dir) {
3548 const char *cfdir, *cfname;
3551 /* Setup the config backend */
3552 be = backend_db_init( "config", NULL, 0, NULL );
3556 cfb = be->be_private;
3557 be->be_dfltaccess = ACL_NONE;
3559 /* If no .conf, or a dir was specified, setup the dir */
3560 if ( !fname || dir ) {
3562 /* If explicitly given, check for existence */
3565 if ( stat( dir, &st ) < 0 ) {
3566 Debug( LDAP_DEBUG_ANY,
3567 "invalid config directory %s, error %d\n",
3573 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3575 /* if fname is defaulted, try reading .d */
3576 rc = config_setup_ldif( be, cfdir, !fname );
3579 /* It may be OK if the base object doesn't exist yet. */
3580 if ( rc != LDAP_NO_SUCH_OBJECT )
3582 /* ITS#4194: But if dir was specified and no fname,
3583 * then we were supposed to read the dir. Unless we're
3584 * trying to slapadd the dir...
3586 if ( dir && !fname ) {
3587 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3589 /* Assume it's slapadd with a config dir, let it continue */
3591 cfb->cb_got_ldif = 1;
3592 cfb->cb_use_ldif = 1;
3597 /* If we read the config from back-ldif, nothing to do here */
3598 if ( cfb->cb_got_ldif ) {
3607 cfname = SLAPD_DEFAULT_CONFIGFILE;
3609 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3612 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3615 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3616 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3617 &frontendDB->be_schemadn );
3618 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3619 if ( rc != LDAP_SUCCESS ) {
3620 Debug(LDAP_DEBUG_ANY, "read_config: "
3621 "unable to normalize default schema DN \"%s\"\n",
3622 frontendDB->be_schemadn.bv_val, 0, 0 );
3623 /* must not happen */
3631 config_back_bind( Operation *op, SlapReply *rs )
3633 if ( be_isroot_pw( op ) ) {
3634 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3635 /* frontend sends result */
3636 return LDAP_SUCCESS;
3639 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3640 send_ldap_result( op, rs );
3646 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3650 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3652 rs->sr_attrs = op->ors_attrs;
3653 rs->sr_entry = ce->ce_entry;
3655 rc = send_search_entry( op, rs );
3656 if ( rc != LDAP_SUCCESS ) {
3660 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3661 if ( ce->ce_kids ) {
3662 rc = config_send( op, rs, ce->ce_kids, 1 );
3663 if ( rc ) return rc;
3666 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3667 rc = config_send( op, rs, ce, 0 );
3675 static ConfigTable *
3676 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3681 for (j=0; j<nocs; j++) {
3682 for (i=0; colst[j]->co_table[i].name; i++)
3683 if ( colst[j]->co_table[i].ad == ad ) {
3684 ca->table = colst[j]->co_type;
3685 return &colst[j]->co_table[i];
3691 /* Sort the attributes of the entry according to the order defined
3692 * in the objectclass, with required attributes occurring before
3693 * allowed attributes. For any attributes with sequencing dependencies
3694 * (e.g., rootDN must be defined after suffix) the objectclass must
3695 * list the attributes in the desired sequence.
3698 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3700 Attribute *a, *head = NULL, *tail = NULL, **prev;
3703 for (i=0; i<nocs; i++) {
3704 if ( colst[i]->co_oc->soc_required ) {
3705 AttributeType **at = colst[i]->co_oc->soc_required;
3706 for (j=0; at[j]; j++) {
3707 for (a=e->e_attrs, prev=&e->e_attrs; a;
3708 prev = &(*prev)->a_next, a=a->a_next) {
3709 if ( a->a_desc == at[j]->sat_ad ) {
3723 if ( colst[i]->co_oc->soc_allowed ) {
3724 AttributeType **at = colst[i]->co_oc->soc_allowed;
3725 for (j=0; at[j]; j++) {
3726 for (a=e->e_attrs, prev=&e->e_attrs; a;
3727 prev = &(*prev)->a_next, a=a->a_next) {
3728 if ( a->a_desc == at[j]->sat_ad ) {
3744 tail->a_next = e->e_attrs;
3750 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3752 Attribute *a = NULL;
3753 AttributeDescription *ad;
3763 Modifications *ml = ptr;
3765 vals = ml->sml_values;
3768 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3769 rc = ordered_value_sort( a, 1 );
3771 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3772 ad->ad_cname.bv_val );
3776 for ( i=0; vals[i].bv_val; i++ ) {
3777 ca->line = vals[i].bv_val;
3778 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3779 ca->line[0] == '{' ) {
3780 char *idx = strchr( ca->line, '}' );
3781 if ( idx ) ca->line = idx+1;
3783 rc = config_parse_vals( ct, ca, i );
3792 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3795 struct berval rtype, rval;
3797 AttributeDescription *ad = NULL;
3799 dnRdn( &e->e_name, rdn );
3800 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3801 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3802 rtype.bv_val = rdn->bv_val;
3803 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3806 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3807 a = attr_find( e->e_attrs, ad );
3808 if (!a ) return LDAP_NAMING_VIOLATION;
3815 config_rename_kids( CfEntryInfo *ce )
3818 struct berval rdn, nrdn;
3820 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3821 struct berval newdn, newndn;
3822 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3823 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3824 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
3825 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
3826 free( ce2->ce_entry->e_name.bv_val );
3827 free( ce2->ce_entry->e_nname.bv_val );
3828 ce2->ce_entry->e_name = newdn;
3829 ce2->ce_entry->e_nname = newndn;
3830 config_rename_kids( ce2 );
3835 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3836 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3837 struct berval *nnewrdn, int use_ldif )
3841 struct berval odn, ondn;
3845 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3846 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3849 free( a->a_vals[0].bv_val );
3850 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3851 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3852 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3853 strcpy( a->a_vals[0].bv_val, ptr1 );
3855 if ( a->a_nvals != a->a_vals ) {
3856 free( a->a_nvals[0].bv_val );
3857 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3858 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3859 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3860 strcpy( a->a_nvals[0].bv_val, ptr1 );
3863 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3864 BackendDB *be = op->o_bd;
3865 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3866 struct berval dn, ndn, xdn, xndn;
3868 op->o_bd = &cfb->cb_db;
3870 /* Save current rootdn; use the underlying DB's rootdn */
3874 xndn = op->o_req_ndn;
3875 op->o_dn = op->o_bd->be_rootdn;
3876 op->o_ndn = op->o_bd->be_rootndn;
3878 op->o_req_ndn = ondn;
3880 scp = op->o_callback;
3881 op->o_callback = ≻
3882 op->orr_newrdn = *newrdn;
3883 op->orr_nnewrdn = *nnewrdn;
3884 op->orr_newSup = NULL;
3885 op->orr_nnewSup = NULL;
3886 op->orr_deleteoldrdn = 1;
3887 op->orr_modlist = NULL;
3888 slap_modrdn2mods( op, rs );
3889 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3890 rc = op->o_bd->be_modrdn( op, rs );
3891 slap_mods_free( op->orr_modlist, 1 );
3894 op->o_callback = scp;
3898 op->o_req_ndn = xndn;
3901 free( ondn.bv_val );
3903 config_rename_kids( e->e_private );
3908 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3909 Entry *e, int idx, int tailindex, int use_ldif )
3911 struct berval ival, newrdn, nnewrdn;
3914 char ibuf[32], *ptr1, *ptr2 = NULL;
3917 rc = config_rename_attr( rs, e, &rdn, &a );
3918 if ( rc ) return rc;
3921 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3922 if ( ival.bv_len >= sizeof( ibuf ) ) {
3923 return LDAP_NAMING_VIOLATION;
3926 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3927 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3930 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3931 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3934 ptr2 = ber_bvchr( &rdn, '}' );
3938 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3940 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3941 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3942 a->a_desc->ad_cname.bv_len );
3944 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3945 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3949 /* Do the equivalent of ModRDN */
3950 /* Replace DN / NDN */
3951 newrdn.bv_len = ptr1 - newrdn.bv_val;
3952 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3953 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3955 free( nnewrdn.bv_val );
3956 free( newrdn.bv_val );
3961 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3962 SlapReply *rs, int *renum, int *ibase )
3965 int index = -1, gotindex = 0, nsibs, rc = 0;
3966 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3967 char *ptr1, *ptr2 = NULL;
3970 if ( renum ) *renum = 0;
3972 /* These entries don't get indexed/renumbered */
3973 if ( ce_type == Cft_Global ) return 0;
3974 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3976 if ( ce_type == Cft_Module )
3979 /* See if the rdn has an index already */
3980 dnRdn( &e->e_name, &rdn );
3981 if ( ce_type == Cft_Database ) {
3982 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3983 "frontend", STRLENOF("frontend") ))
3985 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3986 "config", STRLENOF("config") ))
3989 ptr1 = ber_bvchr( &e->e_name, '{' );
3990 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
3992 ptr2 = strchr( ptr1, '}' );
3993 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
3994 return LDAP_NAMING_VIOLATION;
3995 if ( ptr2-ptr1 == 1)
3996 return LDAP_NAMING_VIOLATION;
3998 index = strtol( ptr1 + 1, &next, 10 );
3999 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4000 return LDAP_NAMING_VIOLATION;
4003 /* Special case, we allow -1 for the frontendDB */
4004 if ( index != -1 || !isfrontend )
4005 return LDAP_NAMING_VIOLATION;
4007 if ( isconfig && index != 0 ){
4008 return LDAP_NAMING_VIOLATION;
4012 /* count related kids */
4013 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4014 if ( ce->ce_type == ce_type ) nsibs++;
4017 /* account for -1 frontend */
4018 if ( ce_type == Cft_Database )
4021 if ( index != nsibs ) {
4023 if ( index < nsibs ) {
4024 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4025 /* Siblings need to be renumbered */
4026 if ( index != -1 || !isfrontend )
4030 /* config DB is always "0" */
4031 if ( isconfig && index == -1 ) {
4034 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4038 /* just make index = nsibs */
4040 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4043 if ( ibase ) *ibase = index;
4044 if ( renum ) *renum = renumber;
4049 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4054 co.co_name = &oc->soc_cname;
4055 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4059 /* check for duplicates */
4060 for ( i = 0; i < *nocs; i++ ) {
4061 if ( *copp && (*copp)[i] == cop ) {
4067 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4068 if ( tmp == NULL ) {
4072 (*copp)[*nocs] = cop;
4077 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4078 if ( count_oc( *sups, copp, nocs ) ) {
4087 count_ocs( Attribute *oc_at, int *nocs )
4090 ConfigOCs **colst = NULL;
4094 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4098 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4100 assert( oc != NULL );
4101 if ( count_oc( oc, &colst, nocs ) ) {
4111 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4113 /* Leftover from RE23. Never parse this entry */
4114 return LDAP_COMPARE_TRUE;
4118 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4122 /* This entry is hardcoded, don't re-parse it */
4123 if ( p->ce_type == Cft_Global ) {
4124 cfn = p->ce_private;
4125 ca->ca_private = cfn;
4126 return LDAP_COMPARE_TRUE;
4128 if ( p->ce_type != Cft_Schema )
4129 return LDAP_CONSTRAINT_VIOLATION;
4131 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4132 ca->ca_private = cfn;
4133 cfo = p->ce_private;
4134 cfn->c_sibs = cfo->c_kids;
4136 return LDAP_SUCCESS;
4140 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4142 if ( p->ce_type != Cft_Global ) {
4143 return LDAP_CONSTRAINT_VIOLATION;
4145 /* config must be {0}, nothing else allowed */
4146 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4147 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4148 return LDAP_CONSTRAINT_VIOLATION;
4150 ca->be = frontendDB; /* just to get past check_vals */
4151 return LDAP_SUCCESS;
4155 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4157 if ( p->ce_type != Cft_Global ) {
4158 return LDAP_CONSTRAINT_VIOLATION;
4160 return LDAP_SUCCESS;
4164 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4166 if ( p->ce_type != Cft_Global ) {
4167 return LDAP_CONSTRAINT_VIOLATION;
4169 return LDAP_SUCCESS;
4173 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4175 if ( p->ce_type != Cft_Database ) {
4176 return LDAP_CONSTRAINT_VIOLATION;
4179 return LDAP_SUCCESS;
4183 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4188 AttributeDescription *ad;
4193 if ( cfn->c_cr_head ) {
4194 struct berval bv = BER_BVC("olcDitContentRules");
4196 slap_bv2ad( &bv, &ad, &text );
4197 ct = config_find_table( colst, nocs, ad, ca );
4198 config_del_vals( ct, ca );
4200 if ( cfn->c_oc_head ) {
4201 struct berval bv = BER_BVC("olcObjectClasses");
4203 slap_bv2ad( &bv, &ad, &text );
4204 ct = config_find_table( colst, nocs, ad, ca );
4205 config_del_vals( ct, ca );
4207 if ( cfn->c_at_head ) {
4208 struct berval bv = BER_BVC("olcAttributeTypes");
4210 slap_bv2ad( &bv, &ad, &text );
4211 ct = config_find_table( colst, nocs, ad, ca );
4212 config_del_vals( ct, ca );
4214 if ( cfn->c_syn_head ) {
4215 struct berval bv = BER_BVC("olcLdapSyntaxes");
4217 slap_bv2ad( &bv, &ad, &text );
4218 ct = config_find_table( colst, nocs, ad, ca );
4219 config_del_vals( ct, ca );
4221 if ( cfn->c_om_head ) {
4222 struct berval bv = BER_BVC("olcObjectIdentifier");
4224 slap_bv2ad( &bv, &ad, &text );
4225 ct = config_find_table( colst, nocs, ad, ca );
4226 config_del_vals( ct, ca );
4228 cfo = p->ce_private;
4229 cfo->c_kids = cfn->c_sibs;
4234 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4236 int rc = LDAP_CONSTRAINT_VIOLATION;
4239 if ( (*cop)->co_ldadd ) {
4240 rc = (*cop)->co_ldadd( last, e, ca );
4241 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4246 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4247 ConfigOCs co = { 0 };
4249 co.co_name = &(*ocp)->soc_cname;
4250 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4251 if ( *cop == NULL ) {
4255 rc = config_add_oc( cop, last, e, ca );
4256 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4264 /* Parse an LDAP entry into config directives */
4266 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4267 int *renum, Operation *op )
4269 CfEntryInfo *ce, *last = NULL;
4270 ConfigOCs co, *coptr, **colst;
4271 Attribute *a, *oc_at, *soc_at;
4272 int i, ibase = -1, nocs, rc = 0;
4275 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4277 memset( ca, 0, sizeof(ConfigArgs));
4279 /* Make sure parent exists and entry does not. But allow
4280 * Databases and Overlays to be inserted. Don't do any
4281 * auto-renumbering if manageDSAit control is present.
4283 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4285 if ( ( op && op->o_managedsait ) ||
4286 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4287 ce->ce_type != Cft_Module ) )
4289 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4290 "DN=\"%s\" already exists\n",
4291 log_prefix, e->e_name.bv_val, 0 );
4292 return LDAP_ALREADY_EXISTS;
4296 dnParent( &e->e_nname, &pdn );
4298 /* If last is NULL, the new entry is the root/suffix entry,
4299 * otherwise last should be the parent.
4301 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4303 rs->sr_matched = last->ce_entry->e_name.bv_val;
4305 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4306 "DN=\"%s\" not child of DN=\"%s\"\n",
4307 log_prefix, e->e_name.bv_val,
4308 last->ce_entry->e_name.bv_val );
4309 return LDAP_NO_SUCH_OBJECT;
4313 /* No parent, must be root. This will never happen... */
4314 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4315 return LDAP_NO_SUCH_OBJECT;
4318 if ( last && !access_allowed( op, last->ce_entry,
4319 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4321 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4322 "DN=\"%s\" no write access to \"children\" of parent\n",
4323 log_prefix, e->e_name.bv_val, 0 );
4324 return LDAP_INSUFFICIENT_ACCESS;
4328 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4330 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4331 "DN=\"%s\" no objectClass\n",
4332 log_prefix, e->e_name.bv_val, 0 );
4333 return LDAP_OBJECT_CLASS_VIOLATION;
4336 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4338 ObjectClass *soc = NULL;
4339 char textbuf[ SLAP_TEXT_BUFLEN ];
4340 const char *text = textbuf;
4342 /* FIXME: check result */
4343 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4344 &text, textbuf, sizeof(textbuf), NULL );
4345 if ( rc != LDAP_SUCCESS ) {
4346 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4347 "DN=\"%s\" no structural objectClass (%s)\n",
4348 log_prefix, e->e_name.bv_val, text );
4351 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4352 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4353 if ( soc_at == NULL ) {
4354 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4355 "DN=\"%s\" no structural objectClass; "
4356 "unable to merge computed class %s\n",
4357 log_prefix, e->e_name.bv_val,
4358 soc->soc_cname.bv_val );
4359 return LDAP_OBJECT_CLASS_VIOLATION;
4362 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4363 "DN=\"%s\" no structural objectClass; "
4364 "computed objectClass %s merged\n",
4365 log_prefix, e->e_name.bv_val,
4366 soc->soc_cname.bv_val );
4369 /* Fake the coordinates based on whether we're part of an
4370 * LDAP Add or if reading the config dir
4373 ca->fname = "slapd";
4376 ca->fname = cfdir.bv_val;
4381 co.co_name = &soc_at->a_nvals[0];
4382 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4383 if ( coptr == NULL ) {
4384 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4385 "DN=\"%s\" no structural objectClass in configuration table\n",
4386 log_prefix, e->e_name.bv_val, 0 );
4387 return LDAP_OBJECT_CLASS_VIOLATION;
4390 /* Only the root can be Cft_Global, everything else must
4391 * have a parent. Only limited nesting arrangements are allowed.
4393 rc = LDAP_CONSTRAINT_VIOLATION;
4394 if ( coptr->co_type == Cft_Global && !last ) {
4395 cfn = cfb->cb_config;
4396 ca->ca_private = cfn;
4397 ca->be = frontendDB; /* just to get past check_vals */
4401 colst = count_ocs( oc_at, &nocs );
4403 /* Check whether the Add is allowed by its parent, and do
4404 * any necessary arg setup
4407 rc = config_add_oc( &coptr, last, e, ca );
4408 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4409 for ( i = 0; i<nocs; i++ ) {
4410 /* Already checked these */
4411 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4413 if ( colst[i]->co_ldadd &&
4414 ( rc = colst[i]->co_ldadd( last, e, ca ))
4415 != LDAP_CONSTRAINT_VIOLATION ) {
4421 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4422 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4423 "DN=\"%s\" no structural objectClass add function\n",
4424 log_prefix, e->e_name.bv_val, 0 );
4425 return LDAP_OBJECT_CLASS_VIOLATION;
4429 /* Add the entry but don't parse it, we already have its contents */
4430 if ( rc == LDAP_COMPARE_TRUE ) {
4435 if ( rc != LDAP_SUCCESS )
4438 /* Parse all the values and check for simple syntax errors before
4439 * performing any set actions.
4441 * If doing an LDAPadd, check for indexed names and any necessary
4442 * renaming/renumbering. Entries that don't need indexed names are
4443 * ignored. Entries that need an indexed name and arrive without one
4444 * are assigned to the end. Entries that arrive with an index may
4445 * cause the following entries to be renumbered/bumped down.
4447 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4448 * don't allow Adding an entry with an index that's already in use.
4449 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4451 * These entries can have auto-assigned indexes (appended to the end)
4452 * but only the other types support auto-renumbering of siblings.
4455 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4460 if ( renum && *renum && coptr->co_type != Cft_Database &&
4461 coptr->co_type != Cft_Overlay )
4463 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4464 "operation requires sibling renumbering" );
4465 rc = LDAP_UNWILLING_TO_PERFORM;
4470 init_config_argv( ca );
4472 /* Make sure we process attrs in the required order */
4473 sort_attrs( e, colst, nocs );
4475 for ( a = e->e_attrs; a; a = a->a_next ) {
4476 if ( a == oc_at ) continue;
4477 ct = config_find_table( colst, nocs, a->a_desc, ca );
4478 if ( !ct ) continue; /* user data? */
4479 rc = check_vals( ct, ca, a, 1 );
4480 if ( rc ) goto done_noop;
4483 /* Basic syntax checks are OK. Do the actual settings. */
4484 for ( a=e->e_attrs; a; a=a->a_next ) {
4485 if ( a == oc_at ) continue;
4486 ct = config_find_table( colst, nocs, a->a_desc, ca );
4487 if ( !ct ) continue; /* user data? */
4488 for (i=0; a->a_vals[i].bv_val; i++) {
4491 ca->line = a->a_vals[i].bv_val;
4492 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4493 ptr = strchr( ca->line, '}' );
4495 iptr = strchr( ca->line, '{' );
4499 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4501 ca->valx = strtol( iptr+1, NULL, 0 );
4506 rc = config_parse_add( ct, ca, i );
4514 /* Newly added databases and overlays need to be started up */
4515 if ( CONFIG_ONLINE_ADD( ca )) {
4516 if ( colst[0]->co_type == Cft_Database ) {
4517 rc = backend_startup_one( ca->be, &ca->reply );
4519 } else if ( colst[0]->co_type == Cft_Overlay ) {
4520 if ( ca->bi->bi_db_open ) {
4521 BackendInfo *bi_orig = ca->be->bd_info;
4522 ca->be->bd_info = ca->bi;
4523 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4524 ca->be->bd_info = bi_orig;
4526 } else if ( ca->cleanup ) {
4527 rc = ca->cleanup( ca );
4530 if (ca->cr_msg[0] == '\0')
4531 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4533 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4534 ca->log, ca->cr_msg, ca->argv[1] );
4541 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4542 ce->ce_parent = last;
4543 ce->ce_entry = entry_dup( e );
4544 ce->ce_entry->e_private = ce;
4545 ce->ce_type = colst[0]->co_type;
4548 ce->ce_private = ca->ca_private;
4549 ca->ca_entry = ce->ce_entry;
4552 } else if ( last->ce_kids ) {
4553 CfEntryInfo *c2, **cprev;
4555 /* Advance to first of this type */
4556 cprev = &last->ce_kids;
4557 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4558 cprev = &c2->ce_sibs;
4561 /* Account for the (-1) frontendDB entry */
4562 if ( ce->ce_type == Cft_Database ) {
4563 if ( ca->be == frontendDB )
4565 else if ( ibase != -1 )
4570 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4571 cprev = &c2->ce_sibs;
4577 for ( i=0; i<ibase; i++ ) {
4579 cprev = &c2->ce_sibs;
4582 ce->ce_sibs = *cprev;
4590 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4591 if ( ca->be != frontendDB )
4592 backend_destroy_one( ca->be, 1 );
4593 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4594 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4595 } else if ( colst[0]->co_type == Cft_Schema ) {
4596 schema_destroy_one( ca, colst, nocs, last );
4601 ch_free( ca->argv );
4602 if ( colst ) ch_free( colst );
4606 #define BIGTMP 10000
4608 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4609 int base, int rebase, int max, int use_ldif )
4611 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4612 ConfigType etype = ce->ce_type;
4613 int count = 0, rc = 0;
4615 /* Reverse ce list */
4616 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4617 if (ce2->ce_type != etype) {
4622 ce2->ce_sibs = cetmp;
4625 if ( max && count >= max ) {
4631 /* Move original to a temp name until increments are done */
4633 ce->ce_entry->e_private = NULL;
4634 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4635 base+BIGTMP, 0, use_ldif );
4636 ce->ce_entry->e_private = ce;
4638 /* start incrementing */
4639 for (ce2=cetmp; ce2; ce2=ce3) {
4641 ce2->ce_sibs = cerem;
4644 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4645 count+base, 0, use_ldif );
4649 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4650 base, 0, use_ldif );
4655 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4656 CfEntryInfo *ce2, int old, int use_ldif )
4660 /* Renumber original to a temp value */
4661 ce->ce_entry->e_private = NULL;
4662 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4663 old+BIGTMP, 0, use_ldif );
4664 ce->ce_entry->e_private = ce;
4666 /* start decrementing */
4667 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4668 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4669 count+old, 0, use_ldif );
4672 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4673 count+old, 0, use_ldif );
4676 /* Parse an LDAP entry into config directives, then store in underlying
4680 config_back_add( Operation *op, SlapReply *rs )
4686 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4687 NULL, ACL_WADD, NULL )) {
4688 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4693 * Check for attribute ACL
4695 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
4696 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4697 rs->sr_text = "no write access to attribute";
4701 cfb = (CfBackInfo *)op->o_bd->be_private;
4703 /* add opattrs for syncprov */
4705 char textbuf[SLAP_TEXT_BUFLEN];
4706 size_t textlen = sizeof textbuf;
4707 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
4708 &rs->sr_text, textbuf, sizeof( textbuf ) );
4709 if ( rs->sr_err != LDAP_SUCCESS )
4711 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4712 if ( rs->sr_err != LDAP_SUCCESS ) {
4713 Debug( LDAP_DEBUG_TRACE,
4714 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4715 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4720 ldap_pvt_thread_pool_pause( &connection_pool );
4723 * 1) check for existence of entry
4724 * 2) check for sibling renumbering
4725 * 3) perform internal add
4726 * 4) perform any necessary renumbering
4727 * 5) store entry in underlying database
4729 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4730 if ( rs->sr_err != LDAP_SUCCESS ) {
4731 rs->sr_text = ca.cr_msg;
4736 CfEntryInfo *ce = ca.ca_entry->e_private;
4737 req_add_s addr = op->oq_add;
4738 op->o_tag = LDAP_REQ_MODRDN;
4739 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4740 op->o_tag = LDAP_REQ_ADD;
4742 if ( rs->sr_err != LDAP_SUCCESS ) {
4747 if ( cfb->cb_use_ldif ) {
4748 BackendDB *be = op->o_bd;
4749 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4750 struct berval dn, ndn;
4752 op->o_bd = &cfb->cb_db;
4754 /* Save current rootdn; use the underlying DB's rootdn */
4757 op->o_dn = op->o_bd->be_rootdn;
4758 op->o_ndn = op->o_bd->be_rootndn;
4760 scp = op->o_callback;
4761 op->o_callback = ≻
4762 op->o_bd->be_add( op, rs );
4764 op->o_callback = scp;
4770 ldap_pvt_thread_pool_resume( &connection_pool );
4773 send_ldap_result( op, rs );
4774 slap_graduate_commit_csn( op );
4778 typedef struct delrec {
4779 struct delrec *next;
4785 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4791 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4792 ca->line[0] == '{' )
4794 char *ptr = strchr( ca->line + 1, '}' );
4798 ca->valx = strtol( ca->line + 1, &next, 0 );
4799 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4805 rc = config_parse_add( ct, ca, i );
4813 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4816 int rc = LDAP_UNWILLING_TO_PERFORM;
4818 Entry *e = ce->ce_entry;
4819 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4824 delrec *dels = NULL, *deltail = NULL;
4826 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4827 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4829 colst = count_ocs( oc_at, &nocs );
4831 /* make sure add/del flags are clear; should always be true */
4832 for ( s = save_attrs; s; s = s->a_next ) {
4833 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4836 e->e_attrs = attrs_dup( e->e_attrs );
4838 init_config_argv( ca );
4841 ca->ca_private = ce->ce_private;
4843 ca->fname = "slapd";
4845 strcpy( ca->log, "back-config" );
4847 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4848 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4849 switch (ml->sml_op) {
4850 case LDAP_MOD_DELETE:
4851 case LDAP_MOD_REPLACE: {
4852 BerVarray vals = NULL, nvals = NULL;
4854 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4856 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4857 ml->sml_desc->ad_cname.bv_val );
4860 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4861 vals = ml->sml_values;
4862 nvals = ml->sml_nvalues;
4863 ml->sml_values = NULL;
4864 ml->sml_nvalues = NULL;
4866 /* If we're deleting by values, remember the indexes of the
4867 * values we deleted.
4869 if ( ct && ml->sml_values ) {
4871 i = ml->sml_numvals;
4872 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4883 rc = modify_delete_vindex(e, &ml->sml_mod,
4884 get_permissiveModify(op),
4885 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4886 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4887 ml->sml_values = vals;
4888 ml->sml_nvalues = nvals;
4893 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4896 case SLAP_MOD_SOFTADD: {
4897 int mop = ml->sml_op;
4899 ml->sml_op = LDAP_MOD_ADD;
4901 if ( ct->arg_type & ARG_NO_INSERT ) {
4902 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4904 navals = a->a_numvals;
4907 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4908 if ( ml->sml_values[i].bv_val[0] == '{' &&
4911 char *next, *val = ml->sml_values[i].bv_val + 1;
4914 j = strtol( val, &next, 0 );
4915 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4917 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4918 ml->sml_desc->ad_cname.bv_val );
4922 rc = check_vals( ct, ca, ml, 0 );
4923 if ( rc ) goto out_noop;
4926 rc = modify_add_values(e, &ml->sml_mod,
4927 get_permissiveModify(op),
4928 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4930 /* If value already exists, show success here
4931 * and ignore this operation down below.
4933 if ( mop == SLAP_MOD_SOFTADD ) {
4934 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4944 case LDAP_MOD_INCREMENT: /* FIXME */
4949 if(rc != LDAP_SUCCESS) break;
4952 if ( rc == LDAP_SUCCESS) {
4953 /* check that the entry still obeys the schema */
4954 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
4955 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4957 if ( rc ) goto out_noop;
4959 /* Basic syntax checks are OK. Do the actual settings. */
4960 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4961 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4962 if ( !ct ) continue;
4964 s = attr_find( save_attrs, ml->sml_desc );
4965 a = attr_find( e->e_attrs, ml->sml_desc );
4967 switch (ml->sml_op) {
4968 case LDAP_MOD_DELETE:
4969 case LDAP_MOD_REPLACE: {
4970 BerVarray vals = NULL, nvals = NULL;
4973 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4974 vals = ml->sml_values;
4975 nvals = ml->sml_nvalues;
4976 ml->sml_values = NULL;
4977 ml->sml_nvalues = NULL;
4980 if ( ml->sml_values )
4983 /* If we didn't delete the whole attribute */
4984 if ( ml->sml_values && a ) {
4985 struct berval *mvals;
4988 if ( ml->sml_nvalues )
4989 mvals = ml->sml_nvalues;
4991 mvals = ml->sml_values;
4993 /* use the indexes we saved up above */
4994 for (i=0; i < d->nidx; i++) {
4995 struct berval bv = *mvals++;
4996 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4997 bv.bv_val[0] == '{' ) {
4998 ptr = strchr( bv.bv_val, '}' ) + 1;
4999 bv.bv_len -= ptr - bv.bv_val;
5002 ca->line = bv.bv_val;
5003 ca->valx = d->idx[i];
5004 rc = config_del_vals( ct, ca );
5005 if ( rc != LDAP_SUCCESS ) break;
5007 s->a_flags |= SLAP_ATTR_IXDEL;
5008 for (j=i+1; j < d->nidx; j++)
5009 if ( d->idx[j] >d->idx[i] )
5015 rc = config_del_vals( ct, ca );
5016 if ( rc ) rc = LDAP_OTHER;
5018 s->a_flags |= SLAP_ATTR_IXDEL;
5020 if ( ml->sml_values ) {
5025 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5026 ml->sml_values = vals;
5027 ml->sml_nvalues = nvals;
5029 if ( !vals || rc != LDAP_SUCCESS )
5032 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5035 for (i=0; ml->sml_values[i].bv_val; i++) {
5036 ca->line = ml->sml_values[i].bv_val;
5038 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5041 a->a_flags |= SLAP_ATTR_IXADD;
5048 /* Undo for a failed operation */
5049 if ( rc != LDAP_SUCCESS ) {
5050 ConfigReply msg = ca->reply;
5051 for ( s = save_attrs; s; s = s->a_next ) {
5052 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5053 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5054 ct = config_find_table( colst, nocs, s->a_desc, ca );
5055 a = attr_find( e->e_attrs, s->a_desc );
5057 /* clear the flag so the add check below will skip it */
5058 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5061 config_del_vals( ct, ca );
5063 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5064 ca->line = s->a_vals[i].bv_val;
5066 config_modify_add( ct, ca, s->a_desc, i );
5070 for ( a = e->e_attrs; a; a = a->a_next ) {
5071 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5072 ct = config_find_table( colst, nocs, a->a_desc, ca );
5075 config_del_vals( ct, ca );
5076 s = attr_find( save_attrs, a->a_desc );
5078 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5079 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5080 ca->line = s->a_vals[i].bv_val;
5082 config_modify_add( ct, ca, s->a_desc, i );
5093 if ( rc == LDAP_SUCCESS ) {
5094 attrs_free( save_attrs );
5096 attrs_free( e->e_attrs );
5097 e->e_attrs = save_attrs;
5099 ch_free( ca->argv );
5100 if ( colst ) ch_free( colst );
5102 deltail = dels->next;
5111 config_back_modify( Operation *op, SlapReply *rs )
5114 CfEntryInfo *ce, *last;
5116 ConfigArgs ca = {0};
5119 AttributeDescription *rad = NULL;
5122 cfb = (CfBackInfo *)op->o_bd->be_private;
5124 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5127 rs->sr_matched = last->ce_entry->e_name.bv_val;
5128 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5132 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5133 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5137 /* Get type of RDN */
5138 rdn = ce->ce_entry->e_nname;
5139 ptr = strchr( rdn.bv_val, '=' );
5140 rdn.bv_len = ptr - rdn.bv_val;
5141 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5143 /* Some basic validation... */
5144 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5145 /* Don't allow Modify of RDN; must use ModRdn for that. */
5146 if ( ml->sml_desc == rad ) {
5147 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5148 rs->sr_text = "Use modrdn to change the entry name";
5151 /* Internal update of contextCSN? */
5152 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5158 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5161 ldap_pvt_thread_pool_pause( &connection_pool );
5164 * 1) perform the Modify on the cached Entry.
5165 * 2) verify that the Entry still satisfies the schema.
5166 * 3) perform the individual config operations.
5167 * 4) store Modified entry in underlying LDIF backend.
5169 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5171 rs->sr_text = ca.cr_msg;
5172 } else if ( cfb->cb_use_ldif ) {
5173 BackendDB *be = op->o_bd;
5174 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5175 struct berval dn, ndn;
5177 op->o_bd = &cfb->cb_db;
5181 op->o_dn = op->o_bd->be_rootdn;
5182 op->o_ndn = op->o_bd->be_rootndn;
5184 scp = op->o_callback;
5185 op->o_callback = ≻
5186 op->o_bd->be_modify( op, rs );
5188 op->o_callback = scp;
5194 ldap_pvt_thread_pool_resume( &connection_pool );
5196 send_ldap_result( op, rs );
5197 slap_graduate_commit_csn( op );
5202 config_back_modrdn( Operation *op, SlapReply *rs )
5205 CfEntryInfo *ce, *last;
5209 cfb = (CfBackInfo *)op->o_bd->be_private;
5211 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5214 rs->sr_matched = last->ce_entry->e_name.bv_val;
5215 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5218 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5219 NULL, ACL_WRITE, NULL )) {
5220 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5224 if ( ce->ce_parent )
5225 parent = ce->ce_parent->ce_entry;
5227 parent = (Entry *)&slap_entry_root;
5228 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5229 NULL, ACL_WRITE, NULL )) {
5230 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5235 /* We don't allow moving objects to new parents.
5236 * Generally we only allow reordering a set of ordered entries.
5238 if ( op->orr_newSup ) {
5239 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5243 /* If newRDN == oldRDN, quietly succeed */
5244 dnRdn( &op->o_req_ndn, &rdn );
5245 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5246 rs->sr_err = LDAP_SUCCESS;
5250 /* Current behavior, subject to change as needed:
5252 * For backends and overlays, we only allow renumbering.
5253 * For schema, we allow renaming with the same number.
5254 * Otherwise, the op is not allowed.
5257 if ( ce->ce_type == Cft_Schema ) {
5261 /* Can't alter the main cn=schema entry */
5262 if ( ce->ce_parent->ce_type == Cft_Global ) {
5263 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5264 rs->sr_text = "renaming not allowed for this entry";
5268 /* We could support this later if desired */
5269 ptr1 = ber_bvchr( &rdn, '}' );
5270 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5271 len = ptr1 - rdn.bv_val;
5272 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5273 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5274 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5275 rs->sr_text = "schema reordering not supported";
5278 } else if ( ce->ce_type == Cft_Database ||
5279 ce->ce_type == Cft_Overlay ) {
5280 char *ptr1, *ptr2, *iptr1, *iptr2;
5283 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5284 if ( *iptr2 != '{' ) {
5285 rs->sr_err = LDAP_NAMING_VIOLATION;
5286 rs->sr_text = "new ordering index is required";
5290 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5291 ptr1 = ber_bvchr( &rdn, '}' );
5292 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5294 rs->sr_err = LDAP_NAMING_VIOLATION;
5295 rs->sr_text = "new ordering index is required";
5299 len1 = ptr1 - rdn.bv_val;
5300 len2 = ptr2 - op->orr_newrdn.bv_val;
5302 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5303 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5304 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5305 rs->sr_text = "changing database/overlay type not allowed";
5308 ixold = strtol( iptr1, NULL, 0 );
5309 ixnew = strtol( iptr2, &ptr1, 0 );
5310 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5311 rs->sr_err = LDAP_NAMING_VIOLATION;
5314 /* config DB is always 0, cannot be changed */
5315 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5316 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5320 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5321 rs->sr_text = "renaming not supported for this entry";
5325 ldap_pvt_thread_pool_pause( &connection_pool );
5327 if ( ce->ce_type == Cft_Schema ) {
5328 req_modrdn_s modr = op->oq_modrdn;
5331 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5332 if ( rs->sr_err == LDAP_SUCCESS ) {
5333 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5334 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5337 op->oq_modrdn = modr;
5339 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5340 req_modrdn_s modr = op->oq_modrdn;
5343 /* Advance to first of this type */
5344 cprev = &ce->ce_parent->ce_kids;
5345 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5346 cprev = &ce2->ce_sibs;
5349 /* Skip the -1 entry */
5350 if ( ce->ce_type == Cft_Database ) {
5351 cprev = &ce2->ce_sibs;
5357 /* Remove from old slot */
5358 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5359 cprev = &ce2->ce_sibs;
5360 *cprev = ce->ce_sibs;
5361 ceold = ce->ce_sibs;
5363 /* Insert into new slot */
5365 for ( i=0; i<ixnew; i++ ) {
5369 cprev = &ce2->ce_sibs;
5371 ce->ce_sibs = *cprev;
5376 /* NOTE: These should be encoded in the OC tables, not inline here */
5377 if ( ce->ce_type == Cft_Database )
5378 backend_db_move( ce->ce_be, ixnew );
5379 else if ( ce->ce_type == Cft_Overlay )
5380 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5382 if ( ixold < ixnew ) {
5383 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5386 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5387 ixold - ixnew, cfb->cb_use_ldif );
5389 op->oq_modrdn = modr;
5392 ldap_pvt_thread_pool_resume( &connection_pool );
5394 send_ldap_result( op, rs );
5399 config_back_delete( Operation *op, SlapReply *rs )
5401 #ifdef SLAP_CONFIG_DELETE
5403 CfEntryInfo *ce, *last, *ce2;
5405 cfb = (CfBackInfo *)op->o_bd->be_private;
5407 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5410 rs->sr_matched = last->ce_entry->e_name.bv_val;
5411 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5412 } else if ( ce->ce_kids ) {
5413 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5414 } else if ( ce->ce_type == Cft_Overlay ){
5418 ldap_pvt_thread_pool_pause( &connection_pool );
5420 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5422 /* remove CfEntryInfo from the siblings list */
5423 if ( ce->ce_parent->ce_kids == ce ) {
5424 ce->ce_parent->ce_kids = ce->ce_sibs;
5426 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5427 if ( ce2->ce_sibs == ce ) {
5428 ce2->ce_sibs = ce->ce_sibs;
5434 /* remove from underlying database */
5435 if ( cfb->cb_use_ldif ) {
5436 BackendDB *be = op->o_bd;
5437 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5438 struct berval dn, ndn, req_dn, req_ndn;
5440 op->o_bd = &cfb->cb_db;
5444 req_dn = op->o_req_dn;
5445 req_ndn = op->o_req_ndn;
5447 op->o_dn = op->o_bd->be_rootdn;
5448 op->o_ndn = op->o_bd->be_rootndn;
5449 op->o_req_dn = ce->ce_entry->e_name;
5450 op->o_req_ndn = ce->ce_entry->e_nname;
5452 scp = op->o_callback;
5453 op->o_callback = ≻
5454 op->o_bd->be_delete( op, rs );
5456 op->o_callback = scp;
5459 op->o_req_dn = req_dn;
5460 op->o_req_ndn = req_ndn;
5463 /* renumber siblings */
5464 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5465 ixold = strtol( iptr, NULL, 0 );
5466 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5467 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5468 count+ixold, 0, cfb->cb_use_ldif );
5472 ce->ce_entry->e_private=NULL;
5473 entry_free(ce->ce_entry);
5475 ldap_pvt_thread_pool_resume( &connection_pool );
5477 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5480 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5481 #endif /* SLAP_CONFIG_DELETE */
5482 send_ldap_result( op, rs );
5487 config_back_search( Operation *op, SlapReply *rs )
5490 CfEntryInfo *ce, *last;
5493 cfb = (CfBackInfo *)op->o_bd->be_private;
5495 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5498 rs->sr_matched = last->ce_entry->e_name.bv_val;
5499 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5502 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5503 ACL_SEARCH, NULL, &mask ))
5505 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5506 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5508 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5512 switch ( op->ors_scope ) {
5513 case LDAP_SCOPE_BASE:
5514 case LDAP_SCOPE_SUBTREE:
5515 rs->sr_err = config_send( op, rs, ce, 0 );
5518 case LDAP_SCOPE_ONELEVEL:
5519 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5520 rs->sr_err = config_send( op, rs, ce, 1 );
5529 send_ldap_result( op, rs );
5533 /* no-op, we never free entries */
5534 int config_entry_release(
5539 if ( !e->e_private ) {
5542 return LDAP_SUCCESS;
5545 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5547 int config_back_entry_get(
5551 AttributeDescription *at,
5556 CfEntryInfo *ce, *last;
5557 int rc = LDAP_NO_SUCH_OBJECT;
5559 cfb = (CfBackInfo *)op->o_bd->be_private;
5561 ce = config_find_base( cfb->cb_root, ndn, &last );
5563 *ent = ce->ce_entry;
5566 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5567 rc = LDAP_NO_SUCH_ATTRIBUTE;
5577 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5578 ConfigTable *ct, ConfigArgs *c )
5582 for (; at && *at; at++) {
5583 /* Skip the naming attr */
5584 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5586 for (i=0;ct[i].name;i++) {
5587 if (ct[i].ad == (*at)->sat_ad) {
5588 rc = config_get_vals(&ct[i], c);
5589 /* NOTE: tolerate that config_get_vals()
5590 * returns success with no values */
5591 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5592 if ( c->rvalue_nvals )
5593 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
5596 slap_syntax_validate_func *validate =
5597 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
5600 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
5601 rc = ordered_value_validate( ct[i].ad,
5602 &c->rvalue_vals[j], LDAP_MOD_ADD );
5604 Debug( LDAP_DEBUG_ANY,
5605 "config_build_attrs: error %d on %s value #%d\n",
5606 rc, ct[i].ad->ad_cname.bv_val, j );
5612 rc = attr_merge_normalize(e, ct[i].ad,
5613 c->rvalue_vals, NULL);
5615 ber_bvarray_free( c->rvalue_nvals );
5616 ber_bvarray_free( c->rvalue_vals );
5618 Debug( LDAP_DEBUG_ANY,
5619 "config_build_attrs: error %d on %s\n",
5620 rc, ct[i].ad->ad_cname.bv_val, 0 );
5632 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5633 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5635 Entry *e = entry_alloc();
5636 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5638 struct berval ad_name;
5639 AttributeDescription *ad = NULL;
5642 const char *text = "";
5646 CfEntryInfo *ceprev = NULL;
5648 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5651 ce->ce_type = main->co_type;
5652 ce->ce_parent = parent;
5654 pdn = parent->ce_entry->e_nname;
5655 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5656 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5657 ceprev->ce_type <= ce->ce_type;
5658 ceprev = ceprev->ce_sibs );
5663 ce->ce_private = c->ca_private;
5667 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5668 ber_dupbv( &e->e_nname, &e->e_name );
5670 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5671 main->co_name, NULL );
5673 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5674 extra->co_name, NULL );
5675 ptr = strchr(rdn->bv_val, '=');
5676 ad_name.bv_val = rdn->bv_val;
5677 ad_name.bv_len = ptr - rdn->bv_val;
5678 rc = slap_bv2ad( &ad_name, &ad, &text );
5683 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5684 attr_merge_normalize_one(e, ad, &val, NULL );
5687 c->table = main->co_type;
5688 if ( oc->soc_required ) {
5689 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5690 if ( rc ) goto fail;
5693 if ( oc->soc_allowed ) {
5694 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5695 if ( rc ) goto fail;
5700 c->table = extra->co_type;
5701 if ( oc->soc_required ) {
5702 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5703 if ( rc ) goto fail;
5706 if ( oc->soc_allowed ) {
5707 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5708 if ( rc ) goto fail;
5712 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5713 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5714 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5715 if ( rc != LDAP_SUCCESS ) {
5717 Debug( LDAP_DEBUG_ANY,
5718 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5719 rdn->bv_val, text, 0);
5722 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5725 op->ora_modlist = NULL;
5726 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5727 if ( !op->o_noop ) {
5728 op->o_bd->be_add( op, rs );
5729 if ( ( rs->sr_err != LDAP_SUCCESS )
5730 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5736 ce->ce_sibs = ceprev->ce_sibs;
5737 ceprev->ce_sibs = ce;
5738 } else if ( parent ) {
5739 ce->ce_sibs = parent->ce_kids;
5740 parent->ce_kids = ce;
5747 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5748 Operation *op, SlapReply *rs )
5751 ConfigFile *cf = c->ca_private;
5753 struct berval bv, rdn;
5755 for (; cf; cf=cf->c_sibs, c->depth++) {
5756 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5757 !cf->c_om_head && !cf->c_syn_head ) continue;
5758 c->value_dn.bv_val = c->log;
5759 LUTIL_SLASHPATH( cf->c_file.bv_val );
5760 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5765 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5767 ptr = strchr( bv.bv_val, '.' );
5769 bv.bv_len = ptr - bv.bv_val;
5770 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5771 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5772 /* FIXME: how can indicate error? */
5775 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5777 c->value_dn.bv_len += bv.bv_len;
5778 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5782 e = config_build_entry( op, rs, ceparent, c, &rdn,
5783 &CFOC_SCHEMA, NULL );
5786 } else if ( e && cf->c_kids ) {
5787 c->ca_private = cf->c_kids;
5788 config_build_schema_inc( c, e->e_private, op, rs );
5794 #ifdef SLAPD_MODULES
5797 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5798 Operation *op, SlapReply *rs )
5803 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5804 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5806 c->value_dn.bv_val = c->log;
5807 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5808 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5809 /* FIXME: how can indicate error? */
5813 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5822 config_check_schema(Operation *op, CfBackInfo *cfb)
5824 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5826 CfEntryInfo *ce, *last;
5829 /* If there's no root entry, we must be in the midst of converting */
5830 if ( !cfb->cb_root )
5833 /* Make sure the main schema entry exists */
5834 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5841 /* Make sure it's up to date */
5842 if ( cf_om_tail != om_sys_tail ) {
5843 a = attr_find( e->e_attrs, cfAd_om );
5845 if ( a->a_nvals != a->a_vals )
5846 ber_bvarray_free( a->a_nvals );
5847 ber_bvarray_free( a->a_vals );
5852 oidm_unparse( &bv, NULL, NULL, 1 );
5853 attr_merge_normalize( e, cfAd_om, bv, NULL );
5854 ber_bvarray_free( bv );
5855 cf_om_tail = om_sys_tail;
5857 if ( cf_at_tail != at_sys_tail ) {
5858 a = attr_find( e->e_attrs, cfAd_attr );
5860 if ( a->a_nvals != a->a_vals )
5861 ber_bvarray_free( a->a_nvals );
5862 ber_bvarray_free( a->a_vals );
5867 at_unparse( &bv, NULL, NULL, 1 );
5868 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5869 ber_bvarray_free( bv );
5870 cf_at_tail = at_sys_tail;
5872 if ( cf_oc_tail != oc_sys_tail ) {
5873 a = attr_find( e->e_attrs, cfAd_oc );
5875 if ( a->a_nvals != a->a_vals )
5876 ber_bvarray_free( a->a_nvals );
5877 ber_bvarray_free( a->a_vals );
5882 oc_unparse( &bv, NULL, NULL, 1 );
5883 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5884 ber_bvarray_free( bv );
5885 cf_oc_tail = oc_sys_tail;
5887 if ( cf_syn_tail != syn_sys_tail ) {
5888 a = attr_find( e->e_attrs, cfAd_syntax );
5890 if ( a->a_nvals != a->a_vals )
5891 ber_bvarray_free( a->a_nvals );
5892 ber_bvarray_free( a->a_vals );
5897 syn_unparse( &bv, NULL, NULL, 1 );
5898 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
5899 ber_bvarray_free( bv );
5900 cf_syn_tail = syn_sys_tail;
5903 SlapReply rs = {REP_RESULT};
5904 c.ca_private = NULL;
5905 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5906 &CFOC_SCHEMA, NULL );
5911 ce->ce_private = cfb->cb_config;
5912 cf_at_tail = at_sys_tail;
5913 cf_oc_tail = oc_sys_tail;
5914 cf_om_tail = om_sys_tail;
5915 cf_syn_tail = syn_sys_tail;
5920 static const char *defacl[] = {
5921 NULL, "to", "*", "by", "*", "none", NULL
5925 config_back_db_open( BackendDB *be, ConfigReply *cr )
5927 CfBackInfo *cfb = be->be_private;
5930 CfEntryInfo *ce, *ceparent;
5934 Connection conn = {0};
5935 OperationBuffer opbuf;
5937 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5938 SlapReply rs = {REP_RESULT};
5939 void *thrctx = NULL;
5941 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5943 /* If we have no explicitly configured ACLs, don't just use
5944 * the global ACLs. Explicitly deny access to everything.
5946 if ( !be->be_acl ) {
5947 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5950 thrctx = ldap_pvt_thread_pool_context();
5951 connection_fake_init( &conn, &opbuf, thrctx );
5954 op->o_tag = LDAP_REQ_ADD;
5955 op->o_callback = &cb;
5956 op->o_bd = &cfb->cb_db;
5957 op->o_dn = op->o_bd->be_rootdn;
5958 op->o_ndn = op->o_bd->be_rootndn;
5960 if ( !cfb->cb_use_ldif ) {
5964 /* If we read the config from back-ldif, do some quick sanity checks */
5965 if ( cfb->cb_got_ldif ) {
5966 return config_check_schema( op, cfb );
5969 /* create root of tree */
5971 c.ca_private = cfb->cb_config;
5973 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5983 #ifdef SLAPD_MODULES
5984 /* Create Module nodes... */
5985 if ( modpaths.mp_loads ) {
5986 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5992 /* Create schema nodes... cn=schema will contain the hardcoded core
5993 * schema, read-only. Child objects will contain runtime loaded schema
5997 c.ca_private = NULL;
5998 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6003 ce->ce_private = cfb->cb_config;
6004 cf_at_tail = at_sys_tail;
6005 cf_oc_tail = oc_sys_tail;
6006 cf_om_tail = om_sys_tail;
6007 cf_syn_tail = syn_sys_tail;
6009 /* Create schema nodes for included schema... */
6010 if ( cfb->cb_config->c_kids ) {
6012 c.ca_private = cfb->cb_config->c_kids;
6013 if (config_build_schema_inc( &c, ce, op, &rs )) {
6018 /* Create backend nodes. Skip if they don't provide a cf_table.
6019 * There usually aren't any of these.
6023 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6024 if (!bi->bi_cf_ocs) {
6025 /* If it only supports the old config mech, complain. */
6026 if ( bi->bi_config ) {
6027 Debug( LDAP_DEBUG_ANY,
6028 "WARNING: No dynamic config support for backend %s.\n",
6029 bi->bi_type, 0, 0 );
6034 if (!bi->bi_private) continue;
6037 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6038 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6039 if ( rdn.bv_len >= sizeof( c.log ) ) {
6040 /* FIXME: holler ... */ ;
6043 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6050 /* Create database nodes... */
6051 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6052 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6053 for ( i = -1, be = frontendDB ; be;
6054 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6055 slap_overinfo *oi = NULL;
6057 if ( overlay_is_over( be )) {
6058 oi = be->bd_info->bi_private;
6064 /* If this backend supports the old config mechanism, but not
6065 * the new mech, complain.
6067 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6068 Debug( LDAP_DEBUG_ANY,
6069 "WARNING: No dynamic config support for database %s.\n",
6070 bi->bi_type, 0, 0 );
6074 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6075 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6077 if ( rdn.bv_len >= sizeof( c.log ) ) {
6078 /* FIXME: holler ... */ ;
6082 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6088 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6089 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6090 /* Iterate through overlays */
6095 voidList *vl, *v0 = NULL;
6097 /* overlays are in LIFO order, must reverse stack */
6098 for (on=oi->oi_list; on; on=on->on_next) {
6099 vl = ch_malloc( sizeof( voidList ));
6104 for (j=0; vl; j++,vl=v0) {
6108 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6109 Debug( LDAP_DEBUG_ANY,
6110 "WARNING: No dynamic config support for overlay %s.\n",
6111 on->on_bi.bi_type, 0, 0 );
6115 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6116 "%s=" SLAP_X_ORDERED_FMT "%s",
6117 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6118 if ( rdn.bv_len >= sizeof( c.log ) ) {
6119 /* FIXME: holler ... */ ;
6123 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6124 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6128 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6129 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6134 ldap_pvt_thread_pool_context_reset( thrctx );
6136 if ( unsupp && cfb->cb_use_ldif ) {
6137 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6138 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6145 cfb_free_cffile( ConfigFile *cf )
6149 for (; cf; cf=next) {
6152 cfb_free_cffile( cf->c_kids );
6153 ch_free( cf->c_file.bv_val );
6154 ber_bvarray_free( cf->c_dseFiles );
6160 cfb_free_entries( CfEntryInfo *ce )
6164 for (; ce; ce=next) {
6167 cfb_free_entries( ce->ce_kids );
6168 ce->ce_entry->e_private = NULL;
6169 entry_free( ce->ce_entry );
6175 config_back_db_close( BackendDB *be, ConfigReply *cr )
6177 CfBackInfo *cfb = be->be_private;
6179 cfb_free_entries( cfb->cb_root );
6180 cfb->cb_root = NULL;
6182 if ( cfb->cb_db.bd_info ) {
6183 backend_shutdown( &cfb->cb_db );
6190 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6192 CfBackInfo *cfb = be->be_private;
6194 cfb_free_cffile( cfb->cb_config );
6196 ch_free( cfdir.bv_val );
6198 avl_free( CfOcTree, NULL );
6200 if ( cfb->cb_db.bd_info ) {
6201 cfb->cb_db.be_suffix = NULL;
6202 cfb->cb_db.be_nsuffix = NULL;
6203 BER_BVZERO( &cfb->cb_db.be_rootdn );
6204 BER_BVZERO( &cfb->cb_db.be_rootndn );
6206 backend_destroy_one( &cfb->cb_db, 0 );
6215 config_back_db_init( BackendDB *be, ConfigReply* cr )
6221 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6222 cfn = cfb->cb_config;
6223 be->be_private = cfb;
6225 ber_dupbv( &be->be_rootdn, &config_rdn );
6226 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6227 ber_dupbv( &dn, &be->be_rootdn );
6228 ber_bvarray_add( &be->be_suffix, &dn );
6229 ber_dupbv( &dn, &be->be_rootdn );
6230 ber_bvarray_add( &be->be_nsuffix, &dn );
6232 /* Hide from namingContexts */
6233 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6235 /* Check ACLs on content of Adds by default */
6236 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6242 config_back_destroy( BackendInfo *bi )
6244 ldif_must_b64_encode_release();
6249 config_tool_entry_open( BackendDB *be, int mode )
6251 CfBackInfo *cfb = be->be_private;
6252 BackendInfo *bi = cfb->cb_db.bd_info;
6254 if ( bi && bi->bi_tool_entry_open )
6255 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6262 config_tool_entry_close( BackendDB *be )
6264 CfBackInfo *cfb = be->be_private;
6265 BackendInfo *bi = cfb->cb_db.bd_info;
6267 if ( bi && bi->bi_tool_entry_close )
6268 return bi->bi_tool_entry_close( &cfb->cb_db );
6274 config_tool_entry_first( BackendDB *be )
6276 CfBackInfo *cfb = be->be_private;
6277 BackendInfo *bi = cfb->cb_db.bd_info;
6279 if ( bi && bi->bi_tool_entry_first )
6280 return bi->bi_tool_entry_first( &cfb->cb_db );
6286 config_tool_entry_next( BackendDB *be )
6288 CfBackInfo *cfb = be->be_private;
6289 BackendInfo *bi = cfb->cb_db.bd_info;
6291 if ( bi && bi->bi_tool_entry_next )
6292 return bi->bi_tool_entry_next( &cfb->cb_db );
6298 config_tool_entry_get( BackendDB *be, ID id )
6300 CfBackInfo *cfb = be->be_private;
6301 BackendInfo *bi = cfb->cb_db.bd_info;
6303 if ( bi && bi->bi_tool_entry_get )
6304 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6309 static int entry_put_got_frontend=0;
6310 static int entry_put_got_config=0;
6312 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6314 CfBackInfo *cfb = be->be_private;
6315 BackendInfo *bi = cfb->cb_db.bd_info;
6317 struct berval rdn, vals[ 2 ];
6319 OperationBuffer opbuf;
6321 Connection conn = {0};
6322 Operation *op = NULL;
6326 /* Create entry for frontend database if it does not exist already */
6327 if ( !entry_put_got_frontend ) {
6328 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6329 STRLENOF( "olcDatabase" ))) {
6330 if ( strncmp( e->e_nname.bv_val +
6331 STRLENOF( "olcDatabase" ), "={-1}frontend",
6332 STRLENOF( "={-1}frontend" )) &&
6333 strncmp( e->e_nname.bv_val +
6334 STRLENOF( "olcDatabase" ), "=frontend",
6335 STRLENOF( "=frontend" ))) {
6337 vals[1].bv_val = NULL;
6338 memset( &ca, 0, sizeof(ConfigArgs));
6340 ca.bi = frontendDB->bd_info;
6341 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6342 rdn.bv_val = ca.log;
6343 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6344 "%s=" SLAP_X_ORDERED_FMT "%s",
6345 cfAd_database->ad_cname.bv_val, -1,
6347 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6348 &CFOC_DATABASE, ca.be->be_cf_ocs );
6349 thrctx = ldap_pvt_thread_pool_context();
6350 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6352 op->o_bd = &cfb->cb_db;
6353 op->o_tag = LDAP_REQ_ADD;
6355 op->o_dn = be->be_rootdn;
6356 op->o_ndn = be->be_rootndn;
6357 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6358 if ( rc != LDAP_SUCCESS ) {
6359 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6360 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6364 if ( ce && bi && bi->bi_tool_entry_put &&
6365 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6366 entry_put_got_frontend++;
6368 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6369 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6373 entry_put_got_frontend++;
6378 /* Create entry for config database if it does not exist already */
6379 if ( !entry_put_got_config && !isFrontend ) {
6380 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6381 STRLENOF( "olcDatabase" ))) {
6382 if ( strncmp( e->e_nname.bv_val +
6383 STRLENOF( "olcDatabase" ), "={0}config",
6384 STRLENOF( "={0}config" )) &&
6385 strncmp( e->e_nname.bv_val +
6386 STRLENOF( "olcDatabase" ), "=config",
6387 STRLENOF( "=config" )) ) {
6389 vals[1].bv_val = NULL;
6390 memset( &ca, 0, sizeof(ConfigArgs));
6391 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6392 ca.bi = ca.be->bd_info;
6393 rdn.bv_val = ca.log;
6394 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6395 "%s=" SLAP_X_ORDERED_FMT "%s",
6396 cfAd_database->ad_cname.bv_val, 0,
6398 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6401 thrctx = ldap_pvt_thread_pool_context();
6402 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6404 op->o_bd = &cfb->cb_db;
6405 op->o_tag = LDAP_REQ_ADD;
6406 op->o_dn = be->be_rootdn;
6407 op->o_ndn = be->be_rootndn;
6410 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6411 if ( rc != LDAP_SUCCESS ) {
6412 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6413 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6416 if (ce && bi && bi->bi_tool_entry_put &&
6417 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6418 entry_put_got_config++;
6420 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6421 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6425 entry_put_got_config++;
6429 if ( bi && bi->bi_tool_entry_put &&
6430 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6431 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6438 AttributeDescription **desc;
6440 { "attribute", &cfAd_attr },
6441 { "backend", &cfAd_backend },
6442 { "database", &cfAd_database },
6443 { "include", &cfAd_include },
6444 { "ldapsyntax", &cfAd_syntax },
6445 { "objectclass", &cfAd_oc },
6446 { "objectidentifier", &cfAd_om },
6447 { "overlay", &cfAd_overlay },
6452 * add / delete: all types that may be added or deleted must use an
6453 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6454 * should automatically renumber the index of any siblings as needed,
6455 * so that no gaps in the numbering sequence exist after the add/delete
6457 * What can be added:
6459 * backend objects for backend-specific config directives
6463 * delete: probably no support this time around.
6465 * modrdn: generally not done. Will be invoked automatically by add/
6466 * delete to update numbering sequence. Perform as an explicit operation
6467 * so that the renumbering effect may be replicated. Subtree rename must
6468 * be supported, since renumbering a database will affect all its child
6471 * modify: must be fully supported.
6475 config_back_initialize( BackendInfo *bi )
6477 ConfigTable *ct = config_back_cf_table;
6481 AttributeDescription *ad = NULL;
6483 static char *controls[] = {
6484 LDAP_CONTROL_MANAGEDSAIT,
6488 /* Make sure we don't exceed the bits reserved for userland */
6489 config_check_userland( CFG_LAST );
6491 bi->bi_controls = controls;
6496 bi->bi_destroy = config_back_destroy;
6498 bi->bi_db_init = config_back_db_init;
6499 bi->bi_db_config = 0;
6500 bi->bi_db_open = config_back_db_open;
6501 bi->bi_db_close = config_back_db_close;
6502 bi->bi_db_destroy = config_back_db_destroy;
6504 bi->bi_op_bind = config_back_bind;
6505 bi->bi_op_unbind = 0;
6506 bi->bi_op_search = config_back_search;
6507 bi->bi_op_compare = 0;
6508 bi->bi_op_modify = config_back_modify;
6509 bi->bi_op_modrdn = config_back_modrdn;
6510 bi->bi_op_add = config_back_add;
6511 bi->bi_op_delete = config_back_delete;
6512 bi->bi_op_abandon = 0;
6514 bi->bi_extended = 0;
6516 bi->bi_chk_referrals = 0;
6518 bi->bi_access_allowed = slap_access_allowed;
6520 bi->bi_connection_init = 0;
6521 bi->bi_connection_destroy = 0;
6523 bi->bi_entry_release_rw = config_entry_release;
6524 bi->bi_entry_get_rw = config_back_entry_get;
6526 bi->bi_tool_entry_open = config_tool_entry_open;
6527 bi->bi_tool_entry_close = config_tool_entry_close;
6528 bi->bi_tool_entry_first = config_tool_entry_first;
6529 bi->bi_tool_entry_next = config_tool_entry_next;
6530 bi->bi_tool_entry_get = config_tool_entry_get;
6531 bi->bi_tool_entry_put = config_tool_entry_put;
6534 argv[ 0 ] = "slapd";
6540 for (i=0; OidMacros[i].name; i++ ) {
6541 argv[1] = OidMacros[i].name;
6542 argv[2] = OidMacros[i].oid;
6543 parse_oidm( &ca, 0, NULL );
6546 bi->bi_cf_ocs = cf_ocs;
6548 i = config_register_schema( ct, cf_ocs );
6551 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6554 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6555 * basically, we don't care if it fails */
6556 i = slap_str2ad( "olcRootPW", &ad, &text );
6558 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6559 "warning, unable to get \"olcRootPW\" "
6560 "attribute description: %d: %s\n",
6563 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6564 ad->ad_type->sat_oid );
6567 /* set up the notable AttributeDescriptions */
6569 for (;ct->name;ct++) {
6570 if (strcmp(ct->name, ads[i].name)) continue;
6571 *ads[i].desc = ct->ad;
6573 if (!ads[i].name) break;