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>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
88 static struct berval cfdir;
91 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
92 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
94 static ConfigFile *cfn;
96 static Avlnode *CfOcTree;
98 /* System schema state */
99 extern AttributeType *at_sys_tail; /* at.c */
100 extern ObjectClass *oc_sys_tail; /* oc.c */
101 extern OidMacro *om_sys_tail; /* oidm.c */
102 extern Syntax *syn_sys_tail; /* syntax.c */
103 static AttributeType *cf_at_tail;
104 static ObjectClass *cf_oc_tail;
105 static OidMacro *cf_om_tail;
106 static Syntax *cf_syn_tail;
108 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
109 SlapReply *rs, int *renumber, Operation *op );
111 static int config_check_schema( Operation *op, CfBackInfo *cfb );
113 static ConfigDriver config_fname;
114 static ConfigDriver config_cfdir;
115 static ConfigDriver config_generic;
116 static ConfigDriver config_search_base;
117 static ConfigDriver config_passwd_hash;
118 static ConfigDriver config_schema_dn;
119 static ConfigDriver config_sizelimit;
120 static ConfigDriver config_timelimit;
121 static ConfigDriver config_overlay;
122 static ConfigDriver config_subordinate;
123 static ConfigDriver config_suffix;
124 #ifdef LDAP_TCP_BUFFER
125 static ConfigDriver config_tcp_buffer;
126 #endif /* LDAP_TCP_BUFFER */
127 static ConfigDriver config_rootdn;
128 static ConfigDriver config_rootpw;
129 static ConfigDriver config_restrict;
130 static ConfigDriver config_allows;
131 static ConfigDriver config_disallows;
132 static ConfigDriver config_requires;
133 static ConfigDriver config_security;
134 static ConfigDriver config_referral;
135 static ConfigDriver config_loglevel;
136 static ConfigDriver config_updatedn;
137 static ConfigDriver config_updateref;
138 static ConfigDriver config_include;
139 static ConfigDriver config_obsolete;
141 static ConfigDriver config_tls_option;
142 static ConfigDriver config_tls_config;
144 extern ConfigDriver syncrepl_config;
152 CFG_TLS_PROTOCOL_MIN,
201 static OidRec OidMacros[] = {
202 /* OpenLDAProot:1.12.2 */
203 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
204 { "OLcfgAt", "OLcfg:3" },
205 { "OLcfgGlAt", "OLcfgAt:0" },
206 { "OLcfgBkAt", "OLcfgAt:1" },
207 { "OLcfgDbAt", "OLcfgAt:2" },
208 { "OLcfgOvAt", "OLcfgAt:3" },
209 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
210 { "OLcfgOc", "OLcfg:4" },
211 { "OLcfgGlOc", "OLcfgOc:0" },
212 { "OLcfgBkOc", "OLcfgOc:1" },
213 { "OLcfgDbOc", "OLcfgOc:2" },
214 { "OLcfgOvOc", "OLcfgOc:3" },
215 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
217 /* Syntaxes. We should just start using the standard names and
218 * document that they are predefined and available for users
219 * to reference in their own schema. Defining schema without
220 * OID macros is for masochists...
222 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
223 { "OMsBoolean", "OMsyn:7" },
224 { "OMsDN", "OMsyn:12" },
225 { "OMsDirectoryString", "OMsyn:15" },
226 { "OMsIA5String", "OMsyn:26" },
227 { "OMsInteger", "OMsyn:27" },
228 { "OMsOID", "OMsyn:38" },
229 { "OMsOctetString", "OMsyn:40" },
234 * Backend/Database registry
236 * OLcfg{Bk|Db}{Oc|At}:0 -> common
237 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
238 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
239 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
240 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
241 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
242 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
243 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
249 * OLcfgOv{Oc|At}:1 -> syncprov
250 * OLcfgOv{Oc|At}:2 -> pcache
251 * OLcfgOv{Oc|At}:3 -> chain
252 * OLcfgOv{Oc|At}:4 -> accesslog
253 * OLcfgOv{Oc|At}:5 -> valsort
254 * OLcfgOv{Oc|At}:7 -> distproc
255 * OLcfgOv{Oc|At}:8 -> dynlist
256 * OLcfgOv{Oc|At}:9 -> dds
257 * OLcfgOv{Oc|At}:10 -> unique
258 * OLcfgOv{Oc|At}:11 -> refint
259 * OLcfgOv{Oc|At}:12 -> ppolicy
260 * OLcfgOv{Oc|At}:13 -> constraint
261 * OLcfgOv{Oc|At}:14 -> translucent
262 * OLcfgOv{Oc|At}:15 -> auditlog
263 * OLcfgOv{Oc|At}:16 -> rwm
264 * OLcfgOv{Oc|At}:17 -> dyngroup
265 * OLcfgOv{Oc|At}:18 -> memberof
266 * OLcfgOv{Oc|At}:19 -> collect
267 * OLcfgOv{Oc|At}:20 -> retcode
268 * OLcfgOv{Oc|At}:21 -> sssvlv
271 /* alphabetical ordering */
273 static ConfigTable config_back_cf_table[] = {
274 /* This attr is read-only */
275 { "", "", 0, 0, 0, ARG_MAGIC,
276 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
277 "DESC 'File for slapd configuration directives' "
278 "EQUALITY caseIgnoreMatch "
279 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
280 { "", "", 0, 0, 0, ARG_MAGIC,
281 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
282 "DESC 'Directory for slapd configuration backend' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
285 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
286 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
287 "DESC 'Access Control List' "
288 "EQUALITY caseIgnoreMatch "
289 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
290 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
291 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
292 "DESC 'Check ACLs against content of Add ops' "
293 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
294 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
295 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
296 "DESC 'Allowed set of deprecated features' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString )", NULL, NULL },
299 { "argsfile", "file", 2, 2, 0, ARG_STRING,
300 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
301 "DESC 'File for slapd command line options' "
302 "EQUALITY caseIgnoreMatch "
303 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
304 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
305 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString )", NULL, NULL },
308 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
309 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
310 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
311 "DESC 'OpenLDAP attributeTypes' "
312 "EQUALITY caseIgnoreMatch "
313 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
315 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
316 #ifdef SLAP_AUTH_REWRITE
317 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
321 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
322 "EQUALITY caseIgnoreMatch "
323 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
324 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
325 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
326 "EQUALITY caseIgnoreMatch "
327 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
328 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
329 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
330 "EQUALITY caseIgnoreMatch "
331 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
332 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
333 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
334 "DESC 'A type of backend' "
335 "EQUALITY caseIgnoreMatch "
336 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
338 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
339 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
340 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
341 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
342 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
343 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
344 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
345 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
346 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
347 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
348 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
349 "DESC 'The backend type for a database instance' "
350 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
351 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
352 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
353 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
354 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
355 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
356 "EQUALITY caseIgnoreMatch "
357 "SYNTAX OMsDirectoryString )", NULL, NULL },
358 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
359 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
360 "DESC 'OpenLDAP DIT content rules' "
361 "EQUALITY caseIgnoreMatch "
362 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
364 { "gentlehup", "on|off", 2, 2, 0,
366 ARG_ON_OFF, &global_gentlehup,
370 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
371 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
372 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
373 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
374 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
375 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
376 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
377 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
378 { "include", "file", 2, 2, 0, ARG_MAGIC,
379 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
380 "SUP labeledURI )", NULL, NULL },
381 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
382 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
383 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
384 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
385 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
386 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
387 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
388 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
389 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
390 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
391 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
392 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
393 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
394 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
395 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
396 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
397 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
398 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
399 { "ldapsyntax", "syntax", 2, 0, 0,
400 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
401 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
402 "DESC 'OpenLDAP ldapSyntax' "
403 "EQUALITY caseIgnoreMatch "
404 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
406 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
407 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
408 "EQUALITY caseIgnoreMatch "
409 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
410 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
411 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
412 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
413 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
414 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
415 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
416 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
417 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
418 "EQUALITY caseIgnoreMatch "
419 "SYNTAX OMsDirectoryString )", NULL, NULL },
420 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
421 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
422 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
423 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
424 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
425 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
426 { "moduleload", "file", 2, 0, 0,
428 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
432 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
433 "EQUALITY caseIgnoreMatch "
434 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
435 { "modulepath", "path", 2, 2, 0,
437 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
441 "( OLcfgGlAt:31 NAME 'olcModulePath' "
442 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
443 { "monitoring", "TRUE|FALSE", 2, 2, 0,
444 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
445 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
446 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
447 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
448 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
449 "DESC 'OpenLDAP object classes' "
450 "EQUALITY caseIgnoreMatch "
451 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
453 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
454 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
455 "EQUALITY caseIgnoreMatch "
456 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
457 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
458 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
459 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
460 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
461 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
462 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
463 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
464 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
465 "EQUALITY caseIgnoreMatch "
466 "SYNTAX OMsDirectoryString )", NULL, NULL },
467 { "pidfile", "file", 2, 2, 0, ARG_STRING,
468 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
469 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
470 { "plugin", NULL, 0, 0, 0,
472 ARG_MAGIC|CFG_PLUGIN, &config_generic,
476 "( OLcfgGlAt:38 NAME 'olcPlugin' "
477 "EQUALITY caseIgnoreMatch "
478 "SYNTAX OMsDirectoryString )", NULL, NULL },
479 { "pluginlog", "filename", 2, 2, 0,
481 ARG_STRING, &slapi_log_file,
485 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
486 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
487 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
488 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
489 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
490 { "referral", "url", 2, 2, 0, ARG_MAGIC,
491 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
492 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
493 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
494 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
495 "EQUALITY caseIgnoreMatch "
496 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
497 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
498 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
499 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
500 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
501 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
502 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
503 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
504 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
505 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
506 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
507 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
508 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
509 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
510 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
511 "EQUALITY caseIgnoreMatch "
512 "SYNTAX OMsDirectoryString )", NULL, NULL },
513 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
514 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
515 "EQUALITY caseIgnoreMatch "
516 "SYNTAX OMsDirectoryString )", NULL, NULL },
517 { "reverse-lookup", "on|off", 2, 2, 0,
518 #ifdef SLAPD_RLOOKUPS
519 ARG_ON_OFF, &use_reverse_lookup,
523 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
524 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
525 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
526 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
527 "EQUALITY distinguishedNameMatch "
528 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
529 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
530 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
531 "EQUALITY caseIgnoreMatch "
532 "SYNTAX OMsDirectoryString )", NULL, NULL },
533 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
534 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
535 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
536 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
537 &config_generic, NULL, NULL, NULL },
538 { "sasl-auxprops", NULL, 2, 0, 0,
539 #ifdef HAVE_CYRUS_SASL
540 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
544 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
545 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
546 { "sasl-host", "host", 2, 2, 0,
547 #ifdef HAVE_CYRUS_SASL
548 ARG_STRING|ARG_UNIQUE, &sasl_host,
552 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
553 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
554 { "sasl-realm", "realm", 2, 2, 0,
555 #ifdef HAVE_CYRUS_SASL
556 ARG_STRING|ARG_UNIQUE, &global_realm,
560 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
561 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
562 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
563 &config_generic, NULL, NULL, NULL },
564 { "sasl-secprops", "properties", 2, 2, 0,
565 #ifdef HAVE_CYRUS_SASL
566 ARG_MAGIC|CFG_SASLSECP, &config_generic,
570 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
571 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
572 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
573 &config_generic, NULL, NULL, NULL },
574 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
575 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
576 "EQUALITY distinguishedNameMatch "
577 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
578 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
579 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
580 "EQUALITY caseIgnoreMatch "
581 "SYNTAX OMsDirectoryString )", NULL, NULL },
582 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
583 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
584 "EQUALITY caseIgnoreMatch "
585 "SYNTAX OMsDirectoryString )", NULL, NULL },
586 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
587 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
588 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
589 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
590 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
591 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
592 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
593 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
594 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
595 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
596 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
597 "DESC 'Attributes whose values will always be sorted' "
598 "EQUALITY caseIgnoreMatch "
599 "SYNTAX OMsDirectoryString )", NULL, NULL },
600 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
601 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
602 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
603 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
604 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
605 "EQUALITY distinguishedNameMatch "
606 "SYNTAX OMsDN )", NULL, NULL },
607 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
608 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
609 "EQUALITY caseIgnoreMatch "
610 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
611 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
612 #ifndef LDAP_TCP_BUFFER
614 #else /* LDAP_TCP_BUFFER */
615 ARG_MAGIC, &config_tcp_buffer,
616 #endif /* LDAP_TCP_BUFFER */
617 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
618 "DESC 'Custom TCP buffer size' "
619 "SYNTAX OMsDirectoryString )", NULL, NULL },
620 { "threads", "count", 2, 2, 0,
624 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
626 "( OLcfgGlAt:66 NAME 'olcThreads' "
627 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
628 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
629 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
630 "SYNTAX OMsDirectoryString )", NULL, NULL },
631 { "TLSCACertificateFile", NULL, 0, 0, 0,
633 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
637 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
638 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
639 { "TLSCACertificatePath", NULL, 0, 0, 0,
641 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
645 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
646 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
647 { "TLSCertificateFile", NULL, 0, 0, 0,
649 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
653 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
654 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
655 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
657 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
661 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
662 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
663 { "TLSCipherSuite", NULL, 0, 0, 0,
665 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
669 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
670 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
671 { "TLSCRLCheck", NULL, 0, 0, 0,
672 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
673 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
677 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
678 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
679 { "TLSCRLFile", NULL, 0, 0, 0,
680 #if defined(HAVE_GNUTLS)
681 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
685 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
686 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
687 { "TLSRandFile", NULL, 0, 0, 0,
689 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
693 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
694 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
695 { "TLSVerifyClient", NULL, 0, 0, 0,
697 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
701 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
702 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
703 { "TLSDHParamFile", NULL, 0, 0, 0,
705 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
709 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
710 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
711 { "TLSProtocolMin", NULL, 0, 0, 0,
713 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
717 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
718 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
719 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
720 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
721 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
722 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
723 NULL, NULL, NULL, NULL },
724 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
725 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
726 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
727 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
728 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
729 "EQUALITY caseIgnoreMatch "
730 "SUP labeledURI )", NULL, NULL },
731 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
732 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
733 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
734 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
735 NULL, NULL, NULL, NULL }
738 /* Need to no-op this keyword for dynamic config */
739 ConfigTable olcDatabaseDummy[] = {
740 { "", "", 0, 0, 0, ARG_IGNORED,
741 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
742 "DESC 'The backend type for a database instance' "
743 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
744 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
747 /* Routines to check if a child can be added to this type */
748 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
749 cfAddBackend, cfAddModule, cfAddOverlay;
751 /* NOTE: be careful when defining array members
752 * that can be conditionally compiled */
753 #define CFOC_GLOBAL cf_ocs[1]
754 #define CFOC_SCHEMA cf_ocs[2]
755 #define CFOC_BACKEND cf_ocs[3]
756 #define CFOC_DATABASE cf_ocs[4]
757 #define CFOC_OVERLAY cf_ocs[5]
758 #define CFOC_INCLUDE cf_ocs[6]
759 #define CFOC_FRONTEND cf_ocs[7]
761 #define CFOC_MODULE cf_ocs[8]
762 #endif /* SLAPD_MODULES */
764 static ConfigOCs cf_ocs[] = {
767 "DESC 'OpenLDAP configuration object' "
768 "ABSTRACT SUP top )", Cft_Abstract, NULL },
771 "DESC 'OpenLDAP Global configuration options' "
772 "SUP olcConfig STRUCTURAL "
773 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
774 "olcAttributeOptions $ olcAuthIDRewrite $ "
775 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
776 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
777 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
778 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
779 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
780 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
781 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
782 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
783 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
785 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
786 "olcSecurity $ olcServerID $ olcSizeLimit $ "
787 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
789 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
790 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
791 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
792 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
793 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
794 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
795 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
797 "NAME 'olcSchemaConfig' "
798 "DESC 'OpenLDAP schema object' "
799 "SUP olcConfig STRUCTURAL "
800 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
801 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
802 Cft_Schema, NULL, cfAddSchema },
804 "NAME 'olcBackendConfig' "
805 "DESC 'OpenLDAP Backend-specific options' "
806 "SUP olcConfig STRUCTURAL "
807 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
809 "NAME 'olcDatabaseConfig' "
810 "DESC 'OpenLDAP Database-specific options' "
811 "SUP olcConfig STRUCTURAL "
813 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
814 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
815 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
816 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
817 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
818 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
819 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
821 Cft_Database, NULL, cfAddDatabase },
823 "NAME 'olcOverlayConfig' "
824 "DESC 'OpenLDAP Overlay-specific options' "
825 "SUP olcConfig STRUCTURAL "
826 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
828 "NAME 'olcIncludeFile' "
829 "DESC 'OpenLDAP configuration include file' "
830 "SUP olcConfig STRUCTURAL "
832 "MAY ( cn $ olcRootDSE ) )",
833 /* Used to be Cft_Include, that def has been removed */
834 Cft_Abstract, NULL, cfAddInclude },
835 /* This should be STRUCTURAL like all the other database classes, but
836 * that would mean inheriting all of the olcDatabaseConfig attributes,
837 * which causes them to be merged twice in config_build_entry.
840 "NAME 'olcFrontendConfig' "
841 "DESC 'OpenLDAP frontend configuration' "
843 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
844 Cft_Database, NULL, NULL },
847 "NAME 'olcModuleList' "
848 "DESC 'OpenLDAP dynamic module info' "
849 "SUP olcConfig STRUCTURAL "
850 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
851 Cft_Module, NULL, cfAddModule },
856 typedef struct ServerID {
857 struct ServerID *si_next;
858 struct berval si_url;
862 static ServerID *sid_list;
864 typedef struct voidList {
865 struct voidList *vl_next;
869 typedef struct ADlist {
870 struct ADlist *al_next;
871 AttributeDescription *al_desc;
874 static ADlist *sortVals;
877 config_generic(ConfigArgs *c) {
880 if ( c->op == SLAP_CONFIG_EMIT ) {
884 c->value_int = ldap_pvt_thread_get_concurrency();
887 c->value_int = connection_pool_max;
890 c->value_int = slap_tool_thread_max;
894 c->value_string = ch_strdup( passwd_salt );
899 if ( c->be->be_limits ) {
903 for ( i=0; c->be->be_limits[i]; i++ ) {
904 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
905 if ( bv.bv_len >= sizeof( buf ) ) {
906 ber_bvarray_free_x( c->rvalue_vals, NULL );
907 c->rvalue_vals = NULL;
911 bv.bv_val = buf + bv.bv_len;
912 limits_unparse( c->be->be_limits[i], &bv,
913 sizeof( buf ) - ( bv.bv_val - buf ) );
914 bv.bv_len += bv.bv_val - buf;
916 value_add_one( &c->rvalue_vals, &bv );
919 if ( !c->rvalue_vals ) rc = 1;
922 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
925 c->value_string = ch_strdup( slap_sasl_getpolicy());
928 slap_sasl_regexp_unparse( &c->rvalue_vals );
929 if ( !c->rvalue_vals ) rc = 1;
931 #ifdef HAVE_CYRUS_SASL
933 struct berval bv = BER_BVNULL;
934 slap_sasl_secprops_unparse( &bv );
935 if ( !BER_BVISNULL( &bv )) {
936 ber_bvarray_add( &c->rvalue_vals, &bv );
944 c->value_int = c->be->be_max_deref_depth;
947 if ( SLAP_DBHIDDEN( c->be )) {
954 ConfigFile *cf = c->ca_private;
956 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
957 else if ( cf->c_om_head )
958 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
960 if ( !c->rvalue_vals )
965 ad_unparse_options( &c->rvalue_vals );
968 ConfigFile *cf = c->ca_private;
970 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
971 else if ( cf->c_oc_head )
972 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
974 if ( !c->rvalue_vals )
979 ConfigFile *cf = c->ca_private;
981 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
982 else if ( cf->c_at_head )
983 at_unparse( &c->rvalue_vals, cf->c_at_head,
985 if ( !c->rvalue_vals )
990 ConfigFile *cf = c->ca_private;
992 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
993 else if ( cf->c_syn_head )
994 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
996 if ( !c->rvalue_vals )
1001 ConfigFile *cf = c->ca_private;
1003 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1004 else if ( cf->c_cr_head )
1005 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1007 if ( !c->rvalue_vals )
1014 char *src, *dst, ibuf[11];
1015 struct berval bv, abv;
1016 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1017 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1018 if ( abv.bv_len >= sizeof( ibuf ) ) {
1019 ber_bvarray_free_x( c->rvalue_vals, NULL );
1020 c->rvalue_vals = NULL;
1024 acl_unparse( a, &bv );
1025 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1026 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1027 /* Turn TAB / EOL into plain space */
1028 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1029 if (isspace((unsigned char)*src)) *dst++ = ' ';
1033 if (dst[-1] == ' ') {
1037 abv.bv_len = dst - abv.bv_val;
1038 ber_bvarray_add( &c->rvalue_vals, &abv );
1044 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1047 ConfigFile *cf = c->ca_private;
1048 if ( cf->c_dseFiles ) {
1049 value_add( &c->rvalue_vals, cf->c_dseFiles );
1060 for ( si = sid_list; si; si=si->si_next ) {
1061 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1062 if ( !BER_BVISEMPTY( &si->si_url )) {
1063 bv.bv_len = si->si_url.bv_len + 6;
1064 bv.bv_val = ch_malloc( bv.bv_len );
1065 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1066 si->si_url.bv_val );
1067 ber_bvarray_add( &c->rvalue_vals, &bv );
1071 bv.bv_len = sprintf( buf, "%d", si->si_num );
1072 value_add_one( &c->rvalue_vals, &bv );
1081 c->value_string = ch_strdup( logfileName );
1086 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1088 case CFG_MIRRORMODE:
1089 if ( SLAP_SHADOW(c->be))
1090 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1094 case CFG_MONITORING:
1095 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1097 case CFG_SSTR_IF_MAX:
1098 c->value_uint = index_substr_if_maxlen;
1100 case CFG_SSTR_IF_MIN:
1101 c->value_uint = index_substr_if_minlen;
1104 c->value_int = index_intlen;
1106 case CFG_SORTVALS: {
1109 for ( sv = sortVals; sv; sv = sv->al_next ) {
1110 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1114 #ifdef SLAPD_MODULES
1116 ModPaths *mp = c->ca_private;
1119 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1122 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1123 SLAP_X_ORDERED_FMT "%s", i,
1124 mp->mp_loads[i].bv_val );
1125 if ( bv.bv_len >= sizeof( c->log ) ) {
1126 ber_bvarray_free_x( c->rvalue_vals, NULL );
1127 c->rvalue_vals = NULL;
1130 value_add_one( &c->rvalue_vals, &bv );
1134 rc = c->rvalue_vals ? 0 : 1;
1138 ModPaths *mp = c->ca_private;
1139 if ( !BER_BVISNULL( &mp->mp_path ))
1140 value_add_one( &c->rvalue_vals, &mp->mp_path );
1142 rc = c->rvalue_vals ? 0 : 1;
1148 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1149 if ( !c->rvalue_vals ) rc = 1;
1152 #ifdef SLAP_AUTH_REWRITE
1154 if ( authz_rewrites ) {
1155 struct berval bv, idx;
1160 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1161 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1162 if ( idx.bv_len >= sizeof( ibuf ) ) {
1163 ber_bvarray_free_x( c->rvalue_vals, NULL );
1164 c->rvalue_vals = NULL;
1167 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1168 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1169 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1170 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1171 authz_rewrites[i].bv_val,
1172 authz_rewrites[i].bv_len + 1 );
1173 ber_bvarray_add( &c->rvalue_vals, &bv );
1176 if ( !c->rvalue_vals ) rc = 1;
1183 } else if ( c->op == LDAP_MOD_DELETE ) {
1186 /* single-valued attrs, no-ops */
1194 case CFG_MIRRORMODE:
1195 case CFG_MONITORING:
1197 case CFG_SSTR_IF_MAX:
1198 case CFG_SSTR_IF_MIN:
1202 /* no-ops, requires slapd restart */
1207 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1211 ch_free( passwd_salt );
1216 ch_free( logfileName );
1224 case CFG_SERVERID: {
1225 ServerID *si, **sip;
1227 for ( i=0, si = sid_list, sip = &sid_list;
1228 si; si = *sip, i++ ) {
1229 if ( c->valx == -1 || i == c->valx ) {
1241 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1245 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1246 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1247 SLAP_INDEX_INTLEN_DEFAULT );
1251 if ( c->valx < 0 ) {
1252 acl_destroy( c->be->be_acl );
1253 c->be->be_acl = NULL;
1256 AccessControl **prev, *a;
1258 for (i=0, prev = &c->be->be_acl; i < c->valx;
1261 prev = &a->acl_next;
1264 *prev = a->acl_next;
1271 /* Can be NULL when undoing a failed add */
1272 if ( c->ca_entry ) {
1273 ce = c->ca_entry->e_private;
1274 /* can't modify the hardcoded schema */
1275 if ( ce->ce_parent->ce_type == Cft_Global )
1279 cfn = c->ca_private;
1280 if ( c->valx < 0 ) {
1283 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1285 if ( oc == cfn->c_oc_tail )
1288 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1290 ObjectClass *oc, *prev = NULL;
1292 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1297 if ( cfn->c_oc_tail == oc ) {
1298 cfn->c_oc_tail = prev;
1300 if ( cfn->c_oc_head == oc ) {
1302 cfn->c_oc_head = oc;
1309 /* Can be NULL when undoing a failed add */
1310 if ( c->ca_entry ) {
1311 ce = c->ca_entry->e_private;
1312 /* can't modify the hardcoded schema */
1313 if ( ce->ce_parent->ce_type == Cft_Global )
1317 cfn = c->ca_private;
1318 if ( c->valx < 0 ) {
1321 for( at = cfn->c_at_head; at; at_next( &at )) {
1323 if ( at == cfn->c_at_tail )
1326 cfn->c_at_head = cfn->c_at_tail = NULL;
1328 AttributeType *at, *prev = NULL;
1330 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1335 if ( cfn->c_at_tail == at ) {
1336 cfn->c_at_tail = prev;
1338 if ( cfn->c_at_head == at ) {
1340 cfn->c_at_head = at;
1347 /* Can be NULL when undoing a failed add */
1348 if ( c->ca_entry ) {
1349 ce = c->ca_entry->e_private;
1350 /* can't modify the hardcoded schema */
1351 if ( ce->ce_parent->ce_type == Cft_Global )
1355 cfn = c->ca_private;
1356 if ( c->valx < 0 ) {
1359 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1361 if ( syn == cfn->c_syn_tail )
1364 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1366 Syntax *syn, *prev = NULL;
1368 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1373 if ( cfn->c_syn_tail == syn ) {
1374 cfn->c_syn_tail = prev;
1376 if ( cfn->c_syn_head == syn ) {
1378 cfn->c_syn_head = syn;
1383 if ( c->valx < 0 ) {
1385 for ( sv = sortVals; sv; sv = sortVals ) {
1386 sortVals = sv->al_next;
1387 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1394 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1395 prev = &sv->al_next;
1398 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1399 *prev = sv->al_next;
1405 /* FIXME: there is no limits_free function */
1406 if ( c->valx < 0 ) {
1407 limits_destroy( c->be->be_limits );
1408 c->be->be_limits = NULL;
1413 if ( c->be->be_limits ) {
1414 for ( num = 0; c->be->be_limits[ num ]; num++ )
1418 if ( c->valx >= num ) {
1423 limits_destroy( c->be->be_limits );
1424 c->be->be_limits = NULL;
1427 limits_free_one( c->be->be_limits[ c->valx ] );
1429 for ( cnt = c->valx; cnt < num; cnt++ ) {
1430 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1437 /* FIXME: there is no ad_option_free function */
1439 /* FIXME: there is no way to remove attributes added by
1453 if(!(c->bi = backend_info(c->argv[1]))) {
1454 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1455 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1456 c->log, c->cr_msg, c->argv[1] );
1463 /* NOTE: config is always the first backend!
1465 if ( !strcasecmp( c->argv[1], "config" )) {
1466 c->be = LDAP_STAILQ_FIRST(&backendDB);
1467 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1470 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1472 if ( c->cr_msg[0] == 0 )
1473 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1474 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1481 ldap_pvt_thread_set_concurrency(c->value_int);
1485 if ( c->value_int < 2 ) {
1486 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1487 "threads=%d smaller than minimum value 2",
1489 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1490 c->log, c->cr_msg, 0 );
1493 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1494 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1495 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1496 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1497 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1498 c->log, c->cr_msg, 0 );
1500 if ( slapMode & SLAP_SERVER_MODE )
1501 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1502 connection_pool_max = c->value_int; /* save for reference */
1506 if ( slapMode & SLAP_TOOL_MODE )
1507 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1508 slap_tool_thread_max = c->value_int; /* save for reference */
1512 if ( passwd_salt ) ch_free( passwd_salt );
1513 passwd_salt = c->value_string;
1514 lutil_salt_format(passwd_salt);
1518 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1524 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1526 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1530 ch_free(c->value_string);
1531 if (slap_sasl_setpolicy( c->argv[1] )) {
1532 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1533 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1534 c->log, c->cr_msg, c->argv[1] );
1540 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1544 #ifdef HAVE_CYRUS_SASL
1547 char *txt = slap_sasl_secprops( c->argv[1] );
1549 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1551 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1559 c->be->be_max_deref_depth = c->value_int;
1565 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1566 cfn = c->ca_private;
1567 if(parse_oidm(c, 1, &om))
1569 if (!cfn->c_om_head) cfn->c_om_head = om;
1570 cfn->c_om_tail = om;
1575 ObjectClass *oc, *prev;
1577 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1578 cfn = c->ca_private;
1579 if ( c->valx < 0 ) {
1580 prev = cfn->c_oc_tail;
1583 /* If adding anything after the first, prev is easy */
1586 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1591 /* If adding the first, and head exists, find its prev */
1592 if (cfn->c_oc_head) {
1593 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1598 /* else prev is NULL, append to end of global list */
1600 if(parse_oc(c, &oc, prev)) return(1);
1601 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1602 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1607 AttributeType *at, *prev;
1609 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1610 cfn = c->ca_private;
1611 if ( c->valx < 0 ) {
1612 prev = cfn->c_at_tail;
1615 /* If adding anything after the first, prev is easy */
1618 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1623 /* If adding the first, and head exists, find its prev */
1624 if (cfn->c_at_head) {
1625 for ( at_start( &at ); at != cfn->c_at_head; ) {
1630 /* else prev is NULL, append to end of global list */
1632 if(parse_at(c, &at, prev)) return(1);
1633 if (!cfn->c_at_head) cfn->c_at_head = at;
1634 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1641 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1642 cfn = c->ca_private;
1643 if ( c->valx < 0 ) {
1644 prev = cfn->c_syn_tail;
1647 /* If adding anything after the first, prev is easy */
1650 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1655 /* If adding the first, and head exists, find its prev */
1656 if (cfn->c_syn_head) {
1657 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1662 /* else prev is NULL, append to end of global list */
1664 if ( parse_syn( c, &syn, prev ) ) return(1);
1665 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1666 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1673 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1674 cfn = c->ca_private;
1675 if(parse_cr(c, &cr)) return(1);
1676 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1677 cfn->c_cr_tail = cr;
1682 ad_define_option(NULL, NULL, 0);
1683 for(i = 1; i < c->argc; i++)
1684 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1689 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1690 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1691 else if ( c->value_int > 255 )
1693 index_intlen = c->value_int;
1694 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1698 case CFG_SORTVALS: {
1699 ADlist *svnew = NULL, *svtail, *sv;
1701 for ( i = 1; i < c->argc; i++ ) {
1702 AttributeDescription *ad = NULL;
1706 rc = slap_str2ad( c->argv[i], &ad, &text );
1708 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1711 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1712 c->log, c->cr_msg, c->argv[i] );
1713 for ( sv = svnew; sv; sv = svnew ) {
1714 svnew = sv->al_next;
1719 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1720 ad->ad_type->sat_single_value ) {
1721 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1723 goto sortval_reject;
1725 sv = ch_malloc( sizeof( ADlist ));
1730 svtail->al_next = sv;
1735 for ( sv = svnew; sv; sv = sv->al_next )
1736 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1737 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1739 sv->al_next = svnew;
1746 /* Don't append to the global ACL if we're on a specific DB */
1748 if ( c->valx == -1 ) {
1751 for ( a=c->be->be_acl; a; a = a->acl_next )
1754 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1761 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1763 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1767 if(root_dse_read_file(c->argv[1])) {
1768 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1769 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1770 c->log, c->cr_msg, c->argv[1] );
1775 ber_str2bv( c->argv[1], 0, 1, &bv );
1776 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1777 cfn = c->ca_private;
1778 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1784 ServerID *si, **sip;
1787 if ( lutil_atoi( &num, c->argv[1] ) ||
1788 num < 0 || num > SLAP_SYNC_SID_MAX )
1790 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1791 "<%s> illegal server ID", c->argv[0] );
1792 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1793 c->log, c->cr_msg, c->argv[1] );
1796 /* only one value allowed if no URL is given */
1797 if ( c->argc > 2 ) {
1800 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1801 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1802 "<%s> only one server ID allowed now", c->argv[0] );
1803 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1804 c->log, c->cr_msg, c->argv[1] );
1808 if ( ldap_url_parse( c->argv[2], &lud )) {
1809 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1810 "<%s> invalid URL", c->argv[0] );
1811 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1812 c->log, c->cr_msg, c->argv[2] );
1815 len = strlen( c->argv[2] );
1816 si = ch_malloc( sizeof(ServerID) + len + 1 );
1817 si->si_url.bv_val = (char *)(si+1);
1818 si->si_url.bv_len = len;
1819 strcpy( si->si_url.bv_val, c->argv[2] );
1822 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1823 "<%s> unqualified server ID not allowed now", c->argv[0] );
1824 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1825 c->log, c->cr_msg, c->argv[1] );
1828 si = ch_malloc( sizeof(ServerID) );
1829 BER_BVZERO( &si->si_url );
1830 slap_serverID = num;
1831 Debug( LDAP_DEBUG_CONFIG,
1833 c->log, slap_serverID, 0 );
1837 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1840 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1841 Listener *l = config_check_my_url( c->argv[2], lud );
1843 slap_serverID = si->si_num;
1844 Debug( LDAP_DEBUG_CONFIG,
1845 "%s: SID=%d (listener=%s)\n",
1846 c->log, slap_serverID,
1851 ldap_free_urldesc( lud );
1855 if ( logfileName ) ch_free( logfileName );
1856 logfileName = c->value_string;
1857 logfile = fopen(logfileName, "w");
1858 if(logfile) lutil_debug_file(logfile);
1862 if(SLAP_NOLASTMODCMD(c->be)) {
1863 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1864 c->argv[0], c->be->bd_info->bi_type );
1865 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1866 c->log, c->cr_msg, 0 );
1870 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1872 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1875 case CFG_MIRRORMODE:
1876 if(c->value_int && !SLAP_SHADOW(c->be)) {
1877 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1879 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1880 c->log, c->cr_msg, 0 );
1884 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1886 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1889 case CFG_MONITORING:
1891 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1893 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1898 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1900 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1903 case CFG_SSTR_IF_MAX:
1904 if (c->value_uint < index_substr_if_minlen) {
1905 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1906 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1907 c->log, c->cr_msg, c->value_int );
1910 index_substr_if_maxlen = c->value_uint;
1913 case CFG_SSTR_IF_MIN:
1914 if (c->value_uint > index_substr_if_maxlen) {
1915 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1916 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1917 c->log, c->cr_msg, c->value_int );
1920 index_substr_if_minlen = c->value_uint;
1923 #ifdef SLAPD_MODULES
1925 /* If we're just adding a module on an existing modpath,
1926 * make sure we've selected the current path.
1928 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1929 modcur = c->ca_private;
1930 /* This should never fail */
1931 if ( module_path( modcur->mp_path.bv_val )) {
1932 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1934 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1935 c->log, c->cr_msg, modcur->mp_path.bv_val );
1939 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1941 /* Record this load on the current path */
1945 if ( c->op == SLAP_CONFIG_ADD ) {
1946 ptr = c->line + STRLENOF("moduleload");
1947 while (!isspace((unsigned char) *ptr)) ptr++;
1948 while (isspace((unsigned char) *ptr)) ptr++;
1952 ber_str2bv(ptr, 0, 1, &bv);
1953 ber_bvarray_add( &modcur->mp_loads, &bv );
1955 /* Check for any new hardcoded schema */
1956 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1957 config_check_schema( NULL, &cfBackInfo );
1962 if(module_path(c->argv[1])) return(1);
1963 /* Record which path was used with each module */
1967 if (!modpaths.mp_loads) {
1970 mp = ch_malloc( sizeof( ModPaths ));
1971 modlast->mp_next = mp;
1973 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1975 mp->mp_loads = NULL;
1986 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1988 slapi_plugins_used++;
1992 #ifdef SLAP_AUTH_REWRITE
1997 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2000 if ( c->argc > 1 ) {
2003 /* quote all args but the first */
2004 line = ldap_charray2str( c->argv, "\" \"" );
2005 ber_str2bv( line, 0, 0, &bv );
2006 s = ber_bvchr( &bv, '"' );
2007 assert( s != NULL );
2008 /* move the trailing quote of argv[0] to the end */
2009 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2010 bv.bv_val[ bv.bv_len - 1 ] = '"';
2013 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2016 ber_bvarray_add( &authz_rewrites, &bv );
2023 Debug( LDAP_DEBUG_ANY,
2024 "%s: unknown CFG_TYPE %d.\n",
2025 c->log, c->type, 0 );
2034 config_fname(ConfigArgs *c) {
2035 if(c->op == SLAP_CONFIG_EMIT) {
2036 if (c->ca_private) {
2037 ConfigFile *cf = c->ca_private;
2038 value_add_one( &c->rvalue_vals, &cf->c_file );
2047 config_cfdir(ConfigArgs *c) {
2048 if(c->op == SLAP_CONFIG_EMIT) {
2049 if ( !BER_BVISEMPTY( &cfdir )) {
2050 value_add_one( &c->rvalue_vals, &cfdir );
2059 config_search_base(ConfigArgs *c) {
2060 if(c->op == SLAP_CONFIG_EMIT) {
2062 if (!BER_BVISEMPTY(&default_search_base)) {
2063 value_add_one(&c->rvalue_vals, &default_search_base);
2064 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2068 } else if( c->op == LDAP_MOD_DELETE ) {
2069 ch_free( default_search_base.bv_val );
2070 ch_free( default_search_nbase.bv_val );
2071 BER_BVZERO( &default_search_base );
2072 BER_BVZERO( &default_search_nbase );
2076 if(c->bi || c->be != frontendDB) {
2077 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2078 "prior to any backend or database definition\n",
2083 if(default_search_nbase.bv_len) {
2084 free(default_search_base.bv_val);
2085 free(default_search_nbase.bv_val);
2088 default_search_base = c->value_dn;
2089 default_search_nbase = c->value_ndn;
2093 /* For RE23 compatibility we allow this in the global entry
2094 * but we now defer it to the frontend entry to allow modules
2095 * to load new hash types.
2098 config_passwd_hash(ConfigArgs *c) {
2100 if (c->op == SLAP_CONFIG_EMIT) {
2102 /* Don't generate it in the global entry */
2103 if ( c->table == Cft_Global )
2105 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2106 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2107 value_add_one(&c->rvalue_vals, &bv);
2110 } else if ( c->op == LDAP_MOD_DELETE ) {
2111 /* Deleting from global is a no-op, only the frontendDB entry matters */
2112 if ( c->table == Cft_Global )
2114 if ( c->valx < 0 ) {
2115 ldap_charray_free( default_passwd_hash );
2116 default_passwd_hash = NULL;
2119 ch_free( default_passwd_hash[i] );
2120 for (; default_passwd_hash[i]; i++ )
2121 default_passwd_hash[i] = default_passwd_hash[i+1];
2125 for(i = 1; i < c->argc; i++) {
2126 if(!lutil_passwd_scheme(c->argv[i])) {
2127 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2128 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2129 c->log, c->cr_msg, c->argv[i]);
2131 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2134 if(!default_passwd_hash) {
2135 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2136 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2137 c->log, c->cr_msg, 0 );
2144 config_schema_dn(ConfigArgs *c) {
2145 if ( c->op == SLAP_CONFIG_EMIT ) {
2147 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2148 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2149 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2153 } else if ( c->op == LDAP_MOD_DELETE ) {
2154 ch_free( c->be->be_schemadn.bv_val );
2155 ch_free( c->be->be_schemandn.bv_val );
2156 BER_BVZERO( &c->be->be_schemadn );
2157 BER_BVZERO( &c->be->be_schemandn );
2160 ch_free( c->be->be_schemadn.bv_val );
2161 ch_free( c->be->be_schemandn.bv_val );
2162 c->be->be_schemadn = c->value_dn;
2163 c->be->be_schemandn = c->value_ndn;
2168 config_sizelimit(ConfigArgs *c) {
2170 struct slap_limits_set *lim = &c->be->be_def_limit;
2171 if (c->op == SLAP_CONFIG_EMIT) {
2176 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2177 if ( !BER_BVISEMPTY( &bv ))
2178 value_add_one( &c->rvalue_vals, &bv );
2182 } else if ( c->op == LDAP_MOD_DELETE ) {
2183 /* Reset to defaults */
2184 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2185 lim->lms_s_hard = 0;
2186 lim->lms_s_unchecked = -1;
2188 lim->lms_s_pr_hide = 0;
2189 lim->lms_s_pr_total = 0;
2192 for(i = 1; i < c->argc; i++) {
2193 if(!strncasecmp(c->argv[i], "size", 4)) {
2194 rc = limits_parse_one(c->argv[i], lim);
2196 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2197 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2198 c->log, c->cr_msg, c->argv[i]);
2202 if(!strcasecmp(c->argv[i], "unlimited")) {
2203 lim->lms_s_soft = -1;
2205 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2206 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2207 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2208 c->log, c->cr_msg, c->argv[i]);
2212 lim->lms_s_hard = 0;
2219 config_timelimit(ConfigArgs *c) {
2221 struct slap_limits_set *lim = &c->be->be_def_limit;
2222 if (c->op == SLAP_CONFIG_EMIT) {
2227 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2228 if ( !BER_BVISEMPTY( &bv ))
2229 value_add_one( &c->rvalue_vals, &bv );
2233 } else if ( c->op == LDAP_MOD_DELETE ) {
2234 /* Reset to defaults */
2235 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2236 lim->lms_t_hard = 0;
2239 for(i = 1; i < c->argc; i++) {
2240 if(!strncasecmp(c->argv[i], "time", 4)) {
2241 rc = limits_parse_one(c->argv[i], lim);
2243 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2244 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2245 c->log, c->cr_msg, c->argv[i]);
2249 if(!strcasecmp(c->argv[i], "unlimited")) {
2250 lim->lms_t_soft = -1;
2252 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2253 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2254 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2255 c->log, c->cr_msg, c->argv[i]);
2259 lim->lms_t_hard = 0;
2266 config_overlay(ConfigArgs *c) {
2267 if (c->op == SLAP_CONFIG_EMIT) {
2269 } else if ( c->op == LDAP_MOD_DELETE ) {
2272 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2273 c->valx, &c->bi, &c->reply)) {
2275 Debug( LDAP_DEBUG_ANY,
2276 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2277 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2279 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2286 config_subordinate(ConfigArgs *c)
2292 case SLAP_CONFIG_EMIT:
2293 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2296 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2297 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2300 value_add_one( &c->rvalue_vals, &bv );
2304 case LDAP_MOD_DELETE:
2305 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2306 glue_sub_del( c->be );
2308 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2313 case SLAP_CONFIG_ADD:
2314 if ( c->be->be_nsuffix == NULL ) {
2316 snprintf( c->cr_msg, sizeof( c->cr_msg),
2317 "subordinate configuration needs a suffix" );
2318 Debug( LDAP_DEBUG_ANY,
2320 c->log, c->cr_msg, 0 );
2325 if ( c->argc == 2 ) {
2326 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2329 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2331 snprintf( c->cr_msg, sizeof( c->cr_msg),
2332 "subordinate must be \"TRUE\" or \"advertise\"" );
2333 Debug( LDAP_DEBUG_ANY,
2334 "%s: suffix \"%s\": %s.\n",
2335 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2341 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2349 * [listener=<listener>] [{read|write}=]<size>
2352 #ifdef LDAP_TCP_BUFFER
2353 static BerVarray tcp_buffer;
2356 #define SLAP_TCP_RMEM (0x1U)
2357 #define SLAP_TCP_WMEM (0x2U)
2360 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2361 int *size, int *rw, Listener **l )
2363 int i, rc = LDAP_SUCCESS;
2364 LDAPURLDesc *lud = NULL;
2367 if ( val != NULL && argv == NULL ) {
2368 char *s = val->bv_val;
2370 argv = ldap_str2charray( s, " \t" );
2371 if ( argv == NULL ) {
2377 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2380 char *url = argv[ i ] + STRLENOF( "listener=" );
2382 if ( ldap_url_parse( url, &lud ) ) {
2383 rc = LDAP_INVALID_SYNTAX;
2387 *l = config_check_my_url( url, lud );
2389 rc = LDAP_NO_SUCH_ATTRIBUTE;
2397 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2398 *rw |= SLAP_TCP_RMEM;
2399 ptr += STRLENOF( "read=" );
2401 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2402 *rw |= SLAP_TCP_WMEM;
2403 ptr += STRLENOF( "write=" );
2406 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2409 /* accept any base */
2410 if ( lutil_atoix( size, ptr, 0 ) ) {
2411 rc = LDAP_INVALID_SYNTAX;
2416 if ( val != NULL && argv != NULL ) {
2417 ldap_charray_free( argv );
2420 if ( lud != NULL ) {
2421 ldap_free_urldesc( lud );
2428 tcp_buffer_delete_one( struct berval *val )
2431 int size = -1, rw = 0;
2434 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2441 Listener **ll = slapd_get_listeners();
2443 for ( i = 0; ll[ i ] != NULL; i++ ) {
2444 if ( ll[ i ] == l ) break;
2447 if ( ll[ i ] == NULL ) {
2448 return LDAP_NO_SUCH_ATTRIBUTE;
2451 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2452 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2454 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2455 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2456 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2460 /* NOTE: this affects listeners without a specific setting,
2461 * does not reset all listeners. If a listener without
2462 * specific settings was assigned a buffer because of
2463 * a global setting, it will not be reset. In any case,
2464 * buffer changes will only take place at restart. */
2465 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2466 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2473 tcp_buffer_delete( BerVarray vals )
2477 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2478 tcp_buffer_delete_one( &vals[ i ] );
2485 tcp_buffer_unparse( int idx, int size, int rw, Listener *l, struct berval *val )
2487 char buf[sizeof("2147483648")], *ptr;
2489 /* unparse for later use */
2490 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2492 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2495 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2496 if ( rw & SLAP_TCP_RMEM ) {
2497 val->bv_len += STRLENOF( "read=" );
2498 } else if ( rw & SLAP_TCP_WMEM ) {
2499 val->bv_len += STRLENOF( "write=" );
2503 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2508 ptr = lutil_strcopy( ptr, "listener=" );
2509 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2513 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2514 if ( rw & SLAP_TCP_RMEM ) {
2515 ptr = lutil_strcopy( ptr, "read=" );
2516 } else if ( rw & SLAP_TCP_WMEM ) {
2517 ptr = lutil_strcopy( ptr, "write=" );
2521 ptr = lutil_strcopy( ptr, buf );
2524 assert( val->bv_val + val->bv_len == ptr );
2526 return LDAP_SUCCESS;
2530 tcp_buffer_add_one( int argc, char **argv, int idx )
2533 int size = -1, rw = 0;
2539 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2544 /* unparse for later use */
2545 rc = tcp_buffer_unparse( idx, size, rw, l, &val );
2546 if ( rc != LDAP_SUCCESS ) {
2550 /* use parsed values */
2553 Listener **ll = slapd_get_listeners();
2555 for ( i = 0; ll[ i ] != NULL; i++ ) {
2556 if ( ll[ i ] == l ) break;
2559 if ( ll[ i ] == NULL ) {
2560 return LDAP_NO_SUCH_ATTRIBUTE;
2563 /* buffer only applies to TCP listeners;
2564 * we do not do any check here, and delegate them
2565 * to setsockopt(2) */
2566 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2567 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2569 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2570 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2571 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2575 /* NOTE: this affects listeners without a specific setting,
2576 * does not set all listeners */
2577 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2578 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2581 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2583 idx = tcp_buffer_num;
2584 tcp_buffer[ idx ] = val;
2587 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2593 config_tcp_buffer( ConfigArgs *c )
2595 if ( c->op == SLAP_CONFIG_EMIT ) {
2596 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2599 value_add( &c->rvalue_vals, tcp_buffer );
2600 value_add( &c->rvalue_nvals, tcp_buffer );
2602 } else if ( c->op == LDAP_MOD_DELETE ) {
2604 tcp_buffer_delete( tcp_buffer );
2605 ber_bvarray_free( tcp_buffer );
2611 int size = -1, rw = 0;
2614 struct berval val = BER_BVNULL;
2618 if ( tcp_buffer_num == 0 ) {
2623 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2628 /* unparse for later use */
2629 rc = tcp_buffer_unparse( tcp_buffer_num, size, rw, l, &val );
2630 if ( rc != LDAP_SUCCESS ) {
2634 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2635 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2640 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2646 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2647 ber_memfree( tcp_buffer[ i ].bv_val );
2648 for ( ; i < tcp_buffer_num; i++ ) {
2649 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2654 if ( !BER_BVISNULL( &val ) ) {
2655 SLAP_FREE( val.bv_val );
2664 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ], idx );
2666 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2667 "<%s> unable to add value #%d",
2669 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2670 c->log, c->cr_msg, 0 );
2677 #endif /* LDAP_TCP_BUFFER */
2680 config_suffix(ConfigArgs *c)
2683 struct berval pdn, ndn;
2684 char *notallowed = NULL;
2686 if ( c->be == frontendDB ) {
2687 notallowed = "frontend";
2689 } else if ( SLAP_MONITOR(c->be) ) {
2690 notallowed = "monitor";
2692 } else if ( SLAP_CONFIG(c->be) ) {
2693 notallowed = "config";
2696 if ( notallowed != NULL ) {
2697 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2701 case LDAP_MOD_DELETE:
2702 case LDAP_MOD_REPLACE:
2703 case LDAP_MOD_INCREMENT:
2704 case SLAP_CONFIG_ADD:
2705 if ( !BER_BVISNULL( &c->value_dn ) ) {
2706 snprintf( buf, sizeof( buf ), "<%s> ",
2707 c->value_dn.bv_val );
2710 Debug(LDAP_DEBUG_ANY,
2711 "%s: suffix %snot allowed in %s database.\n",
2712 c->log, buf, notallowed );
2715 case SLAP_CONFIG_EMIT:
2716 /* don't complain when emitting... */
2720 /* FIXME: don't know what values may be valid;
2721 * please remove assertion, or add legal values
2722 * to either block */
2730 if (c->op == SLAP_CONFIG_EMIT) {
2731 if ( c->be->be_suffix == NULL
2732 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2736 value_add( &c->rvalue_vals, c->be->be_suffix );
2737 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2740 } else if ( c->op == LDAP_MOD_DELETE ) {
2741 if ( c->valx < 0 ) {
2742 ber_bvarray_free( c->be->be_suffix );
2743 ber_bvarray_free( c->be->be_nsuffix );
2744 c->be->be_suffix = NULL;
2745 c->be->be_nsuffix = NULL;
2748 ch_free( c->be->be_suffix[i].bv_val );
2749 ch_free( c->be->be_nsuffix[i].bv_val );
2751 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2752 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2754 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2759 #ifdef SLAPD_MONITOR_DN
2760 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2761 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2763 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2764 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2769 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2770 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2771 c->argv[0], c->be->bd_info->bi_type );
2772 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2773 c->log, c->cr_msg, 0);
2780 if (SLAP_DBHIDDEN( c->be ))
2783 tbe = select_backend(&ndn, 0);
2785 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2791 BackendDB *b2 = tbe;
2793 /* Does tbe precede be? */
2794 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2797 char *type = tbe->bd_info->bi_type;
2799 if ( overlay_is_over( tbe ) ) {
2800 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2801 type = oi->oi_orig->bi_type;
2804 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2805 "already served by a preceding %s database",
2806 c->argv[0], pdn.bv_val, type );
2807 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2808 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2814 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2815 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2816 "base provided \"%s\" (assuming okay)\n",
2817 c->log, default_search_base.bv_val, 0);
2819 ber_bvarray_add(&c->be->be_suffix, &pdn);
2820 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2825 config_rootdn(ConfigArgs *c) {
2826 if (c->op == SLAP_CONFIG_EMIT) {
2827 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2828 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2829 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2834 } else if ( c->op == LDAP_MOD_DELETE ) {
2835 ch_free( c->be->be_rootdn.bv_val );
2836 ch_free( c->be->be_rootndn.bv_val );
2837 BER_BVZERO( &c->be->be_rootdn );
2838 BER_BVZERO( &c->be->be_rootndn );
2841 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2842 ch_free( c->be->be_rootdn.bv_val );
2843 ch_free( c->be->be_rootndn.bv_val );
2845 c->be->be_rootdn = c->value_dn;
2846 c->be->be_rootndn = c->value_ndn;
2851 config_rootpw(ConfigArgs *c) {
2854 if (c->op == SLAP_CONFIG_EMIT) {
2855 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2856 /* don't copy, because "rootpw" is marked
2858 c->value_bv = c->be->be_rootpw;
2862 } else if ( c->op == LDAP_MOD_DELETE ) {
2863 ch_free( c->be->be_rootpw.bv_val );
2864 BER_BVZERO( &c->be->be_rootpw );
2868 tbe = select_backend(&c->be->be_rootndn, 0);
2870 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2872 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2873 c->log, c->cr_msg, 0);
2876 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2877 ch_free( c->be->be_rootpw.bv_val );
2878 c->be->be_rootpw = c->value_bv;
2883 config_restrict(ConfigArgs *c) {
2884 slap_mask_t restrictops = 0;
2886 slap_verbmasks restrictable_ops[] = {
2887 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2888 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2889 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2890 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2891 { BER_BVC("modrdn"), 0 },
2892 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2893 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2894 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2895 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2896 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2897 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2898 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2899 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2900 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2901 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2902 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2906 if (c->op == SLAP_CONFIG_EMIT) {
2907 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2909 } else if ( c->op == LDAP_MOD_DELETE ) {
2911 c->be->be_restrictops = 0;
2913 restrictops = verb_to_mask( c->line, restrictable_ops );
2914 c->be->be_restrictops ^= restrictops;
2918 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2920 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2921 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2922 c->log, c->cr_msg, c->argv[i]);
2925 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2926 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2927 c->be->be_restrictops |= restrictops;
2932 config_allows(ConfigArgs *c) {
2933 slap_mask_t allows = 0;
2935 slap_verbmasks allowable_ops[] = {
2936 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2937 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2938 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2939 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2940 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2943 if (c->op == SLAP_CONFIG_EMIT) {
2944 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2945 } else if ( c->op == LDAP_MOD_DELETE ) {
2949 allows = verb_to_mask( c->line, allowable_ops );
2950 global_allows ^= allows;
2954 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2956 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2957 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2958 c->log, c->cr_msg, c->argv[i]);
2961 global_allows |= allows;
2966 config_disallows(ConfigArgs *c) {
2967 slap_mask_t disallows = 0;
2969 slap_verbmasks disallowable_ops[] = {
2970 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2971 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2972 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2973 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2974 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
2975 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
2978 if (c->op == SLAP_CONFIG_EMIT) {
2979 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2980 } else if ( c->op == LDAP_MOD_DELETE ) {
2982 global_disallows = 0;
2984 disallows = verb_to_mask( c->line, disallowable_ops );
2985 global_disallows ^= disallows;
2989 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2991 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2992 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2993 c->log, c->cr_msg, c->argv[i]);
2996 global_disallows |= disallows;
3001 config_requires(ConfigArgs *c) {
3002 slap_mask_t requires = frontendDB->be_requires;
3003 int i, argc = c->argc;
3004 char **argv = c->argv;
3006 slap_verbmasks requires_ops[] = {
3007 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3008 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3009 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3010 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3011 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3014 if (c->op == SLAP_CONFIG_EMIT) {
3015 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3016 } else if ( c->op == LDAP_MOD_DELETE ) {
3018 c->be->be_requires = 0;
3020 requires = verb_to_mask( c->line, requires_ops );
3021 c->be->be_requires ^= requires;
3025 /* "none" can only be first, to wipe out default/global values */
3026 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3031 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3033 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3034 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3035 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3036 c->log, c->cr_msg, 0);
3038 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3039 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3040 c->log, c->cr_msg, c->argv[i]);
3044 c->be->be_requires = requires;
3048 static slap_verbmasks *loglevel_ops;
3051 loglevel_init( void )
3053 slap_verbmasks lo[] = {
3054 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3055 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3056 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3057 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3058 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3059 { BER_BVC("BER"), LDAP_DEBUG_BER },
3060 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3061 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3062 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3063 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3064 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3065 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3066 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3067 #if 0 /* no longer used (nor supported) */
3068 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3069 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3071 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3072 { BER_BVC("None"), LDAP_DEBUG_NONE },
3076 return slap_verbmasks_init( &loglevel_ops, lo );
3080 loglevel_destroy( void )
3082 if ( loglevel_ops ) {
3083 (void)slap_verbmasks_destroy( loglevel_ops );
3085 loglevel_ops = NULL;
3088 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3091 slap_loglevel_register( slap_mask_t m, struct berval *s )
3095 if ( loglevel_ops == NULL ) {
3099 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3102 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3110 slap_loglevel_get( struct berval *s, int *l )
3115 if ( loglevel_ops == NULL ) {
3119 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3120 m |= loglevel_ops[ i ].mask;
3123 for ( i = 1; m & i; i <<= 1 )
3130 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3133 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3144 str2loglevel( const char *s, int *l )
3148 if ( loglevel_ops == NULL ) {
3152 i = verb_to_mask( s, loglevel_ops );
3154 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3158 *l = loglevel_ops[ i ].mask;
3164 loglevel2str( int l )
3166 struct berval bv = BER_BVNULL;
3168 loglevel2bv( l, &bv );
3174 loglevel2bv( int l, struct berval *bv )
3176 if ( loglevel_ops == NULL ) {
3182 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3186 loglevel2bvarray( int l, BerVarray *bva )
3188 if ( loglevel_ops == NULL ) {
3192 return mask_to_verbs( loglevel_ops, l, bva );
3196 loglevel_print( FILE *out )
3200 if ( loglevel_ops == NULL ) {
3204 fprintf( out, "Installed log subsystems:\n\n" );
3205 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3206 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3208 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3209 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3210 loglevel_ops[ i ].word.bv_val, mask, mask );
3213 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3214 "by specific code\n\n" );
3219 static int config_syslog;
3222 config_loglevel(ConfigArgs *c) {
3225 if ( loglevel_ops == NULL ) {
3229 if (c->op == SLAP_CONFIG_EMIT) {
3230 /* Get default or commandline slapd setting */
3231 if ( ldap_syslog && !config_syslog )
3232 config_syslog = ldap_syslog;
3233 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3235 } else if ( c->op == LDAP_MOD_DELETE ) {
3239 int level = verb_to_mask( c->line, loglevel_ops );
3240 config_syslog ^= level;
3242 if ( slapMode & SLAP_SERVER_MODE ) {
3243 ldap_syslog = config_syslog;
3248 for( i=1; i < c->argc; i++ ) {
3251 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3252 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3253 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3254 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3255 c->log, c->cr_msg, c->argv[i]);
3259 if ( str2loglevel( c->argv[i], &level ) ) {
3260 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3261 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3262 c->log, c->cr_msg, c->argv[i]);
3266 /* Explicitly setting a zero clears all the levels */
3268 config_syslog |= level;
3272 if ( slapMode & SLAP_SERVER_MODE ) {
3273 ldap_syslog = config_syslog;
3279 config_referral(ConfigArgs *c) {
3281 if (c->op == SLAP_CONFIG_EMIT) {
3282 if ( default_referral ) {
3283 value_add( &c->rvalue_vals, default_referral );
3288 } else if ( c->op == LDAP_MOD_DELETE ) {
3289 if ( c->valx < 0 ) {
3290 ber_bvarray_free( default_referral );
3291 default_referral = NULL;
3294 ch_free( default_referral[i].bv_val );
3295 for (; default_referral[i].bv_val; i++ )
3296 default_referral[i] = default_referral[i+1];
3300 if(validate_global_referral(c->argv[1])) {
3301 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3302 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3303 c->log, c->cr_msg, c->argv[1]);
3307 ber_str2bv(c->argv[1], 0, 0, &val);
3308 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3316 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3317 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3318 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3319 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3320 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3321 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3322 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3323 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3324 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3329 config_security(ConfigArgs *c) {
3330 slap_ssf_set_t *set = &c->be->be_ssf_set;
3333 if (c->op == SLAP_CONFIG_EMIT) {
3339 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3340 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3343 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3344 if ( bv.bv_len >= sizeof( numbuf ) ) {
3345 ber_bvarray_free_x( c->rvalue_vals, NULL );
3346 c->rvalue_vals = NULL;
3350 bv.bv_len += sec_keys[i].key.bv_len;
3351 bv.bv_val = ch_malloc( bv.bv_len + 1);
3352 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3353 strcpy( next, numbuf );
3354 ber_bvarray_add( &c->rvalue_vals, &bv );
3359 for(i = 1; i < c->argc; i++) {
3360 slap_ssf_t *tgt = NULL;
3362 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3363 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3364 sec_keys[j].key.bv_len)) {
3365 src = c->argv[i] + sec_keys[j].key.bv_len;
3366 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3371 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3372 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3373 c->log, c->cr_msg, c->argv[i]);
3377 if ( lutil_atou( tgt, src ) != 0 ) {
3378 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3379 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3380 c->log, c->cr_msg, c->argv[i]);
3388 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3392 for (; !BER_BVISNULL( &an->an_name ); an++) {
3393 /* if buflen == 0, assume the buffer size has been
3394 * already checked otherwise */
3395 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3396 if ( comma ) *ptr++ = ',';
3397 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3404 config_updatedn(ConfigArgs *c) {
3405 if (c->op == SLAP_CONFIG_EMIT) {
3406 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3407 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3408 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3412 } else if ( c->op == LDAP_MOD_DELETE ) {
3413 ch_free( c->be->be_update_ndn.bv_val );
3414 BER_BVZERO( &c->be->be_update_ndn );
3415 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3418 if(SLAP_SHADOW(c->be)) {
3419 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3420 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3421 c->log, c->cr_msg, 0);
3425 ber_memfree_x( c->value_dn.bv_val, NULL );
3426 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3427 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3429 c->be->be_update_ndn = c->value_ndn;
3430 BER_BVZERO( &c->value_dn );
3431 BER_BVZERO( &c->value_ndn );
3433 return config_slurp_shadow( c );
3437 config_shadow( ConfigArgs *c, slap_mask_t flag )
3439 char *notallowed = NULL;
3441 if ( c->be == frontendDB ) {
3442 notallowed = "frontend";
3444 } else if ( SLAP_MONITOR(c->be) ) {
3445 notallowed = "monitor";
3448 if ( notallowed != NULL ) {
3449 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3453 if ( SLAP_SHADOW(c->be) ) {
3454 /* if already shadow, only check consistency */
3455 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3456 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3462 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3469 config_updateref(ConfigArgs *c) {
3471 if (c->op == SLAP_CONFIG_EMIT) {
3472 if ( c->be->be_update_refs ) {
3473 value_add( &c->rvalue_vals, c->be->be_update_refs );
3478 } else if ( c->op == LDAP_MOD_DELETE ) {
3479 if ( c->valx < 0 ) {
3480 ber_bvarray_free( c->be->be_update_refs );
3481 c->be->be_update_refs = NULL;
3484 ch_free( c->be->be_update_refs[i].bv_val );
3485 for (; c->be->be_update_refs[i].bv_val; i++)
3486 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3490 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3491 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3493 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3494 c->log, c->cr_msg, 0);
3498 if(validate_global_referral(c->argv[1])) {
3499 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3500 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3501 c->log, c->cr_msg, c->argv[1]);
3504 ber_str2bv(c->argv[1], 0, 0, &val);
3505 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3510 config_obsolete(ConfigArgs *c) {
3511 if (c->op == SLAP_CONFIG_EMIT)
3514 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3516 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3521 config_include(ConfigArgs *c) {
3522 int savelineno = c->lineno;
3525 ConfigFile *cfsave = cfn;
3526 ConfigFile *cf2 = NULL;
3528 /* Leftover from RE23. No dynamic config for include files */
3529 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3532 cf = ch_calloc( 1, sizeof(ConfigFile));
3533 if ( cfn->c_kids ) {
3534 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3540 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3541 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3542 c->lineno = savelineno - 1;
3545 if ( cf2 ) cf2->c_sibs = NULL;
3546 else cfn->c_kids = NULL;
3547 ch_free( cf->c_file.bv_val );
3557 config_tls_cleanup(ConfigArgs *c) {
3560 if ( slap_tls_ld ) {
3563 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3565 /* Force new ctx to be created */
3566 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3568 /* The ctx's refcount is bumped up here */
3569 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3570 /* This is a no-op if it's already loaded */
3571 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3578 config_tls_option(ConfigArgs *c) {
3580 LDAP *ld = slap_tls_ld;
3582 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3583 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3584 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3585 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3586 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3587 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3588 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3590 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3592 default: Debug(LDAP_DEBUG_ANY, "%s: "
3593 "unknown tls_option <0x%x>\n",
3594 c->log, c->type, 0);
3597 if (c->op == SLAP_CONFIG_EMIT) {
3598 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3599 } else if ( c->op == LDAP_MOD_DELETE ) {
3600 c->cleanup = config_tls_cleanup;
3601 return ldap_pvt_tls_set_option( ld, flag, NULL );
3603 ch_free(c->value_string);
3604 c->cleanup = config_tls_cleanup;
3605 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3608 /* FIXME: this ought to be provided by libldap */
3610 config_tls_config(ConfigArgs *c) {
3613 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3614 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3615 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3617 Debug(LDAP_DEBUG_ANY, "%s: "
3618 "unknown tls_option <0x%x>\n",
3619 c->log, c->type, 0);
3622 if (c->op == SLAP_CONFIG_EMIT) {
3623 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3624 } else if ( c->op == LDAP_MOD_DELETE ) {
3626 c->cleanup = config_tls_cleanup;
3627 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3629 ch_free( c->value_string );
3630 c->cleanup = config_tls_cleanup;
3631 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3632 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3633 Debug(LDAP_DEBUG_ANY, "%s: "
3634 "unable to parse %s \"%s\"\n",
3635 c->log, c->argv[0], c->argv[1] );
3638 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3640 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3645 static CfEntryInfo *
3646 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3656 if ( dn_match( &root->ce_entry->e_nname, dn ))
3659 c = dn->bv_val+dn->bv_len;
3660 for (;*c != ',';c--);
3664 for (--c;c>dn->bv_val && *c != ',';c--);
3668 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3670 root = root->ce_kids;
3672 for (;root;root=root->ce_sibs) {
3673 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3674 if ( cdn.bv_val == dn->bv_val ) {
3684 typedef struct setup_cookie {
3694 config_ldif_resp( Operation *op, SlapReply *rs )
3696 if ( rs->sr_type == REP_SEARCH ) {
3697 setup_cookie *sc = op->o_callback->sc_private;
3700 sc->cfb->cb_got_ldif = 1;
3701 /* Does the frontend exist? */
3702 if ( !sc->got_frontend ) {
3703 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3704 "olcDatabase", STRLENOF( "olcDatabase" )))
3706 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3707 STRLENOF( "olcDatabase" ), "={-1}frontend",
3708 STRLENOF( "={-1}frontend" )))
3712 sc->ca->be = frontendDB;
3713 sc->ca->bi = frontendDB->bd_info;
3714 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3715 rdn.bv_val = sc->ca->log;
3716 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3717 "%s=" SLAP_X_ORDERED_FMT "%s",
3718 cfAd_database->ad_cname.bv_val, -1,
3719 sc->ca->bi->bi_type);
3721 sc->frontend = config_build_entry( op, rs,
3722 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3723 sc->ca->be->be_cf_ocs );
3733 dnParent( &rs->sr_entry->e_nname, &pdn );
3735 /* Does the configDB exist? */
3736 if ( sc->got_frontend && !sc->got_config &&
3737 !strncmp( rs->sr_entry->e_nname.bv_val,
3738 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3739 dn_match( &config_rdn, &pdn ) )
3741 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3742 STRLENOF( "olcDatabase" ), "={0}config",
3743 STRLENOF( "={0}config" )))
3747 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3748 sc->ca->bi = sc->ca->be->bd_info;
3749 rdn.bv_val = sc->ca->log;
3750 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3751 "%s=" SLAP_X_ORDERED_FMT "%s",
3752 cfAd_database->ad_cname.bv_val, 0,
3753 sc->ca->bi->bi_type);
3755 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3756 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3763 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3764 if ( rs->sr_err != LDAP_SUCCESS ) {
3765 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3766 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3772 /* Configure and read the underlying back-ldif store */
3774 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3775 CfBackInfo *cfb = be->be_private;
3781 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3782 Connection conn = {0};
3783 OperationBuffer opbuf;
3785 SlapReply rs = {REP_RESULT};
3786 Filter filter = { LDAP_FILTER_PRESENT };
3787 struct berval filterstr = BER_BVC("(objectclass=*)");
3790 /* Is the config directory available? */
3791 if ( stat( dir, &st ) < 0 ) {
3792 /* No, so don't bother using the backing store.
3793 * All changes will be in-memory only.
3798 cfb->cb_db.bd_info = backend_info( "ldif" );
3799 if ( !cfb->cb_db.bd_info )
3800 return 0; /* FIXME: eventually this will be a fatal error */
3802 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3805 cfb->cb_db.be_suffix = be->be_suffix;
3806 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3808 /* The suffix is always "cn=config". The underlying DB's rootdn
3809 * is always the same as the suffix.
3811 cfb->cb_db.be_rootdn = be->be_suffix[0];
3812 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3814 ber_str2bv( dir, 0, 1, &cfdir );
3819 argv[0] = "directory";
3820 argv[1] = (char *)dir;
3825 c.table = Cft_Database;
3827 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3831 if ( config_add_vals( ct, &c ))
3834 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3838 void *thrctx = ldap_pvt_thread_pool_context();
3841 connection_fake_init( &conn, &opbuf, thrctx );
3844 filter.f_desc = slap_schema.si_ad_objectClass;
3846 op->o_tag = LDAP_REQ_SEARCH;
3848 op->ors_filter = &filter;
3849 op->ors_filterstr = filterstr;
3850 op->ors_scope = LDAP_SCOPE_SUBTREE;
3852 op->o_dn = c.be->be_rootdn;
3853 op->o_ndn = c.be->be_rootndn;
3855 op->o_req_dn = be->be_suffix[0];
3856 op->o_req_ndn = be->be_nsuffix[0];
3858 op->ors_tlimit = SLAP_NO_LIMIT;
3859 op->ors_slimit = SLAP_NO_LIMIT;
3861 op->ors_attrs = slap_anlist_all_attributes;
3862 op->ors_attrsonly = 0;
3864 op->o_callback = &cb;
3867 cb.sc_private = ≻
3868 sc.got_frontend = 0;
3873 op->o_bd = &cfb->cb_db;
3875 /* Allow unknown attrs in DNs */
3876 prev_DN_strict = slap_DN_strict;
3879 rc = op->o_bd->be_search( op, &rs );
3881 /* Restore normal DN validation */
3882 slap_DN_strict = prev_DN_strict;
3884 op->o_tag = LDAP_REQ_ADD;
3885 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3886 op->ora_e = sc.frontend;
3887 rc = op->o_bd->be_add( op, &rs );
3889 if ( rc == LDAP_SUCCESS && sc.config ) {
3890 op->ora_e = sc.config;
3891 rc = op->o_bd->be_add( op, &rs );
3893 ldap_pvt_thread_pool_context_reset( thrctx );
3896 /* ITS#4194 - only use if it's present, or we're converting. */
3897 if ( !readit || rc == LDAP_SUCCESS )
3898 cfb->cb_use_ldif = 1;
3904 CfOc_cmp( const void *c1, const void *c2 ) {
3905 const ConfigOCs *co1 = c1;
3906 const ConfigOCs *co2 = c2;
3908 return ber_bvcmp( co1->co_name, co2->co_name );
3912 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3915 i = init_config_attrs( ct );
3918 /* set up the objectclasses */
3919 i = init_config_ocs( ocs );
3922 for (i=0; ocs[i].co_def; i++) {
3923 if ( ocs[i].co_oc ) {
3924 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3925 if ( !ocs[i].co_table )
3926 ocs[i].co_table = ct;
3927 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3934 read_config(const char *fname, const char *dir) {
3937 const char *cfdir, *cfname;
3940 /* Setup the config backend */
3941 be = backend_db_init( "config", NULL, 0, NULL );
3945 cfb = be->be_private;
3946 be->be_dfltaccess = ACL_NONE;
3948 /* If no .conf, or a dir was specified, setup the dir */
3949 if ( !fname || dir ) {
3951 /* If explicitly given, check for existence */
3954 if ( stat( dir, &st ) < 0 ) {
3955 Debug( LDAP_DEBUG_ANY,
3956 "invalid config directory %s, error %d\n",
3962 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3964 /* if fname is defaulted, try reading .d */
3965 rc = config_setup_ldif( be, cfdir, !fname );
3968 /* It may be OK if the base object doesn't exist yet. */
3969 if ( rc != LDAP_NO_SUCH_OBJECT )
3971 /* ITS#4194: But if dir was specified and no fname,
3972 * then we were supposed to read the dir. Unless we're
3973 * trying to slapadd the dir...
3975 if ( dir && !fname ) {
3976 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3978 /* Assume it's slapadd with a config dir, let it continue */
3980 cfb->cb_got_ldif = 1;
3981 cfb->cb_use_ldif = 1;
3986 /* If we read the config from back-ldif, nothing to do here */
3987 if ( cfb->cb_got_ldif ) {
3996 cfname = SLAPD_DEFAULT_CONFIGFILE;
3998 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4001 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4004 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4005 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4006 &frontendDB->be_schemadn );
4007 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4008 if ( rc != LDAP_SUCCESS ) {
4009 Debug(LDAP_DEBUG_ANY, "read_config: "
4010 "unable to normalize default schema DN \"%s\"\n",
4011 frontendDB->be_schemadn.bv_val, 0, 0 );
4012 /* must not happen */
4020 config_back_bind( Operation *op, SlapReply *rs )
4022 if ( be_isroot_pw( op ) ) {
4023 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4024 /* frontend sends result */
4025 return LDAP_SUCCESS;
4028 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4029 send_ldap_result( op, rs );
4035 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4039 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4041 rs->sr_attrs = op->ors_attrs;
4042 rs->sr_entry = ce->ce_entry;
4044 rc = send_search_entry( op, rs );
4045 if ( rc != LDAP_SUCCESS ) {
4049 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4050 if ( ce->ce_kids ) {
4051 rc = config_send( op, rs, ce->ce_kids, 1 );
4052 if ( rc ) return rc;
4055 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4056 rc = config_send( op, rs, ce, 0 );
4064 static ConfigTable *
4065 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4070 for (j=0; j<nocs; j++) {
4071 for (i=0; colst[j]->co_table[i].name; i++)
4072 if ( colst[j]->co_table[i].ad == ad ) {
4073 ca->table = colst[j]->co_type;
4074 return &colst[j]->co_table[i];
4080 /* Sort the attributes of the entry according to the order defined
4081 * in the objectclass, with required attributes occurring before
4082 * allowed attributes. For any attributes with sequencing dependencies
4083 * (e.g., rootDN must be defined after suffix) the objectclass must
4084 * list the attributes in the desired sequence.
4087 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4089 Attribute *a, *head = NULL, *tail = NULL, **prev;
4092 for (i=0; i<nocs; i++) {
4093 if ( colst[i]->co_oc->soc_required ) {
4094 AttributeType **at = colst[i]->co_oc->soc_required;
4095 for (j=0; at[j]; j++) {
4096 for (a=e->e_attrs, prev=&e->e_attrs; a;
4097 prev = &(*prev)->a_next, a=a->a_next) {
4098 if ( a->a_desc == at[j]->sat_ad ) {
4112 if ( colst[i]->co_oc->soc_allowed ) {
4113 AttributeType **at = colst[i]->co_oc->soc_allowed;
4114 for (j=0; at[j]; j++) {
4115 for (a=e->e_attrs, prev=&e->e_attrs; a;
4116 prev = &(*prev)->a_next, a=a->a_next) {
4117 if ( a->a_desc == at[j]->sat_ad ) {
4133 tail->a_next = e->e_attrs;
4139 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4141 Attribute *a = NULL;
4142 AttributeDescription *ad;
4152 Modifications *ml = ptr;
4154 vals = ml->sml_values;
4157 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4158 rc = ordered_value_sort( a, 1 );
4160 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4161 ad->ad_cname.bv_val );
4165 for ( i=0; vals[i].bv_val; i++ ) {
4166 ca->line = vals[i].bv_val;
4167 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4168 ca->line[0] == '{' ) {
4169 char *idx = strchr( ca->line, '}' );
4170 if ( idx ) ca->line = idx+1;
4172 rc = config_parse_vals( ct, ca, i );
4181 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4184 struct berval rtype, rval;
4186 AttributeDescription *ad = NULL;
4188 dnRdn( &e->e_name, rdn );
4189 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4190 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4191 rtype.bv_val = rdn->bv_val;
4192 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4195 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4196 a = attr_find( e->e_attrs, ad );
4197 if (!a ) return LDAP_NAMING_VIOLATION;
4204 config_rename_kids( CfEntryInfo *ce )
4207 struct berval rdn, nrdn;
4209 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4210 struct berval newdn, newndn;
4211 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4212 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4213 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4214 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4215 free( ce2->ce_entry->e_name.bv_val );
4216 free( ce2->ce_entry->e_nname.bv_val );
4217 ce2->ce_entry->e_name = newdn;
4218 ce2->ce_entry->e_nname = newndn;
4219 config_rename_kids( ce2 );
4224 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4225 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4226 struct berval *nnewrdn, int use_ldif )
4230 struct berval odn, ondn;
4234 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4235 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4238 free( a->a_vals[0].bv_val );
4239 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4240 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4241 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4242 strcpy( a->a_vals[0].bv_val, ptr1 );
4244 if ( a->a_nvals != a->a_vals ) {
4245 free( a->a_nvals[0].bv_val );
4246 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4247 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4248 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4249 strcpy( a->a_nvals[0].bv_val, ptr1 );
4252 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4253 BackendDB *be = op->o_bd;
4254 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4255 struct berval dn, ndn, xdn, xndn;
4257 op->o_bd = &cfb->cb_db;
4259 /* Save current rootdn; use the underlying DB's rootdn */
4263 xndn = op->o_req_ndn;
4264 op->o_dn = op->o_bd->be_rootdn;
4265 op->o_ndn = op->o_bd->be_rootndn;
4267 op->o_req_ndn = ondn;
4269 scp = op->o_callback;
4270 op->o_callback = ≻
4271 op->orr_newrdn = *newrdn;
4272 op->orr_nnewrdn = *nnewrdn;
4273 op->orr_newSup = NULL;
4274 op->orr_nnewSup = NULL;
4275 op->orr_deleteoldrdn = 1;
4276 op->orr_modlist = NULL;
4277 slap_modrdn2mods( op, rs );
4278 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4279 rc = op->o_bd->be_modrdn( op, rs );
4280 slap_mods_free( op->orr_modlist, 1 );
4283 op->o_callback = scp;
4287 op->o_req_ndn = xndn;
4290 free( ondn.bv_val );
4292 config_rename_kids( e->e_private );
4297 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4298 Entry *e, int idx, int tailindex, int use_ldif )
4300 struct berval ival, newrdn, nnewrdn;
4303 char ibuf[32], *ptr1, *ptr2 = NULL;
4306 rc = config_rename_attr( rs, e, &rdn, &a );
4307 if ( rc ) return rc;
4310 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4311 if ( ival.bv_len >= sizeof( ibuf ) ) {
4312 return LDAP_NAMING_VIOLATION;
4315 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4316 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4319 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4320 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4323 ptr2 = ber_bvchr( &rdn, '}' );
4327 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4329 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4330 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4331 a->a_desc->ad_cname.bv_len );
4333 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4334 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4338 /* Do the equivalent of ModRDN */
4339 /* Replace DN / NDN */
4340 newrdn.bv_len = ptr1 - newrdn.bv_val;
4341 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4342 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4344 free( nnewrdn.bv_val );
4345 free( newrdn.bv_val );
4350 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4351 SlapReply *rs, int *renum, int *ibase )
4354 int index = -1, gotindex = 0, nsibs, rc = 0;
4355 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4356 char *ptr1, *ptr2 = NULL;
4359 if ( renum ) *renum = 0;
4361 /* These entries don't get indexed/renumbered */
4362 if ( ce_type == Cft_Global ) return 0;
4363 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4365 if ( ce_type == Cft_Module )
4368 /* See if the rdn has an index already */
4369 dnRdn( &e->e_name, &rdn );
4370 if ( ce_type == Cft_Database ) {
4371 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4372 "frontend", STRLENOF("frontend") ))
4374 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4375 "config", STRLENOF("config") ))
4378 ptr1 = ber_bvchr( &e->e_name, '{' );
4379 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4381 ptr2 = strchr( ptr1, '}' );
4382 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4383 return LDAP_NAMING_VIOLATION;
4384 if ( ptr2-ptr1 == 1)
4385 return LDAP_NAMING_VIOLATION;
4387 index = strtol( ptr1 + 1, &next, 10 );
4388 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4389 return LDAP_NAMING_VIOLATION;
4392 /* Special case, we allow -1 for the frontendDB */
4393 if ( index != -1 || !isfrontend )
4394 return LDAP_NAMING_VIOLATION;
4396 if ( isconfig && index != 0 ){
4397 return LDAP_NAMING_VIOLATION;
4401 /* count related kids */
4402 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4403 if ( ce->ce_type == ce_type ) nsibs++;
4406 /* account for -1 frontend */
4407 if ( ce_type == Cft_Database )
4410 if ( index != nsibs ) {
4412 if ( index < nsibs ) {
4413 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4414 /* Siblings need to be renumbered */
4415 if ( index != -1 || !isfrontend )
4419 /* config DB is always "0" */
4420 if ( isconfig && index == -1 ) {
4423 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4427 /* just make index = nsibs */
4429 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4432 if ( ibase ) *ibase = index;
4433 if ( renum ) *renum = renumber;
4438 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4443 co.co_name = &oc->soc_cname;
4444 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4448 /* check for duplicates */
4449 for ( i = 0; i < *nocs; i++ ) {
4450 if ( *copp && (*copp)[i] == cop ) {
4456 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4457 if ( tmp == NULL ) {
4461 (*copp)[*nocs] = cop;
4466 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4467 if ( count_oc( *sups, copp, nocs ) ) {
4476 count_ocs( Attribute *oc_at, int *nocs )
4479 ConfigOCs **colst = NULL;
4483 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4487 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4489 assert( oc != NULL );
4490 if ( count_oc( oc, &colst, nocs ) ) {
4500 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4502 /* Leftover from RE23. Never parse this entry */
4503 return LDAP_COMPARE_TRUE;
4507 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4511 /* This entry is hardcoded, don't re-parse it */
4512 if ( p->ce_type == Cft_Global ) {
4513 cfn = p->ce_private;
4514 ca->ca_private = cfn;
4515 return LDAP_COMPARE_TRUE;
4517 if ( p->ce_type != Cft_Schema )
4518 return LDAP_CONSTRAINT_VIOLATION;
4520 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4521 ca->ca_private = cfn;
4522 cfo = p->ce_private;
4523 cfn->c_sibs = cfo->c_kids;
4525 return LDAP_SUCCESS;
4529 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4531 if ( p->ce_type != Cft_Global ) {
4532 return LDAP_CONSTRAINT_VIOLATION;
4534 /* config must be {0}, nothing else allowed */
4535 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4536 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4537 return LDAP_CONSTRAINT_VIOLATION;
4539 ca->be = frontendDB; /* just to get past check_vals */
4540 return LDAP_SUCCESS;
4544 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4546 if ( p->ce_type != Cft_Global ) {
4547 return LDAP_CONSTRAINT_VIOLATION;
4549 return LDAP_SUCCESS;
4553 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4555 if ( p->ce_type != Cft_Global ) {
4556 return LDAP_CONSTRAINT_VIOLATION;
4558 return LDAP_SUCCESS;
4562 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4564 if ( p->ce_type != Cft_Database ) {
4565 return LDAP_CONSTRAINT_VIOLATION;
4568 return LDAP_SUCCESS;
4572 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4577 AttributeDescription *ad;
4582 if ( cfn->c_cr_head ) {
4583 struct berval bv = BER_BVC("olcDitContentRules");
4585 slap_bv2ad( &bv, &ad, &text );
4586 ct = config_find_table( colst, nocs, ad, ca );
4587 config_del_vals( ct, ca );
4589 if ( cfn->c_oc_head ) {
4590 struct berval bv = BER_BVC("olcObjectClasses");
4592 slap_bv2ad( &bv, &ad, &text );
4593 ct = config_find_table( colst, nocs, ad, ca );
4594 config_del_vals( ct, ca );
4596 if ( cfn->c_at_head ) {
4597 struct berval bv = BER_BVC("olcAttributeTypes");
4599 slap_bv2ad( &bv, &ad, &text );
4600 ct = config_find_table( colst, nocs, ad, ca );
4601 config_del_vals( ct, ca );
4603 if ( cfn->c_syn_head ) {
4604 struct berval bv = BER_BVC("olcLdapSyntaxes");
4606 slap_bv2ad( &bv, &ad, &text );
4607 ct = config_find_table( colst, nocs, ad, ca );
4608 config_del_vals( ct, ca );
4610 if ( cfn->c_om_head ) {
4611 struct berval bv = BER_BVC("olcObjectIdentifier");
4613 slap_bv2ad( &bv, &ad, &text );
4614 ct = config_find_table( colst, nocs, ad, ca );
4615 config_del_vals( ct, ca );
4617 cfo = p->ce_private;
4618 cfo->c_kids = cfn->c_sibs;
4623 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4625 int rc = LDAP_CONSTRAINT_VIOLATION;
4628 if ( (*cop)->co_ldadd ) {
4629 rc = (*cop)->co_ldadd( last, e, ca );
4630 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4635 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4636 ConfigOCs co = { 0 };
4638 co.co_name = &(*ocp)->soc_cname;
4639 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4640 if ( *cop == NULL ) {
4644 rc = config_add_oc( cop, last, e, ca );
4645 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4653 /* Parse an LDAP entry into config directives */
4655 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4656 int *renum, Operation *op )
4658 CfEntryInfo *ce, *last = NULL;
4659 ConfigOCs co, *coptr, **colst;
4660 Attribute *a, *oc_at, *soc_at;
4661 int i, ibase = -1, nocs, rc = 0;
4664 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4666 memset( ca, 0, sizeof(ConfigArgs));
4668 /* Make sure parent exists and entry does not. But allow
4669 * Databases and Overlays to be inserted. Don't do any
4670 * auto-renumbering if manageDSAit control is present.
4672 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4674 if ( ( op && op->o_managedsait ) ||
4675 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4676 ce->ce_type != Cft_Module ) )
4678 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4679 "DN=\"%s\" already exists\n",
4680 log_prefix, e->e_name.bv_val, 0 );
4681 return LDAP_ALREADY_EXISTS;
4685 dnParent( &e->e_nname, &pdn );
4687 /* If last is NULL, the new entry is the root/suffix entry,
4688 * otherwise last should be the parent.
4690 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4692 rs->sr_matched = last->ce_entry->e_name.bv_val;
4694 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4695 "DN=\"%s\" not child of DN=\"%s\"\n",
4696 log_prefix, e->e_name.bv_val,
4697 last->ce_entry->e_name.bv_val );
4698 return LDAP_NO_SUCH_OBJECT;
4702 /* No parent, must be root. This will never happen... */
4703 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4704 return LDAP_NO_SUCH_OBJECT;
4707 if ( last && !access_allowed( op, last->ce_entry,
4708 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4710 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4711 "DN=\"%s\" no write access to \"children\" of parent\n",
4712 log_prefix, e->e_name.bv_val, 0 );
4713 return LDAP_INSUFFICIENT_ACCESS;
4717 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4719 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4720 "DN=\"%s\" no objectClass\n",
4721 log_prefix, e->e_name.bv_val, 0 );
4722 return LDAP_OBJECT_CLASS_VIOLATION;
4725 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4727 ObjectClass *soc = NULL;
4728 char textbuf[ SLAP_TEXT_BUFLEN ];
4729 const char *text = textbuf;
4731 /* FIXME: check result */
4732 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4733 &text, textbuf, sizeof(textbuf), NULL );
4734 if ( rc != LDAP_SUCCESS ) {
4735 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4736 "DN=\"%s\" no structural objectClass (%s)\n",
4737 log_prefix, e->e_name.bv_val, text );
4740 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4741 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4742 if ( soc_at == NULL ) {
4743 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4744 "DN=\"%s\" no structural objectClass; "
4745 "unable to merge computed class %s\n",
4746 log_prefix, e->e_name.bv_val,
4747 soc->soc_cname.bv_val );
4748 return LDAP_OBJECT_CLASS_VIOLATION;
4751 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4752 "DN=\"%s\" no structural objectClass; "
4753 "computed objectClass %s merged\n",
4754 log_prefix, e->e_name.bv_val,
4755 soc->soc_cname.bv_val );
4758 /* Fake the coordinates based on whether we're part of an
4759 * LDAP Add or if reading the config dir
4762 ca->fname = "slapd";
4765 ca->fname = cfdir.bv_val;
4770 co.co_name = &soc_at->a_nvals[0];
4771 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4772 if ( coptr == NULL ) {
4773 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4774 "DN=\"%s\" no structural objectClass in configuration table\n",
4775 log_prefix, e->e_name.bv_val, 0 );
4776 return LDAP_OBJECT_CLASS_VIOLATION;
4779 /* Only the root can be Cft_Global, everything else must
4780 * have a parent. Only limited nesting arrangements are allowed.
4782 rc = LDAP_CONSTRAINT_VIOLATION;
4783 if ( coptr->co_type == Cft_Global && !last ) {
4784 cfn = cfb->cb_config;
4785 ca->ca_private = cfn;
4786 ca->be = frontendDB; /* just to get past check_vals */
4790 colst = count_ocs( oc_at, &nocs );
4792 /* Check whether the Add is allowed by its parent, and do
4793 * any necessary arg setup
4796 rc = config_add_oc( &coptr, last, e, ca );
4797 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4798 for ( i = 0; i<nocs; i++ ) {
4799 /* Already checked these */
4800 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4802 if ( colst[i]->co_ldadd &&
4803 ( rc = colst[i]->co_ldadd( last, e, ca ))
4804 != LDAP_CONSTRAINT_VIOLATION ) {
4810 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4811 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4812 "DN=\"%s\" no structural objectClass add function\n",
4813 log_prefix, e->e_name.bv_val, 0 );
4814 return LDAP_OBJECT_CLASS_VIOLATION;
4818 /* Add the entry but don't parse it, we already have its contents */
4819 if ( rc == LDAP_COMPARE_TRUE ) {
4824 if ( rc != LDAP_SUCCESS )
4827 /* Parse all the values and check for simple syntax errors before
4828 * performing any set actions.
4830 * If doing an LDAPadd, check for indexed names and any necessary
4831 * renaming/renumbering. Entries that don't need indexed names are
4832 * ignored. Entries that need an indexed name and arrive without one
4833 * are assigned to the end. Entries that arrive with an index may
4834 * cause the following entries to be renumbered/bumped down.
4836 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4837 * don't allow Adding an entry with an index that's already in use.
4838 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4840 * These entries can have auto-assigned indexes (appended to the end)
4841 * but only the other types support auto-renumbering of siblings.
4844 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4849 if ( renum && *renum && coptr->co_type != Cft_Database &&
4850 coptr->co_type != Cft_Overlay )
4852 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4853 "operation requires sibling renumbering" );
4854 rc = LDAP_UNWILLING_TO_PERFORM;
4859 init_config_argv( ca );
4861 /* Make sure we process attrs in the required order */
4862 sort_attrs( e, colst, nocs );
4864 for ( a = e->e_attrs; a; a = a->a_next ) {
4865 if ( a == oc_at ) continue;
4866 ct = config_find_table( colst, nocs, a->a_desc, ca );
4867 if ( !ct ) continue; /* user data? */
4868 rc = check_vals( ct, ca, a, 1 );
4869 if ( rc ) goto done_noop;
4872 /* Basic syntax checks are OK. Do the actual settings. */
4873 for ( a=e->e_attrs; a; a=a->a_next ) {
4874 if ( a == oc_at ) continue;
4875 ct = config_find_table( colst, nocs, a->a_desc, ca );
4876 if ( !ct ) continue; /* user data? */
4877 for (i=0; a->a_vals[i].bv_val; i++) {
4880 ca->line = a->a_vals[i].bv_val;
4881 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4882 ptr = strchr( ca->line, '}' );
4884 iptr = strchr( ca->line, '{' );
4888 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4890 ca->valx = strtol( iptr+1, NULL, 0 );
4895 rc = config_parse_add( ct, ca, i );
4903 /* Newly added databases and overlays need to be started up */
4904 if ( CONFIG_ONLINE_ADD( ca )) {
4905 if ( colst[0]->co_type == Cft_Database ) {
4906 rc = backend_startup_one( ca->be, &ca->reply );
4908 } else if ( colst[0]->co_type == Cft_Overlay ) {
4909 if ( ca->bi->bi_db_open ) {
4910 BackendInfo *bi_orig = ca->be->bd_info;
4911 ca->be->bd_info = ca->bi;
4912 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4913 ca->be->bd_info = bi_orig;
4915 } else if ( ca->cleanup ) {
4916 rc = ca->cleanup( ca );
4919 if (ca->cr_msg[0] == '\0')
4920 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4922 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4923 ca->log, ca->cr_msg, ca->argv[1] );
4930 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4931 ce->ce_parent = last;
4932 ce->ce_entry = entry_dup( e );
4933 ce->ce_entry->e_private = ce;
4934 ce->ce_type = colst[0]->co_type;
4937 ce->ce_private = ca->ca_private;
4938 ca->ca_entry = ce->ce_entry;
4941 } else if ( last->ce_kids ) {
4942 CfEntryInfo *c2, **cprev;
4944 /* Advance to first of this type */
4945 cprev = &last->ce_kids;
4946 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4947 cprev = &c2->ce_sibs;
4950 /* Account for the (-1) frontendDB entry */
4951 if ( ce->ce_type == Cft_Database ) {
4952 if ( ca->be == frontendDB )
4954 else if ( ibase != -1 )
4959 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4960 cprev = &c2->ce_sibs;
4966 for ( i=0; i<ibase; i++ ) {
4968 cprev = &c2->ce_sibs;
4971 ce->ce_sibs = *cprev;
4979 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4980 if ( ca->be != frontendDB )
4981 backend_destroy_one( ca->be, 1 );
4982 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4983 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4984 } else if ( colst[0]->co_type == Cft_Schema ) {
4985 schema_destroy_one( ca, colst, nocs, last );
4990 ch_free( ca->argv );
4991 if ( colst ) ch_free( colst );
4995 #define BIGTMP 10000
4997 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4998 int base, int rebase, int max, int use_ldif )
5000 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5001 ConfigType etype = ce->ce_type;
5002 int count = 0, rc = 0;
5004 /* Reverse ce list */
5005 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5006 if (ce2->ce_type != etype) {
5011 ce2->ce_sibs = cetmp;
5014 if ( max && count >= max ) {
5020 /* Move original to a temp name until increments are done */
5022 ce->ce_entry->e_private = NULL;
5023 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5024 base+BIGTMP, 0, use_ldif );
5025 ce->ce_entry->e_private = ce;
5027 /* start incrementing */
5028 for (ce2=cetmp; ce2; ce2=ce3) {
5030 ce2->ce_sibs = cerem;
5033 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5034 count+base, 0, use_ldif );
5038 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5039 base, 0, use_ldif );
5044 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5045 CfEntryInfo *ce2, int old, int use_ldif )
5049 /* Renumber original to a temp value */
5050 ce->ce_entry->e_private = NULL;
5051 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5052 old+BIGTMP, 0, use_ldif );
5053 ce->ce_entry->e_private = ce;
5055 /* start decrementing */
5056 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5057 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5058 count+old, 0, use_ldif );
5061 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5062 count+old, 0, use_ldif );
5065 /* Parse an LDAP entry into config directives, then store in underlying
5069 config_back_add( Operation *op, SlapReply *rs )
5075 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5076 NULL, ACL_WADD, NULL )) {
5077 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5082 * Check for attribute ACL
5084 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5085 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5086 rs->sr_text = "no write access to attribute";
5090 cfb = (CfBackInfo *)op->o_bd->be_private;
5092 /* add opattrs for syncprov */
5094 char textbuf[SLAP_TEXT_BUFLEN];
5095 size_t textlen = sizeof textbuf;
5096 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5097 &rs->sr_text, textbuf, sizeof( textbuf ) );
5098 if ( rs->sr_err != LDAP_SUCCESS )
5100 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5101 if ( rs->sr_err != LDAP_SUCCESS ) {
5102 Debug( LDAP_DEBUG_TRACE,
5103 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5104 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5109 if ( op->o_abandon ) {
5110 rs->sr_err = SLAPD_ABANDON;
5113 ldap_pvt_thread_pool_pause( &connection_pool );
5116 * 1) check for existence of entry
5117 * 2) check for sibling renumbering
5118 * 3) perform internal add
5119 * 4) perform any necessary renumbering
5120 * 5) store entry in underlying database
5122 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5123 if ( rs->sr_err != LDAP_SUCCESS ) {
5124 rs->sr_text = ca.cr_msg;
5129 CfEntryInfo *ce = ca.ca_entry->e_private;
5130 req_add_s addr = op->oq_add;
5131 op->o_tag = LDAP_REQ_MODRDN;
5132 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5133 op->o_tag = LDAP_REQ_ADD;
5135 if ( rs->sr_err != LDAP_SUCCESS ) {
5140 if ( cfb->cb_use_ldif ) {
5141 BackendDB *be = op->o_bd;
5142 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5143 struct berval dn, ndn;
5145 op->o_bd = &cfb->cb_db;
5147 /* Save current rootdn; use the underlying DB's rootdn */
5150 op->o_dn = op->o_bd->be_rootdn;
5151 op->o_ndn = op->o_bd->be_rootndn;
5153 scp = op->o_callback;
5154 op->o_callback = ≻
5155 op->o_bd->be_add( op, rs );
5157 op->o_callback = scp;
5163 ldap_pvt_thread_pool_resume( &connection_pool );
5166 send_ldap_result( op, rs );
5167 slap_graduate_commit_csn( op );
5171 typedef struct delrec {
5172 struct delrec *next;
5178 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5184 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5185 ca->line[0] == '{' )
5187 char *ptr = strchr( ca->line + 1, '}' );
5191 ca->valx = strtol( ca->line + 1, &next, 0 );
5192 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5198 rc = config_parse_add( ct, ca, i );
5206 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5209 int rc = LDAP_UNWILLING_TO_PERFORM;
5211 Entry *e = ce->ce_entry;
5212 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5217 delrec *dels = NULL, *deltail = NULL;
5219 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5220 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5222 colst = count_ocs( oc_at, &nocs );
5224 /* make sure add/del flags are clear; should always be true */
5225 for ( s = save_attrs; s; s = s->a_next ) {
5226 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5229 e->e_attrs = attrs_dup( e->e_attrs );
5231 init_config_argv( ca );
5234 ca->ca_private = ce->ce_private;
5236 ca->fname = "slapd";
5238 strcpy( ca->log, "back-config" );
5240 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5241 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5242 switch (ml->sml_op) {
5243 case LDAP_MOD_DELETE:
5244 case LDAP_MOD_REPLACE: {
5245 BerVarray vals = NULL, nvals = NULL;
5247 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5249 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5250 ml->sml_desc->ad_cname.bv_val );
5253 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5254 vals = ml->sml_values;
5255 nvals = ml->sml_nvalues;
5256 ml->sml_values = NULL;
5257 ml->sml_nvalues = NULL;
5259 /* If we're deleting by values, remember the indexes of the
5260 * values we deleted.
5262 if ( ct && ml->sml_values ) {
5264 i = ml->sml_numvals;
5265 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5276 rc = modify_delete_vindex(e, &ml->sml_mod,
5277 get_permissiveModify(op),
5278 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5279 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5280 ml->sml_values = vals;
5281 ml->sml_nvalues = nvals;
5286 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5289 case SLAP_MOD_SOFTADD: {
5290 int mop = ml->sml_op;
5292 ml->sml_op = LDAP_MOD_ADD;
5294 if ( ct->arg_type & ARG_NO_INSERT ) {
5295 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5297 navals = a->a_numvals;
5300 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5301 if ( ml->sml_values[i].bv_val[0] == '{' &&
5304 char *next, *val = ml->sml_values[i].bv_val + 1;
5307 j = strtol( val, &next, 0 );
5308 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5310 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5311 ml->sml_desc->ad_cname.bv_val );
5315 rc = check_vals( ct, ca, ml, 0 );
5316 if ( rc ) goto out_noop;
5319 rc = modify_add_values(e, &ml->sml_mod,
5320 get_permissiveModify(op),
5321 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5323 /* If value already exists, show success here
5324 * and ignore this operation down below.
5326 if ( mop == SLAP_MOD_SOFTADD ) {
5327 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5337 case LDAP_MOD_INCREMENT: /* FIXME */
5342 if(rc != LDAP_SUCCESS) break;
5345 if ( rc == LDAP_SUCCESS) {
5346 /* check that the entry still obeys the schema */
5347 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5348 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5350 if ( rc ) goto out_noop;
5352 /* Basic syntax checks are OK. Do the actual settings. */
5353 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5354 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5355 if ( !ct ) continue;
5357 s = attr_find( save_attrs, ml->sml_desc );
5358 a = attr_find( e->e_attrs, ml->sml_desc );
5360 switch (ml->sml_op) {
5361 case LDAP_MOD_DELETE:
5362 case LDAP_MOD_REPLACE: {
5363 BerVarray vals = NULL, nvals = NULL;
5366 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5367 vals = ml->sml_values;
5368 nvals = ml->sml_nvalues;
5369 ml->sml_values = NULL;
5370 ml->sml_nvalues = NULL;
5373 if ( ml->sml_values )
5376 /* If we didn't delete the whole attribute */
5377 if ( ml->sml_values && a ) {
5378 struct berval *mvals;
5381 if ( ml->sml_nvalues )
5382 mvals = ml->sml_nvalues;
5384 mvals = ml->sml_values;
5386 /* use the indexes we saved up above */
5387 for (i=0; i < d->nidx; i++) {
5388 struct berval bv = *mvals++;
5389 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5390 bv.bv_val[0] == '{' ) {
5391 ptr = strchr( bv.bv_val, '}' ) + 1;
5392 bv.bv_len -= ptr - bv.bv_val;
5395 ca->line = bv.bv_val;
5396 ca->valx = d->idx[i];
5397 rc = config_del_vals( ct, ca );
5398 if ( rc != LDAP_SUCCESS ) break;
5400 s->a_flags |= SLAP_ATTR_IXDEL;
5401 for (j=i+1; j < d->nidx; j++)
5402 if ( d->idx[j] >d->idx[i] )
5408 rc = config_del_vals( ct, ca );
5409 if ( rc ) rc = LDAP_OTHER;
5411 s->a_flags |= SLAP_ATTR_IXDEL;
5413 if ( ml->sml_values ) {
5418 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5419 ml->sml_values = vals;
5420 ml->sml_nvalues = nvals;
5422 if ( !vals || rc != LDAP_SUCCESS )
5425 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5428 for (i=0; ml->sml_values[i].bv_val; i++) {
5429 ca->line = ml->sml_values[i].bv_val;
5431 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5434 a->a_flags |= SLAP_ATTR_IXADD;
5441 /* Undo for a failed operation */
5442 if ( rc != LDAP_SUCCESS ) {
5443 ConfigReply msg = ca->reply;
5444 for ( s = save_attrs; s; s = s->a_next ) {
5445 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5446 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5447 ct = config_find_table( colst, nocs, s->a_desc, ca );
5448 a = attr_find( e->e_attrs, s->a_desc );
5450 /* clear the flag so the add check below will skip it */
5451 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5454 config_del_vals( ct, ca );
5456 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5457 ca->line = s->a_vals[i].bv_val;
5459 config_modify_add( ct, ca, s->a_desc, i );
5463 for ( a = e->e_attrs; a; a = a->a_next ) {
5464 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5465 ct = config_find_table( colst, nocs, a->a_desc, ca );
5468 config_del_vals( ct, ca );
5469 s = attr_find( save_attrs, a->a_desc );
5471 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5472 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5473 ca->line = s->a_vals[i].bv_val;
5475 config_modify_add( ct, ca, s->a_desc, i );
5486 if ( rc == LDAP_SUCCESS ) {
5487 attrs_free( save_attrs );
5489 attrs_free( e->e_attrs );
5490 e->e_attrs = save_attrs;
5492 ch_free( ca->argv );
5493 if ( colst ) ch_free( colst );
5495 deltail = dels->next;
5504 config_back_modify( Operation *op, SlapReply *rs )
5507 CfEntryInfo *ce, *last;
5509 ConfigArgs ca = {0};
5512 AttributeDescription *rad = NULL;
5515 cfb = (CfBackInfo *)op->o_bd->be_private;
5517 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5520 rs->sr_matched = last->ce_entry->e_name.bv_val;
5521 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5525 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5526 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5530 /* Get type of RDN */
5531 rdn = ce->ce_entry->e_nname;
5532 ptr = strchr( rdn.bv_val, '=' );
5533 rdn.bv_len = ptr - rdn.bv_val;
5534 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5536 /* Some basic validation... */
5537 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5538 /* Don't allow Modify of RDN; must use ModRdn for that. */
5539 if ( ml->sml_desc == rad ) {
5540 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5541 rs->sr_text = "Use modrdn to change the entry name";
5544 /* Internal update of contextCSN? */
5545 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5551 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5554 if ( op->o_abandon ) {
5555 rs->sr_err = SLAPD_ABANDON;
5558 ldap_pvt_thread_pool_pause( &connection_pool );
5562 * 1) perform the Modify on the cached Entry.
5563 * 2) verify that the Entry still satisfies the schema.
5564 * 3) perform the individual config operations.
5565 * 4) store Modified entry in underlying LDIF backend.
5567 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5569 rs->sr_text = ca.cr_msg;
5570 } else if ( cfb->cb_use_ldif ) {
5571 BackendDB *be = op->o_bd;
5572 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5573 struct berval dn, ndn;
5575 op->o_bd = &cfb->cb_db;
5579 op->o_dn = op->o_bd->be_rootdn;
5580 op->o_ndn = op->o_bd->be_rootndn;
5582 scp = op->o_callback;
5583 op->o_callback = ≻
5584 op->o_bd->be_modify( op, rs );
5586 op->o_callback = scp;
5592 ldap_pvt_thread_pool_resume( &connection_pool );
5594 send_ldap_result( op, rs );
5595 slap_graduate_commit_csn( op );
5600 config_back_modrdn( Operation *op, SlapReply *rs )
5603 CfEntryInfo *ce, *last;
5607 cfb = (CfBackInfo *)op->o_bd->be_private;
5609 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5612 rs->sr_matched = last->ce_entry->e_name.bv_val;
5613 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5616 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5617 NULL, ACL_WRITE, NULL )) {
5618 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5622 if ( ce->ce_parent )
5623 parent = ce->ce_parent->ce_entry;
5625 parent = (Entry *)&slap_entry_root;
5626 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5627 NULL, ACL_WRITE, NULL )) {
5628 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5633 /* We don't allow moving objects to new parents.
5634 * Generally we only allow reordering a set of ordered entries.
5636 if ( op->orr_newSup ) {
5637 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5641 /* If newRDN == oldRDN, quietly succeed */
5642 dnRdn( &op->o_req_ndn, &rdn );
5643 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5644 rs->sr_err = LDAP_SUCCESS;
5648 /* Current behavior, subject to change as needed:
5650 * For backends and overlays, we only allow renumbering.
5651 * For schema, we allow renaming with the same number.
5652 * Otherwise, the op is not allowed.
5655 if ( ce->ce_type == Cft_Schema ) {
5659 /* Can't alter the main cn=schema entry */
5660 if ( ce->ce_parent->ce_type == Cft_Global ) {
5661 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5662 rs->sr_text = "renaming not allowed for this entry";
5666 /* We could support this later if desired */
5667 ptr1 = ber_bvchr( &rdn, '}' );
5668 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5669 len = ptr1 - rdn.bv_val;
5670 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5671 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5672 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5673 rs->sr_text = "schema reordering not supported";
5676 } else if ( ce->ce_type == Cft_Database ||
5677 ce->ce_type == Cft_Overlay ) {
5678 char *ptr1, *ptr2, *iptr1, *iptr2;
5681 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5682 if ( *iptr2 != '{' ) {
5683 rs->sr_err = LDAP_NAMING_VIOLATION;
5684 rs->sr_text = "new ordering index is required";
5688 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5689 ptr1 = ber_bvchr( &rdn, '}' );
5690 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5692 rs->sr_err = LDAP_NAMING_VIOLATION;
5693 rs->sr_text = "new ordering index is required";
5697 len1 = ptr1 - rdn.bv_val;
5698 len2 = ptr2 - op->orr_newrdn.bv_val;
5700 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5701 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5702 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5703 rs->sr_text = "changing database/overlay type not allowed";
5706 ixold = strtol( iptr1, NULL, 0 );
5707 ixnew = strtol( iptr2, &ptr1, 0 );
5708 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5709 rs->sr_err = LDAP_NAMING_VIOLATION;
5712 /* config DB is always 0, cannot be changed */
5713 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5714 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5718 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5719 rs->sr_text = "renaming not supported for this entry";
5723 if ( op->o_abandon ) {
5724 rs->sr_err = SLAPD_ABANDON;
5727 ldap_pvt_thread_pool_pause( &connection_pool );
5729 if ( ce->ce_type == Cft_Schema ) {
5730 req_modrdn_s modr = op->oq_modrdn;
5733 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5734 if ( rs->sr_err == LDAP_SUCCESS ) {
5735 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5736 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5739 op->oq_modrdn = modr;
5741 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5742 req_modrdn_s modr = op->oq_modrdn;
5745 /* Advance to first of this type */
5746 cprev = &ce->ce_parent->ce_kids;
5747 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5748 cprev = &ce2->ce_sibs;
5751 /* Skip the -1 entry */
5752 if ( ce->ce_type == Cft_Database ) {
5753 cprev = &ce2->ce_sibs;
5759 /* Remove from old slot */
5760 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5761 cprev = &ce2->ce_sibs;
5762 *cprev = ce->ce_sibs;
5763 ceold = ce->ce_sibs;
5765 /* Insert into new slot */
5767 for ( i=0; i<ixnew; i++ ) {
5771 cprev = &ce2->ce_sibs;
5773 ce->ce_sibs = *cprev;
5778 /* NOTE: These should be encoded in the OC tables, not inline here */
5779 if ( ce->ce_type == Cft_Database )
5780 backend_db_move( ce->ce_be, ixnew );
5781 else if ( ce->ce_type == Cft_Overlay )
5782 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5784 if ( ixold < ixnew ) {
5785 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5788 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5789 ixold - ixnew, cfb->cb_use_ldif );
5791 op->oq_modrdn = modr;
5794 ldap_pvt_thread_pool_resume( &connection_pool );
5796 send_ldap_result( op, rs );
5801 config_back_delete( Operation *op, SlapReply *rs )
5803 #ifdef SLAP_CONFIG_DELETE
5805 CfEntryInfo *ce, *last, *ce2;
5807 cfb = (CfBackInfo *)op->o_bd->be_private;
5809 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5812 rs->sr_matched = last->ce_entry->e_name.bv_val;
5813 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5814 } else if ( ce->ce_kids ) {
5815 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5816 } else if ( op->o_abandon ) {
5817 rs->sr_err = SLAPD_ABANDON;
5818 } else if ( ce->ce_type == Cft_Overlay ){
5822 ldap_pvt_thread_pool_pause( &connection_pool );
5824 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5826 /* remove CfEntryInfo from the siblings list */
5827 if ( ce->ce_parent->ce_kids == ce ) {
5828 ce->ce_parent->ce_kids = ce->ce_sibs;
5830 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5831 if ( ce2->ce_sibs == ce ) {
5832 ce2->ce_sibs = ce->ce_sibs;
5838 /* remove from underlying database */
5839 if ( cfb->cb_use_ldif ) {
5840 BackendDB *be = op->o_bd;
5841 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5842 struct berval dn, ndn, req_dn, req_ndn;
5844 op->o_bd = &cfb->cb_db;
5848 req_dn = op->o_req_dn;
5849 req_ndn = op->o_req_ndn;
5851 op->o_dn = op->o_bd->be_rootdn;
5852 op->o_ndn = op->o_bd->be_rootndn;
5853 op->o_req_dn = ce->ce_entry->e_name;
5854 op->o_req_ndn = ce->ce_entry->e_nname;
5856 scp = op->o_callback;
5857 op->o_callback = ≻
5858 op->o_bd->be_delete( op, rs );
5860 op->o_callback = scp;
5863 op->o_req_dn = req_dn;
5864 op->o_req_ndn = req_ndn;
5867 /* renumber siblings */
5868 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5869 ixold = strtol( iptr, NULL, 0 );
5870 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5871 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5872 count+ixold, 0, cfb->cb_use_ldif );
5876 ce->ce_entry->e_private=NULL;
5877 entry_free(ce->ce_entry);
5879 ldap_pvt_thread_pool_resume( &connection_pool );
5881 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5884 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5885 #endif /* SLAP_CONFIG_DELETE */
5886 send_ldap_result( op, rs );
5891 config_back_search( Operation *op, SlapReply *rs )
5894 CfEntryInfo *ce, *last;
5897 cfb = (CfBackInfo *)op->o_bd->be_private;
5899 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5902 rs->sr_matched = last->ce_entry->e_name.bv_val;
5903 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5906 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5907 ACL_SEARCH, NULL, &mask ))
5909 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5910 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5912 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5916 switch ( op->ors_scope ) {
5917 case LDAP_SCOPE_BASE:
5918 case LDAP_SCOPE_SUBTREE:
5919 rs->sr_err = config_send( op, rs, ce, 0 );
5922 case LDAP_SCOPE_ONELEVEL:
5923 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5924 rs->sr_err = config_send( op, rs, ce, 1 );
5933 send_ldap_result( op, rs );
5937 /* no-op, we never free entries */
5938 int config_entry_release(
5943 if ( !e->e_private ) {
5946 return LDAP_SUCCESS;
5949 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5951 int config_back_entry_get(
5955 AttributeDescription *at,
5960 CfEntryInfo *ce, *last;
5961 int rc = LDAP_NO_SUCH_OBJECT;
5963 cfb = (CfBackInfo *)op->o_bd->be_private;
5965 ce = config_find_base( cfb->cb_root, ndn, &last );
5967 *ent = ce->ce_entry;
5970 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5971 rc = LDAP_NO_SUCH_ATTRIBUTE;
5981 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5982 ConfigTable *ct, ConfigArgs *c )
5986 for (; at && *at; at++) {
5987 /* Skip the naming attr */
5988 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5990 for (i=0;ct[i].name;i++) {
5991 if (ct[i].ad == (*at)->sat_ad) {
5992 rc = config_get_vals(&ct[i], c);
5993 /* NOTE: tolerate that config_get_vals()
5994 * returns success with no values */
5995 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5996 if ( c->rvalue_nvals )
5997 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6000 slap_syntax_validate_func *validate =
6001 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6004 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6005 rc = ordered_value_validate( ct[i].ad,
6006 &c->rvalue_vals[j], LDAP_MOD_ADD );
6008 Debug( LDAP_DEBUG_ANY,
6009 "config_build_attrs: error %d on %s value #%d\n",
6010 rc, ct[i].ad->ad_cname.bv_val, j );
6016 rc = attr_merge_normalize(e, ct[i].ad,
6017 c->rvalue_vals, NULL);
6019 ber_bvarray_free( c->rvalue_nvals );
6020 ber_bvarray_free( c->rvalue_vals );
6022 Debug( LDAP_DEBUG_ANY,
6023 "config_build_attrs: error %d on %s\n",
6024 rc, ct[i].ad->ad_cname.bv_val, 0 );
6036 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6037 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6039 Entry *e = entry_alloc();
6040 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6042 struct berval ad_name;
6043 AttributeDescription *ad = NULL;
6046 const char *text = "";
6050 CfEntryInfo *ceprev = NULL;
6052 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6055 ce->ce_type = main->co_type;
6056 ce->ce_parent = parent;
6058 pdn = parent->ce_entry->e_nname;
6059 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6060 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6061 ceprev->ce_type <= ce->ce_type;
6062 ceprev = ceprev->ce_sibs );
6067 ce->ce_private = c->ca_private;
6071 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6072 ber_dupbv( &e->e_nname, &e->e_name );
6074 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6075 main->co_name, NULL );
6077 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6078 extra->co_name, NULL );
6079 ptr = strchr(rdn->bv_val, '=');
6080 ad_name.bv_val = rdn->bv_val;
6081 ad_name.bv_len = ptr - rdn->bv_val;
6082 rc = slap_bv2ad( &ad_name, &ad, &text );
6087 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6088 attr_merge_normalize_one(e, ad, &val, NULL );
6091 c->table = main->co_type;
6092 if ( oc->soc_required ) {
6093 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6094 if ( rc ) goto fail;
6097 if ( oc->soc_allowed ) {
6098 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6099 if ( rc ) goto fail;
6104 c->table = extra->co_type;
6105 if ( oc->soc_required ) {
6106 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6107 if ( rc ) goto fail;
6110 if ( oc->soc_allowed ) {
6111 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6112 if ( rc ) goto fail;
6116 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6117 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6118 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6119 if ( rc != LDAP_SUCCESS ) {
6121 Debug( LDAP_DEBUG_ANY,
6122 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6123 rdn->bv_val, text, 0);
6126 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6129 op->ora_modlist = NULL;
6130 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6131 if ( !op->o_noop ) {
6132 op->o_bd->be_add( op, rs );
6133 if ( ( rs->sr_err != LDAP_SUCCESS )
6134 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
6140 ce->ce_sibs = ceprev->ce_sibs;
6141 ceprev->ce_sibs = ce;
6142 } else if ( parent ) {
6143 ce->ce_sibs = parent->ce_kids;
6144 parent->ce_kids = ce;
6151 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6152 Operation *op, SlapReply *rs )
6155 ConfigFile *cf = c->ca_private;
6157 struct berval bv, rdn;
6159 for (; cf; cf=cf->c_sibs, c->depth++) {
6160 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6161 !cf->c_om_head && !cf->c_syn_head ) continue;
6162 c->value_dn.bv_val = c->log;
6163 LUTIL_SLASHPATH( cf->c_file.bv_val );
6164 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6169 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6171 ptr = strchr( bv.bv_val, '.' );
6173 bv.bv_len = ptr - bv.bv_val;
6174 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6175 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6176 /* FIXME: how can indicate error? */
6179 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6181 c->value_dn.bv_len += bv.bv_len;
6182 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6186 e = config_build_entry( op, rs, ceparent, c, &rdn,
6187 &CFOC_SCHEMA, NULL );
6190 } else if ( e && cf->c_kids ) {
6191 c->ca_private = cf->c_kids;
6192 config_build_schema_inc( c, e->e_private, op, rs );
6198 #ifdef SLAPD_MODULES
6201 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6202 Operation *op, SlapReply *rs )
6207 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6208 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6210 c->value_dn.bv_val = c->log;
6211 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6212 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6213 /* FIXME: how can indicate error? */
6217 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6226 config_check_schema(Operation *op, CfBackInfo *cfb)
6228 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6230 CfEntryInfo *ce, *last;
6233 /* If there's no root entry, we must be in the midst of converting */
6234 if ( !cfb->cb_root )
6237 /* Make sure the main schema entry exists */
6238 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6245 /* Make sure it's up to date */
6246 if ( cf_om_tail != om_sys_tail ) {
6247 a = attr_find( e->e_attrs, cfAd_om );
6249 if ( a->a_nvals != a->a_vals )
6250 ber_bvarray_free( a->a_nvals );
6251 ber_bvarray_free( a->a_vals );
6256 oidm_unparse( &bv, NULL, NULL, 1 );
6257 attr_merge_normalize( e, cfAd_om, bv, NULL );
6258 ber_bvarray_free( bv );
6259 cf_om_tail = om_sys_tail;
6261 if ( cf_at_tail != at_sys_tail ) {
6262 a = attr_find( e->e_attrs, cfAd_attr );
6264 if ( a->a_nvals != a->a_vals )
6265 ber_bvarray_free( a->a_nvals );
6266 ber_bvarray_free( a->a_vals );
6271 at_unparse( &bv, NULL, NULL, 1 );
6272 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6273 ber_bvarray_free( bv );
6274 cf_at_tail = at_sys_tail;
6276 if ( cf_oc_tail != oc_sys_tail ) {
6277 a = attr_find( e->e_attrs, cfAd_oc );
6279 if ( a->a_nvals != a->a_vals )
6280 ber_bvarray_free( a->a_nvals );
6281 ber_bvarray_free( a->a_vals );
6286 oc_unparse( &bv, NULL, NULL, 1 );
6287 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6288 ber_bvarray_free( bv );
6289 cf_oc_tail = oc_sys_tail;
6291 if ( cf_syn_tail != syn_sys_tail ) {
6292 a = attr_find( e->e_attrs, cfAd_syntax );
6294 if ( a->a_nvals != a->a_vals )
6295 ber_bvarray_free( a->a_nvals );
6296 ber_bvarray_free( a->a_vals );
6301 syn_unparse( &bv, NULL, NULL, 1 );
6302 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6303 ber_bvarray_free( bv );
6304 cf_syn_tail = syn_sys_tail;
6307 SlapReply rs = {REP_RESULT};
6308 c.ca_private = NULL;
6309 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6310 &CFOC_SCHEMA, NULL );
6315 ce->ce_private = cfb->cb_config;
6316 cf_at_tail = at_sys_tail;
6317 cf_oc_tail = oc_sys_tail;
6318 cf_om_tail = om_sys_tail;
6319 cf_syn_tail = syn_sys_tail;
6324 static const char *defacl[] = {
6325 NULL, "to", "*", "by", "*", "none", NULL
6329 config_back_db_open( BackendDB *be, ConfigReply *cr )
6331 CfBackInfo *cfb = be->be_private;
6334 CfEntryInfo *ce, *ceparent;
6338 Connection conn = {0};
6339 OperationBuffer opbuf;
6341 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6342 SlapReply rs = {REP_RESULT};
6343 void *thrctx = NULL;
6345 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6347 /* If we have no explicitly configured ACLs, don't just use
6348 * the global ACLs. Explicitly deny access to everything.
6350 if ( !be->be_acl ) {
6351 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6354 thrctx = ldap_pvt_thread_pool_context();
6355 connection_fake_init( &conn, &opbuf, thrctx );
6358 op->o_tag = LDAP_REQ_ADD;
6359 op->o_callback = &cb;
6360 op->o_bd = &cfb->cb_db;
6361 op->o_dn = op->o_bd->be_rootdn;
6362 op->o_ndn = op->o_bd->be_rootndn;
6364 if ( !cfb->cb_use_ldif ) {
6368 /* If we read the config from back-ldif, do some quick sanity checks */
6369 if ( cfb->cb_got_ldif ) {
6370 return config_check_schema( op, cfb );
6373 /* create root of tree */
6375 c.ca_private = cfb->cb_config;
6377 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6387 #ifdef SLAPD_MODULES
6388 /* Create Module nodes... */
6389 if ( modpaths.mp_loads ) {
6390 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6396 /* Create schema nodes... cn=schema will contain the hardcoded core
6397 * schema, read-only. Child objects will contain runtime loaded schema
6401 c.ca_private = NULL;
6402 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6407 ce->ce_private = cfb->cb_config;
6408 cf_at_tail = at_sys_tail;
6409 cf_oc_tail = oc_sys_tail;
6410 cf_om_tail = om_sys_tail;
6411 cf_syn_tail = syn_sys_tail;
6413 /* Create schema nodes for included schema... */
6414 if ( cfb->cb_config->c_kids ) {
6416 c.ca_private = cfb->cb_config->c_kids;
6417 if (config_build_schema_inc( &c, ce, op, &rs )) {
6422 /* Create backend nodes. Skip if they don't provide a cf_table.
6423 * There usually aren't any of these.
6427 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6428 if (!bi->bi_cf_ocs) {
6429 /* If it only supports the old config mech, complain. */
6430 if ( bi->bi_config ) {
6431 Debug( LDAP_DEBUG_ANY,
6432 "WARNING: No dynamic config support for backend %s.\n",
6433 bi->bi_type, 0, 0 );
6438 if (!bi->bi_private) continue;
6441 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6442 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6443 if ( rdn.bv_len >= sizeof( c.log ) ) {
6444 /* FIXME: holler ... */ ;
6447 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6454 /* Create database nodes... */
6455 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6456 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6457 for ( i = -1, be = frontendDB ; be;
6458 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6459 slap_overinfo *oi = NULL;
6461 if ( overlay_is_over( be )) {
6462 oi = be->bd_info->bi_private;
6468 /* If this backend supports the old config mechanism, but not
6469 * the new mech, complain.
6471 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6472 Debug( LDAP_DEBUG_ANY,
6473 "WARNING: No dynamic config support for database %s.\n",
6474 bi->bi_type, 0, 0 );
6478 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6479 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6481 if ( rdn.bv_len >= sizeof( c.log ) ) {
6482 /* FIXME: holler ... */ ;
6486 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6492 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6493 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6494 /* Iterate through overlays */
6499 voidList *vl, *v0 = NULL;
6501 /* overlays are in LIFO order, must reverse stack */
6502 for (on=oi->oi_list; on; on=on->on_next) {
6503 vl = ch_malloc( sizeof( voidList ));
6508 for (j=0; vl; j++,vl=v0) {
6512 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6513 Debug( LDAP_DEBUG_ANY,
6514 "WARNING: No dynamic config support for overlay %s.\n",
6515 on->on_bi.bi_type, 0, 0 );
6519 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6520 "%s=" SLAP_X_ORDERED_FMT "%s",
6521 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6522 if ( rdn.bv_len >= sizeof( c.log ) ) {
6523 /* FIXME: holler ... */ ;
6527 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6528 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6532 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6533 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6538 ldap_pvt_thread_pool_context_reset( thrctx );
6540 if ( unsupp && cfb->cb_use_ldif ) {
6541 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6542 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6549 cfb_free_cffile( ConfigFile *cf )
6553 for (; cf; cf=next) {
6556 cfb_free_cffile( cf->c_kids );
6557 ch_free( cf->c_file.bv_val );
6558 ber_bvarray_free( cf->c_dseFiles );
6564 cfb_free_entries( CfEntryInfo *ce )
6568 for (; ce; ce=next) {
6571 cfb_free_entries( ce->ce_kids );
6572 ce->ce_entry->e_private = NULL;
6573 entry_free( ce->ce_entry );
6579 config_back_db_close( BackendDB *be, ConfigReply *cr )
6581 CfBackInfo *cfb = be->be_private;
6583 cfb_free_entries( cfb->cb_root );
6584 cfb->cb_root = NULL;
6586 if ( cfb->cb_db.bd_info ) {
6587 backend_shutdown( &cfb->cb_db );
6594 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6596 CfBackInfo *cfb = be->be_private;
6598 cfb_free_cffile( cfb->cb_config );
6600 ch_free( cfdir.bv_val );
6602 avl_free( CfOcTree, NULL );
6604 if ( cfb->cb_db.bd_info ) {
6605 cfb->cb_db.be_suffix = NULL;
6606 cfb->cb_db.be_nsuffix = NULL;
6607 BER_BVZERO( &cfb->cb_db.be_rootdn );
6608 BER_BVZERO( &cfb->cb_db.be_rootndn );
6610 backend_destroy_one( &cfb->cb_db, 0 );
6619 config_back_db_init( BackendDB *be, ConfigReply* cr )
6625 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6626 cfn = cfb->cb_config;
6627 be->be_private = cfb;
6629 ber_dupbv( &be->be_rootdn, &config_rdn );
6630 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6631 ber_dupbv( &dn, &be->be_rootdn );
6632 ber_bvarray_add( &be->be_suffix, &dn );
6633 ber_dupbv( &dn, &be->be_rootdn );
6634 ber_bvarray_add( &be->be_nsuffix, &dn );
6636 /* Hide from namingContexts */
6637 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6639 /* Check ACLs on content of Adds by default */
6640 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6646 config_back_destroy( BackendInfo *bi )
6648 ldif_must_b64_encode_release();
6653 config_tool_entry_open( BackendDB *be, int mode )
6655 CfBackInfo *cfb = be->be_private;
6656 BackendInfo *bi = cfb->cb_db.bd_info;
6658 if ( bi && bi->bi_tool_entry_open )
6659 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6666 config_tool_entry_close( BackendDB *be )
6668 CfBackInfo *cfb = be->be_private;
6669 BackendInfo *bi = cfb->cb_db.bd_info;
6671 if ( bi && bi->bi_tool_entry_close )
6672 return bi->bi_tool_entry_close( &cfb->cb_db );
6678 config_tool_entry_first( BackendDB *be )
6680 CfBackInfo *cfb = be->be_private;
6681 BackendInfo *bi = cfb->cb_db.bd_info;
6683 if ( bi && bi->bi_tool_entry_first )
6684 return bi->bi_tool_entry_first( &cfb->cb_db );
6690 config_tool_entry_next( BackendDB *be )
6692 CfBackInfo *cfb = be->be_private;
6693 BackendInfo *bi = cfb->cb_db.bd_info;
6695 if ( bi && bi->bi_tool_entry_next )
6696 return bi->bi_tool_entry_next( &cfb->cb_db );
6702 config_tool_entry_get( BackendDB *be, ID id )
6704 CfBackInfo *cfb = be->be_private;
6705 BackendInfo *bi = cfb->cb_db.bd_info;
6707 if ( bi && bi->bi_tool_entry_get )
6708 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6713 static int entry_put_got_frontend=0;
6714 static int entry_put_got_config=0;
6716 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6718 CfBackInfo *cfb = be->be_private;
6719 BackendInfo *bi = cfb->cb_db.bd_info;
6721 struct berval rdn, vals[ 2 ];
6723 OperationBuffer opbuf;
6725 Connection conn = {0};
6726 Operation *op = NULL;
6730 /* Create entry for frontend database if it does not exist already */
6731 if ( !entry_put_got_frontend ) {
6732 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6733 STRLENOF( "olcDatabase" ))) {
6734 if ( strncmp( e->e_nname.bv_val +
6735 STRLENOF( "olcDatabase" ), "={-1}frontend",
6736 STRLENOF( "={-1}frontend" )) &&
6737 strncmp( e->e_nname.bv_val +
6738 STRLENOF( "olcDatabase" ), "=frontend",
6739 STRLENOF( "=frontend" ))) {
6741 vals[1].bv_val = NULL;
6742 memset( &ca, 0, sizeof(ConfigArgs));
6744 ca.bi = frontendDB->bd_info;
6745 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6746 rdn.bv_val = ca.log;
6747 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6748 "%s=" SLAP_X_ORDERED_FMT "%s",
6749 cfAd_database->ad_cname.bv_val, -1,
6751 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6752 &CFOC_DATABASE, ca.be->be_cf_ocs );
6753 thrctx = ldap_pvt_thread_pool_context();
6754 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6756 op->o_bd = &cfb->cb_db;
6757 op->o_tag = LDAP_REQ_ADD;
6759 op->o_dn = be->be_rootdn;
6760 op->o_ndn = be->be_rootndn;
6761 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6762 if ( rc != LDAP_SUCCESS ) {
6763 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6764 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6768 if ( ce && bi && bi->bi_tool_entry_put &&
6769 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6770 entry_put_got_frontend++;
6772 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6773 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6777 entry_put_got_frontend++;
6782 /* Create entry for config database if it does not exist already */
6783 if ( !entry_put_got_config && !isFrontend ) {
6784 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6785 STRLENOF( "olcDatabase" ))) {
6786 if ( strncmp( e->e_nname.bv_val +
6787 STRLENOF( "olcDatabase" ), "={0}config",
6788 STRLENOF( "={0}config" )) &&
6789 strncmp( e->e_nname.bv_val +
6790 STRLENOF( "olcDatabase" ), "=config",
6791 STRLENOF( "=config" )) ) {
6793 vals[1].bv_val = NULL;
6794 memset( &ca, 0, sizeof(ConfigArgs));
6795 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6796 ca.bi = ca.be->bd_info;
6797 rdn.bv_val = ca.log;
6798 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6799 "%s=" SLAP_X_ORDERED_FMT "%s",
6800 cfAd_database->ad_cname.bv_val, 0,
6802 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6805 thrctx = ldap_pvt_thread_pool_context();
6806 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6808 op->o_bd = &cfb->cb_db;
6809 op->o_tag = LDAP_REQ_ADD;
6810 op->o_dn = be->be_rootdn;
6811 op->o_ndn = be->be_rootndn;
6814 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6815 if ( rc != LDAP_SUCCESS ) {
6816 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6817 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6820 if (ce && bi && bi->bi_tool_entry_put &&
6821 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6822 entry_put_got_config++;
6824 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6825 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6829 entry_put_got_config++;
6833 if ( bi && bi->bi_tool_entry_put &&
6834 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6835 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6842 AttributeDescription **desc;
6844 { "attribute", &cfAd_attr },
6845 { "backend", &cfAd_backend },
6846 { "database", &cfAd_database },
6847 { "include", &cfAd_include },
6848 { "ldapsyntax", &cfAd_syntax },
6849 { "objectclass", &cfAd_oc },
6850 { "objectidentifier", &cfAd_om },
6851 { "overlay", &cfAd_overlay },
6856 * add / delete: all types that may be added or deleted must use an
6857 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6858 * should automatically renumber the index of any siblings as needed,
6859 * so that no gaps in the numbering sequence exist after the add/delete
6861 * What can be added:
6863 * backend objects for backend-specific config directives
6867 * delete: probably no support this time around.
6869 * modrdn: generally not done. Will be invoked automatically by add/
6870 * delete to update numbering sequence. Perform as an explicit operation
6871 * so that the renumbering effect may be replicated. Subtree rename must
6872 * be supported, since renumbering a database will affect all its child
6875 * modify: must be fully supported.
6879 config_back_initialize( BackendInfo *bi )
6881 ConfigTable *ct = config_back_cf_table;
6885 AttributeDescription *ad = NULL;
6887 static char *controls[] = {
6888 LDAP_CONTROL_MANAGEDSAIT,
6892 /* Make sure we don't exceed the bits reserved for userland */
6893 config_check_userland( CFG_LAST );
6895 bi->bi_controls = controls;
6900 bi->bi_destroy = config_back_destroy;
6902 bi->bi_db_init = config_back_db_init;
6903 bi->bi_db_config = 0;
6904 bi->bi_db_open = config_back_db_open;
6905 bi->bi_db_close = config_back_db_close;
6906 bi->bi_db_destroy = config_back_db_destroy;
6908 bi->bi_op_bind = config_back_bind;
6909 bi->bi_op_unbind = 0;
6910 bi->bi_op_search = config_back_search;
6911 bi->bi_op_compare = 0;
6912 bi->bi_op_modify = config_back_modify;
6913 bi->bi_op_modrdn = config_back_modrdn;
6914 bi->bi_op_add = config_back_add;
6915 bi->bi_op_delete = config_back_delete;
6916 bi->bi_op_abandon = 0;
6918 bi->bi_extended = 0;
6920 bi->bi_chk_referrals = 0;
6922 bi->bi_access_allowed = slap_access_allowed;
6924 bi->bi_connection_init = 0;
6925 bi->bi_connection_destroy = 0;
6927 bi->bi_entry_release_rw = config_entry_release;
6928 bi->bi_entry_get_rw = config_back_entry_get;
6930 bi->bi_tool_entry_open = config_tool_entry_open;
6931 bi->bi_tool_entry_close = config_tool_entry_close;
6932 bi->bi_tool_entry_first = config_tool_entry_first;
6933 bi->bi_tool_entry_next = config_tool_entry_next;
6934 bi->bi_tool_entry_get = config_tool_entry_get;
6935 bi->bi_tool_entry_put = config_tool_entry_put;
6938 argv[ 0 ] = "slapd";
6944 for (i=0; OidMacros[i].name; i++ ) {
6945 argv[1] = OidMacros[i].name;
6946 argv[2] = OidMacros[i].oid;
6947 parse_oidm( &ca, 0, NULL );
6950 bi->bi_cf_ocs = cf_ocs;
6952 i = config_register_schema( ct, cf_ocs );
6955 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6958 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6959 * basically, we don't care if it fails */
6960 i = slap_str2ad( "olcRootPW", &ad, &text );
6962 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6963 "warning, unable to get \"olcRootPW\" "
6964 "attribute description: %d: %s\n",
6967 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6968 ad->ad_type->sat_oid );
6971 /* set up the notable AttributeDescriptions */
6973 for (;ct->name;ct++) {
6974 if (strcmp(ct->name, ads[i].name)) continue;
6975 *ads[i].desc = ct->ad;
6977 if (!ads[i].name) break;