1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2010 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,
202 static OidRec OidMacros[] = {
203 /* OpenLDAProot:1.12.2 */
204 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
205 { "OLcfgAt", "OLcfg:3" },
206 { "OLcfgGlAt", "OLcfgAt:0" },
207 { "OLcfgBkAt", "OLcfgAt:1" },
208 { "OLcfgDbAt", "OLcfgAt:2" },
209 { "OLcfgOvAt", "OLcfgAt:3" },
210 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
211 { "OLcfgOc", "OLcfg:4" },
212 { "OLcfgGlOc", "OLcfgOc:0" },
213 { "OLcfgBkOc", "OLcfgOc:1" },
214 { "OLcfgDbOc", "OLcfgOc:2" },
215 { "OLcfgOvOc", "OLcfgOc:3" },
216 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
218 /* Syntaxes. We should just start using the standard names and
219 * document that they are predefined and available for users
220 * to reference in their own schema. Defining schema without
221 * OID macros is for masochists...
223 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
224 { "OMsBoolean", "OMsyn:7" },
225 { "OMsDN", "OMsyn:12" },
226 { "OMsDirectoryString", "OMsyn:15" },
227 { "OMsIA5String", "OMsyn:26" },
228 { "OMsInteger", "OMsyn:27" },
229 { "OMsOID", "OMsyn:38" },
230 { "OMsOctetString", "OMsyn:40" },
235 * Backend/Database registry
237 * OLcfg{Bk|Db}{Oc|At}:0 -> common
238 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
239 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
240 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
241 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
242 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
243 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
244 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
245 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
251 * OLcfgOv{Oc|At}:1 -> syncprov
252 * OLcfgOv{Oc|At}:2 -> pcache
253 * OLcfgOv{Oc|At}:3 -> chain
254 * OLcfgOv{Oc|At}:4 -> accesslog
255 * OLcfgOv{Oc|At}:5 -> valsort
256 * OLcfgOv{Oc|At}:7 -> distproc
257 * OLcfgOv{Oc|At}:8 -> dynlist
258 * OLcfgOv{Oc|At}:9 -> dds
259 * OLcfgOv{Oc|At}:10 -> unique
260 * OLcfgOv{Oc|At}:11 -> refint
261 * OLcfgOv{Oc|At}:12 -> ppolicy
262 * OLcfgOv{Oc|At}:13 -> constraint
263 * OLcfgOv{Oc|At}:14 -> translucent
264 * OLcfgOv{Oc|At}:15 -> auditlog
265 * OLcfgOv{Oc|At}:16 -> rwm
266 * OLcfgOv{Oc|At}:17 -> dyngroup
267 * OLcfgOv{Oc|At}:18 -> memberof
268 * OLcfgOv{Oc|At}:19 -> collect
269 * OLcfgOv{Oc|At}:20 -> retcode
270 * OLcfgOv{Oc|At}:21 -> sssvlv
273 /* alphabetical ordering */
275 static ConfigTable config_back_cf_table[] = {
276 /* This attr is read-only */
277 { "", "", 0, 0, 0, ARG_MAGIC,
278 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
279 "DESC 'File for slapd configuration directives' "
280 "EQUALITY caseIgnoreMatch "
281 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
282 { "", "", 0, 0, 0, ARG_MAGIC,
283 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
284 "DESC 'Directory for slapd configuration backend' "
285 "EQUALITY caseIgnoreMatch "
286 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
287 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
288 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
289 "DESC 'Access Control List' "
290 "EQUALITY caseIgnoreMatch "
291 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
292 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
293 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
294 "DESC 'Check ACLs against content of Add ops' "
295 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
296 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
297 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
298 "DESC 'Allowed set of deprecated features' "
299 "EQUALITY caseIgnoreMatch "
300 "SYNTAX OMsDirectoryString )", NULL, NULL },
301 { "argsfile", "file", 2, 2, 0, ARG_STRING,
302 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
303 "DESC 'File for slapd command line options' "
304 "EQUALITY caseIgnoreMatch "
305 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
306 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
307 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
308 "EQUALITY caseIgnoreMatch "
309 "SYNTAX OMsDirectoryString )", NULL, NULL },
310 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
311 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
312 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
313 "DESC 'OpenLDAP attributeTypes' "
314 "EQUALITY caseIgnoreMatch "
315 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
317 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
318 #ifdef SLAP_AUTH_REWRITE
319 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
323 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
324 "EQUALITY caseIgnoreMatch "
325 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
326 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
327 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
328 "EQUALITY caseIgnoreMatch "
329 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
330 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
331 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
332 "EQUALITY caseIgnoreMatch "
333 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
334 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
335 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
336 "DESC 'A type of backend' "
337 "EQUALITY caseIgnoreMatch "
338 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
340 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
341 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
342 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
343 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
344 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
345 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
346 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
347 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
348 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
349 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
350 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
351 "DESC 'The backend type for a database instance' "
352 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
353 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
354 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
355 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
356 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
357 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
358 "EQUALITY caseIgnoreMatch "
359 "SYNTAX OMsDirectoryString )", NULL, NULL },
360 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
361 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
362 "DESC 'OpenLDAP DIT content rules' "
363 "EQUALITY caseIgnoreMatch "
364 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
366 { "gentlehup", "on|off", 2, 2, 0,
368 ARG_ON_OFF, &global_gentlehup,
372 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
373 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
374 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
375 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
376 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
377 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
378 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
379 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
380 { "include", "file", 2, 2, 0, ARG_MAGIC,
381 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
382 "SUP labeledURI )", NULL, NULL },
383 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
384 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
385 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
386 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
387 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
388 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
389 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
390 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
391 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
392 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
393 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
394 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
395 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
396 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
397 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
398 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
399 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
400 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
401 { "ldapsyntax", "syntax", 2, 0, 0,
402 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
403 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
404 "DESC 'OpenLDAP ldapSyntax' "
405 "EQUALITY caseIgnoreMatch "
406 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
408 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
409 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
410 "EQUALITY caseIgnoreMatch "
411 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
412 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
413 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
414 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
415 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
416 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
417 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
418 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
419 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
420 "EQUALITY caseIgnoreMatch "
421 "SYNTAX OMsDirectoryString )", NULL, NULL },
422 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
423 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
424 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
425 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
426 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
427 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
428 { "moduleload", "file", 2, 0, 0,
430 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
434 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
435 "EQUALITY caseIgnoreMatch "
436 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
437 { "modulepath", "path", 2, 2, 0,
439 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
443 "( OLcfgGlAt:31 NAME 'olcModulePath' "
444 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
445 { "monitoring", "TRUE|FALSE", 2, 2, 0,
446 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
447 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
448 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
449 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
450 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
451 "DESC 'OpenLDAP object classes' "
452 "EQUALITY caseIgnoreMatch "
453 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
455 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
456 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
457 "EQUALITY caseIgnoreMatch "
458 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
459 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
460 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
461 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
462 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
463 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
464 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
465 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
466 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
467 "EQUALITY caseIgnoreMatch "
468 "SYNTAX OMsDirectoryString )", NULL, NULL },
469 { "pidfile", "file", 2, 2, 0, ARG_STRING,
470 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
471 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
472 { "plugin", NULL, 0, 0, 0,
474 ARG_MAGIC|CFG_PLUGIN, &config_generic,
478 "( OLcfgGlAt:38 NAME 'olcPlugin' "
479 "EQUALITY caseIgnoreMatch "
480 "SYNTAX OMsDirectoryString )", NULL, NULL },
481 { "pluginlog", "filename", 2, 2, 0,
483 ARG_STRING, &slapi_log_file,
487 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
488 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
489 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
490 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
491 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
492 { "referral", "url", 2, 2, 0, ARG_MAGIC,
493 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
494 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
495 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
496 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
497 "EQUALITY caseIgnoreMatch "
498 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
499 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
500 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
501 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
502 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
503 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
504 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
505 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
506 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
507 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
508 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
509 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
510 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
511 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
512 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
513 "EQUALITY caseIgnoreMatch "
514 "SYNTAX OMsDirectoryString )", NULL, NULL },
515 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
516 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
517 "EQUALITY caseIgnoreMatch "
518 "SYNTAX OMsDirectoryString )", NULL, NULL },
519 { "reverse-lookup", "on|off", 2, 2, 0,
520 #ifdef SLAPD_RLOOKUPS
521 ARG_ON_OFF, &use_reverse_lookup,
525 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
526 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
527 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
528 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
529 "EQUALITY distinguishedNameMatch "
530 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
531 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
532 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
533 "EQUALITY caseIgnoreMatch "
534 "SYNTAX OMsDirectoryString )", NULL, NULL },
535 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
536 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
537 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
538 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
539 &config_generic, NULL, NULL, NULL },
540 { "sasl-auxprops", NULL, 2, 0, 0,
541 #ifdef HAVE_CYRUS_SASL
542 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
546 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
547 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
548 { "sasl-host", "host", 2, 2, 0,
549 #ifdef HAVE_CYRUS_SASL
550 ARG_STRING|ARG_UNIQUE, &sasl_host,
554 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
555 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
556 { "sasl-realm", "realm", 2, 2, 0,
557 #ifdef HAVE_CYRUS_SASL
558 ARG_STRING|ARG_UNIQUE, &global_realm,
562 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
563 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
564 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
565 &config_generic, NULL, NULL, NULL },
566 { "sasl-secprops", "properties", 2, 2, 0,
567 #ifdef HAVE_CYRUS_SASL
568 ARG_MAGIC|CFG_SASLSECP, &config_generic,
572 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
573 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
574 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
575 &config_generic, NULL, NULL, NULL },
576 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
577 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
578 "EQUALITY distinguishedNameMatch "
579 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
580 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
581 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
582 "EQUALITY caseIgnoreMatch "
583 "SYNTAX OMsDirectoryString )", NULL, NULL },
584 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
585 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
586 "EQUALITY caseIgnoreMatch "
587 "SYNTAX OMsDirectoryString )", NULL, NULL },
588 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
589 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
590 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
591 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
592 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
593 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
594 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
595 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
596 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
597 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
598 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
599 "DESC 'Attributes whose values will always be sorted' "
600 "EQUALITY caseIgnoreMatch "
601 "SYNTAX OMsDirectoryString )", NULL, NULL },
602 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
603 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
604 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
605 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
606 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
607 "EQUALITY distinguishedNameMatch "
608 "SYNTAX OMsDN )", NULL, NULL },
609 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
610 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
611 "DESC 'Store sync context in a subentry' "
612 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
613 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
614 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
615 "EQUALITY caseIgnoreMatch "
616 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
617 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
618 #ifndef LDAP_TCP_BUFFER
620 #else /* LDAP_TCP_BUFFER */
621 ARG_MAGIC, &config_tcp_buffer,
622 #endif /* LDAP_TCP_BUFFER */
623 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
624 "DESC 'Custom TCP buffer size' "
625 "SYNTAX OMsDirectoryString )", NULL, NULL },
626 { "threads", "count", 2, 2, 0,
630 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
632 "( OLcfgGlAt:66 NAME 'olcThreads' "
633 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
634 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
635 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
636 "SYNTAX OMsDirectoryString )", NULL, NULL },
637 { "TLSCACertificateFile", NULL, 0, 0, 0,
639 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
643 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
644 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
645 { "TLSCACertificatePath", NULL, 0, 0, 0,
647 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
651 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
652 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
653 { "TLSCertificateFile", NULL, 0, 0, 0,
655 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
659 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
660 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
661 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
663 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
667 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
668 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
669 { "TLSCipherSuite", NULL, 0, 0, 0,
671 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
675 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
676 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
677 { "TLSCRLCheck", NULL, 0, 0, 0,
678 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
679 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
683 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
684 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
685 { "TLSCRLFile", NULL, 0, 0, 0,
686 #if defined(HAVE_GNUTLS)
687 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
691 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
692 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
693 { "TLSRandFile", NULL, 0, 0, 0,
695 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
699 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
700 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
701 { "TLSVerifyClient", NULL, 0, 0, 0,
703 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
707 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
708 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
709 { "TLSDHParamFile", NULL, 0, 0, 0,
711 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
715 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
716 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
717 { "TLSProtocolMin", NULL, 0, 0, 0,
719 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
723 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
724 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
725 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
726 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
727 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
728 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
729 NULL, NULL, NULL, NULL },
730 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
731 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
732 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
733 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
734 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
735 "EQUALITY caseIgnoreMatch "
736 "SUP labeledURI )", NULL, NULL },
737 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
738 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
739 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
740 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
741 NULL, NULL, NULL, NULL }
744 /* Need to no-op this keyword for dynamic config */
745 ConfigTable olcDatabaseDummy[] = {
746 { "", "", 0, 0, 0, ARG_IGNORED,
747 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
748 "DESC 'The backend type for a database instance' "
749 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
750 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
753 /* Routines to check if a child can be added to this type */
754 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
755 cfAddBackend, cfAddModule, cfAddOverlay;
757 /* NOTE: be careful when defining array members
758 * that can be conditionally compiled */
759 #define CFOC_GLOBAL cf_ocs[1]
760 #define CFOC_SCHEMA cf_ocs[2]
761 #define CFOC_BACKEND cf_ocs[3]
762 #define CFOC_DATABASE cf_ocs[4]
763 #define CFOC_OVERLAY cf_ocs[5]
764 #define CFOC_INCLUDE cf_ocs[6]
765 #define CFOC_FRONTEND cf_ocs[7]
767 #define CFOC_MODULE cf_ocs[8]
768 #endif /* SLAPD_MODULES */
770 static ConfigOCs cf_ocs[] = {
773 "DESC 'OpenLDAP configuration object' "
774 "ABSTRACT SUP top )", Cft_Abstract, NULL },
777 "DESC 'OpenLDAP Global configuration options' "
778 "SUP olcConfig STRUCTURAL "
779 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
780 "olcAttributeOptions $ olcAuthIDRewrite $ "
781 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
782 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
783 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
784 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
785 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
786 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
787 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
788 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
789 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
791 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
792 "olcSecurity $ olcServerID $ olcSizeLimit $ "
793 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
795 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
796 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
797 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
798 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
799 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
800 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
801 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
803 "NAME 'olcSchemaConfig' "
804 "DESC 'OpenLDAP schema object' "
805 "SUP olcConfig STRUCTURAL "
806 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
807 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
808 Cft_Schema, NULL, cfAddSchema },
810 "NAME 'olcBackendConfig' "
811 "DESC 'OpenLDAP Backend-specific options' "
812 "SUP olcConfig STRUCTURAL "
813 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
815 "NAME 'olcDatabaseConfig' "
816 "DESC 'OpenLDAP Database-specific options' "
817 "SUP olcConfig STRUCTURAL "
819 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
820 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
821 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
822 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
823 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
824 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
825 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
827 Cft_Database, NULL, cfAddDatabase },
829 "NAME 'olcOverlayConfig' "
830 "DESC 'OpenLDAP Overlay-specific options' "
831 "SUP olcConfig STRUCTURAL "
832 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
834 "NAME 'olcIncludeFile' "
835 "DESC 'OpenLDAP configuration include file' "
836 "SUP olcConfig STRUCTURAL "
838 "MAY ( cn $ olcRootDSE ) )",
839 /* Used to be Cft_Include, that def has been removed */
840 Cft_Abstract, NULL, cfAddInclude },
841 /* This should be STRUCTURAL like all the other database classes, but
842 * that would mean inheriting all of the olcDatabaseConfig attributes,
843 * which causes them to be merged twice in config_build_entry.
846 "NAME 'olcFrontendConfig' "
847 "DESC 'OpenLDAP frontend configuration' "
849 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
850 Cft_Database, NULL, NULL },
853 "NAME 'olcModuleList' "
854 "DESC 'OpenLDAP dynamic module info' "
855 "SUP olcConfig STRUCTURAL "
856 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
857 Cft_Module, NULL, cfAddModule },
862 typedef struct ServerID {
863 struct ServerID *si_next;
864 struct berval si_url;
868 static ServerID *sid_list;
870 typedef struct voidList {
871 struct voidList *vl_next;
875 typedef struct ADlist {
876 struct ADlist *al_next;
877 AttributeDescription *al_desc;
880 static ADlist *sortVals;
883 config_generic(ConfigArgs *c) {
886 if ( c->op == SLAP_CONFIG_EMIT ) {
890 c->value_int = ldap_pvt_thread_get_concurrency();
893 c->value_int = connection_pool_max;
896 c->value_int = slap_tool_thread_max;
900 c->value_string = ch_strdup( passwd_salt );
905 if ( c->be->be_limits ) {
909 for ( i=0; c->be->be_limits[i]; i++ ) {
910 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
911 if ( bv.bv_len >= sizeof( buf ) ) {
912 ber_bvarray_free_x( c->rvalue_vals, NULL );
913 c->rvalue_vals = NULL;
917 bv.bv_val = buf + bv.bv_len;
918 limits_unparse( c->be->be_limits[i], &bv,
919 sizeof( buf ) - ( bv.bv_val - buf ) );
920 bv.bv_len += bv.bv_val - buf;
922 value_add_one( &c->rvalue_vals, &bv );
925 if ( !c->rvalue_vals ) rc = 1;
928 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
931 c->value_string = ch_strdup( slap_sasl_getpolicy());
934 slap_sasl_regexp_unparse( &c->rvalue_vals );
935 if ( !c->rvalue_vals ) rc = 1;
937 #ifdef HAVE_CYRUS_SASL
939 struct berval bv = BER_BVNULL;
940 slap_sasl_secprops_unparse( &bv );
941 if ( !BER_BVISNULL( &bv )) {
942 ber_bvarray_add( &c->rvalue_vals, &bv );
950 c->value_int = c->be->be_max_deref_depth;
953 if ( SLAP_DBHIDDEN( c->be )) {
960 ConfigFile *cf = c->ca_private;
962 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
963 else if ( cf->c_om_head )
964 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
966 if ( !c->rvalue_vals )
971 ad_unparse_options( &c->rvalue_vals );
974 ConfigFile *cf = c->ca_private;
976 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
977 else if ( cf->c_oc_head )
978 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
980 if ( !c->rvalue_vals )
985 ConfigFile *cf = c->ca_private;
987 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
988 else if ( cf->c_at_head )
989 at_unparse( &c->rvalue_vals, cf->c_at_head,
991 if ( !c->rvalue_vals )
996 ConfigFile *cf = c->ca_private;
998 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
999 else if ( cf->c_syn_head )
1000 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1001 cf->c_syn_tail, 0 );
1002 if ( !c->rvalue_vals )
1007 ConfigFile *cf = c->ca_private;
1009 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1010 else if ( cf->c_cr_head )
1011 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1013 if ( !c->rvalue_vals )
1020 char *src, *dst, ibuf[11];
1021 struct berval bv, abv;
1022 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1023 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1024 if ( abv.bv_len >= sizeof( ibuf ) ) {
1025 ber_bvarray_free_x( c->rvalue_vals, NULL );
1026 c->rvalue_vals = NULL;
1030 acl_unparse( a, &bv );
1031 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1032 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1033 /* Turn TAB / EOL into plain space */
1034 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1035 if (isspace((unsigned char)*src)) *dst++ = ' ';
1039 if (dst[-1] == ' ') {
1043 abv.bv_len = dst - abv.bv_val;
1044 ber_bvarray_add( &c->rvalue_vals, &abv );
1050 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1053 ConfigFile *cf = c->ca_private;
1054 if ( cf->c_dseFiles ) {
1055 value_add( &c->rvalue_vals, cf->c_dseFiles );
1066 for ( si = sid_list; si; si=si->si_next ) {
1067 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1068 if ( !BER_BVISEMPTY( &si->si_url )) {
1069 bv.bv_len = si->si_url.bv_len + 6;
1070 bv.bv_val = ch_malloc( bv.bv_len );
1071 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1072 si->si_url.bv_val );
1073 ber_bvarray_add( &c->rvalue_vals, &bv );
1077 bv.bv_len = sprintf( buf, "%d", si->si_num );
1078 value_add_one( &c->rvalue_vals, &bv );
1087 c->value_string = ch_strdup( logfileName );
1092 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1094 case CFG_SYNC_SUBENTRY:
1095 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1097 case CFG_MIRRORMODE:
1098 if ( SLAP_SHADOW(c->be))
1099 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1103 case CFG_MONITORING:
1104 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1106 case CFG_SSTR_IF_MAX:
1107 c->value_uint = index_substr_if_maxlen;
1109 case CFG_SSTR_IF_MIN:
1110 c->value_uint = index_substr_if_minlen;
1113 c->value_int = index_intlen;
1115 case CFG_SORTVALS: {
1118 for ( sv = sortVals; sv; sv = sv->al_next ) {
1119 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1123 #ifdef SLAPD_MODULES
1125 ModPaths *mp = c->ca_private;
1128 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1131 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1132 SLAP_X_ORDERED_FMT "%s", i,
1133 mp->mp_loads[i].bv_val );
1134 if ( bv.bv_len >= sizeof( c->log ) ) {
1135 ber_bvarray_free_x( c->rvalue_vals, NULL );
1136 c->rvalue_vals = NULL;
1139 value_add_one( &c->rvalue_vals, &bv );
1143 rc = c->rvalue_vals ? 0 : 1;
1147 ModPaths *mp = c->ca_private;
1148 if ( !BER_BVISNULL( &mp->mp_path ))
1149 value_add_one( &c->rvalue_vals, &mp->mp_path );
1151 rc = c->rvalue_vals ? 0 : 1;
1157 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1158 if ( !c->rvalue_vals ) rc = 1;
1161 #ifdef SLAP_AUTH_REWRITE
1163 if ( authz_rewrites ) {
1164 struct berval bv, idx;
1169 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1170 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1171 if ( idx.bv_len >= sizeof( ibuf ) ) {
1172 ber_bvarray_free_x( c->rvalue_vals, NULL );
1173 c->rvalue_vals = NULL;
1176 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1177 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1178 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1179 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1180 authz_rewrites[i].bv_val,
1181 authz_rewrites[i].bv_len + 1 );
1182 ber_bvarray_add( &c->rvalue_vals, &bv );
1185 if ( !c->rvalue_vals ) rc = 1;
1192 } else if ( c->op == LDAP_MOD_DELETE ) {
1195 /* single-valued attrs, no-ops */
1203 case CFG_MIRRORMODE:
1204 case CFG_MONITORING:
1206 case CFG_SSTR_IF_MAX:
1207 case CFG_SSTR_IF_MIN:
1209 case CFG_SYNC_SUBENTRY:
1212 /* no-ops, requires slapd restart */
1217 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1221 ch_free( passwd_salt );
1226 ch_free( logfileName );
1234 case CFG_SERVERID: {
1235 ServerID *si, **sip;
1237 for ( i=0, si = sid_list, sip = &sid_list;
1238 si; si = *sip, i++ ) {
1239 if ( c->valx == -1 || i == c->valx ) {
1251 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1255 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1256 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1257 SLAP_INDEX_INTLEN_DEFAULT );
1261 if ( c->valx < 0 ) {
1262 acl_destroy( c->be->be_acl );
1263 c->be->be_acl = NULL;
1266 AccessControl **prev, *a;
1268 for (i=0, prev = &c->be->be_acl; i < c->valx;
1271 prev = &a->acl_next;
1274 *prev = a->acl_next;
1281 /* Can be NULL when undoing a failed add */
1282 if ( c->ca_entry ) {
1283 ce = c->ca_entry->e_private;
1284 /* can't modify the hardcoded schema */
1285 if ( ce->ce_parent->ce_type == Cft_Global )
1289 cfn = c->ca_private;
1290 if ( c->valx < 0 ) {
1293 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1295 if ( oc == cfn->c_oc_tail )
1298 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1300 ObjectClass *oc, *prev = NULL;
1302 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1307 if ( cfn->c_oc_tail == oc ) {
1308 cfn->c_oc_tail = prev;
1310 if ( cfn->c_oc_head == oc ) {
1312 cfn->c_oc_head = oc;
1319 /* Can be NULL when undoing a failed add */
1320 if ( c->ca_entry ) {
1321 ce = c->ca_entry->e_private;
1322 /* can't modify the hardcoded schema */
1323 if ( ce->ce_parent->ce_type == Cft_Global )
1327 cfn = c->ca_private;
1328 if ( c->valx < 0 ) {
1331 for( at = cfn->c_at_head; at; at_next( &at )) {
1333 if ( at == cfn->c_at_tail )
1336 cfn->c_at_head = cfn->c_at_tail = NULL;
1338 AttributeType *at, *prev = NULL;
1340 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1345 if ( cfn->c_at_tail == at ) {
1346 cfn->c_at_tail = prev;
1348 if ( cfn->c_at_head == at ) {
1350 cfn->c_at_head = at;
1357 /* Can be NULL when undoing a failed add */
1358 if ( c->ca_entry ) {
1359 ce = c->ca_entry->e_private;
1360 /* can't modify the hardcoded schema */
1361 if ( ce->ce_parent->ce_type == Cft_Global )
1365 cfn = c->ca_private;
1366 if ( c->valx < 0 ) {
1369 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1371 if ( syn == cfn->c_syn_tail )
1374 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1376 Syntax *syn, *prev = NULL;
1378 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1383 if ( cfn->c_syn_tail == syn ) {
1384 cfn->c_syn_tail = prev;
1386 if ( cfn->c_syn_head == syn ) {
1388 cfn->c_syn_head = syn;
1393 if ( c->valx < 0 ) {
1395 for ( sv = sortVals; sv; sv = sortVals ) {
1396 sortVals = sv->al_next;
1397 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1404 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1405 prev = &sv->al_next;
1408 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1409 *prev = sv->al_next;
1415 /* FIXME: there is no limits_free function */
1416 if ( c->valx < 0 ) {
1417 limits_destroy( c->be->be_limits );
1418 c->be->be_limits = NULL;
1423 if ( c->be->be_limits ) {
1424 for ( num = 0; c->be->be_limits[ num ]; num++ )
1428 if ( c->valx >= num ) {
1433 limits_destroy( c->be->be_limits );
1434 c->be->be_limits = NULL;
1437 limits_free_one( c->be->be_limits[ c->valx ] );
1439 for ( cnt = c->valx; cnt < num; cnt++ ) {
1440 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1447 /* FIXME: there is no ad_option_free function */
1449 /* FIXME: there is no way to remove attributes added by
1463 if(!(c->bi = backend_info(c->argv[1]))) {
1464 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1465 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1466 c->log, c->cr_msg, c->argv[1] );
1473 /* NOTE: config is always the first backend!
1475 if ( !strcasecmp( c->argv[1], "config" )) {
1476 c->be = LDAP_STAILQ_FIRST(&backendDB);
1477 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1480 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1482 if ( c->cr_msg[0] == 0 )
1483 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1484 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1491 ldap_pvt_thread_set_concurrency(c->value_int);
1495 if ( c->value_int < 2 ) {
1496 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1497 "threads=%d smaller than minimum value 2",
1499 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1500 c->log, c->cr_msg, 0 );
1503 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1504 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1505 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1506 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1507 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1508 c->log, c->cr_msg, 0 );
1510 if ( slapMode & SLAP_SERVER_MODE )
1511 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1512 connection_pool_max = c->value_int; /* save for reference */
1516 if ( slapMode & SLAP_TOOL_MODE )
1517 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1518 slap_tool_thread_max = c->value_int; /* save for reference */
1522 if ( passwd_salt ) ch_free( passwd_salt );
1523 passwd_salt = c->value_string;
1524 lutil_salt_format(passwd_salt);
1528 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1534 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1536 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1540 ch_free(c->value_string);
1541 if (slap_sasl_setpolicy( c->argv[1] )) {
1542 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1543 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1544 c->log, c->cr_msg, c->argv[1] );
1550 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1554 #ifdef HAVE_CYRUS_SASL
1557 char *txt = slap_sasl_secprops( c->argv[1] );
1559 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1561 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1569 c->be->be_max_deref_depth = c->value_int;
1575 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1576 cfn = c->ca_private;
1577 if(parse_oidm(c, 1, &om))
1579 if (!cfn->c_om_head) cfn->c_om_head = om;
1580 cfn->c_om_tail = om;
1585 ObjectClass *oc, *prev;
1587 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1588 cfn = c->ca_private;
1589 if ( c->valx < 0 ) {
1590 prev = cfn->c_oc_tail;
1593 /* If adding anything after the first, prev is easy */
1596 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1601 /* If adding the first, and head exists, find its prev */
1602 if (cfn->c_oc_head) {
1603 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1608 /* else prev is NULL, append to end of global list */
1610 if(parse_oc(c, &oc, prev)) return(1);
1611 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1612 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1617 AttributeType *at, *prev;
1619 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1620 cfn = c->ca_private;
1621 if ( c->valx < 0 ) {
1622 prev = cfn->c_at_tail;
1625 /* If adding anything after the first, prev is easy */
1628 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1633 /* If adding the first, and head exists, find its prev */
1634 if (cfn->c_at_head) {
1635 for ( at_start( &at ); at != cfn->c_at_head; ) {
1640 /* else prev is NULL, append to end of global list */
1642 if(parse_at(c, &at, prev)) return(1);
1643 if (!cfn->c_at_head) cfn->c_at_head = at;
1644 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1651 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1652 cfn = c->ca_private;
1653 if ( c->valx < 0 ) {
1654 prev = cfn->c_syn_tail;
1657 /* If adding anything after the first, prev is easy */
1660 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1665 /* If adding the first, and head exists, find its prev */
1666 if (cfn->c_syn_head) {
1667 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1672 /* else prev is NULL, append to end of global list */
1674 if ( parse_syn( c, &syn, prev ) ) return(1);
1675 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1676 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1683 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1684 cfn = c->ca_private;
1685 if(parse_cr(c, &cr)) return(1);
1686 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1687 cfn->c_cr_tail = cr;
1692 ad_define_option(NULL, NULL, 0);
1693 for(i = 1; i < c->argc; i++)
1694 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1699 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1700 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1701 else if ( c->value_int > 255 )
1703 index_intlen = c->value_int;
1704 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1708 case CFG_SORTVALS: {
1709 ADlist *svnew = NULL, *svtail, *sv;
1711 for ( i = 1; i < c->argc; i++ ) {
1712 AttributeDescription *ad = NULL;
1716 rc = slap_str2ad( c->argv[i], &ad, &text );
1718 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1721 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1722 c->log, c->cr_msg, c->argv[i] );
1723 for ( sv = svnew; sv; sv = svnew ) {
1724 svnew = sv->al_next;
1729 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1730 ad->ad_type->sat_single_value ) {
1731 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1733 goto sortval_reject;
1735 sv = ch_malloc( sizeof( ADlist ));
1740 svtail->al_next = sv;
1745 for ( sv = svnew; sv; sv = sv->al_next )
1746 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1747 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1749 sv->al_next = svnew;
1756 /* Don't append to the global ACL if we're on a specific DB */
1758 if ( c->valx == -1 ) {
1761 for ( a=c->be->be_acl; a; a = a->acl_next )
1764 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1771 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1773 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1777 if(root_dse_read_file(c->argv[1])) {
1778 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1779 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1780 c->log, c->cr_msg, c->argv[1] );
1785 ber_str2bv( c->argv[1], 0, 1, &bv );
1786 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1787 cfn = c->ca_private;
1788 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1794 ServerID *si, **sip;
1797 if (( lutil_atoi( &num, c->argv[1] ) &&
1798 lutil_atoix( &num, c->argv[1], 16 )) ||
1799 num < 0 || num > SLAP_SYNC_SID_MAX )
1801 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1802 "<%s> illegal server ID", c->argv[0] );
1803 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1804 c->log, c->cr_msg, c->argv[1] );
1807 /* only one value allowed if no URL is given */
1808 if ( c->argc > 2 ) {
1811 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1812 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1813 "<%s> only one server ID allowed now", c->argv[0] );
1814 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1815 c->log, c->cr_msg, c->argv[1] );
1819 if ( ldap_url_parse( c->argv[2], &lud )) {
1820 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1821 "<%s> invalid URL", c->argv[0] );
1822 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1823 c->log, c->cr_msg, c->argv[2] );
1826 len = strlen( c->argv[2] );
1827 si = ch_malloc( sizeof(ServerID) + len + 1 );
1828 si->si_url.bv_val = (char *)(si+1);
1829 si->si_url.bv_len = len;
1830 strcpy( si->si_url.bv_val, c->argv[2] );
1833 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1834 "<%s> unqualified server ID not allowed now", c->argv[0] );
1835 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1836 c->log, c->cr_msg, c->argv[1] );
1839 si = ch_malloc( sizeof(ServerID) );
1840 BER_BVZERO( &si->si_url );
1841 slap_serverID = num;
1842 Debug( LDAP_DEBUG_CONFIG,
1844 c->log, slap_serverID, 0 );
1848 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1851 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1852 Listener *l = config_check_my_url( c->argv[2], lud );
1854 slap_serverID = si->si_num;
1855 Debug( LDAP_DEBUG_CONFIG,
1856 "%s: SID=0x%03x (listener=%s)\n",
1857 c->log, slap_serverID,
1862 ldap_free_urldesc( lud );
1866 if ( logfileName ) ch_free( logfileName );
1867 logfileName = c->value_string;
1868 logfile = fopen(logfileName, "w");
1869 if(logfile) lutil_debug_file(logfile);
1873 if(SLAP_NOLASTMODCMD(c->be)) {
1874 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1875 c->argv[0], c->be->bd_info->bi_type );
1876 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1877 c->log, c->cr_msg, 0 );
1881 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1883 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1886 case CFG_MIRRORMODE:
1887 if(c->value_int && !SLAP_SHADOW(c->be)) {
1888 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1890 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1891 c->log, c->cr_msg, 0 );
1895 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1897 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1900 case CFG_MONITORING:
1902 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1904 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1909 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1911 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1914 case CFG_SYNC_SUBENTRY:
1916 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1918 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1921 case CFG_SSTR_IF_MAX:
1922 if (c->value_uint < index_substr_if_minlen) {
1923 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1924 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1925 c->log, c->cr_msg, c->value_int );
1928 index_substr_if_maxlen = c->value_uint;
1931 case CFG_SSTR_IF_MIN:
1932 if (c->value_uint > index_substr_if_maxlen) {
1933 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1934 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1935 c->log, c->cr_msg, c->value_int );
1938 index_substr_if_minlen = c->value_uint;
1941 #ifdef SLAPD_MODULES
1943 /* If we're just adding a module on an existing modpath,
1944 * make sure we've selected the current path.
1946 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1947 modcur = c->ca_private;
1948 /* This should never fail */
1949 if ( module_path( modcur->mp_path.bv_val )) {
1950 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1952 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1953 c->log, c->cr_msg, modcur->mp_path.bv_val );
1957 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1959 /* Record this load on the current path */
1963 if ( c->op == SLAP_CONFIG_ADD ) {
1964 ptr = c->line + STRLENOF("moduleload");
1965 while (!isspace((unsigned char) *ptr)) ptr++;
1966 while (isspace((unsigned char) *ptr)) ptr++;
1970 ber_str2bv(ptr, 0, 1, &bv);
1971 ber_bvarray_add( &modcur->mp_loads, &bv );
1973 /* Check for any new hardcoded schema */
1974 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1975 config_check_schema( NULL, &cfBackInfo );
1980 if(module_path(c->argv[1])) return(1);
1981 /* Record which path was used with each module */
1985 if (!modpaths.mp_loads) {
1988 mp = ch_malloc( sizeof( ModPaths ));
1989 modlast->mp_next = mp;
1991 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1993 mp->mp_loads = NULL;
2004 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2006 slapi_plugins_used++;
2010 #ifdef SLAP_AUTH_REWRITE
2016 if ( c->op == LDAP_MOD_ADD ) {
2020 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2024 if ( c->argc > 1 ) {
2027 /* quote all args but the first */
2028 line = ldap_charray2str( c->argv, "\" \"" );
2029 ber_str2bv( line, 0, 0, &bv );
2030 s = ber_bvchr( &bv, '"' );
2031 assert( s != NULL );
2032 /* move the trailing quote of argv[0] to the end */
2033 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2034 bv.bv_val[ bv.bv_len - 1 ] = '"';
2037 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2040 ber_bvarray_add( &authz_rewrites, &bv );
2042 if ( c->op == LDAP_MOD_ADD ) {
2052 Debug( LDAP_DEBUG_ANY,
2053 "%s: unknown CFG_TYPE %d.\n",
2054 c->log, c->type, 0 );
2063 config_fname(ConfigArgs *c) {
2064 if(c->op == SLAP_CONFIG_EMIT) {
2065 if (c->ca_private) {
2066 ConfigFile *cf = c->ca_private;
2067 value_add_one( &c->rvalue_vals, &cf->c_file );
2076 config_cfdir(ConfigArgs *c) {
2077 if(c->op == SLAP_CONFIG_EMIT) {
2078 if ( !BER_BVISEMPTY( &cfdir )) {
2079 value_add_one( &c->rvalue_vals, &cfdir );
2088 config_search_base(ConfigArgs *c) {
2089 if(c->op == SLAP_CONFIG_EMIT) {
2091 if (!BER_BVISEMPTY(&default_search_base)) {
2092 value_add_one(&c->rvalue_vals, &default_search_base);
2093 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2097 } else if( c->op == LDAP_MOD_DELETE ) {
2098 ch_free( default_search_base.bv_val );
2099 ch_free( default_search_nbase.bv_val );
2100 BER_BVZERO( &default_search_base );
2101 BER_BVZERO( &default_search_nbase );
2105 if(c->bi || c->be != frontendDB) {
2106 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2107 "prior to any backend or database definition\n",
2112 if(default_search_nbase.bv_len) {
2113 free(default_search_base.bv_val);
2114 free(default_search_nbase.bv_val);
2117 default_search_base = c->value_dn;
2118 default_search_nbase = c->value_ndn;
2122 /* For RE23 compatibility we allow this in the global entry
2123 * but we now defer it to the frontend entry to allow modules
2124 * to load new hash types.
2127 config_passwd_hash(ConfigArgs *c) {
2129 if (c->op == SLAP_CONFIG_EMIT) {
2131 /* Don't generate it in the global entry */
2132 if ( c->table == Cft_Global )
2134 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2135 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2136 value_add_one(&c->rvalue_vals, &bv);
2139 } else if ( c->op == LDAP_MOD_DELETE ) {
2140 /* Deleting from global is a no-op, only the frontendDB entry matters */
2141 if ( c->table == Cft_Global )
2143 if ( c->valx < 0 ) {
2144 ldap_charray_free( default_passwd_hash );
2145 default_passwd_hash = NULL;
2148 ch_free( default_passwd_hash[i] );
2149 for (; default_passwd_hash[i]; i++ )
2150 default_passwd_hash[i] = default_passwd_hash[i+1];
2154 for(i = 1; i < c->argc; i++) {
2155 if(!lutil_passwd_scheme(c->argv[i])) {
2156 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2157 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2158 c->log, c->cr_msg, c->argv[i]);
2160 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2163 if(!default_passwd_hash) {
2164 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2165 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2166 c->log, c->cr_msg, 0 );
2173 config_schema_dn(ConfigArgs *c) {
2174 if ( c->op == SLAP_CONFIG_EMIT ) {
2176 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2177 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2178 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2182 } else if ( c->op == LDAP_MOD_DELETE ) {
2183 ch_free( c->be->be_schemadn.bv_val );
2184 ch_free( c->be->be_schemandn.bv_val );
2185 BER_BVZERO( &c->be->be_schemadn );
2186 BER_BVZERO( &c->be->be_schemandn );
2189 ch_free( c->be->be_schemadn.bv_val );
2190 ch_free( c->be->be_schemandn.bv_val );
2191 c->be->be_schemadn = c->value_dn;
2192 c->be->be_schemandn = c->value_ndn;
2197 config_sizelimit(ConfigArgs *c) {
2199 struct slap_limits_set *lim = &c->be->be_def_limit;
2200 if (c->op == SLAP_CONFIG_EMIT) {
2205 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2206 if ( !BER_BVISEMPTY( &bv ))
2207 value_add_one( &c->rvalue_vals, &bv );
2211 } else if ( c->op == LDAP_MOD_DELETE ) {
2212 /* Reset to defaults or values from frontend */
2213 if ( c->be == frontendDB ) {
2214 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2215 lim->lms_s_hard = 0;
2216 lim->lms_s_unchecked = -1;
2218 lim->lms_s_pr_hide = 0;
2219 lim->lms_s_pr_total = 0;
2221 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2222 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2223 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2224 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2225 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2226 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2230 for(i = 1; i < c->argc; i++) {
2231 if(!strncasecmp(c->argv[i], "size", 4)) {
2232 rc = limits_parse_one(c->argv[i], lim);
2234 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2235 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2236 c->log, c->cr_msg, c->argv[i]);
2240 if(!strcasecmp(c->argv[i], "unlimited")) {
2241 lim->lms_s_soft = -1;
2243 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2244 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2245 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2246 c->log, c->cr_msg, c->argv[i]);
2250 lim->lms_s_hard = 0;
2255 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2256 /* This is a modification to the global limits apply it to
2257 * the other databases as needed */
2258 AttributeDescription *ad=NULL;
2259 const char *text = NULL;
2260 CfEntryInfo *ce = c->ca_entry->e_private;
2262 slap_str2ad(c->argv[0], &ad, &text);
2263 /* if we got here... */
2264 assert( ad != NULL );
2266 if ( ce->ce_type == Cft_Global ){
2269 for (; ce; ce=ce->ce_sibs) {
2270 Entry *dbe = ce->ce_entry;
2271 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2272 && (!attr_find(dbe->e_attrs, ad)) ) {
2273 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2274 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2275 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2276 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2277 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2278 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2286 config_timelimit(ConfigArgs *c) {
2288 struct slap_limits_set *lim = &c->be->be_def_limit;
2289 if (c->op == SLAP_CONFIG_EMIT) {
2294 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2295 if ( !BER_BVISEMPTY( &bv ))
2296 value_add_one( &c->rvalue_vals, &bv );
2300 } else if ( c->op == LDAP_MOD_DELETE ) {
2301 /* Reset to defaults or values from frontend */
2302 if ( c->be == frontendDB ) {
2303 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2304 lim->lms_t_hard = 0;
2306 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2307 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2311 for(i = 1; i < c->argc; i++) {
2312 if(!strncasecmp(c->argv[i], "time", 4)) {
2313 rc = limits_parse_one(c->argv[i], lim);
2315 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2316 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2317 c->log, c->cr_msg, c->argv[i]);
2321 if(!strcasecmp(c->argv[i], "unlimited")) {
2322 lim->lms_t_soft = -1;
2324 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2325 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2326 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2327 c->log, c->cr_msg, c->argv[i]);
2331 lim->lms_t_hard = 0;
2336 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2337 /* This is a modification to the global limits apply it to
2338 * the other databases as needed */
2339 AttributeDescription *ad=NULL;
2340 const char *text = NULL;
2341 CfEntryInfo *ce = c->ca_entry->e_private;
2343 slap_str2ad(c->argv[0], &ad, &text);
2344 /* if we got here... */
2345 assert( ad != NULL );
2347 if ( ce->ce_type == Cft_Global ){
2350 for (; ce; ce=ce->ce_sibs) {
2351 Entry *dbe = ce->ce_entry;
2352 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2353 && (!attr_find(dbe->e_attrs, ad)) ) {
2354 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2355 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2363 config_overlay(ConfigArgs *c) {
2364 if (c->op == SLAP_CONFIG_EMIT) {
2366 } else if ( c->op == LDAP_MOD_DELETE ) {
2369 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2370 c->valx, &c->bi, &c->reply)) {
2372 Debug( LDAP_DEBUG_ANY,
2373 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2374 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2376 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2383 config_subordinate(ConfigArgs *c)
2389 case SLAP_CONFIG_EMIT:
2390 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2393 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2394 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2397 value_add_one( &c->rvalue_vals, &bv );
2401 case LDAP_MOD_DELETE:
2402 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2403 glue_sub_del( c->be );
2405 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2410 case SLAP_CONFIG_ADD:
2411 if ( c->be->be_nsuffix == NULL ) {
2413 snprintf( c->cr_msg, sizeof( c->cr_msg),
2414 "subordinate configuration needs a suffix" );
2415 Debug( LDAP_DEBUG_ANY,
2417 c->log, c->cr_msg, 0 );
2422 if ( c->argc == 2 ) {
2423 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2426 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2428 snprintf( c->cr_msg, sizeof( c->cr_msg),
2429 "subordinate must be \"TRUE\" or \"advertise\"" );
2430 Debug( LDAP_DEBUG_ANY,
2431 "%s: suffix \"%s\": %s.\n",
2432 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2438 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2446 * [listener=<listener>] [{read|write}=]<size>
2449 #ifdef LDAP_TCP_BUFFER
2450 static BerVarray tcp_buffer;
2453 #define SLAP_TCP_RMEM (0x1U)
2454 #define SLAP_TCP_WMEM (0x2U)
2457 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2458 int *size, int *rw, Listener **l )
2460 int i, rc = LDAP_SUCCESS;
2461 LDAPURLDesc *lud = NULL;
2464 if ( val != NULL && argv == NULL ) {
2465 char *s = val->bv_val;
2467 argv = ldap_str2charray( s, " \t" );
2468 if ( argv == NULL ) {
2474 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2477 char *url = argv[ i ] + STRLENOF( "listener=" );
2479 if ( ldap_url_parse( url, &lud ) ) {
2480 rc = LDAP_INVALID_SYNTAX;
2484 *l = config_check_my_url( url, lud );
2486 rc = LDAP_NO_SUCH_ATTRIBUTE;
2494 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2495 *rw |= SLAP_TCP_RMEM;
2496 ptr += STRLENOF( "read=" );
2498 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2499 *rw |= SLAP_TCP_WMEM;
2500 ptr += STRLENOF( "write=" );
2503 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2506 /* accept any base */
2507 if ( lutil_atoix( size, ptr, 0 ) ) {
2508 rc = LDAP_INVALID_SYNTAX;
2513 if ( val != NULL && argv != NULL ) {
2514 ldap_charray_free( argv );
2517 if ( lud != NULL ) {
2518 ldap_free_urldesc( lud );
2525 tcp_buffer_delete_one( struct berval *val )
2528 int size = -1, rw = 0;
2531 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2538 Listener **ll = slapd_get_listeners();
2540 for ( i = 0; ll[ i ] != NULL; i++ ) {
2541 if ( ll[ i ] == l ) break;
2544 if ( ll[ i ] == NULL ) {
2545 return LDAP_NO_SUCH_ATTRIBUTE;
2548 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2549 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2551 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2552 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2553 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2557 /* NOTE: this affects listeners without a specific setting,
2558 * does not reset all listeners. If a listener without
2559 * specific settings was assigned a buffer because of
2560 * a global setting, it will not be reset. In any case,
2561 * buffer changes will only take place at restart. */
2562 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2563 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2570 tcp_buffer_delete( BerVarray vals )
2574 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2575 tcp_buffer_delete_one( &vals[ i ] );
2582 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2584 char buf[sizeof("2147483648")], *ptr;
2586 /* unparse for later use */
2587 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2589 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2592 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2593 if ( rw & SLAP_TCP_RMEM ) {
2594 val->bv_len += STRLENOF( "read=" );
2595 } else if ( rw & SLAP_TCP_WMEM ) {
2596 val->bv_len += STRLENOF( "write=" );
2600 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2605 ptr = lutil_strcopy( ptr, "listener=" );
2606 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2610 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2611 if ( rw & SLAP_TCP_RMEM ) {
2612 ptr = lutil_strcopy( ptr, "read=" );
2613 } else if ( rw & SLAP_TCP_WMEM ) {
2614 ptr = lutil_strcopy( ptr, "write=" );
2618 ptr = lutil_strcopy( ptr, buf );
2621 assert( val->bv_val + val->bv_len == ptr );
2623 return LDAP_SUCCESS;
2627 tcp_buffer_add_one( int argc, char **argv )
2630 int size = -1, rw = 0;
2636 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2641 /* unparse for later use */
2642 rc = tcp_buffer_unparse( size, rw, l, &val );
2643 if ( rc != LDAP_SUCCESS ) {
2647 /* use parsed values */
2650 Listener **ll = slapd_get_listeners();
2652 for ( i = 0; ll[ i ] != NULL; i++ ) {
2653 if ( ll[ i ] == l ) break;
2656 if ( ll[ i ] == NULL ) {
2657 return LDAP_NO_SUCH_ATTRIBUTE;
2660 /* buffer only applies to TCP listeners;
2661 * we do not do any check here, and delegate them
2662 * to setsockopt(2) */
2663 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2664 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2666 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2667 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2668 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2672 /* NOTE: this affects listeners without a specific setting,
2673 * does not set all listeners */
2674 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2675 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2678 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2680 tcp_buffer[ tcp_buffer_num ] = val;
2683 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2689 config_tcp_buffer( ConfigArgs *c )
2691 if ( c->op == SLAP_CONFIG_EMIT ) {
2692 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2695 value_add( &c->rvalue_vals, tcp_buffer );
2696 value_add( &c->rvalue_nvals, tcp_buffer );
2698 } else if ( c->op == LDAP_MOD_DELETE ) {
2700 tcp_buffer_delete( tcp_buffer );
2701 ber_bvarray_free( tcp_buffer );
2707 int size = -1, rw = 0;
2710 struct berval val = BER_BVNULL;
2714 if ( tcp_buffer_num == 0 ) {
2719 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2724 /* unparse for later use */
2725 rc = tcp_buffer_unparse( size, rw, l, &val );
2726 if ( rc != LDAP_SUCCESS ) {
2730 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2731 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2736 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2742 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2743 ber_memfree( tcp_buffer[ i ].bv_val );
2744 for ( ; i < tcp_buffer_num; i++ ) {
2745 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2750 if ( !BER_BVISNULL( &val ) ) {
2751 SLAP_FREE( val.bv_val );
2759 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2761 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2762 "<%s> unable to add value #%d",
2763 c->argv[0], tcp_buffer_num );
2764 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2765 c->log, c->cr_msg, 0 );
2772 #endif /* LDAP_TCP_BUFFER */
2775 config_suffix(ConfigArgs *c)
2778 struct berval pdn, ndn;
2779 char *notallowed = NULL;
2781 if ( c->be == frontendDB ) {
2782 notallowed = "frontend";
2784 } else if ( SLAP_MONITOR(c->be) ) {
2785 notallowed = "monitor";
2787 } else if ( SLAP_CONFIG(c->be) ) {
2788 notallowed = "config";
2791 if ( notallowed != NULL ) {
2792 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2796 case LDAP_MOD_DELETE:
2797 case LDAP_MOD_REPLACE:
2798 case LDAP_MOD_INCREMENT:
2799 case SLAP_CONFIG_ADD:
2800 if ( !BER_BVISNULL( &c->value_dn ) ) {
2801 snprintf( buf, sizeof( buf ), "<%s> ",
2802 c->value_dn.bv_val );
2805 Debug(LDAP_DEBUG_ANY,
2806 "%s: suffix %snot allowed in %s database.\n",
2807 c->log, buf, notallowed );
2810 case SLAP_CONFIG_EMIT:
2811 /* don't complain when emitting... */
2815 /* FIXME: don't know what values may be valid;
2816 * please remove assertion, or add legal values
2817 * to either block */
2825 if (c->op == SLAP_CONFIG_EMIT) {
2826 if ( c->be->be_suffix == NULL
2827 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2831 value_add( &c->rvalue_vals, c->be->be_suffix );
2832 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2835 } else if ( c->op == LDAP_MOD_DELETE ) {
2836 if ( c->valx < 0 ) {
2837 ber_bvarray_free( c->be->be_suffix );
2838 ber_bvarray_free( c->be->be_nsuffix );
2839 c->be->be_suffix = NULL;
2840 c->be->be_nsuffix = NULL;
2843 ch_free( c->be->be_suffix[i].bv_val );
2844 ch_free( c->be->be_nsuffix[i].bv_val );
2846 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2847 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2849 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2854 #ifdef SLAPD_MONITOR_DN
2855 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2856 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2858 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2859 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2864 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2865 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2866 c->argv[0], c->be->bd_info->bi_type );
2867 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2868 c->log, c->cr_msg, 0);
2875 if (SLAP_DBHIDDEN( c->be ))
2878 tbe = select_backend(&ndn, 0);
2880 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2886 BackendDB *b2 = tbe;
2888 /* Does tbe precede be? */
2889 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2892 char *type = tbe->bd_info->bi_type;
2894 if ( overlay_is_over( tbe ) ) {
2895 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2896 type = oi->oi_orig->bi_type;
2899 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2900 "already served by a preceding %s database",
2901 c->argv[0], pdn.bv_val, type );
2902 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2903 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2909 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2910 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2911 "base provided \"%s\" (assuming okay)\n",
2912 c->log, default_search_base.bv_val, 0);
2914 ber_bvarray_add(&c->be->be_suffix, &pdn);
2915 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2920 config_rootdn(ConfigArgs *c) {
2921 if (c->op == SLAP_CONFIG_EMIT) {
2922 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2923 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2924 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2929 } else if ( c->op == LDAP_MOD_DELETE ) {
2930 ch_free( c->be->be_rootdn.bv_val );
2931 ch_free( c->be->be_rootndn.bv_val );
2932 BER_BVZERO( &c->be->be_rootdn );
2933 BER_BVZERO( &c->be->be_rootndn );
2936 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2937 ch_free( c->be->be_rootdn.bv_val );
2938 ch_free( c->be->be_rootndn.bv_val );
2940 c->be->be_rootdn = c->value_dn;
2941 c->be->be_rootndn = c->value_ndn;
2946 config_rootpw(ConfigArgs *c) {
2949 if (c->op == SLAP_CONFIG_EMIT) {
2950 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2951 /* don't copy, because "rootpw" is marked
2953 c->value_bv = c->be->be_rootpw;
2957 } else if ( c->op == LDAP_MOD_DELETE ) {
2958 ch_free( c->be->be_rootpw.bv_val );
2959 BER_BVZERO( &c->be->be_rootpw );
2963 tbe = select_backend(&c->be->be_rootndn, 0);
2965 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2967 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2968 c->log, c->cr_msg, 0);
2971 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2972 ch_free( c->be->be_rootpw.bv_val );
2973 c->be->be_rootpw = c->value_bv;
2978 config_restrict(ConfigArgs *c) {
2979 slap_mask_t restrictops = 0;
2981 slap_verbmasks restrictable_ops[] = {
2982 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2983 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2984 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2985 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2986 { BER_BVC("modrdn"), 0 },
2987 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2988 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2989 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2990 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2991 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2992 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2993 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2994 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2995 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2996 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2997 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3001 if (c->op == SLAP_CONFIG_EMIT) {
3002 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3004 } else if ( c->op == LDAP_MOD_DELETE ) {
3006 c->be->be_restrictops = 0;
3008 restrictops = verb_to_mask( c->line, restrictable_ops );
3009 c->be->be_restrictops ^= restrictops;
3013 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3015 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3016 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3017 c->log, c->cr_msg, c->argv[i]);
3020 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3021 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3022 c->be->be_restrictops |= restrictops;
3027 config_allows(ConfigArgs *c) {
3028 slap_mask_t allows = 0;
3030 slap_verbmasks allowable_ops[] = {
3031 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3032 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3033 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3034 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3035 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3038 if (c->op == SLAP_CONFIG_EMIT) {
3039 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3040 } else if ( c->op == LDAP_MOD_DELETE ) {
3044 allows = verb_to_mask( c->line, allowable_ops );
3045 global_allows ^= allows;
3049 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3051 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3052 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3053 c->log, c->cr_msg, c->argv[i]);
3056 global_allows |= allows;
3061 config_disallows(ConfigArgs *c) {
3062 slap_mask_t disallows = 0;
3064 slap_verbmasks disallowable_ops[] = {
3065 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3066 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3067 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3068 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3069 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3070 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3073 if (c->op == SLAP_CONFIG_EMIT) {
3074 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3075 } else if ( c->op == LDAP_MOD_DELETE ) {
3077 global_disallows = 0;
3079 disallows = verb_to_mask( c->line, disallowable_ops );
3080 global_disallows ^= disallows;
3084 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3086 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3087 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3088 c->log, c->cr_msg, c->argv[i]);
3091 global_disallows |= disallows;
3096 config_requires(ConfigArgs *c) {
3097 slap_mask_t requires = frontendDB->be_requires;
3098 int i, argc = c->argc;
3099 char **argv = c->argv;
3101 slap_verbmasks requires_ops[] = {
3102 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3103 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3104 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3105 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3106 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3109 if (c->op == SLAP_CONFIG_EMIT) {
3110 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3111 } else if ( c->op == LDAP_MOD_DELETE ) {
3113 c->be->be_requires = 0;
3115 requires = verb_to_mask( c->line, requires_ops );
3116 c->be->be_requires ^= requires;
3120 /* "none" can only be first, to wipe out default/global values */
3121 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3126 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3128 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3129 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3130 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3131 c->log, c->cr_msg, 0);
3133 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3134 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3135 c->log, c->cr_msg, c->argv[i]);
3139 c->be->be_requires = requires;
3143 static slap_verbmasks *loglevel_ops;
3146 loglevel_init( void )
3148 slap_verbmasks lo[] = {
3149 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3150 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3151 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3152 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3153 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3154 { BER_BVC("BER"), LDAP_DEBUG_BER },
3155 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3156 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3157 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3158 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3159 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3160 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3161 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3162 #if 0 /* no longer used (nor supported) */
3163 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3164 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3166 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3167 { BER_BVC("None"), LDAP_DEBUG_NONE },
3171 return slap_verbmasks_init( &loglevel_ops, lo );
3175 loglevel_destroy( void )
3177 if ( loglevel_ops ) {
3178 (void)slap_verbmasks_destroy( loglevel_ops );
3180 loglevel_ops = NULL;
3183 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3186 slap_loglevel_register( slap_mask_t m, struct berval *s )
3190 if ( loglevel_ops == NULL ) {
3194 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3197 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3205 slap_loglevel_get( struct berval *s, int *l )
3210 if ( loglevel_ops == NULL ) {
3214 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3215 m |= loglevel_ops[ i ].mask;
3218 for ( i = 1; m & i; i <<= 1 )
3225 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3228 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3239 str2loglevel( const char *s, int *l )
3243 if ( loglevel_ops == NULL ) {
3247 i = verb_to_mask( s, loglevel_ops );
3249 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3253 *l = loglevel_ops[ i ].mask;
3259 loglevel2str( int l )
3261 struct berval bv = BER_BVNULL;
3263 loglevel2bv( l, &bv );
3269 loglevel2bv( int l, struct berval *bv )
3271 if ( loglevel_ops == NULL ) {
3277 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3281 loglevel2bvarray( int l, BerVarray *bva )
3283 if ( loglevel_ops == NULL ) {
3287 return mask_to_verbs( loglevel_ops, l, bva );
3291 loglevel_print( FILE *out )
3295 if ( loglevel_ops == NULL ) {
3299 fprintf( out, "Installed log subsystems:\n\n" );
3300 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3301 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3303 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3304 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3305 loglevel_ops[ i ].word.bv_val, mask, mask );
3308 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3309 "by specific code\n\n" );
3314 static int config_syslog;
3317 config_loglevel(ConfigArgs *c) {
3320 if ( loglevel_ops == NULL ) {
3324 if (c->op == SLAP_CONFIG_EMIT) {
3325 /* Get default or commandline slapd setting */
3326 if ( ldap_syslog && !config_syslog )
3327 config_syslog = ldap_syslog;
3328 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3330 } else if ( c->op == LDAP_MOD_DELETE ) {
3334 int level = verb_to_mask( c->line, loglevel_ops );
3335 config_syslog ^= level;
3337 if ( slapMode & SLAP_SERVER_MODE ) {
3338 ldap_syslog = config_syslog;
3343 for( i=1; i < c->argc; i++ ) {
3346 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3347 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3348 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3349 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3350 c->log, c->cr_msg, c->argv[i]);
3354 if ( str2loglevel( c->argv[i], &level ) ) {
3355 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3356 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3357 c->log, c->cr_msg, c->argv[i]);
3361 /* Explicitly setting a zero clears all the levels */
3363 config_syslog |= level;
3367 if ( slapMode & SLAP_SERVER_MODE ) {
3368 ldap_syslog = config_syslog;
3374 config_referral(ConfigArgs *c) {
3376 if (c->op == SLAP_CONFIG_EMIT) {
3377 if ( default_referral ) {
3378 value_add( &c->rvalue_vals, default_referral );
3383 } else if ( c->op == LDAP_MOD_DELETE ) {
3384 if ( c->valx < 0 ) {
3385 ber_bvarray_free( default_referral );
3386 default_referral = NULL;
3389 ch_free( default_referral[i].bv_val );
3390 for (; default_referral[i].bv_val; i++ )
3391 default_referral[i] = default_referral[i+1];
3395 if(validate_global_referral(c->argv[1])) {
3396 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3397 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3398 c->log, c->cr_msg, c->argv[1]);
3402 ber_str2bv(c->argv[1], 0, 0, &val);
3403 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3411 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3412 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3413 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3414 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3415 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3416 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3417 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3418 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3419 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3424 config_security(ConfigArgs *c) {
3425 slap_ssf_set_t *set = &c->be->be_ssf_set;
3428 if (c->op == SLAP_CONFIG_EMIT) {
3434 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3435 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3438 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3439 if ( bv.bv_len >= sizeof( numbuf ) ) {
3440 ber_bvarray_free_x( c->rvalue_vals, NULL );
3441 c->rvalue_vals = NULL;
3445 bv.bv_len += sec_keys[i].key.bv_len;
3446 bv.bv_val = ch_malloc( bv.bv_len + 1);
3447 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3448 strcpy( next, numbuf );
3449 ber_bvarray_add( &c->rvalue_vals, &bv );
3454 for(i = 1; i < c->argc; i++) {
3455 slap_ssf_t *tgt = NULL;
3457 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3458 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3459 sec_keys[j].key.bv_len)) {
3460 src = c->argv[i] + sec_keys[j].key.bv_len;
3461 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3466 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3467 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3468 c->log, c->cr_msg, c->argv[i]);
3472 if ( lutil_atou( tgt, src ) != 0 ) {
3473 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3474 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3475 c->log, c->cr_msg, c->argv[i]);
3483 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3487 for (; !BER_BVISNULL( &an->an_name ); an++) {
3488 /* if buflen == 0, assume the buffer size has been
3489 * already checked otherwise */
3490 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3491 if ( comma ) *ptr++ = ',';
3492 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3499 config_updatedn(ConfigArgs *c) {
3500 if (c->op == SLAP_CONFIG_EMIT) {
3501 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3502 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3503 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3507 } else if ( c->op == LDAP_MOD_DELETE ) {
3508 ch_free( c->be->be_update_ndn.bv_val );
3509 BER_BVZERO( &c->be->be_update_ndn );
3510 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3513 if(SLAP_SHADOW(c->be)) {
3514 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3515 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3516 c->log, c->cr_msg, 0);
3520 ber_memfree_x( c->value_dn.bv_val, NULL );
3521 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3522 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3524 c->be->be_update_ndn = c->value_ndn;
3525 BER_BVZERO( &c->value_dn );
3526 BER_BVZERO( &c->value_ndn );
3528 return config_slurp_shadow( c );
3532 config_shadow( ConfigArgs *c, slap_mask_t flag )
3534 char *notallowed = NULL;
3536 if ( c->be == frontendDB ) {
3537 notallowed = "frontend";
3539 } else if ( SLAP_MONITOR(c->be) ) {
3540 notallowed = "monitor";
3543 if ( notallowed != NULL ) {
3544 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3548 if ( SLAP_SHADOW(c->be) ) {
3549 /* if already shadow, only check consistency */
3550 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3551 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3557 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3564 config_updateref(ConfigArgs *c) {
3566 if (c->op == SLAP_CONFIG_EMIT) {
3567 if ( c->be->be_update_refs ) {
3568 value_add( &c->rvalue_vals, c->be->be_update_refs );
3573 } else if ( c->op == LDAP_MOD_DELETE ) {
3574 if ( c->valx < 0 ) {
3575 ber_bvarray_free( c->be->be_update_refs );
3576 c->be->be_update_refs = NULL;
3579 ch_free( c->be->be_update_refs[i].bv_val );
3580 for (; c->be->be_update_refs[i].bv_val; i++)
3581 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3585 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3586 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3588 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3589 c->log, c->cr_msg, 0);
3593 if(validate_global_referral(c->argv[1])) {
3594 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3595 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3596 c->log, c->cr_msg, c->argv[1]);
3599 ber_str2bv(c->argv[1], 0, 0, &val);
3600 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3605 config_obsolete(ConfigArgs *c) {
3606 if (c->op == SLAP_CONFIG_EMIT)
3609 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3611 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3616 config_include(ConfigArgs *c) {
3617 int savelineno = c->lineno;
3620 ConfigFile *cfsave = cfn;
3621 ConfigFile *cf2 = NULL;
3623 /* Leftover from RE23. No dynamic config for include files */
3624 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3627 cf = ch_calloc( 1, sizeof(ConfigFile));
3628 if ( cfn->c_kids ) {
3629 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3635 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3636 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3637 c->lineno = savelineno - 1;
3640 if ( cf2 ) cf2->c_sibs = NULL;
3641 else cfn->c_kids = NULL;
3642 ch_free( cf->c_file.bv_val );
3652 config_tls_cleanup(ConfigArgs *c) {
3655 if ( slap_tls_ld ) {
3658 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3660 /* Force new ctx to be created */
3661 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3663 /* The ctx's refcount is bumped up here */
3664 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3665 /* This is a no-op if it's already loaded */
3666 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3673 config_tls_option(ConfigArgs *c) {
3675 LDAP *ld = slap_tls_ld;
3677 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3678 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3679 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3680 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3681 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3682 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3683 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3685 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3687 default: Debug(LDAP_DEBUG_ANY, "%s: "
3688 "unknown tls_option <0x%x>\n",
3689 c->log, c->type, 0);
3692 if (c->op == SLAP_CONFIG_EMIT) {
3693 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3694 } else if ( c->op == LDAP_MOD_DELETE ) {
3695 c->cleanup = config_tls_cleanup;
3696 return ldap_pvt_tls_set_option( ld, flag, NULL );
3698 ch_free(c->value_string);
3699 c->cleanup = config_tls_cleanup;
3700 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3703 /* FIXME: this ought to be provided by libldap */
3705 config_tls_config(ConfigArgs *c) {
3708 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3709 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3710 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3712 Debug(LDAP_DEBUG_ANY, "%s: "
3713 "unknown tls_option <0x%x>\n",
3714 c->log, c->type, 0);
3717 if (c->op == SLAP_CONFIG_EMIT) {
3718 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3719 } else if ( c->op == LDAP_MOD_DELETE ) {
3721 c->cleanup = config_tls_cleanup;
3722 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3724 ch_free( c->value_string );
3725 c->cleanup = config_tls_cleanup;
3726 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3727 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3728 Debug(LDAP_DEBUG_ANY, "%s: "
3729 "unable to parse %s \"%s\"\n",
3730 c->log, c->argv[0], c->argv[1] );
3733 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3735 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3740 static CfEntryInfo *
3741 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3751 if ( dn_match( &root->ce_entry->e_nname, dn ))
3754 c = dn->bv_val+dn->bv_len;
3755 for (;*c != ',';c--);
3759 for (--c;c>dn->bv_val && *c != ',';c--);
3763 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3765 root = root->ce_kids;
3767 for (;root;root=root->ce_sibs) {
3768 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3769 if ( cdn.bv_val == dn->bv_val ) {
3779 typedef struct setup_cookie {
3789 config_ldif_resp( Operation *op, SlapReply *rs )
3791 if ( rs->sr_type == REP_SEARCH ) {
3792 setup_cookie *sc = op->o_callback->sc_private;
3795 sc->cfb->cb_got_ldif = 1;
3796 /* Does the frontend exist? */
3797 if ( !sc->got_frontend ) {
3798 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3799 "olcDatabase", STRLENOF( "olcDatabase" )))
3801 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3802 STRLENOF( "olcDatabase" ), "={-1}frontend",
3803 STRLENOF( "={-1}frontend" )))
3807 sc->ca->be = frontendDB;
3808 sc->ca->bi = frontendDB->bd_info;
3809 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3810 rdn.bv_val = sc->ca->log;
3811 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3812 "%s=" SLAP_X_ORDERED_FMT "%s",
3813 cfAd_database->ad_cname.bv_val, -1,
3814 sc->ca->bi->bi_type);
3816 sc->frontend = config_build_entry( op, rs,
3817 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3818 sc->ca->be->be_cf_ocs );
3828 dnParent( &rs->sr_entry->e_nname, &pdn );
3830 /* Does the configDB exist? */
3831 if ( sc->got_frontend && !sc->got_config &&
3832 !strncmp( rs->sr_entry->e_nname.bv_val,
3833 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3834 dn_match( &config_rdn, &pdn ) )
3836 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3837 STRLENOF( "olcDatabase" ), "={0}config",
3838 STRLENOF( "={0}config" )))
3842 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3843 sc->ca->bi = sc->ca->be->bd_info;
3844 rdn.bv_val = sc->ca->log;
3845 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3846 "%s=" SLAP_X_ORDERED_FMT "%s",
3847 cfAd_database->ad_cname.bv_val, 0,
3848 sc->ca->bi->bi_type);
3850 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3851 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3858 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3859 if ( rs->sr_err != LDAP_SUCCESS ) {
3860 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3861 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3867 /* Configure and read the underlying back-ldif store */
3869 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3870 CfBackInfo *cfb = be->be_private;
3876 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3877 Connection conn = {0};
3878 OperationBuffer opbuf;
3880 SlapReply rs = {REP_RESULT};
3881 Filter filter = { LDAP_FILTER_PRESENT };
3882 struct berval filterstr = BER_BVC("(objectclass=*)");
3885 /* Is the config directory available? */
3886 if ( stat( dir, &st ) < 0 ) {
3887 /* No, so don't bother using the backing store.
3888 * All changes will be in-memory only.
3893 cfb->cb_db.bd_info = backend_info( "ldif" );
3894 if ( !cfb->cb_db.bd_info )
3895 return 0; /* FIXME: eventually this will be a fatal error */
3897 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3900 cfb->cb_db.be_suffix = be->be_suffix;
3901 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3903 /* The suffix is always "cn=config". The underlying DB's rootdn
3904 * is always the same as the suffix.
3906 cfb->cb_db.be_rootdn = be->be_suffix[0];
3907 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3909 ber_str2bv( dir, 0, 1, &cfdir );
3914 argv[0] = "directory";
3915 argv[1] = (char *)dir;
3920 c.table = Cft_Database;
3922 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3926 if ( config_add_vals( ct, &c ))
3929 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3933 void *thrctx = ldap_pvt_thread_pool_context();
3936 connection_fake_init( &conn, &opbuf, thrctx );
3939 filter.f_desc = slap_schema.si_ad_objectClass;
3941 op->o_tag = LDAP_REQ_SEARCH;
3943 op->ors_filter = &filter;
3944 op->ors_filterstr = filterstr;
3945 op->ors_scope = LDAP_SCOPE_SUBTREE;
3947 op->o_dn = c.be->be_rootdn;
3948 op->o_ndn = c.be->be_rootndn;
3950 op->o_req_dn = be->be_suffix[0];
3951 op->o_req_ndn = be->be_nsuffix[0];
3953 op->ors_tlimit = SLAP_NO_LIMIT;
3954 op->ors_slimit = SLAP_NO_LIMIT;
3956 op->ors_attrs = slap_anlist_all_attributes;
3957 op->ors_attrsonly = 0;
3959 op->o_callback = &cb;
3962 cb.sc_private = ≻
3963 sc.got_frontend = 0;
3968 op->o_bd = &cfb->cb_db;
3970 /* Allow unknown attrs in DNs */
3971 prev_DN_strict = slap_DN_strict;
3974 rc = op->o_bd->be_search( op, &rs );
3976 /* Restore normal DN validation */
3977 slap_DN_strict = prev_DN_strict;
3979 op->o_tag = LDAP_REQ_ADD;
3980 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3981 op->ora_e = sc.frontend;
3982 rc = op->o_bd->be_add( op, &rs );
3984 if ( rc == LDAP_SUCCESS && sc.config ) {
3985 op->ora_e = sc.config;
3986 rc = op->o_bd->be_add( op, &rs );
3988 ldap_pvt_thread_pool_context_reset( thrctx );
3991 /* ITS#4194 - only use if it's present, or we're converting. */
3992 if ( !readit || rc == LDAP_SUCCESS )
3993 cfb->cb_use_ldif = 1;
3999 CfOc_cmp( const void *c1, const void *c2 ) {
4000 const ConfigOCs *co1 = c1;
4001 const ConfigOCs *co2 = c2;
4003 return ber_bvcmp( co1->co_name, co2->co_name );
4007 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4010 i = init_config_attrs( ct );
4013 /* set up the objectclasses */
4014 i = init_config_ocs( ocs );
4017 for (i=0; ocs[i].co_def; i++) {
4018 if ( ocs[i].co_oc ) {
4019 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4020 if ( !ocs[i].co_table )
4021 ocs[i].co_table = ct;
4022 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4029 read_config(const char *fname, const char *dir) {
4032 const char *cfdir, *cfname;
4035 /* Setup the config backend */
4036 be = backend_db_init( "config", NULL, 0, NULL );
4040 cfb = be->be_private;
4041 be->be_dfltaccess = ACL_NONE;
4043 /* If no .conf, or a dir was specified, setup the dir */
4044 if ( !fname || dir ) {
4046 /* If explicitly given, check for existence */
4049 if ( stat( dir, &st ) < 0 ) {
4050 Debug( LDAP_DEBUG_ANY,
4051 "invalid config directory %s, error %d\n",
4057 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4059 /* if fname is defaulted, try reading .d */
4060 rc = config_setup_ldif( be, cfdir, !fname );
4063 /* It may be OK if the base object doesn't exist yet. */
4064 if ( rc != LDAP_NO_SUCH_OBJECT )
4066 /* ITS#4194: But if dir was specified and no fname,
4067 * then we were supposed to read the dir. Unless we're
4068 * trying to slapadd the dir...
4070 if ( dir && !fname ) {
4071 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4073 /* Assume it's slapadd with a config dir, let it continue */
4075 cfb->cb_got_ldif = 1;
4076 cfb->cb_use_ldif = 1;
4081 /* If we read the config from back-ldif, nothing to do here */
4082 if ( cfb->cb_got_ldif ) {
4091 cfname = SLAPD_DEFAULT_CONFIGFILE;
4093 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4096 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4099 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4100 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4101 &frontendDB->be_schemadn );
4102 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4103 if ( rc != LDAP_SUCCESS ) {
4104 Debug(LDAP_DEBUG_ANY, "read_config: "
4105 "unable to normalize default schema DN \"%s\"\n",
4106 frontendDB->be_schemadn.bv_val, 0, 0 );
4107 /* must not happen */
4115 config_back_bind( Operation *op, SlapReply *rs )
4117 if ( be_isroot_pw( op ) ) {
4118 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4119 /* frontend sends result */
4120 return LDAP_SUCCESS;
4123 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4124 send_ldap_result( op, rs );
4130 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4134 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4136 rs->sr_attrs = op->ors_attrs;
4137 rs->sr_entry = ce->ce_entry;
4139 rc = send_search_entry( op, rs );
4140 if ( rc != LDAP_SUCCESS ) {
4144 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4145 if ( ce->ce_kids ) {
4146 rc = config_send( op, rs, ce->ce_kids, 1 );
4147 if ( rc ) return rc;
4150 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4151 rc = config_send( op, rs, ce, 0 );
4159 static ConfigTable *
4160 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4165 for (j=0; j<nocs; j++) {
4166 for (i=0; colst[j]->co_table[i].name; i++)
4167 if ( colst[j]->co_table[i].ad == ad ) {
4168 ca->table = colst[j]->co_type;
4169 return &colst[j]->co_table[i];
4175 /* Sort the attributes of the entry according to the order defined
4176 * in the objectclass, with required attributes occurring before
4177 * allowed attributes. For any attributes with sequencing dependencies
4178 * (e.g., rootDN must be defined after suffix) the objectclass must
4179 * list the attributes in the desired sequence.
4182 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4184 Attribute *a, *head = NULL, *tail = NULL, **prev;
4187 for (i=0; i<nocs; i++) {
4188 if ( colst[i]->co_oc->soc_required ) {
4189 AttributeType **at = colst[i]->co_oc->soc_required;
4190 for (j=0; at[j]; j++) {
4191 for (a=e->e_attrs, prev=&e->e_attrs; a;
4192 prev = &(*prev)->a_next, a=a->a_next) {
4193 if ( a->a_desc == at[j]->sat_ad ) {
4207 if ( colst[i]->co_oc->soc_allowed ) {
4208 AttributeType **at = colst[i]->co_oc->soc_allowed;
4209 for (j=0; at[j]; j++) {
4210 for (a=e->e_attrs, prev=&e->e_attrs; a;
4211 prev = &(*prev)->a_next, a=a->a_next) {
4212 if ( a->a_desc == at[j]->sat_ad ) {
4228 tail->a_next = e->e_attrs;
4234 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4236 Attribute *a = NULL;
4237 AttributeDescription *ad;
4247 Modifications *ml = ptr;
4249 vals = ml->sml_values;
4252 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4253 rc = ordered_value_sort( a, 1 );
4255 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4256 ad->ad_cname.bv_val );
4260 for ( i=0; vals[i].bv_val; i++ ) {
4261 ca->line = vals[i].bv_val;
4262 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4263 ca->line[0] == '{' ) {
4264 char *idx = strchr( ca->line, '}' );
4265 if ( idx ) ca->line = idx+1;
4267 rc = config_parse_vals( ct, ca, i );
4276 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4279 struct berval rtype, rval;
4281 AttributeDescription *ad = NULL;
4283 dnRdn( &e->e_name, rdn );
4284 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4285 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4286 rtype.bv_val = rdn->bv_val;
4287 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4290 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4291 a = attr_find( e->e_attrs, ad );
4292 if (!a ) return LDAP_NAMING_VIOLATION;
4299 config_rename_kids( CfEntryInfo *ce )
4302 struct berval rdn, nrdn;
4304 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4305 struct berval newdn, newndn;
4306 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4307 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4308 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4309 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4310 free( ce2->ce_entry->e_name.bv_val );
4311 free( ce2->ce_entry->e_nname.bv_val );
4312 ce2->ce_entry->e_name = newdn;
4313 ce2->ce_entry->e_nname = newndn;
4314 config_rename_kids( ce2 );
4319 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4320 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4321 struct berval *nnewrdn, int use_ldif )
4325 struct berval odn, ondn;
4329 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4330 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4333 free( a->a_vals[0].bv_val );
4334 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4335 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4336 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4337 strcpy( a->a_vals[0].bv_val, ptr1 );
4339 if ( a->a_nvals != a->a_vals ) {
4340 free( a->a_nvals[0].bv_val );
4341 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4342 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4343 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4344 strcpy( a->a_nvals[0].bv_val, ptr1 );
4347 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4348 BackendDB *be = op->o_bd;
4349 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4350 struct berval dn, ndn, xdn, xndn;
4352 op->o_bd = &cfb->cb_db;
4354 /* Save current rootdn; use the underlying DB's rootdn */
4358 xndn = op->o_req_ndn;
4359 op->o_dn = op->o_bd->be_rootdn;
4360 op->o_ndn = op->o_bd->be_rootndn;
4362 op->o_req_ndn = ondn;
4364 scp = op->o_callback;
4365 op->o_callback = ≻
4366 op->orr_newrdn = *newrdn;
4367 op->orr_nnewrdn = *nnewrdn;
4368 op->orr_newSup = NULL;
4369 op->orr_nnewSup = NULL;
4370 op->orr_deleteoldrdn = 1;
4371 op->orr_modlist = NULL;
4372 slap_modrdn2mods( op, rs );
4373 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4374 rc = op->o_bd->be_modrdn( op, rs );
4375 slap_mods_free( op->orr_modlist, 1 );
4378 op->o_callback = scp;
4382 op->o_req_ndn = xndn;
4385 free( ondn.bv_val );
4387 config_rename_kids( e->e_private );
4392 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4393 Entry *e, int idx, int tailindex, int use_ldif )
4395 struct berval ival, newrdn, nnewrdn;
4398 char ibuf[32], *ptr1, *ptr2 = NULL;
4401 rc = config_rename_attr( rs, e, &rdn, &a );
4402 if ( rc ) return rc;
4405 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4406 if ( ival.bv_len >= sizeof( ibuf ) ) {
4407 return LDAP_NAMING_VIOLATION;
4410 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4411 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4414 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4415 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4418 ptr2 = ber_bvchr( &rdn, '}' );
4422 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4424 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4425 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4426 a->a_desc->ad_cname.bv_len );
4428 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4429 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4433 /* Do the equivalent of ModRDN */
4434 /* Replace DN / NDN */
4435 newrdn.bv_len = ptr1 - newrdn.bv_val;
4436 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4437 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4439 free( nnewrdn.bv_val );
4440 free( newrdn.bv_val );
4445 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4446 SlapReply *rs, int *renum, int *ibase )
4449 int index = -1, gotindex = 0, nsibs, rc = 0;
4450 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4451 char *ptr1, *ptr2 = NULL;
4454 if ( renum ) *renum = 0;
4456 /* These entries don't get indexed/renumbered */
4457 if ( ce_type == Cft_Global ) return 0;
4458 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4460 if ( ce_type == Cft_Module )
4463 /* See if the rdn has an index already */
4464 dnRdn( &e->e_name, &rdn );
4465 if ( ce_type == Cft_Database ) {
4466 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4467 "frontend", STRLENOF("frontend") ))
4469 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4470 "config", STRLENOF("config") ))
4473 ptr1 = ber_bvchr( &e->e_name, '{' );
4474 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4476 ptr2 = strchr( ptr1, '}' );
4477 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4478 return LDAP_NAMING_VIOLATION;
4479 if ( ptr2-ptr1 == 1)
4480 return LDAP_NAMING_VIOLATION;
4482 index = strtol( ptr1 + 1, &next, 10 );
4483 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4484 return LDAP_NAMING_VIOLATION;
4487 /* Special case, we allow -1 for the frontendDB */
4488 if ( index != -1 || !isfrontend )
4489 return LDAP_NAMING_VIOLATION;
4491 if ( isconfig && index != 0 ){
4492 return LDAP_NAMING_VIOLATION;
4496 /* count related kids */
4497 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4498 if ( ce->ce_type == ce_type ) nsibs++;
4501 /* account for -1 frontend */
4502 if ( ce_type == Cft_Database )
4505 if ( index != nsibs ) {
4507 if ( index < nsibs ) {
4508 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4509 /* Siblings need to be renumbered */
4510 if ( index != -1 || !isfrontend )
4514 /* config DB is always "0" */
4515 if ( isconfig && index == -1 ) {
4518 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4522 /* just make index = nsibs */
4524 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4527 if ( ibase ) *ibase = index;
4528 if ( renum ) *renum = renumber;
4533 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4538 co.co_name = &oc->soc_cname;
4539 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4543 /* check for duplicates */
4544 for ( i = 0; i < *nocs; i++ ) {
4545 if ( *copp && (*copp)[i] == cop ) {
4551 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4552 if ( tmp == NULL ) {
4556 (*copp)[*nocs] = cop;
4561 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4562 if ( count_oc( *sups, copp, nocs ) ) {
4571 count_ocs( Attribute *oc_at, int *nocs )
4574 ConfigOCs **colst = NULL;
4578 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4582 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4584 assert( oc != NULL );
4585 if ( count_oc( oc, &colst, nocs ) ) {
4595 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4597 /* Leftover from RE23. Never parse this entry */
4598 return LDAP_COMPARE_TRUE;
4602 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4606 /* This entry is hardcoded, don't re-parse it */
4607 if ( p->ce_type == Cft_Global ) {
4608 cfn = p->ce_private;
4609 ca->ca_private = cfn;
4610 return LDAP_COMPARE_TRUE;
4612 if ( p->ce_type != Cft_Schema )
4613 return LDAP_CONSTRAINT_VIOLATION;
4615 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4616 ca->ca_private = cfn;
4617 cfo = p->ce_private;
4618 cfn->c_sibs = cfo->c_kids;
4620 return LDAP_SUCCESS;
4624 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4626 if ( p->ce_type != Cft_Global ) {
4627 return LDAP_CONSTRAINT_VIOLATION;
4629 /* config must be {0}, nothing else allowed */
4630 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4631 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4632 return LDAP_CONSTRAINT_VIOLATION;
4634 ca->be = frontendDB; /* just to get past check_vals */
4635 return LDAP_SUCCESS;
4639 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4641 if ( p->ce_type != Cft_Global ) {
4642 return LDAP_CONSTRAINT_VIOLATION;
4644 return LDAP_SUCCESS;
4648 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4650 if ( p->ce_type != Cft_Global ) {
4651 return LDAP_CONSTRAINT_VIOLATION;
4653 return LDAP_SUCCESS;
4657 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4659 if ( p->ce_type != Cft_Database ) {
4660 return LDAP_CONSTRAINT_VIOLATION;
4663 return LDAP_SUCCESS;
4667 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4672 AttributeDescription *ad;
4678 if ( cfn->c_cr_head ) {
4679 struct berval bv = BER_BVC("olcDitContentRules");
4681 slap_bv2ad( &bv, &ad, &text );
4682 ct = config_find_table( colst, nocs, ad, ca );
4683 config_del_vals( ct, ca );
4685 if ( cfn->c_oc_head ) {
4686 struct berval bv = BER_BVC("olcObjectClasses");
4688 slap_bv2ad( &bv, &ad, &text );
4689 ct = config_find_table( colst, nocs, ad, ca );
4690 config_del_vals( ct, ca );
4692 if ( cfn->c_at_head ) {
4693 struct berval bv = BER_BVC("olcAttributeTypes");
4695 slap_bv2ad( &bv, &ad, &text );
4696 ct = config_find_table( colst, nocs, ad, ca );
4697 config_del_vals( ct, ca );
4699 if ( cfn->c_syn_head ) {
4700 struct berval bv = BER_BVC("olcLdapSyntaxes");
4702 slap_bv2ad( &bv, &ad, &text );
4703 ct = config_find_table( colst, nocs, ad, ca );
4704 config_del_vals( ct, ca );
4706 if ( cfn->c_om_head ) {
4707 struct berval bv = BER_BVC("olcObjectIdentifier");
4709 slap_bv2ad( &bv, &ad, &text );
4710 ct = config_find_table( colst, nocs, ad, ca );
4711 config_del_vals( ct, ca );
4713 cfo = p->ce_private;
4714 cfo->c_kids = cfn->c_sibs;
4719 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4721 int rc = LDAP_CONSTRAINT_VIOLATION;
4724 if ( (*cop)->co_ldadd ) {
4725 rc = (*cop)->co_ldadd( last, e, ca );
4726 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4731 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4732 ConfigOCs co = { 0 };
4734 co.co_name = &(*ocp)->soc_cname;
4735 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4736 if ( *cop == NULL ) {
4740 rc = config_add_oc( cop, last, e, ca );
4741 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4749 /* Parse an LDAP entry into config directives */
4751 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4752 int *renum, Operation *op )
4754 CfEntryInfo *ce, *last = NULL;
4755 ConfigOCs co, *coptr, **colst;
4756 Attribute *a, *oc_at, *soc_at;
4757 int i, ibase = -1, nocs, rc = 0;
4760 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4762 memset( ca, 0, sizeof(ConfigArgs));
4764 /* Make sure parent exists and entry does not. But allow
4765 * Databases and Overlays to be inserted. Don't do any
4766 * auto-renumbering if manageDSAit control is present.
4768 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4770 if ( ( op && op->o_managedsait ) ||
4771 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4772 ce->ce_type != Cft_Module ) )
4774 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4775 "DN=\"%s\" already exists\n",
4776 log_prefix, e->e_name.bv_val, 0 );
4777 /* global schema ignores all writes */
4778 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4779 return LDAP_COMPARE_TRUE;
4780 return LDAP_ALREADY_EXISTS;
4784 dnParent( &e->e_nname, &pdn );
4786 /* If last is NULL, the new entry is the root/suffix entry,
4787 * otherwise last should be the parent.
4789 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4791 rs->sr_matched = last->ce_entry->e_name.bv_val;
4793 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4794 "DN=\"%s\" not child of DN=\"%s\"\n",
4795 log_prefix, e->e_name.bv_val,
4796 last->ce_entry->e_name.bv_val );
4797 return LDAP_NO_SUCH_OBJECT;
4801 /* No parent, must be root. This will never happen... */
4802 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4803 return LDAP_NO_SUCH_OBJECT;
4806 if ( last && !access_allowed( op, last->ce_entry,
4807 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4809 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4810 "DN=\"%s\" no write access to \"children\" of parent\n",
4811 log_prefix, e->e_name.bv_val, 0 );
4812 return LDAP_INSUFFICIENT_ACCESS;
4816 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4818 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4819 "DN=\"%s\" no objectClass\n",
4820 log_prefix, e->e_name.bv_val, 0 );
4821 return LDAP_OBJECT_CLASS_VIOLATION;
4824 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4826 ObjectClass *soc = NULL;
4827 char textbuf[ SLAP_TEXT_BUFLEN ];
4828 const char *text = textbuf;
4830 /* FIXME: check result */
4831 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4832 &text, textbuf, sizeof(textbuf), NULL );
4833 if ( rc != LDAP_SUCCESS ) {
4834 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4835 "DN=\"%s\" no structural objectClass (%s)\n",
4836 log_prefix, e->e_name.bv_val, text );
4839 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4840 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4841 if ( soc_at == NULL ) {
4842 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4843 "DN=\"%s\" no structural objectClass; "
4844 "unable to merge computed class %s\n",
4845 log_prefix, e->e_name.bv_val,
4846 soc->soc_cname.bv_val );
4847 return LDAP_OBJECT_CLASS_VIOLATION;
4850 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4851 "DN=\"%s\" no structural objectClass; "
4852 "computed objectClass %s merged\n",
4853 log_prefix, e->e_name.bv_val,
4854 soc->soc_cname.bv_val );
4857 /* Fake the coordinates based on whether we're part of an
4858 * LDAP Add or if reading the config dir
4861 ca->fname = "slapd";
4864 ca->fname = cfdir.bv_val;
4869 co.co_name = &soc_at->a_nvals[0];
4870 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4871 if ( coptr == NULL ) {
4872 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4873 "DN=\"%s\" no structural objectClass in configuration table\n",
4874 log_prefix, e->e_name.bv_val, 0 );
4875 return LDAP_OBJECT_CLASS_VIOLATION;
4878 /* Only the root can be Cft_Global, everything else must
4879 * have a parent. Only limited nesting arrangements are allowed.
4881 rc = LDAP_CONSTRAINT_VIOLATION;
4882 if ( coptr->co_type == Cft_Global && !last ) {
4883 cfn = cfb->cb_config;
4884 ca->ca_private = cfn;
4885 ca->be = frontendDB; /* just to get past check_vals */
4889 colst = count_ocs( oc_at, &nocs );
4891 /* Check whether the Add is allowed by its parent, and do
4892 * any necessary arg setup
4895 rc = config_add_oc( &coptr, last, e, ca );
4896 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4897 for ( i = 0; i<nocs; i++ ) {
4898 /* Already checked these */
4899 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4901 if ( colst[i]->co_ldadd &&
4902 ( rc = colst[i]->co_ldadd( last, e, ca ))
4903 != LDAP_CONSTRAINT_VIOLATION ) {
4909 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4910 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4911 "DN=\"%s\" no structural objectClass add function\n",
4912 log_prefix, e->e_name.bv_val, 0 );
4913 return LDAP_OBJECT_CLASS_VIOLATION;
4917 /* Add the entry but don't parse it, we already have its contents */
4918 if ( rc == LDAP_COMPARE_TRUE ) {
4923 if ( rc != LDAP_SUCCESS )
4926 /* Parse all the values and check for simple syntax errors before
4927 * performing any set actions.
4929 * If doing an LDAPadd, check for indexed names and any necessary
4930 * renaming/renumbering. Entries that don't need indexed names are
4931 * ignored. Entries that need an indexed name and arrive without one
4932 * are assigned to the end. Entries that arrive with an index may
4933 * cause the following entries to be renumbered/bumped down.
4935 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4936 * don't allow Adding an entry with an index that's already in use.
4937 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4939 * These entries can have auto-assigned indexes (appended to the end)
4940 * but only the other types support auto-renumbering of siblings.
4943 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4948 if ( renum && *renum && coptr->co_type != Cft_Database &&
4949 coptr->co_type != Cft_Overlay )
4951 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4952 "operation requires sibling renumbering" );
4953 rc = LDAP_UNWILLING_TO_PERFORM;
4958 init_config_argv( ca );
4960 /* Make sure we process attrs in the required order */
4961 sort_attrs( e, colst, nocs );
4963 for ( a = e->e_attrs; a; a = a->a_next ) {
4964 if ( a == oc_at ) continue;
4965 ct = config_find_table( colst, nocs, a->a_desc, ca );
4966 if ( !ct ) continue; /* user data? */
4967 rc = check_vals( ct, ca, a, 1 );
4968 if ( rc ) goto done_noop;
4971 /* Basic syntax checks are OK. Do the actual settings. */
4972 for ( a=e->e_attrs; a; a=a->a_next ) {
4973 if ( a == oc_at ) continue;
4974 ct = config_find_table( colst, nocs, a->a_desc, ca );
4975 if ( !ct ) continue; /* user data? */
4976 for (i=0; a->a_vals[i].bv_val; i++) {
4979 ca->line = a->a_vals[i].bv_val;
4980 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4981 ptr = strchr( ca->line, '}' );
4983 iptr = strchr( ca->line, '{' );
4987 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4989 ca->valx = strtol( iptr+1, NULL, 0 );
4994 rc = config_parse_add( ct, ca, i );
5002 /* Newly added databases and overlays need to be started up */
5003 if ( CONFIG_ONLINE_ADD( ca )) {
5004 if ( coptr->co_type == Cft_Database ) {
5005 rc = backend_startup_one( ca->be, &ca->reply );
5007 } else if ( coptr->co_type == Cft_Overlay ) {
5008 if ( ca->bi->bi_db_open ) {
5009 BackendInfo *bi_orig = ca->be->bd_info;
5010 ca->be->bd_info = ca->bi;
5011 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5012 ca->be->bd_info = bi_orig;
5014 } else if ( ca->cleanup ) {
5015 rc = ca->cleanup( ca );
5018 if (ca->cr_msg[0] == '\0')
5019 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5021 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5022 ca->log, ca->cr_msg, ca->argv[1] );
5029 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5030 ce->ce_parent = last;
5031 ce->ce_entry = entry_dup( e );
5032 ce->ce_entry->e_private = ce;
5033 ce->ce_type = coptr->co_type;
5036 ce->ce_private = ca->ca_private;
5037 ca->ca_entry = ce->ce_entry;
5040 } else if ( last->ce_kids ) {
5041 CfEntryInfo *c2, **cprev;
5043 /* Advance to first of this type */
5044 cprev = &last->ce_kids;
5045 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5046 cprev = &c2->ce_sibs;
5049 /* Account for the (-1) frontendDB entry */
5050 if ( ce->ce_type == Cft_Database ) {
5051 if ( ca->be == frontendDB )
5053 else if ( ibase != -1 )
5058 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5059 cprev = &c2->ce_sibs;
5065 for ( i=0; i<ibase; i++ ) {
5067 cprev = &c2->ce_sibs;
5070 ce->ce_sibs = *cprev;
5078 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5079 if ( ca->be != frontendDB )
5080 backend_destroy_one( ca->be, 1 );
5081 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5082 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5083 } else if ( coptr->co_type == Cft_Schema ) {
5084 schema_destroy_one( ca, colst, nocs, last );
5089 ch_free( ca->argv );
5090 if ( colst ) ch_free( colst );
5094 #define BIGTMP 10000
5096 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5097 int base, int rebase, int max, int use_ldif )
5099 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5100 ConfigType etype = ce->ce_type;
5101 int count = 0, rc = 0;
5103 /* Reverse ce list */
5104 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5105 if (ce2->ce_type != etype) {
5110 ce2->ce_sibs = cetmp;
5113 if ( max && count >= max ) {
5119 /* Move original to a temp name until increments are done */
5121 ce->ce_entry->e_private = NULL;
5122 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5123 base+BIGTMP, 0, use_ldif );
5124 ce->ce_entry->e_private = ce;
5126 /* start incrementing */
5127 for (ce2=cetmp; ce2; ce2=ce3) {
5129 ce2->ce_sibs = cerem;
5132 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5133 count+base, 0, use_ldif );
5137 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5138 base, 0, use_ldif );
5143 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5144 CfEntryInfo *ce2, int old, int use_ldif )
5148 /* Renumber original to a temp value */
5149 ce->ce_entry->e_private = NULL;
5150 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5151 old+BIGTMP, 0, use_ldif );
5152 ce->ce_entry->e_private = ce;
5154 /* start decrementing */
5155 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5156 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5157 count+old, 0, use_ldif );
5160 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5161 count+old, 0, use_ldif );
5164 /* Parse an LDAP entry into config directives, then store in underlying
5168 config_back_add( Operation *op, SlapReply *rs )
5174 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5175 NULL, ACL_WADD, NULL )) {
5176 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5181 * Check for attribute ACL
5183 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5184 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5185 rs->sr_text = "no write access to attribute";
5189 cfb = (CfBackInfo *)op->o_bd->be_private;
5191 /* add opattrs for syncprov */
5193 char textbuf[SLAP_TEXT_BUFLEN];
5194 size_t textlen = sizeof textbuf;
5195 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5196 &rs->sr_text, textbuf, sizeof( textbuf ) );
5197 if ( rs->sr_err != LDAP_SUCCESS )
5199 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5200 if ( rs->sr_err != LDAP_SUCCESS ) {
5201 Debug( LDAP_DEBUG_TRACE,
5202 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5203 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5208 if ( op->o_abandon ) {
5209 rs->sr_err = SLAPD_ABANDON;
5212 ldap_pvt_thread_pool_pause( &connection_pool );
5215 * 1) check for existence of entry
5216 * 2) check for sibling renumbering
5217 * 3) perform internal add
5218 * 4) perform any necessary renumbering
5219 * 5) store entry in underlying database
5221 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5222 if ( rs->sr_err != LDAP_SUCCESS ) {
5223 rs->sr_text = ca.cr_msg;
5228 CfEntryInfo *ce = ca.ca_entry->e_private;
5229 req_add_s addr = op->oq_add;
5230 op->o_tag = LDAP_REQ_MODRDN;
5231 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5232 op->o_tag = LDAP_REQ_ADD;
5234 if ( rs->sr_err != LDAP_SUCCESS ) {
5239 if ( cfb->cb_use_ldif ) {
5240 BackendDB *be = op->o_bd;
5241 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5242 struct berval dn, ndn;
5244 op->o_bd = &cfb->cb_db;
5246 /* Save current rootdn; use the underlying DB's rootdn */
5249 op->o_dn = op->o_bd->be_rootdn;
5250 op->o_ndn = op->o_bd->be_rootndn;
5252 scp = op->o_callback;
5253 op->o_callback = ≻
5254 op->o_bd->be_add( op, rs );
5256 op->o_callback = scp;
5262 ldap_pvt_thread_pool_resume( &connection_pool );
5265 { int repl = op->o_dont_replicate;
5266 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5267 rs->sr_err = LDAP_SUCCESS;
5268 op->o_dont_replicate = 1;
5270 send_ldap_result( op, rs );
5271 op->o_dont_replicate = repl;
5273 slap_graduate_commit_csn( op );
5277 typedef struct delrec {
5278 struct delrec *next;
5284 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5290 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5291 ca->line[0] == '{' )
5293 char *ptr = strchr( ca->line + 1, '}' );
5297 ca->valx = strtol( ca->line + 1, &next, 0 );
5298 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5304 rc = config_parse_add( ct, ca, i );
5312 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5315 int rc = LDAP_UNWILLING_TO_PERFORM;
5317 Entry *e = ce->ce_entry;
5318 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5323 delrec *dels = NULL, *deltail = NULL;
5325 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5326 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5328 colst = count_ocs( oc_at, &nocs );
5330 /* make sure add/del flags are clear; should always be true */
5331 for ( s = save_attrs; s; s = s->a_next ) {
5332 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5335 e->e_attrs = attrs_dup( e->e_attrs );
5337 init_config_argv( ca );
5340 ca->ca_private = ce->ce_private;
5342 ca->fname = "slapd";
5344 strcpy( ca->log, "back-config" );
5346 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5347 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5348 switch (ml->sml_op) {
5349 case LDAP_MOD_DELETE:
5350 case LDAP_MOD_REPLACE: {
5351 BerVarray vals = NULL, nvals = NULL;
5353 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5355 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5356 ml->sml_desc->ad_cname.bv_val );
5359 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5360 vals = ml->sml_values;
5361 nvals = ml->sml_nvalues;
5362 ml->sml_values = NULL;
5363 ml->sml_nvalues = NULL;
5365 /* If we're deleting by values, remember the indexes of the
5366 * values we deleted.
5368 if ( ct && ml->sml_values ) {
5370 i = ml->sml_numvals;
5371 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5382 rc = modify_delete_vindex(e, &ml->sml_mod,
5383 get_permissiveModify(op),
5384 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5385 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5386 ml->sml_values = vals;
5387 ml->sml_nvalues = nvals;
5392 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5395 case SLAP_MOD_SOFTADD: {
5396 int mop = ml->sml_op;
5398 ml->sml_op = LDAP_MOD_ADD;
5400 if ( ct->arg_type & ARG_NO_INSERT ) {
5401 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5403 navals = a->a_numvals;
5406 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5407 if ( ml->sml_values[i].bv_val[0] == '{' &&
5410 char *next, *val = ml->sml_values[i].bv_val + 1;
5413 j = strtol( val, &next, 0 );
5414 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5416 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5417 ml->sml_desc->ad_cname.bv_val );
5421 rc = check_vals( ct, ca, ml, 0 );
5422 if ( rc ) goto out_noop;
5425 rc = modify_add_values(e, &ml->sml_mod,
5426 get_permissiveModify(op),
5427 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5429 /* If value already exists, show success here
5430 * and ignore this operation down below.
5432 if ( mop == SLAP_MOD_SOFTADD ) {
5433 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5443 case LDAP_MOD_INCREMENT: /* FIXME */
5448 if(rc != LDAP_SUCCESS) break;
5451 if ( rc == LDAP_SUCCESS) {
5452 /* check that the entry still obeys the schema */
5453 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5454 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5456 if ( rc ) goto out_noop;
5458 /* Basic syntax checks are OK. Do the actual settings. */
5459 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5460 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5461 if ( !ct ) continue;
5463 s = attr_find( save_attrs, ml->sml_desc );
5464 a = attr_find( e->e_attrs, ml->sml_desc );
5466 switch (ml->sml_op) {
5467 case LDAP_MOD_DELETE:
5468 case LDAP_MOD_REPLACE: {
5469 BerVarray vals = NULL, nvals = NULL;
5472 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5473 vals = ml->sml_values;
5474 nvals = ml->sml_nvalues;
5475 ml->sml_values = NULL;
5476 ml->sml_nvalues = NULL;
5479 if ( ml->sml_values )
5482 /* If we didn't delete the whole attribute */
5483 if ( ml->sml_values && a ) {
5484 struct berval *mvals;
5487 if ( ml->sml_nvalues )
5488 mvals = ml->sml_nvalues;
5490 mvals = ml->sml_values;
5492 /* use the indexes we saved up above */
5493 for (i=0; i < d->nidx; i++) {
5494 struct berval bv = *mvals++;
5495 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5496 bv.bv_val[0] == '{' ) {
5497 ptr = strchr( bv.bv_val, '}' ) + 1;
5498 bv.bv_len -= ptr - bv.bv_val;
5501 ca->line = bv.bv_val;
5502 ca->valx = d->idx[i];
5503 config_parse_vals(ct, ca, d->idx[i] );
5504 rc = config_del_vals( ct, ca );
5505 if ( rc != LDAP_SUCCESS ) break;
5507 s->a_flags |= SLAP_ATTR_IXDEL;
5508 for (j=i+1; j < d->nidx; j++)
5509 if ( d->idx[j] >d->idx[i] )
5516 rc = config_del_vals( ct, ca );
5517 if ( rc ) rc = LDAP_OTHER;
5519 s->a_flags |= SLAP_ATTR_IXDEL;
5521 if ( ml->sml_values ) {
5526 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5527 ml->sml_values = vals;
5528 ml->sml_nvalues = nvals;
5530 if ( !vals || rc != LDAP_SUCCESS )
5533 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5536 for (i=0; ml->sml_values[i].bv_val; i++) {
5537 ca->line = ml->sml_values[i].bv_val;
5539 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5542 a->a_flags |= SLAP_ATTR_IXADD;
5549 /* Undo for a failed operation */
5550 if ( rc != LDAP_SUCCESS ) {
5551 ConfigReply msg = ca->reply;
5552 for ( s = save_attrs; s; s = s->a_next ) {
5553 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5554 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5555 ct = config_find_table( colst, nocs, s->a_desc, ca );
5556 a = attr_find( e->e_attrs, s->a_desc );
5558 /* clear the flag so the add check below will skip it */
5559 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5563 config_del_vals( ct, ca );
5565 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5566 ca->line = s->a_vals[i].bv_val;
5568 config_modify_add( ct, ca, s->a_desc, i );
5572 for ( a = e->e_attrs; a; a = a->a_next ) {
5573 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5574 ct = config_find_table( colst, nocs, a->a_desc, ca );
5578 config_del_vals( ct, ca );
5579 s = attr_find( save_attrs, a->a_desc );
5581 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5582 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5583 ca->line = s->a_vals[i].bv_val;
5585 config_modify_add( ct, ca, s->a_desc, i );
5596 if ( rc == LDAP_SUCCESS ) {
5597 attrs_free( save_attrs );
5599 attrs_free( e->e_attrs );
5600 e->e_attrs = save_attrs;
5602 ch_free( ca->argv );
5603 if ( colst ) ch_free( colst );
5605 deltail = dels->next;
5614 config_back_modify( Operation *op, SlapReply *rs )
5617 CfEntryInfo *ce, *last;
5619 ConfigArgs ca = {0};
5622 AttributeDescription *rad = NULL;
5625 cfb = (CfBackInfo *)op->o_bd->be_private;
5627 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5630 rs->sr_matched = last->ce_entry->e_name.bv_val;
5631 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5635 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5636 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5640 /* Get type of RDN */
5641 rdn = ce->ce_entry->e_nname;
5642 ptr = strchr( rdn.bv_val, '=' );
5643 rdn.bv_len = ptr - rdn.bv_val;
5644 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5646 /* Some basic validation... */
5647 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5648 /* Don't allow Modify of RDN; must use ModRdn for that. */
5649 if ( ml->sml_desc == rad ) {
5650 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5651 rs->sr_text = "Use modrdn to change the entry name";
5654 /* Internal update of contextCSN? */
5655 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5661 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5664 if ( op->o_abandon ) {
5665 rs->sr_err = SLAPD_ABANDON;
5668 ldap_pvt_thread_pool_pause( &connection_pool );
5672 * 1) perform the Modify on the cached Entry.
5673 * 2) verify that the Entry still satisfies the schema.
5674 * 3) perform the individual config operations.
5675 * 4) store Modified entry in underlying LDIF backend.
5677 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5679 rs->sr_text = ca.cr_msg;
5680 } else if ( cfb->cb_use_ldif ) {
5681 BackendDB *be = op->o_bd;
5682 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5683 struct berval dn, ndn;
5685 op->o_bd = &cfb->cb_db;
5689 op->o_dn = op->o_bd->be_rootdn;
5690 op->o_ndn = op->o_bd->be_rootndn;
5692 scp = op->o_callback;
5693 op->o_callback = ≻
5694 op->o_bd->be_modify( op, rs );
5696 op->o_callback = scp;
5702 ldap_pvt_thread_pool_resume( &connection_pool );
5704 send_ldap_result( op, rs );
5705 slap_graduate_commit_csn( op );
5710 config_back_modrdn( Operation *op, SlapReply *rs )
5713 CfEntryInfo *ce, *last;
5717 cfb = (CfBackInfo *)op->o_bd->be_private;
5719 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5722 rs->sr_matched = last->ce_entry->e_name.bv_val;
5723 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5726 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5727 NULL, ACL_WRITE, NULL )) {
5728 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5732 if ( ce->ce_parent )
5733 parent = ce->ce_parent->ce_entry;
5735 parent = (Entry *)&slap_entry_root;
5736 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5737 NULL, ACL_WRITE, NULL )) {
5738 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5743 /* We don't allow moving objects to new parents.
5744 * Generally we only allow reordering a set of ordered entries.
5746 if ( op->orr_newSup ) {
5747 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5751 /* If newRDN == oldRDN, quietly succeed */
5752 dnRdn( &op->o_req_ndn, &rdn );
5753 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5754 rs->sr_err = LDAP_SUCCESS;
5758 /* Current behavior, subject to change as needed:
5760 * For backends and overlays, we only allow renumbering.
5761 * For schema, we allow renaming with the same number.
5762 * Otherwise, the op is not allowed.
5765 if ( ce->ce_type == Cft_Schema ) {
5769 /* Can't alter the main cn=schema entry */
5770 if ( ce->ce_parent->ce_type == Cft_Global ) {
5771 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5772 rs->sr_text = "renaming not allowed for this entry";
5776 /* We could support this later if desired */
5777 ptr1 = ber_bvchr( &rdn, '}' );
5778 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5779 len = ptr1 - rdn.bv_val;
5780 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5781 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5782 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5783 rs->sr_text = "schema reordering not supported";
5786 } else if ( ce->ce_type == Cft_Database ||
5787 ce->ce_type == Cft_Overlay ) {
5788 char *ptr1, *ptr2, *iptr1, *iptr2;
5791 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5792 if ( *iptr2 != '{' ) {
5793 rs->sr_err = LDAP_NAMING_VIOLATION;
5794 rs->sr_text = "new ordering index is required";
5798 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5799 ptr1 = ber_bvchr( &rdn, '}' );
5800 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5802 rs->sr_err = LDAP_NAMING_VIOLATION;
5803 rs->sr_text = "new ordering index is required";
5807 len1 = ptr1 - rdn.bv_val;
5808 len2 = ptr2 - op->orr_newrdn.bv_val;
5810 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5811 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5812 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5813 rs->sr_text = "changing database/overlay type not allowed";
5816 ixold = strtol( iptr1, NULL, 0 );
5817 ixnew = strtol( iptr2, &ptr1, 0 );
5818 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5819 rs->sr_err = LDAP_NAMING_VIOLATION;
5822 /* config DB is always 0, cannot be changed */
5823 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5824 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5828 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5829 rs->sr_text = "renaming not supported for this entry";
5833 if ( op->o_abandon ) {
5834 rs->sr_err = SLAPD_ABANDON;
5837 ldap_pvt_thread_pool_pause( &connection_pool );
5839 if ( ce->ce_type == Cft_Schema ) {
5840 req_modrdn_s modr = op->oq_modrdn;
5843 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5844 if ( rs->sr_err == LDAP_SUCCESS ) {
5845 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5846 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5849 op->oq_modrdn = modr;
5851 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5852 req_modrdn_s modr = op->oq_modrdn;
5855 /* Advance to first of this type */
5856 cprev = &ce->ce_parent->ce_kids;
5857 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5858 cprev = &ce2->ce_sibs;
5861 /* Skip the -1 entry */
5862 if ( ce->ce_type == Cft_Database ) {
5863 cprev = &ce2->ce_sibs;
5869 /* Remove from old slot */
5870 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5871 cprev = &ce2->ce_sibs;
5872 *cprev = ce->ce_sibs;
5873 ceold = ce->ce_sibs;
5875 /* Insert into new slot */
5877 for ( i=0; i<ixnew; i++ ) {
5881 cprev = &ce2->ce_sibs;
5883 ce->ce_sibs = *cprev;
5888 /* NOTE: These should be encoded in the OC tables, not inline here */
5889 if ( ce->ce_type == Cft_Database )
5890 backend_db_move( ce->ce_be, ixnew );
5891 else if ( ce->ce_type == Cft_Overlay )
5892 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5894 if ( ixold < ixnew ) {
5895 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5898 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5899 ixold - ixnew, cfb->cb_use_ldif );
5901 op->oq_modrdn = modr;
5904 ldap_pvt_thread_pool_resume( &connection_pool );
5906 send_ldap_result( op, rs );
5911 config_back_delete( Operation *op, SlapReply *rs )
5913 #ifdef SLAP_CONFIG_DELETE
5915 CfEntryInfo *ce, *last, *ce2;
5917 cfb = (CfBackInfo *)op->o_bd->be_private;
5919 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5922 rs->sr_matched = last->ce_entry->e_name.bv_val;
5923 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5924 } else if ( ce->ce_kids ) {
5925 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5926 } else if ( op->o_abandon ) {
5927 rs->sr_err = SLAPD_ABANDON;
5928 } else if ( ce->ce_type == Cft_Overlay ){
5932 ldap_pvt_thread_pool_pause( &connection_pool );
5934 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5936 /* remove CfEntryInfo from the siblings list */
5937 if ( ce->ce_parent->ce_kids == ce ) {
5938 ce->ce_parent->ce_kids = ce->ce_sibs;
5940 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5941 if ( ce2->ce_sibs == ce ) {
5942 ce2->ce_sibs = ce->ce_sibs;
5948 /* remove from underlying database */
5949 if ( cfb->cb_use_ldif ) {
5950 BackendDB *be = op->o_bd;
5951 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5952 struct berval dn, ndn, req_dn, req_ndn;
5954 op->o_bd = &cfb->cb_db;
5958 req_dn = op->o_req_dn;
5959 req_ndn = op->o_req_ndn;
5961 op->o_dn = op->o_bd->be_rootdn;
5962 op->o_ndn = op->o_bd->be_rootndn;
5963 op->o_req_dn = ce->ce_entry->e_name;
5964 op->o_req_ndn = ce->ce_entry->e_nname;
5966 scp = op->o_callback;
5967 op->o_callback = ≻
5968 op->o_bd->be_delete( op, rs );
5970 op->o_callback = scp;
5973 op->o_req_dn = req_dn;
5974 op->o_req_ndn = req_ndn;
5977 /* renumber siblings */
5978 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5979 ixold = strtol( iptr, NULL, 0 );
5980 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5981 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5982 count+ixold, 0, cfb->cb_use_ldif );
5986 ce->ce_entry->e_private=NULL;
5987 entry_free(ce->ce_entry);
5989 ldap_pvt_thread_pool_resume( &connection_pool );
5991 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5994 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5995 #endif /* SLAP_CONFIG_DELETE */
5996 send_ldap_result( op, rs );
6001 config_back_search( Operation *op, SlapReply *rs )
6004 CfEntryInfo *ce, *last;
6007 cfb = (CfBackInfo *)op->o_bd->be_private;
6009 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6012 rs->sr_matched = last->ce_entry->e_name.bv_val;
6013 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6016 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6017 ACL_SEARCH, NULL, &mask ))
6019 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6020 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6022 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6026 switch ( op->ors_scope ) {
6027 case LDAP_SCOPE_BASE:
6028 case LDAP_SCOPE_SUBTREE:
6029 rs->sr_err = config_send( op, rs, ce, 0 );
6032 case LDAP_SCOPE_ONELEVEL:
6033 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6034 rs->sr_err = config_send( op, rs, ce, 1 );
6043 send_ldap_result( op, rs );
6047 /* no-op, we never free entries */
6048 int config_entry_release(
6053 if ( !e->e_private ) {
6056 return LDAP_SUCCESS;
6059 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6061 int config_back_entry_get(
6065 AttributeDescription *at,
6070 CfEntryInfo *ce, *last;
6071 int rc = LDAP_NO_SUCH_OBJECT;
6073 cfb = (CfBackInfo *)op->o_bd->be_private;
6075 ce = config_find_base( cfb->cb_root, ndn, &last );
6077 *ent = ce->ce_entry;
6080 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6081 rc = LDAP_NO_SUCH_ATTRIBUTE;
6091 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6092 ConfigTable *ct, ConfigArgs *c )
6096 for (; at && *at; at++) {
6097 /* Skip the naming attr */
6098 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6100 for (i=0;ct[i].name;i++) {
6101 if (ct[i].ad == (*at)->sat_ad) {
6102 rc = config_get_vals(&ct[i], c);
6103 /* NOTE: tolerate that config_get_vals()
6104 * returns success with no values */
6105 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6106 if ( c->rvalue_nvals )
6107 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6110 slap_syntax_validate_func *validate =
6111 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6114 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6115 rc = ordered_value_validate( ct[i].ad,
6116 &c->rvalue_vals[j], LDAP_MOD_ADD );
6118 Debug( LDAP_DEBUG_ANY,
6119 "config_build_attrs: error %d on %s value #%d\n",
6120 rc, ct[i].ad->ad_cname.bv_val, j );
6126 rc = attr_merge_normalize(e, ct[i].ad,
6127 c->rvalue_vals, NULL);
6129 ber_bvarray_free( c->rvalue_nvals );
6130 ber_bvarray_free( c->rvalue_vals );
6132 Debug( LDAP_DEBUG_ANY,
6133 "config_build_attrs: error %d on %s\n",
6134 rc, ct[i].ad->ad_cname.bv_val, 0 );
6146 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6147 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6149 Entry *e = entry_alloc();
6150 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6152 struct berval ad_name;
6153 AttributeDescription *ad = NULL;
6156 const char *text = "";
6160 CfEntryInfo *ceprev = NULL;
6162 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6165 ce->ce_type = main->co_type;
6166 ce->ce_parent = parent;
6168 pdn = parent->ce_entry->e_nname;
6169 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6170 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6171 ceprev->ce_type <= ce->ce_type;
6172 ceprev = ceprev->ce_sibs );
6177 ce->ce_private = c->ca_private;
6181 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6182 ber_dupbv( &e->e_nname, &e->e_name );
6184 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6185 main->co_name, NULL );
6187 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6188 extra->co_name, NULL );
6189 ptr = strchr(rdn->bv_val, '=');
6190 ad_name.bv_val = rdn->bv_val;
6191 ad_name.bv_len = ptr - rdn->bv_val;
6192 rc = slap_bv2ad( &ad_name, &ad, &text );
6197 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6198 attr_merge_normalize_one(e, ad, &val, NULL );
6201 c->table = main->co_type;
6202 if ( oc->soc_required ) {
6203 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6204 if ( rc ) goto fail;
6207 if ( oc->soc_allowed ) {
6208 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6209 if ( rc ) goto fail;
6214 c->table = extra->co_type;
6215 if ( oc->soc_required ) {
6216 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6217 if ( rc ) goto fail;
6220 if ( oc->soc_allowed ) {
6221 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6222 if ( rc ) goto fail;
6226 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6227 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6228 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6229 if ( rc != LDAP_SUCCESS ) {
6231 Debug( LDAP_DEBUG_ANY,
6232 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6233 rdn->bv_val, text, 0);
6236 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6239 op->ora_modlist = NULL;
6240 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6241 if ( !op->o_noop ) {
6242 op->o_bd->be_add( op, rs );
6243 if ( ( rs->sr_err != LDAP_SUCCESS )
6244 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
6250 ce->ce_sibs = ceprev->ce_sibs;
6251 ceprev->ce_sibs = ce;
6252 } else if ( parent ) {
6253 ce->ce_sibs = parent->ce_kids;
6254 parent->ce_kids = ce;
6261 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6262 Operation *op, SlapReply *rs )
6265 ConfigFile *cf = c->ca_private;
6267 struct berval bv, rdn;
6269 for (; cf; cf=cf->c_sibs, c->depth++) {
6270 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6271 !cf->c_om_head && !cf->c_syn_head ) continue;
6272 c->value_dn.bv_val = c->log;
6273 LUTIL_SLASHPATH( cf->c_file.bv_val );
6274 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6279 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6281 ptr = strchr( bv.bv_val, '.' );
6283 bv.bv_len = ptr - bv.bv_val;
6284 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6285 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6286 /* FIXME: how can indicate error? */
6289 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6291 c->value_dn.bv_len += bv.bv_len;
6292 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6296 e = config_build_entry( op, rs, ceparent, c, &rdn,
6297 &CFOC_SCHEMA, NULL );
6300 } else if ( e && cf->c_kids ) {
6301 c->ca_private = cf->c_kids;
6302 config_build_schema_inc( c, e->e_private, op, rs );
6308 #ifdef SLAPD_MODULES
6311 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6312 Operation *op, SlapReply *rs )
6317 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6318 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6320 c->value_dn.bv_val = c->log;
6321 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6322 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6323 /* FIXME: how can indicate error? */
6327 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6336 config_check_schema(Operation *op, CfBackInfo *cfb)
6338 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6340 CfEntryInfo *ce, *last;
6343 /* If there's no root entry, we must be in the midst of converting */
6344 if ( !cfb->cb_root )
6347 /* Make sure the main schema entry exists */
6348 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6355 /* Make sure it's up to date */
6356 if ( cf_om_tail != om_sys_tail ) {
6357 a = attr_find( e->e_attrs, cfAd_om );
6359 if ( a->a_nvals != a->a_vals )
6360 ber_bvarray_free( a->a_nvals );
6361 ber_bvarray_free( a->a_vals );
6366 oidm_unparse( &bv, NULL, NULL, 1 );
6367 attr_merge_normalize( e, cfAd_om, bv, NULL );
6368 ber_bvarray_free( bv );
6369 cf_om_tail = om_sys_tail;
6371 if ( cf_at_tail != at_sys_tail ) {
6372 a = attr_find( e->e_attrs, cfAd_attr );
6374 if ( a->a_nvals != a->a_vals )
6375 ber_bvarray_free( a->a_nvals );
6376 ber_bvarray_free( a->a_vals );
6381 at_unparse( &bv, NULL, NULL, 1 );
6382 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6383 ber_bvarray_free( bv );
6384 cf_at_tail = at_sys_tail;
6386 if ( cf_oc_tail != oc_sys_tail ) {
6387 a = attr_find( e->e_attrs, cfAd_oc );
6389 if ( a->a_nvals != a->a_vals )
6390 ber_bvarray_free( a->a_nvals );
6391 ber_bvarray_free( a->a_vals );
6396 oc_unparse( &bv, NULL, NULL, 1 );
6397 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6398 ber_bvarray_free( bv );
6399 cf_oc_tail = oc_sys_tail;
6401 if ( cf_syn_tail != syn_sys_tail ) {
6402 a = attr_find( e->e_attrs, cfAd_syntax );
6404 if ( a->a_nvals != a->a_vals )
6405 ber_bvarray_free( a->a_nvals );
6406 ber_bvarray_free( a->a_vals );
6411 syn_unparse( &bv, NULL, NULL, 1 );
6412 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6413 ber_bvarray_free( bv );
6414 cf_syn_tail = syn_sys_tail;
6417 SlapReply rs = {REP_RESULT};
6418 c.ca_private = NULL;
6419 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6420 &CFOC_SCHEMA, NULL );
6425 ce->ce_private = cfb->cb_config;
6426 cf_at_tail = at_sys_tail;
6427 cf_oc_tail = oc_sys_tail;
6428 cf_om_tail = om_sys_tail;
6429 cf_syn_tail = syn_sys_tail;
6434 static const char *defacl[] = {
6435 NULL, "to", "*", "by", "*", "none", NULL
6439 config_back_db_open( BackendDB *be, ConfigReply *cr )
6441 CfBackInfo *cfb = be->be_private;
6444 CfEntryInfo *ce, *ceparent;
6448 Connection conn = {0};
6449 OperationBuffer opbuf;
6451 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6452 SlapReply rs = {REP_RESULT};
6453 void *thrctx = NULL;
6455 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6457 /* If we have no explicitly configured ACLs, don't just use
6458 * the global ACLs. Explicitly deny access to everything.
6460 if ( !be->be_acl ) {
6461 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6464 thrctx = ldap_pvt_thread_pool_context();
6465 connection_fake_init( &conn, &opbuf, thrctx );
6468 op->o_tag = LDAP_REQ_ADD;
6469 op->o_callback = &cb;
6470 op->o_bd = &cfb->cb_db;
6471 op->o_dn = op->o_bd->be_rootdn;
6472 op->o_ndn = op->o_bd->be_rootndn;
6474 if ( !cfb->cb_use_ldif ) {
6478 /* If we read the config from back-ldif, do some quick sanity checks */
6479 if ( cfb->cb_got_ldif ) {
6480 return config_check_schema( op, cfb );
6483 /* create root of tree */
6485 c.ca_private = cfb->cb_config;
6487 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6497 #ifdef SLAPD_MODULES
6498 /* Create Module nodes... */
6499 if ( modpaths.mp_loads ) {
6500 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6506 /* Create schema nodes... cn=schema will contain the hardcoded core
6507 * schema, read-only. Child objects will contain runtime loaded schema
6511 c.ca_private = NULL;
6512 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6517 ce->ce_private = cfb->cb_config;
6518 cf_at_tail = at_sys_tail;
6519 cf_oc_tail = oc_sys_tail;
6520 cf_om_tail = om_sys_tail;
6521 cf_syn_tail = syn_sys_tail;
6523 /* Create schema nodes for included schema... */
6524 if ( cfb->cb_config->c_kids ) {
6526 c.ca_private = cfb->cb_config->c_kids;
6527 if (config_build_schema_inc( &c, ce, op, &rs )) {
6532 /* Create backend nodes. Skip if they don't provide a cf_table.
6533 * There usually aren't any of these.
6537 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6538 if (!bi->bi_cf_ocs) {
6539 /* If it only supports the old config mech, complain. */
6540 if ( bi->bi_config ) {
6541 Debug( LDAP_DEBUG_ANY,
6542 "WARNING: No dynamic config support for backend %s.\n",
6543 bi->bi_type, 0, 0 );
6548 if (!bi->bi_private) continue;
6551 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6552 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6553 if ( rdn.bv_len >= sizeof( c.log ) ) {
6554 /* FIXME: holler ... */ ;
6557 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6564 /* Create database nodes... */
6565 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6566 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6567 for ( i = -1, be = frontendDB ; be;
6568 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6569 slap_overinfo *oi = NULL;
6571 if ( overlay_is_over( be )) {
6572 oi = be->bd_info->bi_private;
6578 /* If this backend supports the old config mechanism, but not
6579 * the new mech, complain.
6581 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6582 Debug( LDAP_DEBUG_ANY,
6583 "WARNING: No dynamic config support for database %s.\n",
6584 bi->bi_type, 0, 0 );
6588 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6589 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6591 if ( rdn.bv_len >= sizeof( c.log ) ) {
6592 /* FIXME: holler ... */ ;
6596 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6602 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6603 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6604 /* Iterate through overlays */
6609 voidList *vl, *v0 = NULL;
6611 /* overlays are in LIFO order, must reverse stack */
6612 for (on=oi->oi_list; on; on=on->on_next) {
6613 vl = ch_malloc( sizeof( voidList ));
6618 for (j=0; vl; j++,vl=v0) {
6622 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6623 Debug( LDAP_DEBUG_ANY,
6624 "WARNING: No dynamic config support for overlay %s.\n",
6625 on->on_bi.bi_type, 0, 0 );
6629 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6630 "%s=" SLAP_X_ORDERED_FMT "%s",
6631 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6632 if ( rdn.bv_len >= sizeof( c.log ) ) {
6633 /* FIXME: holler ... */ ;
6637 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6638 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6642 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6643 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6648 ldap_pvt_thread_pool_context_reset( thrctx );
6650 if ( unsupp && cfb->cb_use_ldif ) {
6651 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6652 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6659 cfb_free_cffile( ConfigFile *cf )
6663 for (; cf; cf=next) {
6666 cfb_free_cffile( cf->c_kids );
6667 ch_free( cf->c_file.bv_val );
6668 ber_bvarray_free( cf->c_dseFiles );
6674 cfb_free_entries( CfEntryInfo *ce )
6678 for (; ce; ce=next) {
6681 cfb_free_entries( ce->ce_kids );
6682 ce->ce_entry->e_private = NULL;
6683 entry_free( ce->ce_entry );
6689 config_back_db_close( BackendDB *be, ConfigReply *cr )
6691 CfBackInfo *cfb = be->be_private;
6693 cfb_free_entries( cfb->cb_root );
6694 cfb->cb_root = NULL;
6696 if ( cfb->cb_db.bd_info ) {
6697 backend_shutdown( &cfb->cb_db );
6704 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6706 CfBackInfo *cfb = be->be_private;
6708 cfb_free_cffile( cfb->cb_config );
6710 ch_free( cfdir.bv_val );
6712 avl_free( CfOcTree, NULL );
6714 if ( cfb->cb_db.bd_info ) {
6715 cfb->cb_db.be_suffix = NULL;
6716 cfb->cb_db.be_nsuffix = NULL;
6717 BER_BVZERO( &cfb->cb_db.be_rootdn );
6718 BER_BVZERO( &cfb->cb_db.be_rootndn );
6720 backend_destroy_one( &cfb->cb_db, 0 );
6729 config_back_db_init( BackendDB *be, ConfigReply* cr )
6735 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6736 cfn = cfb->cb_config;
6737 be->be_private = cfb;
6739 ber_dupbv( &be->be_rootdn, &config_rdn );
6740 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6741 ber_dupbv( &dn, &be->be_rootdn );
6742 ber_bvarray_add( &be->be_suffix, &dn );
6743 ber_dupbv( &dn, &be->be_rootdn );
6744 ber_bvarray_add( &be->be_nsuffix, &dn );
6746 /* Hide from namingContexts */
6747 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6749 /* Check ACLs on content of Adds by default */
6750 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6756 config_back_destroy( BackendInfo *bi )
6758 ldif_must_b64_encode_release();
6763 config_tool_entry_open( BackendDB *be, int mode )
6765 CfBackInfo *cfb = be->be_private;
6766 BackendInfo *bi = cfb->cb_db.bd_info;
6768 if ( bi && bi->bi_tool_entry_open )
6769 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6776 config_tool_entry_close( BackendDB *be )
6778 CfBackInfo *cfb = be->be_private;
6779 BackendInfo *bi = cfb->cb_db.bd_info;
6781 if ( bi && bi->bi_tool_entry_close )
6782 return bi->bi_tool_entry_close( &cfb->cb_db );
6788 config_tool_entry_first( BackendDB *be )
6790 CfBackInfo *cfb = be->be_private;
6791 BackendInfo *bi = cfb->cb_db.bd_info;
6793 if ( bi && bi->bi_tool_entry_first ) {
6794 return bi->bi_tool_entry_first( &cfb->cb_db );
6796 if ( bi && bi->bi_tool_entry_first_x ) {
6797 return bi->bi_tool_entry_first_x( &cfb->cb_db,
6798 NULL, LDAP_SCOPE_DEFAULT, NULL );
6804 config_tool_entry_first_x(
6806 struct berval *base,
6810 CfBackInfo *cfb = be->be_private;
6811 BackendInfo *bi = cfb->cb_db.bd_info;
6813 if ( bi && bi->bi_tool_entry_first_x ) {
6814 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
6820 config_tool_entry_next( BackendDB *be )
6822 CfBackInfo *cfb = be->be_private;
6823 BackendInfo *bi = cfb->cb_db.bd_info;
6825 if ( bi && bi->bi_tool_entry_next )
6826 return bi->bi_tool_entry_next( &cfb->cb_db );
6832 config_tool_entry_get( BackendDB *be, ID id )
6834 CfBackInfo *cfb = be->be_private;
6835 BackendInfo *bi = cfb->cb_db.bd_info;
6837 if ( bi && bi->bi_tool_entry_get )
6838 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6843 static int entry_put_got_frontend=0;
6844 static int entry_put_got_config=0;
6846 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6848 CfBackInfo *cfb = be->be_private;
6849 BackendInfo *bi = cfb->cb_db.bd_info;
6851 struct berval rdn, vals[ 2 ];
6853 OperationBuffer opbuf;
6855 Connection conn = {0};
6856 Operation *op = NULL;
6860 /* Create entry for frontend database if it does not exist already */
6861 if ( !entry_put_got_frontend ) {
6862 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6863 STRLENOF( "olcDatabase" ))) {
6864 if ( strncmp( e->e_nname.bv_val +
6865 STRLENOF( "olcDatabase" ), "={-1}frontend",
6866 STRLENOF( "={-1}frontend" )) &&
6867 strncmp( e->e_nname.bv_val +
6868 STRLENOF( "olcDatabase" ), "=frontend",
6869 STRLENOF( "=frontend" ))) {
6871 vals[1].bv_val = NULL;
6872 memset( &ca, 0, sizeof(ConfigArgs));
6874 ca.bi = frontendDB->bd_info;
6875 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6876 rdn.bv_val = ca.log;
6877 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6878 "%s=" SLAP_X_ORDERED_FMT "%s",
6879 cfAd_database->ad_cname.bv_val, -1,
6881 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6882 &CFOC_DATABASE, ca.be->be_cf_ocs );
6883 thrctx = ldap_pvt_thread_pool_context();
6884 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6886 op->o_bd = &cfb->cb_db;
6887 op->o_tag = LDAP_REQ_ADD;
6889 op->o_dn = be->be_rootdn;
6890 op->o_ndn = be->be_rootndn;
6891 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6892 if ( rc != LDAP_SUCCESS ) {
6893 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6894 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6898 if ( ce && bi && bi->bi_tool_entry_put &&
6899 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6900 entry_put_got_frontend++;
6902 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6903 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6907 entry_put_got_frontend++;
6912 /* Create entry for config database if it does not exist already */
6913 if ( !entry_put_got_config && !isFrontend ) {
6914 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6915 STRLENOF( "olcDatabase" ))) {
6916 if ( strncmp( e->e_nname.bv_val +
6917 STRLENOF( "olcDatabase" ), "={0}config",
6918 STRLENOF( "={0}config" )) &&
6919 strncmp( e->e_nname.bv_val +
6920 STRLENOF( "olcDatabase" ), "=config",
6921 STRLENOF( "=config" )) ) {
6923 vals[1].bv_val = NULL;
6924 memset( &ca, 0, sizeof(ConfigArgs));
6925 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6926 ca.bi = ca.be->bd_info;
6927 rdn.bv_val = ca.log;
6928 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6929 "%s=" SLAP_X_ORDERED_FMT "%s",
6930 cfAd_database->ad_cname.bv_val, 0,
6932 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6935 thrctx = ldap_pvt_thread_pool_context();
6936 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6938 op->o_bd = &cfb->cb_db;
6939 op->o_tag = LDAP_REQ_ADD;
6940 op->o_dn = be->be_rootdn;
6941 op->o_ndn = be->be_rootndn;
6944 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6945 if ( rc != LDAP_SUCCESS ) {
6946 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6947 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6950 if (ce && bi && bi->bi_tool_entry_put &&
6951 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6952 entry_put_got_config++;
6954 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6955 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6959 entry_put_got_config++;
6963 if ( bi && bi->bi_tool_entry_put &&
6964 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6965 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6972 AttributeDescription **desc;
6974 { "attribute", &cfAd_attr },
6975 { "backend", &cfAd_backend },
6976 { "database", &cfAd_database },
6977 { "include", &cfAd_include },
6978 { "ldapsyntax", &cfAd_syntax },
6979 { "objectclass", &cfAd_oc },
6980 { "objectidentifier", &cfAd_om },
6981 { "overlay", &cfAd_overlay },
6986 * add / delete: all types that may be added or deleted must use an
6987 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6988 * should automatically renumber the index of any siblings as needed,
6989 * so that no gaps in the numbering sequence exist after the add/delete
6991 * What can be added:
6993 * backend objects for backend-specific config directives
6997 * delete: probably no support this time around.
6999 * modrdn: generally not done. Will be invoked automatically by add/
7000 * delete to update numbering sequence. Perform as an explicit operation
7001 * so that the renumbering effect may be replicated. Subtree rename must
7002 * be supported, since renumbering a database will affect all its child
7005 * modify: must be fully supported.
7009 config_back_initialize( BackendInfo *bi )
7011 ConfigTable *ct = config_back_cf_table;
7015 AttributeDescription *ad = NULL;
7017 static char *controls[] = {
7018 LDAP_CONTROL_MANAGEDSAIT,
7022 /* Make sure we don't exceed the bits reserved for userland */
7023 config_check_userland( CFG_LAST );
7025 bi->bi_controls = controls;
7030 bi->bi_destroy = config_back_destroy;
7032 bi->bi_db_init = config_back_db_init;
7033 bi->bi_db_config = 0;
7034 bi->bi_db_open = config_back_db_open;
7035 bi->bi_db_close = config_back_db_close;
7036 bi->bi_db_destroy = config_back_db_destroy;
7038 bi->bi_op_bind = config_back_bind;
7039 bi->bi_op_unbind = 0;
7040 bi->bi_op_search = config_back_search;
7041 bi->bi_op_compare = 0;
7042 bi->bi_op_modify = config_back_modify;
7043 bi->bi_op_modrdn = config_back_modrdn;
7044 bi->bi_op_add = config_back_add;
7045 bi->bi_op_delete = config_back_delete;
7046 bi->bi_op_abandon = 0;
7048 bi->bi_extended = 0;
7050 bi->bi_chk_referrals = 0;
7052 bi->bi_access_allowed = slap_access_allowed;
7054 bi->bi_connection_init = 0;
7055 bi->bi_connection_destroy = 0;
7057 bi->bi_entry_release_rw = config_entry_release;
7058 bi->bi_entry_get_rw = config_back_entry_get;
7060 bi->bi_tool_entry_open = config_tool_entry_open;
7061 bi->bi_tool_entry_close = config_tool_entry_close;
7062 bi->bi_tool_entry_first = config_tool_entry_first;
7063 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7064 bi->bi_tool_entry_next = config_tool_entry_next;
7065 bi->bi_tool_entry_get = config_tool_entry_get;
7066 bi->bi_tool_entry_put = config_tool_entry_put;
7069 argv[ 0 ] = "slapd";
7075 for (i=0; OidMacros[i].name; i++ ) {
7076 argv[1] = OidMacros[i].name;
7077 argv[2] = OidMacros[i].oid;
7078 parse_oidm( &ca, 0, NULL );
7081 bi->bi_cf_ocs = cf_ocs;
7083 i = config_register_schema( ct, cf_ocs );
7086 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7089 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7090 * basically, we don't care if it fails */
7091 i = slap_str2ad( "olcRootPW", &ad, &text );
7093 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7094 "warning, unable to get \"olcRootPW\" "
7095 "attribute description: %d: %s\n",
7098 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7099 ad->ad_type->sat_oid );
7102 /* set up the notable AttributeDescriptions */
7104 for (;ct->name;ct++) {
7105 if (strcmp(ct->name, ads[i].name)) continue;
7106 *ads[i].desc = ct->ad;
7108 if (!ads[i].name) break;