1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2011 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,
203 static OidRec OidMacros[] = {
204 /* OpenLDAProot:1.12.2 */
205 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
206 { "OLcfgAt", "OLcfg:3" },
207 { "OLcfgGlAt", "OLcfgAt:0" },
208 { "OLcfgBkAt", "OLcfgAt:1" },
209 { "OLcfgDbAt", "OLcfgAt:2" },
210 { "OLcfgOvAt", "OLcfgAt:3" },
211 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
212 { "OLcfgOc", "OLcfg:4" },
213 { "OLcfgGlOc", "OLcfgOc:0" },
214 { "OLcfgBkOc", "OLcfgOc:1" },
215 { "OLcfgDbOc", "OLcfgOc:2" },
216 { "OLcfgOvOc", "OLcfgOc:3" },
217 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
219 /* Syntaxes. We should just start using the standard names and
220 * document that they are predefined and available for users
221 * to reference in their own schema. Defining schema without
222 * OID macros is for masochists...
224 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
225 { "OMsBoolean", "OMsyn:7" },
226 { "OMsDN", "OMsyn:12" },
227 { "OMsDirectoryString", "OMsyn:15" },
228 { "OMsIA5String", "OMsyn:26" },
229 { "OMsInteger", "OMsyn:27" },
230 { "OMsOID", "OMsyn:38" },
231 { "OMsOctetString", "OMsyn:40" },
236 * Backend/Database registry
238 * OLcfg{Bk|Db}{Oc|At}:0 -> common
239 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
240 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
241 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
242 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
243 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
244 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
245 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
246 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
252 * OLcfgOv{Oc|At}:1 -> syncprov
253 * OLcfgOv{Oc|At}:2 -> pcache
254 * OLcfgOv{Oc|At}:3 -> chain
255 * OLcfgOv{Oc|At}:4 -> accesslog
256 * OLcfgOv{Oc|At}:5 -> valsort
257 * OLcfgOv{Oc|At}:7 -> distproc
258 * OLcfgOv{Oc|At}:8 -> dynlist
259 * OLcfgOv{Oc|At}:9 -> dds
260 * OLcfgOv{Oc|At}:10 -> unique
261 * OLcfgOv{Oc|At}:11 -> refint
262 * OLcfgOv{Oc|At}:12 -> ppolicy
263 * OLcfgOv{Oc|At}:13 -> constraint
264 * OLcfgOv{Oc|At}:14 -> translucent
265 * OLcfgOv{Oc|At}:15 -> auditlog
266 * OLcfgOv{Oc|At}:16 -> rwm
267 * OLcfgOv{Oc|At}:17 -> dyngroup
268 * OLcfgOv{Oc|At}:18 -> memberof
269 * OLcfgOv{Oc|At}:19 -> collect
270 * OLcfgOv{Oc|At}:20 -> retcode
271 * OLcfgOv{Oc|At}:21 -> sssvlv
274 /* alphabetical ordering */
276 static ConfigTable config_back_cf_table[] = {
277 /* This attr is read-only */
278 { "", "", 0, 0, 0, ARG_MAGIC,
279 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
280 "DESC 'File for slapd configuration directives' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
283 { "", "", 0, 0, 0, ARG_MAGIC,
284 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
285 "DESC 'Directory for slapd configuration backend' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
288 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
289 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
290 "DESC 'Access Control List' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
293 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
294 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
295 "DESC 'Check ACLs against content of Add ops' "
296 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
297 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
298 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
299 "DESC 'Allowed set of deprecated features' "
300 "EQUALITY caseIgnoreMatch "
301 "SYNTAX OMsDirectoryString )", NULL, NULL },
302 { "argsfile", "file", 2, 2, 0, ARG_STRING,
303 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
304 "DESC 'File for slapd command line options' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
307 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
308 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
309 "EQUALITY caseIgnoreMatch "
310 "SYNTAX OMsDirectoryString )", NULL, NULL },
311 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
312 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
313 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
314 "DESC 'OpenLDAP attributeTypes' "
315 "EQUALITY caseIgnoreMatch "
316 "SUBSTR caseIgnoreSubstringsMatch "
317 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
319 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
320 #ifdef SLAP_AUTH_REWRITE
321 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
325 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
326 "EQUALITY caseIgnoreMatch "
327 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
328 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
329 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
330 "EQUALITY caseIgnoreMatch "
331 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
332 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
333 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
334 "EQUALITY caseIgnoreMatch "
335 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
336 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
337 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
338 "DESC 'A type of backend' "
339 "EQUALITY caseIgnoreMatch "
340 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
342 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
343 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
344 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
345 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
346 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
347 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
348 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
349 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
350 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
351 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
352 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
353 "DESC 'The backend type for a database instance' "
354 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
355 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
356 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
357 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
358 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
359 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
360 "EQUALITY caseIgnoreMatch "
361 "SYNTAX OMsDirectoryString )", NULL, NULL },
362 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
363 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
364 "DESC 'OpenLDAP DIT content rules' "
365 "EQUALITY caseIgnoreMatch "
366 "SUBSTR caseIgnoreSubstringsMatch "
367 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
369 { "gentlehup", "on|off", 2, 2, 0,
371 ARG_ON_OFF, &global_gentlehup,
375 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
376 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
377 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
378 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
379 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
380 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
381 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
382 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
383 { "include", "file", 2, 2, 0, ARG_MAGIC,
384 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
385 "SUP labeledURI )", NULL, NULL },
386 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
387 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
388 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
389 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
390 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
391 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
392 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
393 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
394 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
395 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
396 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
397 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
398 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
399 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
402 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
403 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
404 { "ldapsyntax", "syntax", 2, 0, 0,
405 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
406 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
407 "DESC 'OpenLDAP ldapSyntax' "
408 "EQUALITY caseIgnoreMatch "
409 "SUBSTR caseIgnoreSubstringsMatch "
410 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
412 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
413 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
414 "EQUALITY caseIgnoreMatch "
415 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
416 { "listener-threads", "count", 2, 0, 0,
420 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
422 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
423 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
424 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
425 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
426 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
427 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
428 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
429 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
430 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
431 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
432 "EQUALITY caseIgnoreMatch "
433 "SYNTAX OMsDirectoryString )", NULL, NULL },
434 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
435 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
436 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
437 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
438 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
439 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
440 { "moduleload", "file", 2, 0, 0,
442 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
446 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
447 "EQUALITY caseIgnoreMatch "
448 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
449 { "modulepath", "path", 2, 2, 0,
451 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
455 "( OLcfgGlAt:31 NAME 'olcModulePath' "
456 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
457 { "monitoring", "TRUE|FALSE", 2, 2, 0,
458 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
459 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
460 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
461 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
462 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
463 "DESC 'OpenLDAP object classes' "
464 "EQUALITY caseIgnoreMatch "
465 "SUBSTR caseIgnoreSubstringsMatch "
466 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
468 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
469 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
470 "EQUALITY caseIgnoreMatch "
471 "SUBSTR caseIgnoreSubstringsMatch "
472 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
473 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
474 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
475 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
476 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
477 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
478 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
479 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
480 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
481 "EQUALITY caseIgnoreMatch "
482 "SYNTAX OMsDirectoryString )", NULL, NULL },
483 { "pidfile", "file", 2, 2, 0, ARG_STRING,
484 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
485 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
486 { "plugin", NULL, 0, 0, 0,
488 ARG_MAGIC|CFG_PLUGIN, &config_generic,
492 "( OLcfgGlAt:38 NAME 'olcPlugin' "
493 "EQUALITY caseIgnoreMatch "
494 "SYNTAX OMsDirectoryString )", NULL, NULL },
495 { "pluginlog", "filename", 2, 2, 0,
497 ARG_STRING, &slapi_log_file,
501 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
502 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
503 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
504 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
505 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
506 { "referral", "url", 2, 2, 0, ARG_MAGIC,
507 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
508 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
509 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
510 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
511 "EQUALITY caseIgnoreMatch "
512 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
513 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
514 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
515 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
516 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
517 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
518 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
519 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
520 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
521 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
522 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
523 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
526 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
527 "EQUALITY caseIgnoreMatch "
528 "SYNTAX OMsDirectoryString )", NULL, NULL },
529 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
530 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
531 "EQUALITY caseIgnoreMatch "
532 "SYNTAX OMsDirectoryString )", NULL, NULL },
533 { "reverse-lookup", "on|off", 2, 2, 0,
534 #ifdef SLAPD_RLOOKUPS
535 ARG_ON_OFF, &use_reverse_lookup,
539 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
540 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
541 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
542 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
543 "EQUALITY distinguishedNameMatch "
544 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
545 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
546 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
547 "EQUALITY caseIgnoreMatch "
548 "SYNTAX OMsDirectoryString )", NULL, NULL },
549 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
550 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
551 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
552 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
553 &config_generic, NULL, NULL, NULL },
554 { "sasl-auxprops", NULL, 2, 0, 0,
555 #ifdef HAVE_CYRUS_SASL
556 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
560 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
561 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
562 { "sasl-host", "host", 2, 2, 0,
563 #ifdef HAVE_CYRUS_SASL
564 ARG_STRING|ARG_UNIQUE, &sasl_host,
568 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
569 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
570 { "sasl-realm", "realm", 2, 2, 0,
571 #ifdef HAVE_CYRUS_SASL
572 ARG_STRING|ARG_UNIQUE, &global_realm,
576 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
577 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
578 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
579 &config_generic, NULL, NULL, NULL },
580 { "sasl-secprops", "properties", 2, 2, 0,
581 #ifdef HAVE_CYRUS_SASL
582 ARG_MAGIC|CFG_SASLSECP, &config_generic,
586 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
587 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
588 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
589 &config_generic, NULL, NULL, NULL },
590 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
591 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
592 "EQUALITY distinguishedNameMatch "
593 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
594 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
595 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
596 "EQUALITY caseIgnoreMatch "
597 "SYNTAX OMsDirectoryString )", NULL, NULL },
598 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
599 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
600 "EQUALITY caseIgnoreMatch "
601 "SYNTAX OMsDirectoryString )", NULL, NULL },
602 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
603 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
604 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
605 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
606 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
607 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
608 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
609 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
610 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
611 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
612 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
613 "DESC 'Attributes whose values will always be sorted' "
614 "EQUALITY caseIgnoreMatch "
615 "SYNTAX OMsDirectoryString )", NULL, NULL },
616 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
617 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
618 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
619 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
620 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
621 "EQUALITY distinguishedNameMatch "
622 "SYNTAX OMsDN )", NULL, NULL },
623 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
624 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
625 "DESC 'Store sync context in a subentry' "
626 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
627 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
628 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
629 "EQUALITY caseIgnoreMatch "
630 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
631 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
632 #ifndef LDAP_TCP_BUFFER
634 #else /* LDAP_TCP_BUFFER */
635 ARG_MAGIC, &config_tcp_buffer,
636 #endif /* LDAP_TCP_BUFFER */
637 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
638 "DESC 'Custom TCP buffer size' "
639 "SYNTAX OMsDirectoryString )", NULL, NULL },
640 { "threads", "count", 2, 2, 0,
644 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
646 "( OLcfgGlAt:66 NAME 'olcThreads' "
647 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
648 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
649 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
650 "SYNTAX OMsDirectoryString )", NULL, NULL },
651 { "TLSCACertificateFile", NULL, 0, 0, 0,
653 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
657 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
658 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
659 { "TLSCACertificatePath", NULL, 0, 0, 0,
661 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
665 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
666 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
667 { "TLSCertificateFile", NULL, 0, 0, 0,
669 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
673 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
674 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
675 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
677 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
681 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
682 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
683 { "TLSCipherSuite", NULL, 0, 0, 0,
685 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
689 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
690 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
691 { "TLSCRLCheck", NULL, 0, 0, 0,
692 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
693 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
697 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
698 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
699 { "TLSCRLFile", NULL, 0, 0, 0,
700 #if defined(HAVE_GNUTLS)
701 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
705 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
706 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
707 { "TLSRandFile", NULL, 0, 0, 0,
709 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
713 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
714 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
715 { "TLSVerifyClient", NULL, 0, 0, 0,
717 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
721 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
722 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
723 { "TLSDHParamFile", NULL, 0, 0, 0,
725 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
729 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
730 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
731 { "TLSProtocolMin", NULL, 0, 0, 0,
733 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
737 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
738 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
739 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
740 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
741 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
742 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
743 NULL, NULL, NULL, NULL },
744 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
745 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
746 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
747 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
748 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
749 "EQUALITY caseIgnoreMatch "
750 "SUP labeledURI )", NULL, NULL },
751 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
752 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
753 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
754 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
755 NULL, NULL, NULL, NULL }
758 /* Need to no-op this keyword for dynamic config */
759 ConfigTable olcDatabaseDummy[] = {
760 { "", "", 0, 0, 0, ARG_IGNORED,
761 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
762 "DESC 'The backend type for a database instance' "
763 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
764 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
767 /* Routines to check if a child can be added to this type */
768 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
769 cfAddBackend, cfAddModule, cfAddOverlay;
771 /* NOTE: be careful when defining array members
772 * that can be conditionally compiled */
773 #define CFOC_GLOBAL cf_ocs[1]
774 #define CFOC_SCHEMA cf_ocs[2]
775 #define CFOC_BACKEND cf_ocs[3]
776 #define CFOC_DATABASE cf_ocs[4]
777 #define CFOC_OVERLAY cf_ocs[5]
778 #define CFOC_INCLUDE cf_ocs[6]
779 #define CFOC_FRONTEND cf_ocs[7]
781 #define CFOC_MODULE cf_ocs[8]
782 #endif /* SLAPD_MODULES */
784 static ConfigOCs cf_ocs[] = {
787 "DESC 'OpenLDAP configuration object' "
788 "ABSTRACT SUP top )", Cft_Abstract, NULL },
791 "DESC 'OpenLDAP Global configuration options' "
792 "SUP olcConfig STRUCTURAL "
793 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
794 "olcAttributeOptions $ olcAuthIDRewrite $ "
795 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
796 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
797 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
798 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
799 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
800 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
801 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
802 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
803 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
805 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
806 "olcSecurity $ olcServerID $ olcSizeLimit $ "
807 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
809 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
810 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
811 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
812 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
813 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
814 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
815 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
817 "NAME 'olcSchemaConfig' "
818 "DESC 'OpenLDAP schema object' "
819 "SUP olcConfig STRUCTURAL "
820 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
821 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
822 Cft_Schema, NULL, cfAddSchema },
824 "NAME 'olcBackendConfig' "
825 "DESC 'OpenLDAP Backend-specific options' "
826 "SUP olcConfig STRUCTURAL "
827 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
829 "NAME 'olcDatabaseConfig' "
830 "DESC 'OpenLDAP Database-specific options' "
831 "SUP olcConfig STRUCTURAL "
833 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
834 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
835 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
836 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
837 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
838 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
839 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
841 Cft_Database, NULL, cfAddDatabase },
843 "NAME 'olcOverlayConfig' "
844 "DESC 'OpenLDAP Overlay-specific options' "
845 "SUP olcConfig STRUCTURAL "
846 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
848 "NAME 'olcIncludeFile' "
849 "DESC 'OpenLDAP configuration include file' "
850 "SUP olcConfig STRUCTURAL "
852 "MAY ( cn $ olcRootDSE ) )",
853 /* Used to be Cft_Include, that def has been removed */
854 Cft_Abstract, NULL, cfAddInclude },
855 /* This should be STRUCTURAL like all the other database classes, but
856 * that would mean inheriting all of the olcDatabaseConfig attributes,
857 * which causes them to be merged twice in config_build_entry.
860 "NAME 'olcFrontendConfig' "
861 "DESC 'OpenLDAP frontend configuration' "
863 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
864 Cft_Database, NULL, NULL },
867 "NAME 'olcModuleList' "
868 "DESC 'OpenLDAP dynamic module info' "
869 "SUP olcConfig STRUCTURAL "
870 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
871 Cft_Module, NULL, cfAddModule },
876 typedef struct ServerID {
877 struct ServerID *si_next;
878 struct berval si_url;
882 static ServerID *sid_list;
884 typedef struct voidList {
885 struct voidList *vl_next;
889 typedef struct ADlist {
890 struct ADlist *al_next;
891 AttributeDescription *al_desc;
894 static ADlist *sortVals;
897 config_generic(ConfigArgs *c) {
900 if ( c->op == SLAP_CONFIG_EMIT ) {
904 c->value_int = ldap_pvt_thread_get_concurrency();
907 c->value_int = connection_pool_max;
910 c->value_int = slap_tool_thread_max;
913 c->value_uint = slapd_daemon_threads;
917 c->value_string = ch_strdup( passwd_salt );
922 if ( c->be->be_limits ) {
926 for ( i=0; c->be->be_limits[i]; i++ ) {
927 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
928 if ( bv.bv_len >= sizeof( buf ) ) {
929 ber_bvarray_free_x( c->rvalue_vals, NULL );
930 c->rvalue_vals = NULL;
934 bv.bv_val = buf + bv.bv_len;
935 limits_unparse( c->be->be_limits[i], &bv,
936 sizeof( buf ) - ( bv.bv_val - buf ) );
937 bv.bv_len += bv.bv_val - buf;
939 value_add_one( &c->rvalue_vals, &bv );
942 if ( !c->rvalue_vals ) rc = 1;
945 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
948 c->value_string = ch_strdup( slap_sasl_getpolicy());
951 slap_sasl_regexp_unparse( &c->rvalue_vals );
952 if ( !c->rvalue_vals ) rc = 1;
954 #ifdef HAVE_CYRUS_SASL
956 struct berval bv = BER_BVNULL;
957 slap_sasl_secprops_unparse( &bv );
958 if ( !BER_BVISNULL( &bv )) {
959 ber_bvarray_add( &c->rvalue_vals, &bv );
967 c->value_int = c->be->be_max_deref_depth;
970 if ( SLAP_DBHIDDEN( c->be )) {
977 ConfigFile *cf = c->ca_private;
979 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
980 else if ( cf->c_om_head )
981 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
983 if ( !c->rvalue_vals )
988 ad_unparse_options( &c->rvalue_vals );
991 ConfigFile *cf = c->ca_private;
993 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
994 else if ( cf->c_oc_head )
995 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
997 if ( !c->rvalue_vals )
1002 ConfigFile *cf = c->ca_private;
1004 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1005 else if ( cf->c_at_head )
1006 at_unparse( &c->rvalue_vals, cf->c_at_head,
1008 if ( !c->rvalue_vals )
1013 ConfigFile *cf = c->ca_private;
1015 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1016 else if ( cf->c_syn_head )
1017 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1018 cf->c_syn_tail, 0 );
1019 if ( !c->rvalue_vals )
1024 ConfigFile *cf = c->ca_private;
1026 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1027 else if ( cf->c_cr_head )
1028 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1030 if ( !c->rvalue_vals )
1037 char *src, *dst, ibuf[11];
1038 struct berval bv, abv;
1039 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1040 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1041 if ( abv.bv_len >= sizeof( ibuf ) ) {
1042 ber_bvarray_free_x( c->rvalue_vals, NULL );
1043 c->rvalue_vals = NULL;
1047 acl_unparse( a, &bv );
1048 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1049 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1050 /* Turn TAB / EOL into plain space */
1051 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1052 if (isspace((unsigned char)*src)) *dst++ = ' ';
1056 if (dst[-1] == ' ') {
1060 abv.bv_len = dst - abv.bv_val;
1061 ber_bvarray_add( &c->rvalue_vals, &abv );
1067 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1070 ConfigFile *cf = c->ca_private;
1071 if ( cf->c_dseFiles ) {
1072 value_add( &c->rvalue_vals, cf->c_dseFiles );
1083 for ( si = sid_list; si; si=si->si_next ) {
1084 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1085 if ( !BER_BVISEMPTY( &si->si_url )) {
1086 bv.bv_len = si->si_url.bv_len + 6;
1087 bv.bv_val = ch_malloc( bv.bv_len );
1088 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1089 si->si_url.bv_val );
1090 ber_bvarray_add( &c->rvalue_vals, &bv );
1094 bv.bv_len = sprintf( buf, "%d", si->si_num );
1095 value_add_one( &c->rvalue_vals, &bv );
1104 c->value_string = ch_strdup( logfileName );
1109 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1111 case CFG_SYNC_SUBENTRY:
1112 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1114 case CFG_MIRRORMODE:
1115 if ( SLAP_SHADOW(c->be))
1116 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1120 case CFG_MONITORING:
1121 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1123 case CFG_SSTR_IF_MAX:
1124 c->value_uint = index_substr_if_maxlen;
1126 case CFG_SSTR_IF_MIN:
1127 c->value_uint = index_substr_if_minlen;
1130 c->value_int = index_intlen;
1132 case CFG_SORTVALS: {
1135 for ( sv = sortVals; sv; sv = sv->al_next ) {
1136 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1140 #ifdef SLAPD_MODULES
1142 ModPaths *mp = c->ca_private;
1145 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1148 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1149 SLAP_X_ORDERED_FMT "%s", i,
1150 mp->mp_loads[i].bv_val );
1151 if ( bv.bv_len >= sizeof( c->log ) ) {
1152 ber_bvarray_free_x( c->rvalue_vals, NULL );
1153 c->rvalue_vals = NULL;
1156 value_add_one( &c->rvalue_vals, &bv );
1160 rc = c->rvalue_vals ? 0 : 1;
1164 ModPaths *mp = c->ca_private;
1165 if ( !BER_BVISNULL( &mp->mp_path ))
1166 value_add_one( &c->rvalue_vals, &mp->mp_path );
1168 rc = c->rvalue_vals ? 0 : 1;
1174 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1175 if ( !c->rvalue_vals ) rc = 1;
1178 #ifdef SLAP_AUTH_REWRITE
1180 if ( authz_rewrites ) {
1181 struct berval bv, idx;
1186 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1187 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1188 if ( idx.bv_len >= sizeof( ibuf ) ) {
1189 ber_bvarray_free_x( c->rvalue_vals, NULL );
1190 c->rvalue_vals = NULL;
1193 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1194 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1195 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1196 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1197 authz_rewrites[i].bv_val,
1198 authz_rewrites[i].bv_len + 1 );
1199 ber_bvarray_add( &c->rvalue_vals, &bv );
1202 if ( !c->rvalue_vals ) rc = 1;
1209 } else if ( c->op == LDAP_MOD_DELETE ) {
1212 /* single-valued attrs, no-ops */
1221 case CFG_MIRRORMODE:
1222 case CFG_MONITORING:
1224 case CFG_SSTR_IF_MAX:
1225 case CFG_SSTR_IF_MIN:
1227 case CFG_SYNC_SUBENTRY:
1230 /* no-ops, requires slapd restart */
1235 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1239 ch_free( passwd_salt );
1244 ch_free( logfileName );
1252 case CFG_SERVERID: {
1253 ServerID *si, **sip;
1255 for ( i=0, si = sid_list, sip = &sid_list;
1256 si; si = *sip, i++ ) {
1257 if ( c->valx == -1 || i == c->valx ) {
1269 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1273 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1274 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1275 SLAP_INDEX_INTLEN_DEFAULT );
1279 if ( c->valx < 0 ) {
1280 acl_destroy( c->be->be_acl );
1281 c->be->be_acl = NULL;
1284 AccessControl **prev, *a;
1286 for (i=0, prev = &c->be->be_acl; i < c->valx;
1289 prev = &a->acl_next;
1292 *prev = a->acl_next;
1299 /* Can be NULL when undoing a failed add */
1300 if ( c->ca_entry ) {
1301 ce = c->ca_entry->e_private;
1302 /* can't modify the hardcoded schema */
1303 if ( ce->ce_parent->ce_type == Cft_Global )
1307 cfn = c->ca_private;
1308 if ( c->valx < 0 ) {
1311 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1313 if ( oc == cfn->c_oc_tail )
1316 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1318 ObjectClass *oc, *prev = NULL;
1320 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1325 if ( cfn->c_oc_tail == oc ) {
1326 cfn->c_oc_tail = prev;
1328 if ( cfn->c_oc_head == oc ) {
1330 cfn->c_oc_head = oc;
1337 /* Can be NULL when undoing a failed add */
1338 if ( c->ca_entry ) {
1339 ce = c->ca_entry->e_private;
1340 /* can't modify the hardcoded schema */
1341 if ( ce->ce_parent->ce_type == Cft_Global )
1345 cfn = c->ca_private;
1346 if ( c->valx < 0 ) {
1349 for( at = cfn->c_at_head; at; at_next( &at )) {
1351 if ( at == cfn->c_at_tail )
1354 cfn->c_at_head = cfn->c_at_tail = NULL;
1356 AttributeType *at, *prev = NULL;
1358 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1363 if ( cfn->c_at_tail == at ) {
1364 cfn->c_at_tail = prev;
1366 if ( cfn->c_at_head == at ) {
1368 cfn->c_at_head = at;
1375 /* Can be NULL when undoing a failed add */
1376 if ( c->ca_entry ) {
1377 ce = c->ca_entry->e_private;
1378 /* can't modify the hardcoded schema */
1379 if ( ce->ce_parent->ce_type == Cft_Global )
1383 cfn = c->ca_private;
1384 if ( c->valx < 0 ) {
1387 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1389 if ( syn == cfn->c_syn_tail )
1392 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1394 Syntax *syn, *prev = NULL;
1396 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1401 if ( cfn->c_syn_tail == syn ) {
1402 cfn->c_syn_tail = prev;
1404 if ( cfn->c_syn_head == syn ) {
1406 cfn->c_syn_head = syn;
1411 if ( c->valx < 0 ) {
1413 for ( sv = sortVals; sv; sv = sortVals ) {
1414 sortVals = sv->al_next;
1415 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1422 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1423 prev = &sv->al_next;
1426 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1427 *prev = sv->al_next;
1433 /* FIXME: there is no limits_free function */
1434 if ( c->valx < 0 ) {
1435 limits_destroy( c->be->be_limits );
1436 c->be->be_limits = NULL;
1441 if ( c->be->be_limits ) {
1442 for ( num = 0; c->be->be_limits[ num ]; num++ )
1446 if ( c->valx >= num ) {
1451 limits_destroy( c->be->be_limits );
1452 c->be->be_limits = NULL;
1455 limits_free_one( c->be->be_limits[ c->valx ] );
1457 for ( cnt = c->valx; cnt < num; cnt++ ) {
1458 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1465 /* FIXME: there is no ad_option_free function */
1467 /* FIXME: there is no way to remove attributes added by
1481 if(!(c->bi = backend_info(c->argv[1]))) {
1482 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1483 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1484 c->log, c->cr_msg, c->argv[1] );
1491 /* NOTE: config is always the first backend!
1493 if ( !strcasecmp( c->argv[1], "config" )) {
1494 c->be = LDAP_STAILQ_FIRST(&backendDB);
1495 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1498 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1500 if ( c->cr_msg[0] == 0 )
1501 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1502 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1509 ldap_pvt_thread_set_concurrency(c->value_int);
1513 if ( c->value_int < 2 ) {
1514 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1515 "threads=%d smaller than minimum value 2",
1517 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1518 c->log, c->cr_msg, 0 );
1521 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1522 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1523 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1524 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1525 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1526 c->log, c->cr_msg, 0 );
1528 if ( slapMode & SLAP_SERVER_MODE )
1529 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1530 connection_pool_max = c->value_int; /* save for reference */
1534 if ( slapMode & SLAP_TOOL_MODE )
1535 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1536 slap_tool_thread_max = c->value_int; /* save for reference */
1541 /* use a power of two */
1542 while (c->value_uint > 1) {
1543 c->value_uint >>= 1;
1547 slapd_daemon_mask = mask;
1548 slapd_daemon_threads = mask+1;
1553 if ( passwd_salt ) ch_free( passwd_salt );
1554 passwd_salt = c->value_string;
1555 lutil_salt_format(passwd_salt);
1559 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1565 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1567 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1571 ch_free(c->value_string);
1572 if (slap_sasl_setpolicy( c->argv[1] )) {
1573 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1574 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1575 c->log, c->cr_msg, c->argv[1] );
1581 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1585 #ifdef HAVE_CYRUS_SASL
1588 char *txt = slap_sasl_secprops( c->argv[1] );
1590 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1592 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1600 c->be->be_max_deref_depth = c->value_int;
1606 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1607 cfn = c->ca_private;
1608 if(parse_oidm(c, 1, &om))
1610 if (!cfn->c_om_head) cfn->c_om_head = om;
1611 cfn->c_om_tail = om;
1616 ObjectClass *oc, *prev;
1618 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1619 cfn = c->ca_private;
1620 if ( c->valx < 0 ) {
1621 prev = cfn->c_oc_tail;
1624 /* If adding anything after the first, prev is easy */
1627 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1629 if ( !oc_next( &oc ))
1633 /* If adding the first, and head exists, find its prev */
1634 if (cfn->c_oc_head) {
1635 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1640 /* else prev is NULL, append to end of global list */
1642 if(parse_oc(c, &oc, prev)) return(1);
1643 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1644 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1649 AttributeType *at, *prev;
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_at_tail;
1657 /* If adding anything after the first, prev is easy */
1660 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1662 if ( !at_next( &at ))
1666 /* If adding the first, and head exists, find its prev */
1667 if (cfn->c_at_head) {
1668 for ( at_start( &at ); at != cfn->c_at_head; ) {
1673 /* else prev is NULL, append to end of global list */
1675 if(parse_at(c, &at, prev)) return(1);
1676 if (!cfn->c_at_head) cfn->c_at_head = at;
1677 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1684 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1685 cfn = c->ca_private;
1686 if ( c->valx < 0 ) {
1687 prev = cfn->c_syn_tail;
1690 /* If adding anything after the first, prev is easy */
1693 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1695 if ( !syn_next( &syn ))
1699 /* If adding the first, and head exists, find its prev */
1700 if (cfn->c_syn_head) {
1701 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1706 /* else prev is NULL, append to end of global list */
1708 if ( parse_syn( c, &syn, prev ) ) return(1);
1709 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1710 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1717 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1718 cfn = c->ca_private;
1719 if(parse_cr(c, &cr)) return(1);
1720 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1721 cfn->c_cr_tail = cr;
1726 ad_define_option(NULL, NULL, 0);
1727 for(i = 1; i < c->argc; i++)
1728 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1733 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1734 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1735 else if ( c->value_int > 255 )
1737 index_intlen = c->value_int;
1738 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1742 case CFG_SORTVALS: {
1743 ADlist *svnew = NULL, *svtail, *sv;
1745 for ( i = 1; i < c->argc; i++ ) {
1746 AttributeDescription *ad = NULL;
1750 rc = slap_str2ad( c->argv[i], &ad, &text );
1752 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1755 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1756 c->log, c->cr_msg, c->argv[i] );
1757 for ( sv = svnew; sv; sv = svnew ) {
1758 svnew = sv->al_next;
1763 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1764 ad->ad_type->sat_single_value ) {
1765 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1767 goto sortval_reject;
1769 sv = ch_malloc( sizeof( ADlist ));
1774 svtail->al_next = sv;
1779 for ( sv = svnew; sv; sv = sv->al_next )
1780 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1781 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1783 sv->al_next = svnew;
1790 /* Don't append to the global ACL if we're on a specific DB */
1792 if ( c->valx == -1 ) {
1795 for ( a=c->be->be_acl; a; a = a->acl_next )
1798 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1805 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1807 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1811 if(root_dse_read_file(c->argv[1])) {
1812 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1813 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1814 c->log, c->cr_msg, c->argv[1] );
1819 ber_str2bv( c->argv[1], 0, 1, &bv );
1820 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1821 cfn = c->ca_private;
1822 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1828 ServerID *si, **sip;
1831 if (( lutil_atoi( &num, c->argv[1] ) &&
1832 lutil_atoix( &num, c->argv[1], 16 )) ||
1833 num < 0 || num > SLAP_SYNC_SID_MAX )
1835 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1836 "<%s> illegal server ID", c->argv[0] );
1837 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1838 c->log, c->cr_msg, c->argv[1] );
1841 /* only one value allowed if no URL is given */
1842 if ( c->argc > 2 ) {
1845 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1846 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1847 "<%s> only one server ID allowed now", c->argv[0] );
1848 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1849 c->log, c->cr_msg, c->argv[1] );
1853 if ( ldap_url_parse( c->argv[2], &lud )) {
1854 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1855 "<%s> invalid URL", c->argv[0] );
1856 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1857 c->log, c->cr_msg, c->argv[2] );
1860 len = strlen( c->argv[2] );
1861 si = ch_malloc( sizeof(ServerID) + len + 1 );
1862 si->si_url.bv_val = (char *)(si+1);
1863 si->si_url.bv_len = len;
1864 strcpy( si->si_url.bv_val, c->argv[2] );
1867 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1868 "<%s> unqualified server ID not allowed now", c->argv[0] );
1869 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1870 c->log, c->cr_msg, c->argv[1] );
1873 si = ch_malloc( sizeof(ServerID) );
1874 BER_BVZERO( &si->si_url );
1875 slap_serverID = num;
1876 Debug( LDAP_DEBUG_CONFIG,
1878 c->log, slap_serverID, 0 );
1882 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1885 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1886 Listener *l = config_check_my_url( c->argv[2], lud );
1888 slap_serverID = si->si_num;
1889 Debug( LDAP_DEBUG_CONFIG,
1890 "%s: SID=0x%03x (listener=%s)\n",
1891 c->log, slap_serverID,
1896 ldap_free_urldesc( lud );
1900 if ( logfileName ) ch_free( logfileName );
1901 logfileName = c->value_string;
1902 logfile = fopen(logfileName, "w");
1903 if(logfile) lutil_debug_file(logfile);
1907 if(SLAP_NOLASTMODCMD(c->be)) {
1908 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1909 c->argv[0], c->be->bd_info->bi_type );
1910 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1911 c->log, c->cr_msg, 0 );
1915 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1917 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1920 case CFG_MIRRORMODE:
1921 if(c->value_int && !SLAP_SHADOW(c->be)) {
1922 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1924 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1925 c->log, c->cr_msg, 0 );
1929 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1931 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1934 case CFG_MONITORING:
1936 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1938 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1943 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1945 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1948 case CFG_SYNC_SUBENTRY:
1950 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1952 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1955 case CFG_SSTR_IF_MAX:
1956 if (c->value_uint < index_substr_if_minlen) {
1957 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1958 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1959 c->log, c->cr_msg, c->value_int );
1962 index_substr_if_maxlen = c->value_uint;
1965 case CFG_SSTR_IF_MIN:
1966 if (c->value_uint > index_substr_if_maxlen) {
1967 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1968 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1969 c->log, c->cr_msg, c->value_int );
1972 index_substr_if_minlen = c->value_uint;
1975 #ifdef SLAPD_MODULES
1977 /* If we're just adding a module on an existing modpath,
1978 * make sure we've selected the current path.
1980 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1981 modcur = c->ca_private;
1982 /* This should never fail */
1983 if ( module_path( modcur->mp_path.bv_val )) {
1984 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1986 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1987 c->log, c->cr_msg, modcur->mp_path.bv_val );
1991 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1993 /* Record this load on the current path */
1997 if ( c->op == SLAP_CONFIG_ADD ) {
1998 ptr = c->line + STRLENOF("moduleload");
1999 while (!isspace((unsigned char) *ptr)) ptr++;
2000 while (isspace((unsigned char) *ptr)) ptr++;
2004 ber_str2bv(ptr, 0, 1, &bv);
2005 ber_bvarray_add( &modcur->mp_loads, &bv );
2007 /* Check for any new hardcoded schema */
2008 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2009 config_check_schema( NULL, &cfBackInfo );
2014 if(module_path(c->argv[1])) return(1);
2015 /* Record which path was used with each module */
2019 if (!modpaths.mp_loads) {
2022 mp = ch_malloc( sizeof( ModPaths ));
2023 modlast->mp_next = mp;
2025 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2027 mp->mp_loads = NULL;
2038 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2040 slapi_plugins_used++;
2044 #ifdef SLAP_AUTH_REWRITE
2050 if ( c->op == LDAP_MOD_ADD ) {
2054 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2058 if ( c->argc > 1 ) {
2061 /* quote all args but the first */
2062 line = ldap_charray2str( c->argv, "\" \"" );
2063 ber_str2bv( line, 0, 0, &bv );
2064 s = ber_bvchr( &bv, '"' );
2065 assert( s != NULL );
2066 /* move the trailing quote of argv[0] to the end */
2067 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2068 bv.bv_val[ bv.bv_len - 1 ] = '"';
2071 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2074 ber_bvarray_add( &authz_rewrites, &bv );
2076 if ( c->op == LDAP_MOD_ADD ) {
2086 Debug( LDAP_DEBUG_ANY,
2087 "%s: unknown CFG_TYPE %d.\n",
2088 c->log, c->type, 0 );
2097 config_fname(ConfigArgs *c) {
2098 if(c->op == SLAP_CONFIG_EMIT) {
2099 if (c->ca_private) {
2100 ConfigFile *cf = c->ca_private;
2101 value_add_one( &c->rvalue_vals, &cf->c_file );
2110 config_cfdir(ConfigArgs *c) {
2111 if(c->op == SLAP_CONFIG_EMIT) {
2112 if ( !BER_BVISEMPTY( &cfdir )) {
2113 value_add_one( &c->rvalue_vals, &cfdir );
2122 config_search_base(ConfigArgs *c) {
2123 if(c->op == SLAP_CONFIG_EMIT) {
2125 if (!BER_BVISEMPTY(&default_search_base)) {
2126 value_add_one(&c->rvalue_vals, &default_search_base);
2127 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2131 } else if( c->op == LDAP_MOD_DELETE ) {
2132 ch_free( default_search_base.bv_val );
2133 ch_free( default_search_nbase.bv_val );
2134 BER_BVZERO( &default_search_base );
2135 BER_BVZERO( &default_search_nbase );
2139 if(c->bi || c->be != frontendDB) {
2140 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2141 "prior to any backend or database definition\n",
2146 if(default_search_nbase.bv_len) {
2147 free(default_search_base.bv_val);
2148 free(default_search_nbase.bv_val);
2151 default_search_base = c->value_dn;
2152 default_search_nbase = c->value_ndn;
2156 /* For RE23 compatibility we allow this in the global entry
2157 * but we now defer it to the frontend entry to allow modules
2158 * to load new hash types.
2161 config_passwd_hash(ConfigArgs *c) {
2163 if (c->op == SLAP_CONFIG_EMIT) {
2165 /* Don't generate it in the global entry */
2166 if ( c->table == Cft_Global )
2168 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2169 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2170 value_add_one(&c->rvalue_vals, &bv);
2173 } else if ( c->op == LDAP_MOD_DELETE ) {
2174 /* Deleting from global is a no-op, only the frontendDB entry matters */
2175 if ( c->table == Cft_Global )
2177 if ( c->valx < 0 ) {
2178 ldap_charray_free( default_passwd_hash );
2179 default_passwd_hash = NULL;
2182 ch_free( default_passwd_hash[i] );
2183 for (; default_passwd_hash[i]; i++ )
2184 default_passwd_hash[i] = default_passwd_hash[i+1];
2188 for(i = 1; i < c->argc; i++) {
2189 if(!lutil_passwd_scheme(c->argv[i])) {
2190 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2191 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2192 c->log, c->cr_msg, c->argv[i]);
2194 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2197 if(!default_passwd_hash) {
2198 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2199 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2200 c->log, c->cr_msg, 0 );
2207 config_schema_dn(ConfigArgs *c) {
2208 if ( c->op == SLAP_CONFIG_EMIT ) {
2210 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2211 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2212 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2216 } else if ( c->op == LDAP_MOD_DELETE ) {
2217 ch_free( c->be->be_schemadn.bv_val );
2218 ch_free( c->be->be_schemandn.bv_val );
2219 BER_BVZERO( &c->be->be_schemadn );
2220 BER_BVZERO( &c->be->be_schemandn );
2223 ch_free( c->be->be_schemadn.bv_val );
2224 ch_free( c->be->be_schemandn.bv_val );
2225 c->be->be_schemadn = c->value_dn;
2226 c->be->be_schemandn = c->value_ndn;
2231 config_sizelimit(ConfigArgs *c) {
2233 struct slap_limits_set *lim = &c->be->be_def_limit;
2234 if (c->op == SLAP_CONFIG_EMIT) {
2239 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2240 if ( !BER_BVISEMPTY( &bv ))
2241 value_add_one( &c->rvalue_vals, &bv );
2245 } else if ( c->op == LDAP_MOD_DELETE ) {
2246 /* Reset to defaults or values from frontend */
2247 if ( c->be == frontendDB ) {
2248 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2249 lim->lms_s_hard = 0;
2250 lim->lms_s_unchecked = -1;
2252 lim->lms_s_pr_hide = 0;
2253 lim->lms_s_pr_total = 0;
2255 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2256 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2257 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2258 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2259 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2260 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2264 for(i = 1; i < c->argc; i++) {
2265 if(!strncasecmp(c->argv[i], "size", 4)) {
2266 rc = limits_parse_one(c->argv[i], lim);
2268 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2269 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2270 c->log, c->cr_msg, c->argv[i]);
2274 if(!strcasecmp(c->argv[i], "unlimited")) {
2275 lim->lms_s_soft = -1;
2277 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2278 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2279 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2280 c->log, c->cr_msg, c->argv[i]);
2284 lim->lms_s_hard = 0;
2289 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2290 /* This is a modification to the global limits apply it to
2291 * the other databases as needed */
2292 AttributeDescription *ad=NULL;
2293 const char *text = NULL;
2294 CfEntryInfo *ce = c->ca_entry->e_private;
2296 slap_str2ad(c->argv[0], &ad, &text);
2297 /* if we got here... */
2298 assert( ad != NULL );
2300 if ( ce->ce_type == Cft_Global ){
2303 for (; ce; ce=ce->ce_sibs) {
2304 Entry *dbe = ce->ce_entry;
2305 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2306 && (!attr_find(dbe->e_attrs, ad)) ) {
2307 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2308 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2309 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2310 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2311 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2312 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2320 config_timelimit(ConfigArgs *c) {
2322 struct slap_limits_set *lim = &c->be->be_def_limit;
2323 if (c->op == SLAP_CONFIG_EMIT) {
2328 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2329 if ( !BER_BVISEMPTY( &bv ))
2330 value_add_one( &c->rvalue_vals, &bv );
2334 } else if ( c->op == LDAP_MOD_DELETE ) {
2335 /* Reset to defaults or values from frontend */
2336 if ( c->be == frontendDB ) {
2337 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2338 lim->lms_t_hard = 0;
2340 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2341 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2345 for(i = 1; i < c->argc; i++) {
2346 if(!strncasecmp(c->argv[i], "time", 4)) {
2347 rc = limits_parse_one(c->argv[i], lim);
2349 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2350 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2351 c->log, c->cr_msg, c->argv[i]);
2355 if(!strcasecmp(c->argv[i], "unlimited")) {
2356 lim->lms_t_soft = -1;
2358 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2359 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2360 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2361 c->log, c->cr_msg, c->argv[i]);
2365 lim->lms_t_hard = 0;
2370 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2371 /* This is a modification to the global limits apply it to
2372 * the other databases as needed */
2373 AttributeDescription *ad=NULL;
2374 const char *text = NULL;
2375 CfEntryInfo *ce = c->ca_entry->e_private;
2377 slap_str2ad(c->argv[0], &ad, &text);
2378 /* if we got here... */
2379 assert( ad != NULL );
2381 if ( ce->ce_type == Cft_Global ){
2384 for (; ce; ce=ce->ce_sibs) {
2385 Entry *dbe = ce->ce_entry;
2386 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2387 && (!attr_find(dbe->e_attrs, ad)) ) {
2388 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2389 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2397 config_overlay(ConfigArgs *c) {
2398 if (c->op == SLAP_CONFIG_EMIT) {
2400 } else if ( c->op == LDAP_MOD_DELETE ) {
2403 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2404 c->valx, &c->bi, &c->reply)) {
2406 Debug( LDAP_DEBUG_ANY,
2407 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2408 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2410 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2417 config_subordinate(ConfigArgs *c)
2423 case SLAP_CONFIG_EMIT:
2424 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2427 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2428 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2431 value_add_one( &c->rvalue_vals, &bv );
2435 case LDAP_MOD_DELETE:
2436 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2437 glue_sub_del( c->be );
2439 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2444 case SLAP_CONFIG_ADD:
2445 if ( c->be->be_nsuffix == NULL ) {
2447 snprintf( c->cr_msg, sizeof( c->cr_msg),
2448 "subordinate configuration needs a suffix" );
2449 Debug( LDAP_DEBUG_ANY,
2451 c->log, c->cr_msg, 0 );
2456 if ( c->argc == 2 ) {
2457 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2460 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2462 snprintf( c->cr_msg, sizeof( c->cr_msg),
2463 "subordinate must be \"TRUE\" or \"advertise\"" );
2464 Debug( LDAP_DEBUG_ANY,
2465 "%s: suffix \"%s\": %s.\n",
2466 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2472 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2480 * [listener=<listener>] [{read|write}=]<size>
2483 #ifdef LDAP_TCP_BUFFER
2484 static BerVarray tcp_buffer;
2487 #define SLAP_TCP_RMEM (0x1U)
2488 #define SLAP_TCP_WMEM (0x2U)
2491 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2492 int *size, int *rw, Listener **l )
2494 int i, rc = LDAP_SUCCESS;
2495 LDAPURLDesc *lud = NULL;
2498 if ( val != NULL && argv == NULL ) {
2499 char *s = val->bv_val;
2501 argv = ldap_str2charray( s, " \t" );
2502 if ( argv == NULL ) {
2508 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2511 char *url = argv[ i ] + STRLENOF( "listener=" );
2513 if ( ldap_url_parse( url, &lud ) ) {
2514 rc = LDAP_INVALID_SYNTAX;
2518 *l = config_check_my_url( url, lud );
2520 rc = LDAP_NO_SUCH_ATTRIBUTE;
2528 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2529 *rw |= SLAP_TCP_RMEM;
2530 ptr += STRLENOF( "read=" );
2532 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2533 *rw |= SLAP_TCP_WMEM;
2534 ptr += STRLENOF( "write=" );
2537 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2540 /* accept any base */
2541 if ( lutil_atoix( size, ptr, 0 ) ) {
2542 rc = LDAP_INVALID_SYNTAX;
2547 if ( val != NULL && argv != NULL ) {
2548 ldap_charray_free( argv );
2551 if ( lud != NULL ) {
2552 ldap_free_urldesc( lud );
2559 tcp_buffer_delete_one( struct berval *val )
2562 int size = -1, rw = 0;
2565 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2572 Listener **ll = slapd_get_listeners();
2574 for ( i = 0; ll[ i ] != NULL; i++ ) {
2575 if ( ll[ i ] == l ) break;
2578 if ( ll[ i ] == NULL ) {
2579 return LDAP_NO_SUCH_ATTRIBUTE;
2582 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2583 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2585 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2586 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2587 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2591 /* NOTE: this affects listeners without a specific setting,
2592 * does not reset all listeners. If a listener without
2593 * specific settings was assigned a buffer because of
2594 * a global setting, it will not be reset. In any case,
2595 * buffer changes will only take place at restart. */
2596 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2597 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2604 tcp_buffer_delete( BerVarray vals )
2608 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2609 tcp_buffer_delete_one( &vals[ i ] );
2616 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2618 char buf[sizeof("2147483648")], *ptr;
2620 /* unparse for later use */
2621 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2623 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2626 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2627 if ( rw & SLAP_TCP_RMEM ) {
2628 val->bv_len += STRLENOF( "read=" );
2629 } else if ( rw & SLAP_TCP_WMEM ) {
2630 val->bv_len += STRLENOF( "write=" );
2634 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2639 ptr = lutil_strcopy( ptr, "listener=" );
2640 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2644 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2645 if ( rw & SLAP_TCP_RMEM ) {
2646 ptr = lutil_strcopy( ptr, "read=" );
2647 } else if ( rw & SLAP_TCP_WMEM ) {
2648 ptr = lutil_strcopy( ptr, "write=" );
2652 ptr = lutil_strcopy( ptr, buf );
2655 assert( val->bv_val + val->bv_len == ptr );
2657 return LDAP_SUCCESS;
2661 tcp_buffer_add_one( int argc, char **argv )
2664 int size = -1, rw = 0;
2670 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2675 /* unparse for later use */
2676 rc = tcp_buffer_unparse( size, rw, l, &val );
2677 if ( rc != LDAP_SUCCESS ) {
2681 /* use parsed values */
2684 Listener **ll = slapd_get_listeners();
2686 for ( i = 0; ll[ i ] != NULL; i++ ) {
2687 if ( ll[ i ] == l ) break;
2690 if ( ll[ i ] == NULL ) {
2691 return LDAP_NO_SUCH_ATTRIBUTE;
2694 /* buffer only applies to TCP listeners;
2695 * we do not do any check here, and delegate them
2696 * to setsockopt(2) */
2697 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2698 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2700 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2701 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2702 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2706 /* NOTE: this affects listeners without a specific setting,
2707 * does not set all listeners */
2708 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2709 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2712 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2714 tcp_buffer[ tcp_buffer_num ] = val;
2717 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2723 config_tcp_buffer( ConfigArgs *c )
2725 if ( c->op == SLAP_CONFIG_EMIT ) {
2726 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2729 value_add( &c->rvalue_vals, tcp_buffer );
2730 value_add( &c->rvalue_nvals, tcp_buffer );
2732 } else if ( c->op == LDAP_MOD_DELETE ) {
2734 tcp_buffer_delete( tcp_buffer );
2735 ber_bvarray_free( tcp_buffer );
2741 int size = -1, rw = 0;
2744 struct berval val = BER_BVNULL;
2748 if ( tcp_buffer_num == 0 ) {
2753 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2758 /* unparse for later use */
2759 rc = tcp_buffer_unparse( size, rw, l, &val );
2760 if ( rc != LDAP_SUCCESS ) {
2764 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2765 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2770 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2776 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2777 ber_memfree( tcp_buffer[ i ].bv_val );
2778 for ( ; i < tcp_buffer_num; i++ ) {
2779 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2784 if ( !BER_BVISNULL( &val ) ) {
2785 SLAP_FREE( val.bv_val );
2793 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2795 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2796 "<%s> unable to add value #%d",
2797 c->argv[0], tcp_buffer_num );
2798 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2799 c->log, c->cr_msg, 0 );
2806 #endif /* LDAP_TCP_BUFFER */
2809 config_suffix(ConfigArgs *c)
2812 struct berval pdn, ndn;
2813 char *notallowed = NULL;
2815 if ( c->be == frontendDB ) {
2816 notallowed = "frontend";
2818 } else if ( SLAP_MONITOR(c->be) ) {
2819 notallowed = "monitor";
2821 } else if ( SLAP_CONFIG(c->be) ) {
2822 notallowed = "config";
2825 if ( notallowed != NULL ) {
2826 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2830 case LDAP_MOD_DELETE:
2831 case LDAP_MOD_REPLACE:
2832 case LDAP_MOD_INCREMENT:
2833 case SLAP_CONFIG_ADD:
2834 if ( !BER_BVISNULL( &c->value_dn ) ) {
2835 snprintf( buf, sizeof( buf ), "<%s> ",
2836 c->value_dn.bv_val );
2839 Debug(LDAP_DEBUG_ANY,
2840 "%s: suffix %snot allowed in %s database.\n",
2841 c->log, buf, notallowed );
2844 case SLAP_CONFIG_EMIT:
2845 /* don't complain when emitting... */
2849 /* FIXME: don't know what values may be valid;
2850 * please remove assertion, or add legal values
2851 * to either block */
2859 if (c->op == SLAP_CONFIG_EMIT) {
2860 if ( c->be->be_suffix == NULL
2861 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2865 value_add( &c->rvalue_vals, c->be->be_suffix );
2866 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2869 } else if ( c->op == LDAP_MOD_DELETE ) {
2870 if ( c->valx < 0 ) {
2871 ber_bvarray_free( c->be->be_suffix );
2872 ber_bvarray_free( c->be->be_nsuffix );
2873 c->be->be_suffix = NULL;
2874 c->be->be_nsuffix = NULL;
2877 ch_free( c->be->be_suffix[i].bv_val );
2878 ch_free( c->be->be_nsuffix[i].bv_val );
2880 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2881 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2883 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2888 #ifdef SLAPD_MONITOR_DN
2889 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2890 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2892 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2893 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2898 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2899 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2900 c->argv[0], c->be->bd_info->bi_type );
2901 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2902 c->log, c->cr_msg, 0);
2909 if (SLAP_DBHIDDEN( c->be ))
2912 tbe = select_backend(&ndn, 0);
2914 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2920 BackendDB *b2 = tbe;
2922 /* Does tbe precede be? */
2923 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2926 char *type = tbe->bd_info->bi_type;
2928 if ( overlay_is_over( tbe ) ) {
2929 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2930 type = oi->oi_orig->bi_type;
2933 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2934 "already served by a preceding %s database",
2935 c->argv[0], pdn.bv_val, type );
2936 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2937 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2943 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2944 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2945 "base provided \"%s\" (assuming okay)\n",
2946 c->log, default_search_base.bv_val, 0);
2948 ber_bvarray_add(&c->be->be_suffix, &pdn);
2949 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2954 config_rootdn(ConfigArgs *c) {
2955 if (c->op == SLAP_CONFIG_EMIT) {
2956 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2957 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2958 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2963 } else if ( c->op == LDAP_MOD_DELETE ) {
2964 ch_free( c->be->be_rootdn.bv_val );
2965 ch_free( c->be->be_rootndn.bv_val );
2966 BER_BVZERO( &c->be->be_rootdn );
2967 BER_BVZERO( &c->be->be_rootndn );
2970 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2971 ch_free( c->be->be_rootdn.bv_val );
2972 ch_free( c->be->be_rootndn.bv_val );
2974 c->be->be_rootdn = c->value_dn;
2975 c->be->be_rootndn = c->value_ndn;
2980 config_rootpw(ConfigArgs *c) {
2983 if (c->op == SLAP_CONFIG_EMIT) {
2984 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2985 /* don't copy, because "rootpw" is marked
2987 c->value_bv = c->be->be_rootpw;
2991 } else if ( c->op == LDAP_MOD_DELETE ) {
2992 ch_free( c->be->be_rootpw.bv_val );
2993 BER_BVZERO( &c->be->be_rootpw );
2997 tbe = select_backend(&c->be->be_rootndn, 0);
2999 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3001 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3002 c->log, c->cr_msg, 0);
3005 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3006 ch_free( c->be->be_rootpw.bv_val );
3007 c->be->be_rootpw = c->value_bv;
3012 config_restrict(ConfigArgs *c) {
3013 slap_mask_t restrictops = 0;
3015 slap_verbmasks restrictable_ops[] = {
3016 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3017 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3018 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3019 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3020 { BER_BVC("modrdn"), 0 },
3021 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3022 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3023 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3024 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3025 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3026 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3027 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3028 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3029 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3030 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3031 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3035 if (c->op == SLAP_CONFIG_EMIT) {
3036 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3038 } else if ( c->op == LDAP_MOD_DELETE ) {
3040 c->be->be_restrictops = 0;
3042 restrictops = verb_to_mask( c->line, restrictable_ops );
3043 c->be->be_restrictops ^= restrictops;
3047 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3049 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3050 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3051 c->log, c->cr_msg, c->argv[i]);
3054 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3055 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3056 c->be->be_restrictops |= restrictops;
3061 config_allows(ConfigArgs *c) {
3062 slap_mask_t allows = 0;
3064 slap_verbmasks allowable_ops[] = {
3065 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3066 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3067 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3068 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3069 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3072 if (c->op == SLAP_CONFIG_EMIT) {
3073 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3074 } else if ( c->op == LDAP_MOD_DELETE ) {
3078 allows = verb_to_mask( c->line, allowable_ops );
3079 global_allows ^= allows;
3083 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3085 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3086 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3087 c->log, c->cr_msg, c->argv[i]);
3090 global_allows |= allows;
3095 config_disallows(ConfigArgs *c) {
3096 slap_mask_t disallows = 0;
3098 slap_verbmasks disallowable_ops[] = {
3099 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3100 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3101 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3102 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3103 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3104 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3107 if (c->op == SLAP_CONFIG_EMIT) {
3108 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3109 } else if ( c->op == LDAP_MOD_DELETE ) {
3111 global_disallows = 0;
3113 disallows = verb_to_mask( c->line, disallowable_ops );
3114 global_disallows ^= disallows;
3118 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3120 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3121 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3122 c->log, c->cr_msg, c->argv[i]);
3125 global_disallows |= disallows;
3130 config_requires(ConfigArgs *c) {
3131 slap_mask_t requires = frontendDB->be_requires;
3132 int i, argc = c->argc;
3133 char **argv = c->argv;
3135 slap_verbmasks requires_ops[] = {
3136 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3137 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3138 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3139 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3140 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3143 if (c->op == SLAP_CONFIG_EMIT) {
3144 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3145 } else if ( c->op == LDAP_MOD_DELETE ) {
3147 c->be->be_requires = 0;
3149 requires = verb_to_mask( c->line, requires_ops );
3150 c->be->be_requires ^= requires;
3154 /* "none" can only be first, to wipe out default/global values */
3155 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3160 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3162 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3163 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3164 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3165 c->log, c->cr_msg, 0);
3167 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3168 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3169 c->log, c->cr_msg, c->argv[i]);
3173 c->be->be_requires = requires;
3177 static slap_verbmasks *loglevel_ops;
3180 loglevel_init( void )
3182 slap_verbmasks lo[] = {
3183 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3184 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3185 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3186 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3187 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3188 { BER_BVC("BER"), LDAP_DEBUG_BER },
3189 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3190 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3191 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3192 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3193 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3194 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3195 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3196 #if 0 /* no longer used (nor supported) */
3197 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3198 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3200 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3201 { BER_BVC("None"), LDAP_DEBUG_NONE },
3205 return slap_verbmasks_init( &loglevel_ops, lo );
3209 loglevel_destroy( void )
3211 if ( loglevel_ops ) {
3212 (void)slap_verbmasks_destroy( loglevel_ops );
3214 loglevel_ops = NULL;
3217 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3220 slap_loglevel_register( slap_mask_t m, struct berval *s )
3224 if ( loglevel_ops == NULL ) {
3228 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3231 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3239 slap_loglevel_get( struct berval *s, int *l )
3244 if ( loglevel_ops == NULL ) {
3248 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3249 m |= loglevel_ops[ i ].mask;
3252 for ( i = 1; m & i; i <<= 1 )
3259 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3262 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3273 str2loglevel( const char *s, int *l )
3277 if ( loglevel_ops == NULL ) {
3281 i = verb_to_mask( s, loglevel_ops );
3283 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3287 *l = loglevel_ops[ i ].mask;
3293 loglevel2str( int l )
3295 struct berval bv = BER_BVNULL;
3297 loglevel2bv( l, &bv );
3303 loglevel2bv( int l, struct berval *bv )
3305 if ( loglevel_ops == NULL ) {
3311 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3315 loglevel2bvarray( int l, BerVarray *bva )
3317 if ( loglevel_ops == NULL ) {
3321 return mask_to_verbs( loglevel_ops, l, bva );
3325 loglevel_print( FILE *out )
3329 if ( loglevel_ops == NULL ) {
3333 fprintf( out, "Installed log subsystems:\n\n" );
3334 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3335 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3337 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3338 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3339 loglevel_ops[ i ].word.bv_val, mask, mask );
3342 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3343 "by specific code\n\n" );
3348 static int config_syslog;
3351 config_loglevel(ConfigArgs *c) {
3354 if ( loglevel_ops == NULL ) {
3358 if (c->op == SLAP_CONFIG_EMIT) {
3359 /* Get default or commandline slapd setting */
3360 if ( ldap_syslog && !config_syslog )
3361 config_syslog = ldap_syslog;
3362 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3364 } else if ( c->op == LDAP_MOD_DELETE ) {
3368 int level = verb_to_mask( c->line, loglevel_ops );
3369 config_syslog ^= level;
3371 if ( slapMode & SLAP_SERVER_MODE ) {
3372 ldap_syslog = config_syslog;
3377 for( i=1; i < c->argc; i++ ) {
3380 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3381 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3382 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3383 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3384 c->log, c->cr_msg, c->argv[i]);
3388 if ( str2loglevel( c->argv[i], &level ) ) {
3389 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3390 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3391 c->log, c->cr_msg, c->argv[i]);
3395 /* Explicitly setting a zero clears all the levels */
3397 config_syslog |= level;
3401 if ( slapMode & SLAP_SERVER_MODE ) {
3402 ldap_syslog = config_syslog;
3408 config_referral(ConfigArgs *c) {
3410 if (c->op == SLAP_CONFIG_EMIT) {
3411 if ( default_referral ) {
3412 value_add( &c->rvalue_vals, default_referral );
3417 } else if ( c->op == LDAP_MOD_DELETE ) {
3418 if ( c->valx < 0 ) {
3419 ber_bvarray_free( default_referral );
3420 default_referral = NULL;
3423 ch_free( default_referral[i].bv_val );
3424 for (; default_referral[i].bv_val; i++ )
3425 default_referral[i] = default_referral[i+1];
3429 if(validate_global_referral(c->argv[1])) {
3430 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3431 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3432 c->log, c->cr_msg, c->argv[1]);
3436 ber_str2bv(c->argv[1], 0, 0, &val);
3437 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3445 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3446 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3447 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3448 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3449 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3450 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3451 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3452 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3453 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3458 config_security(ConfigArgs *c) {
3459 slap_ssf_set_t *set = &c->be->be_ssf_set;
3462 if (c->op == SLAP_CONFIG_EMIT) {
3468 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3469 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3472 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3473 if ( bv.bv_len >= sizeof( numbuf ) ) {
3474 ber_bvarray_free_x( c->rvalue_vals, NULL );
3475 c->rvalue_vals = NULL;
3479 bv.bv_len += sec_keys[i].key.bv_len;
3480 bv.bv_val = ch_malloc( bv.bv_len + 1);
3481 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3482 strcpy( next, numbuf );
3483 ber_bvarray_add( &c->rvalue_vals, &bv );
3488 for(i = 1; i < c->argc; i++) {
3489 slap_ssf_t *tgt = NULL;
3491 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3492 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3493 sec_keys[j].key.bv_len)) {
3494 src = c->argv[i] + sec_keys[j].key.bv_len;
3495 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3500 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3501 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3502 c->log, c->cr_msg, c->argv[i]);
3506 if ( lutil_atou( tgt, src ) != 0 ) {
3507 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3508 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3509 c->log, c->cr_msg, c->argv[i]);
3517 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3521 for (; !BER_BVISNULL( &an->an_name ); an++) {
3522 /* if buflen == 0, assume the buffer size has been
3523 * already checked otherwise */
3524 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3525 if ( comma ) *ptr++ = ',';
3526 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3533 config_updatedn(ConfigArgs *c) {
3534 if (c->op == SLAP_CONFIG_EMIT) {
3535 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3536 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3537 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3541 } else if ( c->op == LDAP_MOD_DELETE ) {
3542 ch_free( c->be->be_update_ndn.bv_val );
3543 BER_BVZERO( &c->be->be_update_ndn );
3544 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3547 if(SLAP_SHADOW(c->be)) {
3548 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3549 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3550 c->log, c->cr_msg, 0);
3554 ber_memfree_x( c->value_dn.bv_val, NULL );
3555 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3556 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3558 c->be->be_update_ndn = c->value_ndn;
3559 BER_BVZERO( &c->value_dn );
3560 BER_BVZERO( &c->value_ndn );
3562 return config_slurp_shadow( c );
3566 config_shadow( ConfigArgs *c, slap_mask_t flag )
3568 char *notallowed = NULL;
3570 if ( c->be == frontendDB ) {
3571 notallowed = "frontend";
3573 } else if ( SLAP_MONITOR(c->be) ) {
3574 notallowed = "monitor";
3577 if ( notallowed != NULL ) {
3578 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3582 if ( SLAP_SHADOW(c->be) ) {
3583 /* if already shadow, only check consistency */
3584 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3585 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3591 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3598 config_updateref(ConfigArgs *c) {
3600 if (c->op == SLAP_CONFIG_EMIT) {
3601 if ( c->be->be_update_refs ) {
3602 value_add( &c->rvalue_vals, c->be->be_update_refs );
3607 } else if ( c->op == LDAP_MOD_DELETE ) {
3608 if ( c->valx < 0 ) {
3609 ber_bvarray_free( c->be->be_update_refs );
3610 c->be->be_update_refs = NULL;
3613 ch_free( c->be->be_update_refs[i].bv_val );
3614 for (; c->be->be_update_refs[i].bv_val; i++)
3615 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3619 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3620 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3622 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3623 c->log, c->cr_msg, 0);
3627 if(validate_global_referral(c->argv[1])) {
3628 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3629 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3630 c->log, c->cr_msg, c->argv[1]);
3633 ber_str2bv(c->argv[1], 0, 0, &val);
3634 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3639 config_obsolete(ConfigArgs *c) {
3640 if (c->op == SLAP_CONFIG_EMIT)
3643 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3645 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3650 config_include(ConfigArgs *c) {
3651 int savelineno = c->lineno;
3654 ConfigFile *cfsave = cfn;
3655 ConfigFile *cf2 = NULL;
3657 /* Leftover from RE23. No dynamic config for include files */
3658 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3661 cf = ch_calloc( 1, sizeof(ConfigFile));
3662 if ( cfn->c_kids ) {
3663 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3669 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3670 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3671 c->lineno = savelineno - 1;
3674 if ( cf2 ) cf2->c_sibs = NULL;
3675 else cfn->c_kids = NULL;
3676 ch_free( cf->c_file.bv_val );
3686 config_tls_cleanup(ConfigArgs *c) {
3689 if ( slap_tls_ld ) {
3692 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3694 /* Force new ctx to be created */
3695 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3697 /* The ctx's refcount is bumped up here */
3698 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3699 /* This is a no-op if it's already loaded */
3700 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3707 config_tls_option(ConfigArgs *c) {
3709 LDAP *ld = slap_tls_ld;
3711 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3712 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3713 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3714 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3715 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3716 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3717 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3719 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3721 default: Debug(LDAP_DEBUG_ANY, "%s: "
3722 "unknown tls_option <0x%x>\n",
3723 c->log, c->type, 0);
3726 if (c->op == SLAP_CONFIG_EMIT) {
3727 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3728 } else if ( c->op == LDAP_MOD_DELETE ) {
3729 c->cleanup = config_tls_cleanup;
3730 return ldap_pvt_tls_set_option( ld, flag, NULL );
3732 ch_free(c->value_string);
3733 c->cleanup = config_tls_cleanup;
3734 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3737 /* FIXME: this ought to be provided by libldap */
3739 config_tls_config(ConfigArgs *c) {
3742 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3743 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3744 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3746 Debug(LDAP_DEBUG_ANY, "%s: "
3747 "unknown tls_option <0x%x>\n",
3748 c->log, c->type, 0);
3751 if (c->op == SLAP_CONFIG_EMIT) {
3752 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3753 } else if ( c->op == LDAP_MOD_DELETE ) {
3755 c->cleanup = config_tls_cleanup;
3756 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3758 ch_free( c->value_string );
3759 c->cleanup = config_tls_cleanup;
3760 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3761 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3762 Debug(LDAP_DEBUG_ANY, "%s: "
3763 "unable to parse %s \"%s\"\n",
3764 c->log, c->argv[0], c->argv[1] );
3767 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3769 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3774 static CfEntryInfo *
3775 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3785 if ( dn_match( &root->ce_entry->e_nname, dn ))
3788 c = dn->bv_val+dn->bv_len;
3789 for (;*c != ',';c--);
3793 for (--c;c>dn->bv_val && *c != ',';c--);
3797 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3799 root = root->ce_kids;
3801 for (;root;root=root->ce_sibs) {
3802 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3803 if ( cdn.bv_val == dn->bv_val ) {
3813 typedef struct setup_cookie {
3823 config_ldif_resp( Operation *op, SlapReply *rs )
3825 if ( rs->sr_type == REP_SEARCH ) {
3826 setup_cookie *sc = op->o_callback->sc_private;
3829 sc->cfb->cb_got_ldif = 1;
3830 /* Does the frontend exist? */
3831 if ( !sc->got_frontend ) {
3832 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3833 "olcDatabase", STRLENOF( "olcDatabase" )))
3835 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3836 STRLENOF( "olcDatabase" ), "={-1}frontend",
3837 STRLENOF( "={-1}frontend" )))
3841 sc->ca->be = frontendDB;
3842 sc->ca->bi = frontendDB->bd_info;
3843 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
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, -1,
3848 sc->ca->bi->bi_type);
3850 sc->frontend = config_build_entry( op, rs,
3851 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3852 sc->ca->be->be_cf_ocs );
3862 dnParent( &rs->sr_entry->e_nname, &pdn );
3864 /* Does the configDB exist? */
3865 if ( sc->got_frontend && !sc->got_config &&
3866 !strncmp( rs->sr_entry->e_nname.bv_val,
3867 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3868 dn_match( &config_rdn, &pdn ) )
3870 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3871 STRLENOF( "olcDatabase" ), "={0}config",
3872 STRLENOF( "={0}config" )))
3876 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3877 sc->ca->bi = sc->ca->be->bd_info;
3878 rdn.bv_val = sc->ca->log;
3879 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3880 "%s=" SLAP_X_ORDERED_FMT "%s",
3881 cfAd_database->ad_cname.bv_val, 0,
3882 sc->ca->bi->bi_type);
3884 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3885 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3892 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3893 if ( rs->sr_err != LDAP_SUCCESS ) {
3894 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3895 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3901 /* Configure and read the underlying back-ldif store */
3903 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3904 CfBackInfo *cfb = be->be_private;
3910 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3911 Connection conn = {0};
3912 OperationBuffer opbuf;
3914 SlapReply rs = {REP_RESULT};
3915 Filter filter = { LDAP_FILTER_PRESENT };
3916 struct berval filterstr = BER_BVC("(objectclass=*)");
3919 /* Is the config directory available? */
3920 if ( stat( dir, &st ) < 0 ) {
3921 /* No, so don't bother using the backing store.
3922 * All changes will be in-memory only.
3927 cfb->cb_db.bd_info = backend_info( "ldif" );
3928 if ( !cfb->cb_db.bd_info )
3929 return 0; /* FIXME: eventually this will be a fatal error */
3931 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3934 cfb->cb_db.be_suffix = be->be_suffix;
3935 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3937 /* The suffix is always "cn=config". The underlying DB's rootdn
3938 * is always the same as the suffix.
3940 cfb->cb_db.be_rootdn = be->be_suffix[0];
3941 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3943 ber_str2bv( dir, 0, 1, &cfdir );
3948 argv[0] = "directory";
3949 argv[1] = (char *)dir;
3954 c.table = Cft_Database;
3956 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3960 if ( config_add_vals( ct, &c ))
3963 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3967 void *thrctx = ldap_pvt_thread_pool_context();
3970 connection_fake_init( &conn, &opbuf, thrctx );
3973 filter.f_desc = slap_schema.si_ad_objectClass;
3975 op->o_tag = LDAP_REQ_SEARCH;
3977 op->ors_filter = &filter;
3978 op->ors_filterstr = filterstr;
3979 op->ors_scope = LDAP_SCOPE_SUBTREE;
3981 op->o_dn = c.be->be_rootdn;
3982 op->o_ndn = c.be->be_rootndn;
3984 op->o_req_dn = be->be_suffix[0];
3985 op->o_req_ndn = be->be_nsuffix[0];
3987 op->ors_tlimit = SLAP_NO_LIMIT;
3988 op->ors_slimit = SLAP_NO_LIMIT;
3990 op->ors_attrs = slap_anlist_all_attributes;
3991 op->ors_attrsonly = 0;
3993 op->o_callback = &cb;
3996 cb.sc_private = ≻
3997 sc.got_frontend = 0;
4002 op->o_bd = &cfb->cb_db;
4004 /* Allow unknown attrs in DNs */
4005 prev_DN_strict = slap_DN_strict;
4008 rc = op->o_bd->be_search( op, &rs );
4010 /* Restore normal DN validation */
4011 slap_DN_strict = prev_DN_strict;
4013 op->o_tag = LDAP_REQ_ADD;
4014 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4015 rs_reinit( &rs, REP_RESULT );
4016 op->ora_e = sc.frontend;
4017 rc = op->o_bd->be_add( op, &rs );
4019 if ( rc == LDAP_SUCCESS && sc.config ) {
4020 rs_reinit( &rs, REP_RESULT );
4021 op->ora_e = sc.config;
4022 rc = op->o_bd->be_add( op, &rs );
4024 ldap_pvt_thread_pool_context_reset( thrctx );
4027 /* ITS#4194 - only use if it's present, or we're converting. */
4028 if ( !readit || rc == LDAP_SUCCESS )
4029 cfb->cb_use_ldif = 1;
4035 CfOc_cmp( const void *c1, const void *c2 ) {
4036 const ConfigOCs *co1 = c1;
4037 const ConfigOCs *co2 = c2;
4039 return ber_bvcmp( co1->co_name, co2->co_name );
4043 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4046 i = init_config_attrs( ct );
4049 /* set up the objectclasses */
4050 i = init_config_ocs( ocs );
4053 for (i=0; ocs[i].co_def; i++) {
4054 if ( ocs[i].co_oc ) {
4055 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4056 if ( !ocs[i].co_table )
4057 ocs[i].co_table = ct;
4058 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4065 read_config(const char *fname, const char *dir) {
4068 const char *cfdir, *cfname;
4071 /* Setup the config backend */
4072 be = backend_db_init( "config", NULL, 0, NULL );
4076 cfb = be->be_private;
4077 be->be_dfltaccess = ACL_NONE;
4079 /* If no .conf, or a dir was specified, setup the dir */
4080 if ( !fname || dir ) {
4082 /* If explicitly given, check for existence */
4085 if ( stat( dir, &st ) < 0 ) {
4086 Debug( LDAP_DEBUG_ANY,
4087 "invalid config directory %s, error %d\n",
4093 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4095 /* if fname is defaulted, try reading .d */
4096 rc = config_setup_ldif( be, cfdir, !fname );
4099 /* It may be OK if the base object doesn't exist yet. */
4100 if ( rc != LDAP_NO_SUCH_OBJECT )
4102 /* ITS#4194: But if dir was specified and no fname,
4103 * then we were supposed to read the dir. Unless we're
4104 * trying to slapadd the dir...
4106 if ( dir && !fname ) {
4107 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4109 /* Assume it's slapadd with a config dir, let it continue */
4111 cfb->cb_got_ldif = 1;
4112 cfb->cb_use_ldif = 1;
4117 /* If we read the config from back-ldif, nothing to do here */
4118 if ( cfb->cb_got_ldif ) {
4127 cfname = SLAPD_DEFAULT_CONFIGFILE;
4129 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4132 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4135 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4136 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4137 &frontendDB->be_schemadn );
4138 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4139 if ( rc != LDAP_SUCCESS ) {
4140 Debug(LDAP_DEBUG_ANY, "read_config: "
4141 "unable to normalize default schema DN \"%s\"\n",
4142 frontendDB->be_schemadn.bv_val, 0, 0 );
4143 /* must not happen */
4151 config_back_bind( Operation *op, SlapReply *rs )
4153 if ( be_isroot_pw( op ) ) {
4154 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4155 /* frontend sends result */
4156 return LDAP_SUCCESS;
4159 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4160 send_ldap_result( op, rs );
4166 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4170 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4172 rs->sr_attrs = op->ors_attrs;
4173 rs->sr_entry = ce->ce_entry;
4175 rc = send_search_entry( op, rs );
4176 if ( rc != LDAP_SUCCESS ) {
4180 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4181 if ( ce->ce_kids ) {
4182 rc = config_send( op, rs, ce->ce_kids, 1 );
4183 if ( rc ) return rc;
4186 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4187 rc = config_send( op, rs, ce, 0 );
4195 static ConfigTable *
4196 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4201 for (j=0; j<nocs; j++) {
4202 for (i=0; colst[j]->co_table[i].name; i++)
4203 if ( colst[j]->co_table[i].ad == ad ) {
4204 ca->table = colst[j]->co_type;
4205 return &colst[j]->co_table[i];
4211 /* Sort the attributes of the entry according to the order defined
4212 * in the objectclass, with required attributes occurring before
4213 * allowed attributes. For any attributes with sequencing dependencies
4214 * (e.g., rootDN must be defined after suffix) the objectclass must
4215 * list the attributes in the desired sequence.
4218 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4220 Attribute *a, *head = NULL, *tail = NULL, **prev;
4223 for (i=0; i<nocs; i++) {
4224 if ( colst[i]->co_oc->soc_required ) {
4225 AttributeType **at = colst[i]->co_oc->soc_required;
4226 for (j=0; at[j]; j++) {
4227 for (a=e->e_attrs, prev=&e->e_attrs; a;
4228 prev = &(*prev)->a_next, a=a->a_next) {
4229 if ( a->a_desc == at[j]->sat_ad ) {
4243 if ( colst[i]->co_oc->soc_allowed ) {
4244 AttributeType **at = colst[i]->co_oc->soc_allowed;
4245 for (j=0; at[j]; j++) {
4246 for (a=e->e_attrs, prev=&e->e_attrs; a;
4247 prev = &(*prev)->a_next, a=a->a_next) {
4248 if ( a->a_desc == at[j]->sat_ad ) {
4264 tail->a_next = e->e_attrs;
4270 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4272 Attribute *a = NULL;
4273 AttributeDescription *ad;
4283 Modifications *ml = ptr;
4285 vals = ml->sml_values;
4288 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4289 rc = ordered_value_sort( a, 1 );
4291 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4292 ad->ad_cname.bv_val );
4296 for ( i=0; vals[i].bv_val; i++ ) {
4297 ca->line = vals[i].bv_val;
4298 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4299 ca->line[0] == '{' ) {
4300 char *idx = strchr( ca->line, '}' );
4301 if ( idx ) ca->line = idx+1;
4303 rc = config_parse_vals( ct, ca, i );
4312 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4315 struct berval rtype, rval;
4317 AttributeDescription *ad = NULL;
4319 dnRdn( &e->e_name, rdn );
4320 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4321 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4322 rtype.bv_val = rdn->bv_val;
4323 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4326 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4327 a = attr_find( e->e_attrs, ad );
4328 if (!a ) return LDAP_NAMING_VIOLATION;
4335 config_rename_kids( CfEntryInfo *ce )
4338 struct berval rdn, nrdn;
4340 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4341 struct berval newdn, newndn;
4342 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4343 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4344 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4345 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4346 free( ce2->ce_entry->e_name.bv_val );
4347 free( ce2->ce_entry->e_nname.bv_val );
4348 ce2->ce_entry->e_name = newdn;
4349 ce2->ce_entry->e_nname = newndn;
4350 config_rename_kids( ce2 );
4355 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4356 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4357 struct berval *nnewrdn, int use_ldif )
4361 struct berval odn, ondn;
4365 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4366 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4369 free( a->a_vals[0].bv_val );
4370 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4371 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4372 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4373 strcpy( a->a_vals[0].bv_val, ptr1 );
4375 if ( a->a_nvals != a->a_vals ) {
4376 free( a->a_nvals[0].bv_val );
4377 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4378 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4379 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4380 strcpy( a->a_nvals[0].bv_val, ptr1 );
4383 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4384 BackendDB *be = op->o_bd;
4385 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4386 struct berval dn, ndn, xdn, xndn;
4388 op->o_bd = &cfb->cb_db;
4390 /* Save current rootdn; use the underlying DB's rootdn */
4394 xndn = op->o_req_ndn;
4395 op->o_dn = op->o_bd->be_rootdn;
4396 op->o_ndn = op->o_bd->be_rootndn;
4398 op->o_req_ndn = ondn;
4400 scp = op->o_callback;
4401 op->o_callback = ≻
4402 op->orr_newrdn = *newrdn;
4403 op->orr_nnewrdn = *nnewrdn;
4404 op->orr_newSup = NULL;
4405 op->orr_nnewSup = NULL;
4406 op->orr_deleteoldrdn = 1;
4407 op->orr_modlist = NULL;
4408 slap_modrdn2mods( op, rs );
4409 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4410 rc = op->o_bd->be_modrdn( op, rs );
4411 slap_mods_free( op->orr_modlist, 1 );
4414 op->o_callback = scp;
4418 op->o_req_ndn = xndn;
4421 free( ondn.bv_val );
4423 config_rename_kids( e->e_private );
4428 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4429 Entry *e, int idx, int tailindex, int use_ldif )
4431 struct berval ival, newrdn, nnewrdn;
4434 char ibuf[32], *ptr1, *ptr2 = NULL;
4437 rc = config_rename_attr( rs, e, &rdn, &a );
4438 if ( rc ) return rc;
4441 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4442 if ( ival.bv_len >= sizeof( ibuf ) ) {
4443 return LDAP_NAMING_VIOLATION;
4446 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4447 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4450 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4451 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4454 ptr2 = ber_bvchr( &rdn, '}' );
4458 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4460 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4461 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4462 a->a_desc->ad_cname.bv_len );
4464 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4465 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4469 /* Do the equivalent of ModRDN */
4470 /* Replace DN / NDN */
4471 newrdn.bv_len = ptr1 - newrdn.bv_val;
4472 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4473 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4475 free( nnewrdn.bv_val );
4476 free( newrdn.bv_val );
4481 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4482 SlapReply *rs, int *renum, int *ibase )
4485 int index = -1, gotindex = 0, nsibs, rc = 0;
4486 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4487 char *ptr1, *ptr2 = NULL;
4490 if ( renum ) *renum = 0;
4492 /* These entries don't get indexed/renumbered */
4493 if ( ce_type == Cft_Global ) return 0;
4494 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4496 if ( ce_type == Cft_Module )
4499 /* See if the rdn has an index already */
4500 dnRdn( &e->e_name, &rdn );
4501 if ( ce_type == Cft_Database ) {
4502 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4503 "frontend", STRLENOF("frontend") ))
4505 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4506 "config", STRLENOF("config") ))
4509 ptr1 = ber_bvchr( &e->e_name, '{' );
4510 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4512 ptr2 = strchr( ptr1, '}' );
4513 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4514 return LDAP_NAMING_VIOLATION;
4515 if ( ptr2-ptr1 == 1)
4516 return LDAP_NAMING_VIOLATION;
4518 index = strtol( ptr1 + 1, &next, 10 );
4519 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4520 return LDAP_NAMING_VIOLATION;
4523 /* Special case, we allow -1 for the frontendDB */
4524 if ( index != -1 || !isfrontend )
4525 return LDAP_NAMING_VIOLATION;
4527 if ( isconfig && index != 0 ){
4528 return LDAP_NAMING_VIOLATION;
4532 /* count related kids */
4533 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4534 if ( ce->ce_type == ce_type ) nsibs++;
4537 /* account for -1 frontend */
4538 if ( ce_type == Cft_Database )
4541 if ( index != nsibs ) {
4543 if ( index < nsibs ) {
4544 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4545 /* Siblings need to be renumbered */
4546 if ( index != -1 || !isfrontend )
4550 /* config DB is always "0" */
4551 if ( isconfig && index == -1 ) {
4554 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4558 /* just make index = nsibs */
4560 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4563 if ( ibase ) *ibase = index;
4564 if ( renum ) *renum = renumber;
4569 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4574 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4575 if ( count_oc( *sups, copp, nocs ) ) {
4580 co.co_name = &oc->soc_cname;
4581 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4585 /* check for duplicates */
4586 for ( i = 0; i < *nocs; i++ ) {
4587 if ( *copp && (*copp)[i] == cop ) {
4593 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4594 if ( tmp == NULL ) {
4598 (*copp)[*nocs] = cop;
4607 count_ocs( Attribute *oc_at, int *nocs )
4610 ConfigOCs **colst = NULL;
4614 for ( i = oc_at->a_numvals; i--; ) {
4615 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4617 assert( oc != NULL );
4618 if ( count_oc( oc, &colst, nocs ) ) {
4628 ConfigOCs *tmp = colst[i];
4629 colst[i] = colst[j];
4638 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4640 /* Leftover from RE23. Never parse this entry */
4641 return LDAP_COMPARE_TRUE;
4645 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4649 /* This entry is hardcoded, don't re-parse it */
4650 if ( p->ce_type == Cft_Global ) {
4651 cfn = p->ce_private;
4652 ca->ca_private = cfn;
4653 return LDAP_COMPARE_TRUE;
4655 if ( p->ce_type != Cft_Schema )
4656 return LDAP_CONSTRAINT_VIOLATION;
4658 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4659 ca->ca_private = cfn;
4660 cfo = p->ce_private;
4661 cfn->c_sibs = cfo->c_kids;
4663 return LDAP_SUCCESS;
4667 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4669 if ( p->ce_type != Cft_Global ) {
4670 return LDAP_CONSTRAINT_VIOLATION;
4672 /* config must be {0}, nothing else allowed */
4673 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4674 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4675 return LDAP_CONSTRAINT_VIOLATION;
4677 ca->be = frontendDB; /* just to get past check_vals */
4678 return LDAP_SUCCESS;
4682 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4684 if ( p->ce_type != Cft_Global ) {
4685 return LDAP_CONSTRAINT_VIOLATION;
4687 return LDAP_SUCCESS;
4691 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4693 if ( p->ce_type != Cft_Global ) {
4694 return LDAP_CONSTRAINT_VIOLATION;
4696 return LDAP_SUCCESS;
4700 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4702 if ( p->ce_type != Cft_Database ) {
4703 return LDAP_CONSTRAINT_VIOLATION;
4706 return LDAP_SUCCESS;
4710 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4715 AttributeDescription *ad;
4721 if ( cfn->c_cr_head ) {
4722 struct berval bv = BER_BVC("olcDitContentRules");
4724 slap_bv2ad( &bv, &ad, &text );
4725 ct = config_find_table( colst, nocs, ad, ca );
4726 config_del_vals( ct, ca );
4728 if ( cfn->c_oc_head ) {
4729 struct berval bv = BER_BVC("olcObjectClasses");
4731 slap_bv2ad( &bv, &ad, &text );
4732 ct = config_find_table( colst, nocs, ad, ca );
4733 config_del_vals( ct, ca );
4735 if ( cfn->c_at_head ) {
4736 struct berval bv = BER_BVC("olcAttributeTypes");
4738 slap_bv2ad( &bv, &ad, &text );
4739 ct = config_find_table( colst, nocs, ad, ca );
4740 config_del_vals( ct, ca );
4742 if ( cfn->c_syn_head ) {
4743 struct berval bv = BER_BVC("olcLdapSyntaxes");
4745 slap_bv2ad( &bv, &ad, &text );
4746 ct = config_find_table( colst, nocs, ad, ca );
4747 config_del_vals( ct, ca );
4749 if ( cfn->c_om_head ) {
4750 struct berval bv = BER_BVC("olcObjectIdentifier");
4752 slap_bv2ad( &bv, &ad, &text );
4753 ct = config_find_table( colst, nocs, ad, ca );
4754 config_del_vals( ct, ca );
4756 cfo = p->ce_private;
4757 cfo->c_kids = cfn->c_sibs;
4762 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4764 int rc = LDAP_CONSTRAINT_VIOLATION;
4767 if ( (*cop)->co_ldadd ) {
4768 rc = (*cop)->co_ldadd( last, e, ca );
4769 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4774 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4775 ConfigOCs co = { 0 };
4777 co.co_name = &(*ocp)->soc_cname;
4778 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4779 if ( *cop == NULL ) {
4783 rc = config_add_oc( cop, last, e, ca );
4784 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4792 /* Parse an LDAP entry into config directives */
4794 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4795 int *renum, Operation *op )
4797 CfEntryInfo *ce, *last = NULL;
4798 ConfigOCs co, *coptr, **colst;
4799 Attribute *a, *oc_at, *soc_at;
4800 int i, ibase = -1, nocs, rc = 0;
4803 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4805 memset( ca, 0, sizeof(ConfigArgs));
4807 /* Make sure parent exists and entry does not. But allow
4808 * Databases and Overlays to be inserted. Don't do any
4809 * auto-renumbering if manageDSAit control is present.
4811 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4813 if ( ( op && op->o_managedsait ) ||
4814 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4815 ce->ce_type != Cft_Module ) )
4817 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4818 "DN=\"%s\" already exists\n",
4819 log_prefix, e->e_name.bv_val, 0 );
4820 /* global schema ignores all writes */
4821 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4822 return LDAP_COMPARE_TRUE;
4823 return LDAP_ALREADY_EXISTS;
4827 dnParent( &e->e_nname, &pdn );
4829 /* If last is NULL, the new entry is the root/suffix entry,
4830 * otherwise last should be the parent.
4832 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4834 rs->sr_matched = last->ce_entry->e_name.bv_val;
4836 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4837 "DN=\"%s\" not child of DN=\"%s\"\n",
4838 log_prefix, e->e_name.bv_val,
4839 last->ce_entry->e_name.bv_val );
4840 return LDAP_NO_SUCH_OBJECT;
4844 /* No parent, must be root. This will never happen... */
4845 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4846 return LDAP_NO_SUCH_OBJECT;
4849 if ( last && !access_allowed( op, last->ce_entry,
4850 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4852 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4853 "DN=\"%s\" no write access to \"children\" of parent\n",
4854 log_prefix, e->e_name.bv_val, 0 );
4855 return LDAP_INSUFFICIENT_ACCESS;
4859 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4861 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4862 "DN=\"%s\" no objectClass\n",
4863 log_prefix, e->e_name.bv_val, 0 );
4864 return LDAP_OBJECT_CLASS_VIOLATION;
4867 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4869 ObjectClass *soc = NULL;
4870 char textbuf[ SLAP_TEXT_BUFLEN ];
4871 const char *text = textbuf;
4873 /* FIXME: check result */
4874 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4875 &text, textbuf, sizeof(textbuf), NULL );
4876 if ( rc != LDAP_SUCCESS ) {
4877 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4878 "DN=\"%s\" no structural objectClass (%s)\n",
4879 log_prefix, e->e_name.bv_val, text );
4882 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4883 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4884 if ( soc_at == NULL ) {
4885 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4886 "DN=\"%s\" no structural objectClass; "
4887 "unable to merge computed class %s\n",
4888 log_prefix, e->e_name.bv_val,
4889 soc->soc_cname.bv_val );
4890 return LDAP_OBJECT_CLASS_VIOLATION;
4893 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4894 "DN=\"%s\" no structural objectClass; "
4895 "computed objectClass %s merged\n",
4896 log_prefix, e->e_name.bv_val,
4897 soc->soc_cname.bv_val );
4900 /* Fake the coordinates based on whether we're part of an
4901 * LDAP Add or if reading the config dir
4904 ca->fname = "slapd";
4907 ca->fname = cfdir.bv_val;
4912 co.co_name = &soc_at->a_nvals[0];
4913 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4914 if ( coptr == NULL ) {
4915 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4916 "DN=\"%s\" no structural objectClass in configuration table\n",
4917 log_prefix, e->e_name.bv_val, 0 );
4918 return LDAP_OBJECT_CLASS_VIOLATION;
4921 /* Only the root can be Cft_Global, everything else must
4922 * have a parent. Only limited nesting arrangements are allowed.
4924 rc = LDAP_CONSTRAINT_VIOLATION;
4925 if ( coptr->co_type == Cft_Global && !last ) {
4926 cfn = cfb->cb_config;
4927 ca->ca_private = cfn;
4928 ca->be = frontendDB; /* just to get past check_vals */
4932 colst = count_ocs( oc_at, &nocs );
4934 /* Check whether the Add is allowed by its parent, and do
4935 * any necessary arg setup
4938 rc = config_add_oc( &coptr, last, e, ca );
4939 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4940 for ( i = 0; i<nocs; i++ ) {
4941 /* Already checked these */
4942 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4944 if ( colst[i]->co_ldadd &&
4945 ( rc = colst[i]->co_ldadd( last, e, ca ))
4946 != LDAP_CONSTRAINT_VIOLATION ) {
4952 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4953 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4954 "DN=\"%s\" no structural objectClass add function\n",
4955 log_prefix, e->e_name.bv_val, 0 );
4956 return LDAP_OBJECT_CLASS_VIOLATION;
4960 /* Add the entry but don't parse it, we already have its contents */
4961 if ( rc == LDAP_COMPARE_TRUE ) {
4966 if ( rc != LDAP_SUCCESS )
4969 /* Parse all the values and check for simple syntax errors before
4970 * performing any set actions.
4972 * If doing an LDAPadd, check for indexed names and any necessary
4973 * renaming/renumbering. Entries that don't need indexed names are
4974 * ignored. Entries that need an indexed name and arrive without one
4975 * are assigned to the end. Entries that arrive with an index may
4976 * cause the following entries to be renumbered/bumped down.
4978 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4979 * don't allow Adding an entry with an index that's already in use.
4980 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4982 * These entries can have auto-assigned indexes (appended to the end)
4983 * but only the other types support auto-renumbering of siblings.
4986 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4991 if ( renum && *renum && coptr->co_type != Cft_Database &&
4992 coptr->co_type != Cft_Overlay )
4994 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4995 "operation requires sibling renumbering" );
4996 rc = LDAP_UNWILLING_TO_PERFORM;
5001 init_config_argv( ca );
5003 /* Make sure we process attrs in the required order */
5004 sort_attrs( e, colst, nocs );
5006 for ( a = e->e_attrs; a; a = a->a_next ) {
5007 if ( a == oc_at ) continue;
5008 ct = config_find_table( colst, nocs, a->a_desc, ca );
5009 if ( !ct ) continue; /* user data? */
5010 rc = check_vals( ct, ca, a, 1 );
5011 if ( rc ) goto done_noop;
5014 /* Basic syntax checks are OK. Do the actual settings. */
5015 for ( a=e->e_attrs; a; a=a->a_next ) {
5016 if ( a == oc_at ) continue;
5017 ct = config_find_table( colst, nocs, a->a_desc, ca );
5018 if ( !ct ) continue; /* user data? */
5019 for (i=0; a->a_vals[i].bv_val; i++) {
5022 ca->line = a->a_vals[i].bv_val;
5023 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5024 ptr = strchr( ca->line, '}' );
5026 iptr = strchr( ca->line, '{' );
5030 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5032 ca->valx = strtol( iptr+1, NULL, 0 );
5037 rc = config_parse_add( ct, ca, i );
5045 /* Newly added databases and overlays need to be started up */
5046 if ( CONFIG_ONLINE_ADD( ca )) {
5047 if ( coptr->co_type == Cft_Database ) {
5048 rc = backend_startup_one( ca->be, &ca->reply );
5050 } else if ( coptr->co_type == Cft_Overlay ) {
5051 if ( ca->bi->bi_db_open ) {
5052 BackendInfo *bi_orig = ca->be->bd_info;
5053 ca->be->bd_info = ca->bi;
5054 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5055 ca->be->bd_info = bi_orig;
5057 } else if ( ca->cleanup ) {
5058 rc = ca->cleanup( ca );
5061 if (ca->cr_msg[0] == '\0')
5062 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5064 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5065 ca->log, ca->cr_msg, ca->argv[1] );
5072 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5073 ce->ce_parent = last;
5074 ce->ce_entry = entry_dup( e );
5075 ce->ce_entry->e_private = ce;
5076 ce->ce_type = coptr->co_type;
5079 ce->ce_private = ca->ca_private;
5080 ca->ca_entry = ce->ce_entry;
5083 } else if ( last->ce_kids ) {
5084 CfEntryInfo *c2, **cprev;
5086 /* Advance to first of this type */
5087 cprev = &last->ce_kids;
5088 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5089 cprev = &c2->ce_sibs;
5092 /* Account for the (-1) frontendDB entry */
5093 if ( ce->ce_type == Cft_Database ) {
5094 if ( ca->be == frontendDB )
5096 else if ( ibase != -1 )
5101 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5102 cprev = &c2->ce_sibs;
5108 for ( i=0; i<ibase; i++ ) {
5110 cprev = &c2->ce_sibs;
5113 ce->ce_sibs = *cprev;
5121 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5122 if ( ca->be != frontendDB )
5123 backend_destroy_one( ca->be, 1 );
5124 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5125 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5126 } else if ( coptr->co_type == Cft_Schema ) {
5127 schema_destroy_one( ca, colst, nocs, last );
5132 ch_free( ca->argv );
5133 if ( colst ) ch_free( colst );
5137 #define BIGTMP 10000
5139 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5140 int base, int rebase, int max, int use_ldif )
5142 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5143 ConfigType etype = ce->ce_type;
5144 int count = 0, rc = 0;
5146 /* Reverse ce list */
5147 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5148 if (ce2->ce_type != etype) {
5153 ce2->ce_sibs = cetmp;
5156 if ( max && count >= max ) {
5162 /* Move original to a temp name until increments are done */
5164 ce->ce_entry->e_private = NULL;
5165 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5166 base+BIGTMP, 0, use_ldif );
5167 ce->ce_entry->e_private = ce;
5169 /* start incrementing */
5170 for (ce2=cetmp; ce2; ce2=ce3) {
5172 ce2->ce_sibs = cerem;
5175 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5176 count+base, 0, use_ldif );
5180 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5181 base, 0, use_ldif );
5186 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5187 CfEntryInfo *ce2, int old, int use_ldif )
5191 /* Renumber original to a temp value */
5192 ce->ce_entry->e_private = NULL;
5193 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5194 old+BIGTMP, 0, use_ldif );
5195 ce->ce_entry->e_private = ce;
5197 /* start decrementing */
5198 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5199 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5200 count+old, 0, use_ldif );
5203 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5204 count+old, 0, use_ldif );
5207 /* Parse an LDAP entry into config directives, then store in underlying
5211 config_back_add( Operation *op, SlapReply *rs )
5217 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5218 NULL, ACL_WADD, NULL )) {
5219 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5224 * Check for attribute ACL
5226 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5227 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5228 rs->sr_text = "no write access to attribute";
5232 cfb = (CfBackInfo *)op->o_bd->be_private;
5234 /* add opattrs for syncprov */
5236 char textbuf[SLAP_TEXT_BUFLEN];
5237 size_t textlen = sizeof textbuf;
5238 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5239 &rs->sr_text, textbuf, sizeof( textbuf ) );
5240 if ( rs->sr_err != LDAP_SUCCESS )
5242 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5243 if ( rs->sr_err != LDAP_SUCCESS ) {
5244 Debug( LDAP_DEBUG_TRACE,
5245 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5246 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5251 if ( op->o_abandon ) {
5252 rs->sr_err = SLAPD_ABANDON;
5255 ldap_pvt_thread_pool_pause( &connection_pool );
5258 * 1) check for existence of entry
5259 * 2) check for sibling renumbering
5260 * 3) perform internal add
5261 * 4) perform any necessary renumbering
5262 * 5) store entry in underlying database
5264 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5265 if ( rs->sr_err != LDAP_SUCCESS ) {
5266 rs->sr_text = ca.cr_msg;
5271 CfEntryInfo *ce = ca.ca_entry->e_private;
5272 req_add_s addr = op->oq_add;
5273 op->o_tag = LDAP_REQ_MODRDN;
5274 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5275 op->o_tag = LDAP_REQ_ADD;
5277 if ( rs->sr_err != LDAP_SUCCESS ) {
5282 if ( cfb->cb_use_ldif ) {
5283 BackendDB *be = op->o_bd;
5284 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5285 struct berval dn, ndn;
5287 op->o_bd = &cfb->cb_db;
5289 /* Save current rootdn; use the underlying DB's rootdn */
5292 op->o_dn = op->o_bd->be_rootdn;
5293 op->o_ndn = op->o_bd->be_rootndn;
5295 scp = op->o_callback;
5296 op->o_callback = ≻
5297 op->o_bd->be_add( op, rs );
5299 op->o_callback = scp;
5305 ldap_pvt_thread_pool_resume( &connection_pool );
5308 { int repl = op->o_dont_replicate;
5309 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5310 rs->sr_text = NULL; /* Set after config_add_internal */
5311 rs->sr_err = LDAP_SUCCESS;
5312 op->o_dont_replicate = 1;
5314 send_ldap_result( op, rs );
5315 op->o_dont_replicate = repl;
5317 slap_graduate_commit_csn( op );
5321 typedef struct delrec {
5322 struct delrec *next;
5328 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5334 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5335 ca->line[0] == '{' )
5337 char *ptr = strchr( ca->line + 1, '}' );
5341 ca->valx = strtol( ca->line + 1, &next, 0 );
5342 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5348 rc = config_parse_add( ct, ca, i );
5356 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5359 int rc = LDAP_UNWILLING_TO_PERFORM;
5361 Entry *e = ce->ce_entry;
5362 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5367 delrec *dels = NULL, *deltail = NULL;
5369 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5370 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5372 colst = count_ocs( oc_at, &nocs );
5374 /* make sure add/del flags are clear; should always be true */
5375 for ( s = save_attrs; s; s = s->a_next ) {
5376 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5379 e->e_attrs = attrs_dup( e->e_attrs );
5381 init_config_argv( ca );
5384 ca->ca_private = ce->ce_private;
5386 ca->fname = "slapd";
5388 strcpy( ca->log, "back-config" );
5390 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5391 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5392 switch (ml->sml_op) {
5393 case LDAP_MOD_DELETE:
5394 case LDAP_MOD_REPLACE: {
5395 BerVarray vals = NULL, nvals = NULL;
5397 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5399 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5400 ml->sml_desc->ad_cname.bv_val );
5403 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5404 vals = ml->sml_values;
5405 nvals = ml->sml_nvalues;
5406 ml->sml_values = NULL;
5407 ml->sml_nvalues = NULL;
5409 /* If we're deleting by values, remember the indexes of the
5410 * values we deleted.
5412 if ( ct && ml->sml_values ) {
5414 i = ml->sml_numvals;
5415 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5426 rc = modify_delete_vindex(e, &ml->sml_mod,
5427 get_permissiveModify(op),
5428 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5429 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5430 ml->sml_values = vals;
5431 ml->sml_nvalues = nvals;
5436 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5439 case SLAP_MOD_SOFTADD: {
5440 int mop = ml->sml_op;
5442 ml->sml_op = LDAP_MOD_ADD;
5444 if ( ct->arg_type & ARG_NO_INSERT ) {
5445 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5447 navals = a->a_numvals;
5450 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5451 if ( ml->sml_values[i].bv_val[0] == '{' &&
5454 char *next, *val = ml->sml_values[i].bv_val + 1;
5457 j = strtol( val, &next, 0 );
5458 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5460 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5461 ml->sml_desc->ad_cname.bv_val );
5465 rc = check_vals( ct, ca, ml, 0 );
5466 if ( rc ) goto out_noop;
5469 rc = modify_add_values(e, &ml->sml_mod,
5470 get_permissiveModify(op),
5471 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5473 /* If value already exists, show success here
5474 * and ignore this operation down below.
5476 if ( mop == SLAP_MOD_SOFTADD ) {
5477 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5487 case LDAP_MOD_INCREMENT: /* FIXME */
5492 if(rc != LDAP_SUCCESS) break;
5495 if ( rc == LDAP_SUCCESS) {
5496 /* check that the entry still obeys the schema */
5497 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5498 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5500 if ( rc ) goto out_noop;
5502 /* Basic syntax checks are OK. Do the actual settings. */
5503 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5504 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5505 if ( !ct ) continue;
5507 s = attr_find( save_attrs, ml->sml_desc );
5508 a = attr_find( e->e_attrs, ml->sml_desc );
5510 switch (ml->sml_op) {
5511 case LDAP_MOD_DELETE:
5512 case LDAP_MOD_REPLACE: {
5513 BerVarray vals = NULL, nvals = NULL;
5516 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5517 vals = ml->sml_values;
5518 nvals = ml->sml_nvalues;
5519 ml->sml_values = NULL;
5520 ml->sml_nvalues = NULL;
5523 if ( ml->sml_values )
5526 /* If we didn't delete the whole attribute */
5527 if ( ml->sml_values && a ) {
5528 struct berval *mvals;
5531 if ( ml->sml_nvalues )
5532 mvals = ml->sml_nvalues;
5534 mvals = ml->sml_values;
5536 /* use the indexes we saved up above */
5537 for (i=0; i < d->nidx; i++) {
5538 struct berval bv = *mvals++;
5539 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5540 bv.bv_val[0] == '{' ) {
5541 ptr = strchr( bv.bv_val, '}' ) + 1;
5542 bv.bv_len -= ptr - bv.bv_val;
5545 ca->line = bv.bv_val;
5546 ca->valx = d->idx[i];
5547 config_parse_vals(ct, ca, d->idx[i] );
5548 rc = config_del_vals( ct, ca );
5549 if ( rc != LDAP_SUCCESS ) break;
5551 s->a_flags |= SLAP_ATTR_IXDEL;
5552 for (j=i+1; j < d->nidx; j++)
5553 if ( d->idx[j] >d->idx[i] )
5560 rc = config_del_vals( ct, ca );
5561 if ( rc ) rc = LDAP_OTHER;
5563 s->a_flags |= SLAP_ATTR_IXDEL;
5565 if ( ml->sml_values ) {
5570 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5571 ml->sml_values = vals;
5572 ml->sml_nvalues = nvals;
5574 if ( !vals || rc != LDAP_SUCCESS )
5577 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5580 for (i=0; ml->sml_values[i].bv_val; i++) {
5581 ca->line = ml->sml_values[i].bv_val;
5583 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5586 a->a_flags |= SLAP_ATTR_IXADD;
5593 /* Undo for a failed operation */
5594 if ( rc != LDAP_SUCCESS ) {
5595 ConfigReply msg = ca->reply;
5596 for ( s = save_attrs; s; s = s->a_next ) {
5597 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5598 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5599 ct = config_find_table( colst, nocs, s->a_desc, ca );
5600 a = attr_find( e->e_attrs, s->a_desc );
5602 /* clear the flag so the add check below will skip it */
5603 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5607 config_del_vals( ct, ca );
5609 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5610 ca->line = s->a_vals[i].bv_val;
5612 config_modify_add( ct, ca, s->a_desc, i );
5616 for ( a = e->e_attrs; a; a = a->a_next ) {
5617 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5618 ct = config_find_table( colst, nocs, a->a_desc, ca );
5622 config_del_vals( ct, ca );
5623 s = attr_find( save_attrs, a->a_desc );
5625 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5626 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5627 ca->line = s->a_vals[i].bv_val;
5629 config_modify_add( ct, ca, s->a_desc, i );
5640 if ( rc == LDAP_SUCCESS ) {
5641 attrs_free( save_attrs );
5644 attrs_free( e->e_attrs );
5645 e->e_attrs = save_attrs;
5647 ch_free( ca->argv );
5648 if ( colst ) ch_free( colst );
5650 deltail = dels->next;
5659 config_back_modify( Operation *op, SlapReply *rs )
5662 CfEntryInfo *ce, *last;
5664 ConfigArgs ca = {0};
5667 AttributeDescription *rad = NULL;
5670 cfb = (CfBackInfo *)op->o_bd->be_private;
5672 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5675 rs->sr_matched = last->ce_entry->e_name.bv_val;
5676 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5680 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5681 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5685 /* Get type of RDN */
5686 rdn = ce->ce_entry->e_nname;
5687 ptr = strchr( rdn.bv_val, '=' );
5688 rdn.bv_len = ptr - rdn.bv_val;
5689 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5690 if ( rs->sr_err != LDAP_SUCCESS ) {
5694 /* Some basic validation... */
5695 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5696 /* Don't allow Modify of RDN; must use ModRdn for that. */
5697 if ( ml->sml_desc == rad ) {
5698 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5699 rs->sr_text = "Use modrdn to change the entry name";
5702 /* Internal update of contextCSN? */
5703 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5709 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5712 if ( op->o_abandon ) {
5713 rs->sr_err = SLAPD_ABANDON;
5716 ldap_pvt_thread_pool_pause( &connection_pool );
5720 * 1) perform the Modify on the cached Entry.
5721 * 2) verify that the Entry still satisfies the schema.
5722 * 3) perform the individual config operations.
5723 * 4) store Modified entry in underlying LDIF backend.
5725 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5727 rs->sr_text = ca.cr_msg;
5728 } else if ( cfb->cb_use_ldif ) {
5729 BackendDB *be = op->o_bd;
5730 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5731 struct berval dn, ndn;
5733 op->o_bd = &cfb->cb_db;
5737 op->o_dn = op->o_bd->be_rootdn;
5738 op->o_ndn = op->o_bd->be_rootndn;
5740 scp = op->o_callback;
5741 op->o_callback = ≻
5742 op->o_bd->be_modify( op, rs );
5744 op->o_callback = scp;
5750 ldap_pvt_thread_pool_resume( &connection_pool );
5752 send_ldap_result( op, rs );
5753 slap_graduate_commit_csn( op );
5758 config_back_modrdn( Operation *op, SlapReply *rs )
5761 CfEntryInfo *ce, *last;
5765 cfb = (CfBackInfo *)op->o_bd->be_private;
5767 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5770 rs->sr_matched = last->ce_entry->e_name.bv_val;
5771 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5774 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5775 NULL, ACL_WRITE, NULL )) {
5776 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5780 if ( ce->ce_parent )
5781 parent = ce->ce_parent->ce_entry;
5783 parent = (Entry *)&slap_entry_root;
5784 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5785 NULL, ACL_WRITE, NULL )) {
5786 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5791 /* We don't allow moving objects to new parents.
5792 * Generally we only allow reordering a set of ordered entries.
5794 if ( op->orr_newSup ) {
5795 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5799 /* If newRDN == oldRDN, quietly succeed */
5800 dnRdn( &op->o_req_ndn, &rdn );
5801 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5802 rs->sr_err = LDAP_SUCCESS;
5806 /* Current behavior, subject to change as needed:
5808 * For backends and overlays, we only allow renumbering.
5809 * For schema, we allow renaming with the same number.
5810 * Otherwise, the op is not allowed.
5813 if ( ce->ce_type == Cft_Schema ) {
5817 /* Can't alter the main cn=schema entry */
5818 if ( ce->ce_parent->ce_type == Cft_Global ) {
5819 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5820 rs->sr_text = "renaming not allowed for this entry";
5824 /* We could support this later if desired */
5825 ptr1 = ber_bvchr( &rdn, '}' );
5826 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5827 len = ptr1 - rdn.bv_val;
5828 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5829 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5830 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5831 rs->sr_text = "schema reordering not supported";
5834 } else if ( ce->ce_type == Cft_Database ||
5835 ce->ce_type == Cft_Overlay ) {
5836 char *ptr1, *ptr2, *iptr1, *iptr2;
5839 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5840 if ( *iptr2 != '{' ) {
5841 rs->sr_err = LDAP_NAMING_VIOLATION;
5842 rs->sr_text = "new ordering index is required";
5846 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5847 ptr1 = ber_bvchr( &rdn, '}' );
5848 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5850 rs->sr_err = LDAP_NAMING_VIOLATION;
5851 rs->sr_text = "new ordering index is required";
5855 len1 = ptr1 - rdn.bv_val;
5856 len2 = ptr2 - op->orr_newrdn.bv_val;
5858 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5859 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5860 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5861 rs->sr_text = "changing database/overlay type not allowed";
5864 ixold = strtol( iptr1, NULL, 0 );
5865 ixnew = strtol( iptr2, &ptr1, 0 );
5866 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5867 rs->sr_err = LDAP_NAMING_VIOLATION;
5870 /* config DB is always 0, cannot be changed */
5871 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5872 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5876 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5877 rs->sr_text = "renaming not supported for this entry";
5881 if ( op->o_abandon ) {
5882 rs->sr_err = SLAPD_ABANDON;
5885 ldap_pvt_thread_pool_pause( &connection_pool );
5887 if ( ce->ce_type == Cft_Schema ) {
5888 req_modrdn_s modr = op->oq_modrdn;
5891 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5892 if ( rs->sr_err == LDAP_SUCCESS ) {
5893 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5894 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5897 op->oq_modrdn = modr;
5899 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5900 req_modrdn_s modr = op->oq_modrdn;
5903 /* Advance to first of this type */
5904 cprev = &ce->ce_parent->ce_kids;
5905 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5906 cprev = &ce2->ce_sibs;
5909 /* Skip the -1 entry */
5910 if ( ce->ce_type == Cft_Database ) {
5911 cprev = &ce2->ce_sibs;
5917 /* Remove from old slot */
5918 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5919 cprev = &ce2->ce_sibs;
5920 *cprev = ce->ce_sibs;
5921 ceold = ce->ce_sibs;
5923 /* Insert into new slot */
5925 for ( i=0; i<ixnew; i++ ) {
5929 cprev = &ce2->ce_sibs;
5931 ce->ce_sibs = *cprev;
5936 /* NOTE: These should be encoded in the OC tables, not inline here */
5937 if ( ce->ce_type == Cft_Database )
5938 backend_db_move( ce->ce_be, ixnew );
5939 else if ( ce->ce_type == Cft_Overlay )
5940 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5942 if ( ixold < ixnew ) {
5943 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5946 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5947 ixold - ixnew, cfb->cb_use_ldif );
5949 op->oq_modrdn = modr;
5952 ldap_pvt_thread_pool_resume( &connection_pool );
5954 send_ldap_result( op, rs );
5959 config_back_delete( Operation *op, SlapReply *rs )
5961 #ifdef SLAP_CONFIG_DELETE
5963 CfEntryInfo *ce, *last, *ce2;
5965 cfb = (CfBackInfo *)op->o_bd->be_private;
5967 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5970 rs->sr_matched = last->ce_entry->e_name.bv_val;
5971 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5972 } else if ( ce->ce_kids ) {
5973 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5974 } else if ( op->o_abandon ) {
5975 rs->sr_err = SLAPD_ABANDON;
5976 } else if ( ce->ce_type == Cft_Overlay ){
5980 ldap_pvt_thread_pool_pause( &connection_pool );
5982 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5984 /* remove CfEntryInfo from the siblings list */
5985 if ( ce->ce_parent->ce_kids == ce ) {
5986 ce->ce_parent->ce_kids = ce->ce_sibs;
5988 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5989 if ( ce2->ce_sibs == ce ) {
5990 ce2->ce_sibs = ce->ce_sibs;
5996 /* remove from underlying database */
5997 if ( cfb->cb_use_ldif ) {
5998 BackendDB *be = op->o_bd;
5999 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6000 struct berval dn, ndn, req_dn, req_ndn;
6002 op->o_bd = &cfb->cb_db;
6006 req_dn = op->o_req_dn;
6007 req_ndn = op->o_req_ndn;
6009 op->o_dn = op->o_bd->be_rootdn;
6010 op->o_ndn = op->o_bd->be_rootndn;
6011 op->o_req_dn = ce->ce_entry->e_name;
6012 op->o_req_ndn = ce->ce_entry->e_nname;
6014 scp = op->o_callback;
6015 op->o_callback = ≻
6016 op->o_bd->be_delete( op, rs );
6018 op->o_callback = scp;
6021 op->o_req_dn = req_dn;
6022 op->o_req_ndn = req_ndn;
6025 /* renumber siblings */
6026 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6027 ixold = strtol( iptr, NULL, 0 );
6028 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6029 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6030 count+ixold, 0, cfb->cb_use_ldif );
6034 ce->ce_entry->e_private=NULL;
6035 entry_free(ce->ce_entry);
6037 ldap_pvt_thread_pool_resume( &connection_pool );
6039 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6042 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6043 #endif /* SLAP_CONFIG_DELETE */
6044 send_ldap_result( op, rs );
6049 config_back_search( Operation *op, SlapReply *rs )
6052 CfEntryInfo *ce, *last;
6055 cfb = (CfBackInfo *)op->o_bd->be_private;
6057 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6060 rs->sr_matched = last->ce_entry->e_name.bv_val;
6061 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6064 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6065 ACL_SEARCH, NULL, &mask ))
6067 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6068 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6070 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6074 switch ( op->ors_scope ) {
6075 case LDAP_SCOPE_BASE:
6076 case LDAP_SCOPE_SUBTREE:
6077 rs->sr_err = config_send( op, rs, ce, 0 );
6080 case LDAP_SCOPE_ONELEVEL:
6081 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6082 rs->sr_err = config_send( op, rs, ce, 1 );
6091 send_ldap_result( op, rs );
6095 /* no-op, we never free entries */
6096 int config_entry_release(
6101 if ( !e->e_private ) {
6104 return LDAP_SUCCESS;
6107 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6109 int config_back_entry_get(
6113 AttributeDescription *at,
6118 CfEntryInfo *ce, *last;
6119 int rc = LDAP_NO_SUCH_OBJECT;
6121 cfb = (CfBackInfo *)op->o_bd->be_private;
6123 ce = config_find_base( cfb->cb_root, ndn, &last );
6125 *ent = ce->ce_entry;
6128 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6129 rc = LDAP_NO_SUCH_ATTRIBUTE;
6139 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6140 ConfigTable *ct, ConfigArgs *c )
6144 for (; at && *at; at++) {
6145 /* Skip the naming attr */
6146 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6148 for (i=0;ct[i].name;i++) {
6149 if (ct[i].ad == (*at)->sat_ad) {
6150 rc = config_get_vals(&ct[i], c);
6151 /* NOTE: tolerate that config_get_vals()
6152 * returns success with no values */
6153 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6154 if ( c->rvalue_nvals )
6155 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6158 slap_syntax_validate_func *validate =
6159 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6162 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6163 rc = ordered_value_validate( ct[i].ad,
6164 &c->rvalue_vals[j], LDAP_MOD_ADD );
6166 Debug( LDAP_DEBUG_ANY,
6167 "config_build_attrs: error %d on %s value #%d\n",
6168 rc, ct[i].ad->ad_cname.bv_val, j );
6174 rc = attr_merge_normalize(e, ct[i].ad,
6175 c->rvalue_vals, NULL);
6177 ber_bvarray_free( c->rvalue_nvals );
6178 ber_bvarray_free( c->rvalue_vals );
6180 Debug( LDAP_DEBUG_ANY,
6181 "config_build_attrs: error %d on %s\n",
6182 rc, ct[i].ad->ad_cname.bv_val, 0 );
6193 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6196 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6197 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6199 Entry *e = entry_alloc();
6200 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6202 struct berval ad_name;
6203 AttributeDescription *ad = NULL;
6206 const char *text = "";
6210 CfEntryInfo *ceprev = NULL;
6212 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6215 ce->ce_type = main->co_type;
6216 ce->ce_parent = parent;
6218 pdn = parent->ce_entry->e_nname;
6219 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6220 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6221 ceprev->ce_type <= ce->ce_type;
6222 ceprev = ceprev->ce_sibs );
6227 ce->ce_private = c->ca_private;
6231 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6232 ber_dupbv( &e->e_nname, &e->e_name );
6234 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6235 main->co_name, NULL );
6237 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6238 extra->co_name, NULL );
6239 ptr = strchr(rdn->bv_val, '=');
6240 ad_name.bv_val = rdn->bv_val;
6241 ad_name.bv_len = ptr - rdn->bv_val;
6242 rc = slap_bv2ad( &ad_name, &ad, &text );
6247 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6248 attr_merge_normalize_one(e, ad, &val, NULL );
6251 c->table = main->co_type;
6252 if ( oc->soc_required ) {
6253 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6254 if ( rc ) goto fail;
6257 if ( oc->soc_allowed ) {
6258 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6259 if ( rc ) goto fail;
6264 c->table = extra->co_type;
6265 if ( oc->soc_required ) {
6266 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6267 if ( rc ) goto fail;
6270 if ( oc->soc_allowed ) {
6271 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6272 if ( rc ) goto fail;
6276 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6277 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6278 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6279 if ( rc != LDAP_SUCCESS ) {
6281 Debug( LDAP_DEBUG_ANY,
6282 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6283 rdn->bv_val, text, 0);
6286 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6289 op->ora_modlist = NULL;
6290 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6291 if ( !op->o_noop ) {
6292 SlapReply rs2 = {REP_RESULT};
6293 op->o_bd->be_add( op, &rs2 );
6294 rs->sr_err = rs2.sr_err;
6295 rs_assert_done( &rs2 );
6296 if ( ( rs2.sr_err != LDAP_SUCCESS )
6297 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6303 ce->ce_sibs = ceprev->ce_sibs;
6304 ceprev->ce_sibs = ce;
6305 } else if ( parent ) {
6306 ce->ce_sibs = parent->ce_kids;
6307 parent->ce_kids = ce;
6314 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6315 Operation *op, SlapReply *rs )
6318 ConfigFile *cf = c->ca_private;
6320 struct berval bv, rdn;
6322 for (; cf; cf=cf->c_sibs, c->depth++) {
6323 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6324 !cf->c_om_head && !cf->c_syn_head ) continue;
6325 c->value_dn.bv_val = c->log;
6326 LUTIL_SLASHPATH( cf->c_file.bv_val );
6327 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6332 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6334 ptr = strchr( bv.bv_val, '.' );
6336 bv.bv_len = ptr - bv.bv_val;
6337 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6338 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6339 /* FIXME: how can indicate error? */
6342 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6344 c->value_dn.bv_len += bv.bv_len;
6345 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6349 e = config_build_entry( op, rs, ceparent, c, &rdn,
6350 &CFOC_SCHEMA, NULL );
6353 } else if ( e && cf->c_kids ) {
6354 c->ca_private = cf->c_kids;
6355 config_build_schema_inc( c, e->e_private, op, rs );
6361 #ifdef SLAPD_MODULES
6364 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6365 Operation *op, SlapReply *rs )
6370 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6371 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6373 c->value_dn.bv_val = c->log;
6374 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6375 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6376 /* FIXME: how can indicate error? */
6380 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6389 config_check_schema(Operation *op, CfBackInfo *cfb)
6391 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6393 CfEntryInfo *ce, *last;
6396 /* If there's no root entry, we must be in the midst of converting */
6397 if ( !cfb->cb_root )
6400 /* Make sure the main schema entry exists */
6401 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6408 /* Make sure it's up to date */
6409 if ( cf_om_tail != om_sys_tail ) {
6410 a = attr_find( e->e_attrs, cfAd_om );
6412 if ( a->a_nvals != a->a_vals )
6413 ber_bvarray_free( a->a_nvals );
6414 ber_bvarray_free( a->a_vals );
6419 oidm_unparse( &bv, NULL, NULL, 1 );
6420 attr_merge_normalize( e, cfAd_om, bv, NULL );
6421 ber_bvarray_free( bv );
6422 cf_om_tail = om_sys_tail;
6424 if ( cf_at_tail != at_sys_tail ) {
6425 a = attr_find( e->e_attrs, cfAd_attr );
6427 if ( a->a_nvals != a->a_vals )
6428 ber_bvarray_free( a->a_nvals );
6429 ber_bvarray_free( a->a_vals );
6434 at_unparse( &bv, NULL, NULL, 1 );
6435 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6436 ber_bvarray_free( bv );
6437 cf_at_tail = at_sys_tail;
6439 if ( cf_oc_tail != oc_sys_tail ) {
6440 a = attr_find( e->e_attrs, cfAd_oc );
6442 if ( a->a_nvals != a->a_vals )
6443 ber_bvarray_free( a->a_nvals );
6444 ber_bvarray_free( a->a_vals );
6449 oc_unparse( &bv, NULL, NULL, 1 );
6450 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6451 ber_bvarray_free( bv );
6452 cf_oc_tail = oc_sys_tail;
6454 if ( cf_syn_tail != syn_sys_tail ) {
6455 a = attr_find( e->e_attrs, cfAd_syntax );
6457 if ( a->a_nvals != a->a_vals )
6458 ber_bvarray_free( a->a_nvals );
6459 ber_bvarray_free( a->a_vals );
6464 syn_unparse( &bv, NULL, NULL, 1 );
6465 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6466 ber_bvarray_free( bv );
6467 cf_syn_tail = syn_sys_tail;
6470 SlapReply rs = {REP_RESULT};
6471 c.ca_private = NULL;
6472 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6473 &CFOC_SCHEMA, NULL );
6478 ce->ce_private = cfb->cb_config;
6479 cf_at_tail = at_sys_tail;
6480 cf_oc_tail = oc_sys_tail;
6481 cf_om_tail = om_sys_tail;
6482 cf_syn_tail = syn_sys_tail;
6487 static const char *defacl[] = {
6488 NULL, "to", "*", "by", "*", "none", NULL
6492 config_back_db_open( BackendDB *be, ConfigReply *cr )
6494 CfBackInfo *cfb = be->be_private;
6497 CfEntryInfo *ce, *ceparent;
6501 Connection conn = {0};
6502 OperationBuffer opbuf;
6504 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6505 SlapReply rs = {REP_RESULT};
6506 void *thrctx = NULL;
6508 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6510 /* If we have no explicitly configured ACLs, don't just use
6511 * the global ACLs. Explicitly deny access to everything.
6513 if ( !be->bd_self->be_acl ) {
6514 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6517 thrctx = ldap_pvt_thread_pool_context();
6518 connection_fake_init( &conn, &opbuf, thrctx );
6521 op->o_tag = LDAP_REQ_ADD;
6522 op->o_callback = &cb;
6523 op->o_bd = &cfb->cb_db;
6524 op->o_dn = op->o_bd->be_rootdn;
6525 op->o_ndn = op->o_bd->be_rootndn;
6527 if ( !cfb->cb_use_ldif ) {
6531 /* If we read the config from back-ldif, do some quick sanity checks */
6532 if ( cfb->cb_got_ldif ) {
6533 return config_check_schema( op, cfb );
6536 /* create root of tree */
6538 c.ca_private = cfb->cb_config;
6540 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6550 #ifdef SLAPD_MODULES
6551 /* Create Module nodes... */
6552 if ( modpaths.mp_loads ) {
6553 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6559 /* Create schema nodes... cn=schema will contain the hardcoded core
6560 * schema, read-only. Child objects will contain runtime loaded schema
6564 c.ca_private = NULL;
6565 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6570 ce->ce_private = cfb->cb_config;
6571 cf_at_tail = at_sys_tail;
6572 cf_oc_tail = oc_sys_tail;
6573 cf_om_tail = om_sys_tail;
6574 cf_syn_tail = syn_sys_tail;
6576 /* Create schema nodes for included schema... */
6577 if ( cfb->cb_config->c_kids ) {
6580 c.ca_private = cfb->cb_config->c_kids;
6581 rc = config_build_schema_inc( &c, ce, op, &rs );
6587 /* Create backend nodes. Skip if they don't provide a cf_table.
6588 * There usually aren't any of these.
6592 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6593 if (!bi->bi_cf_ocs) {
6594 /* If it only supports the old config mech, complain. */
6595 if ( bi->bi_config ) {
6596 Debug( LDAP_DEBUG_ANY,
6597 "WARNING: No dynamic config support for backend %s.\n",
6598 bi->bi_type, 0, 0 );
6603 if (!bi->bi_private) continue;
6606 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6607 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6608 if ( rdn.bv_len >= sizeof( c.log ) ) {
6609 /* FIXME: holler ... */ ;
6612 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6619 /* Create database nodes... */
6620 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6621 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6622 for ( i = -1, be = frontendDB ; be;
6623 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6624 slap_overinfo *oi = NULL;
6626 if ( overlay_is_over( be )) {
6627 oi = be->bd_info->bi_private;
6633 /* If this backend supports the old config mechanism, but not
6634 * the new mech, complain.
6636 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6637 Debug( LDAP_DEBUG_ANY,
6638 "WARNING: No dynamic config support for database %s.\n",
6639 bi->bi_type, 0, 0 );
6643 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6644 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6646 if ( rdn.bv_len >= sizeof( c.log ) ) {
6647 /* FIXME: holler ... */ ;
6651 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6657 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6658 rs_reinit( &rs, REP_RESULT );
6659 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6661 /* Iterate through overlays */
6666 voidList *vl, *v0 = NULL;
6668 /* overlays are in LIFO order, must reverse stack */
6669 for (on=oi->oi_list; on; on=on->on_next) {
6670 vl = ch_malloc( sizeof( voidList ));
6675 for (j=0; vl; j++,vl=v0) {
6679 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6680 Debug( LDAP_DEBUG_ANY,
6681 "WARNING: No dynamic config support for overlay %s.\n",
6682 on->on_bi.bi_type, 0, 0 );
6686 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6687 "%s=" SLAP_X_ORDERED_FMT "%s",
6688 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6689 if ( rdn.bv_len >= sizeof( c.log ) ) {
6690 /* FIXME: holler ... */ ;
6694 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6695 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6699 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6700 rs_reinit( &rs, REP_RESULT );
6701 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6707 ldap_pvt_thread_pool_context_reset( thrctx );
6709 if ( unsupp && cfb->cb_use_ldif ) {
6710 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6711 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6718 cfb_free_cffile( ConfigFile *cf )
6722 for (; cf; cf=next) {
6725 cfb_free_cffile( cf->c_kids );
6726 ch_free( cf->c_file.bv_val );
6727 ber_bvarray_free( cf->c_dseFiles );
6733 cfb_free_entries( CfEntryInfo *ce )
6737 for (; ce; ce=next) {
6740 cfb_free_entries( ce->ce_kids );
6741 ce->ce_entry->e_private = NULL;
6742 entry_free( ce->ce_entry );
6748 config_back_db_close( BackendDB *be, ConfigReply *cr )
6750 CfBackInfo *cfb = be->be_private;
6752 cfb_free_entries( cfb->cb_root );
6753 cfb->cb_root = NULL;
6755 if ( cfb->cb_db.bd_info ) {
6756 backend_shutdown( &cfb->cb_db );
6763 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6765 CfBackInfo *cfb = be->be_private;
6767 cfb_free_cffile( cfb->cb_config );
6769 ch_free( cfdir.bv_val );
6771 avl_free( CfOcTree, NULL );
6773 if ( cfb->cb_db.bd_info ) {
6774 cfb->cb_db.be_suffix = NULL;
6775 cfb->cb_db.be_nsuffix = NULL;
6776 BER_BVZERO( &cfb->cb_db.be_rootdn );
6777 BER_BVZERO( &cfb->cb_db.be_rootndn );
6779 backend_destroy_one( &cfb->cb_db, 0 );
6788 config_back_db_init( BackendDB *be, ConfigReply* cr )
6794 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6795 cfn = cfb->cb_config;
6796 be->be_private = cfb;
6798 ber_dupbv( &be->be_rootdn, &config_rdn );
6799 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6800 ber_dupbv( &dn, &be->be_rootdn );
6801 ber_bvarray_add( &be->be_suffix, &dn );
6802 ber_dupbv( &dn, &be->be_rootdn );
6803 ber_bvarray_add( &be->be_nsuffix, &dn );
6805 /* Hide from namingContexts */
6806 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6808 /* Check ACLs on content of Adds by default */
6809 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6815 config_back_destroy( BackendInfo *bi )
6817 ldif_must_b64_encode_release();
6822 config_tool_entry_open( BackendDB *be, int mode )
6824 CfBackInfo *cfb = be->be_private;
6825 BackendInfo *bi = cfb->cb_db.bd_info;
6827 if ( bi && bi->bi_tool_entry_open )
6828 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6835 config_tool_entry_close( BackendDB *be )
6837 CfBackInfo *cfb = be->be_private;
6838 BackendInfo *bi = cfb->cb_db.bd_info;
6840 if ( bi && bi->bi_tool_entry_close )
6841 return bi->bi_tool_entry_close( &cfb->cb_db );
6847 config_tool_entry_first( BackendDB *be )
6849 CfBackInfo *cfb = be->be_private;
6850 BackendInfo *bi = cfb->cb_db.bd_info;
6852 if ( bi && bi->bi_tool_entry_first ) {
6853 return bi->bi_tool_entry_first( &cfb->cb_db );
6855 if ( bi && bi->bi_tool_entry_first_x ) {
6856 return bi->bi_tool_entry_first_x( &cfb->cb_db,
6857 NULL, LDAP_SCOPE_DEFAULT, NULL );
6863 config_tool_entry_first_x(
6865 struct berval *base,
6869 CfBackInfo *cfb = be->be_private;
6870 BackendInfo *bi = cfb->cb_db.bd_info;
6872 if ( bi && bi->bi_tool_entry_first_x ) {
6873 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
6879 config_tool_entry_next( BackendDB *be )
6881 CfBackInfo *cfb = be->be_private;
6882 BackendInfo *bi = cfb->cb_db.bd_info;
6884 if ( bi && bi->bi_tool_entry_next )
6885 return bi->bi_tool_entry_next( &cfb->cb_db );
6891 config_tool_entry_get( BackendDB *be, ID id )
6893 CfBackInfo *cfb = be->be_private;
6894 BackendInfo *bi = cfb->cb_db.bd_info;
6896 if ( bi && bi->bi_tool_entry_get )
6897 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6902 static int entry_put_got_frontend=0;
6903 static int entry_put_got_config=0;
6905 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6907 CfBackInfo *cfb = be->be_private;
6908 BackendInfo *bi = cfb->cb_db.bd_info;
6910 struct berval rdn, vals[ 2 ];
6912 OperationBuffer opbuf;
6914 Connection conn = {0};
6915 Operation *op = NULL;
6919 /* Create entry for frontend database if it does not exist already */
6920 if ( !entry_put_got_frontend ) {
6921 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6922 STRLENOF( "olcDatabase" ))) {
6923 if ( strncmp( e->e_nname.bv_val +
6924 STRLENOF( "olcDatabase" ), "={-1}frontend",
6925 STRLENOF( "={-1}frontend" )) &&
6926 strncmp( e->e_nname.bv_val +
6927 STRLENOF( "olcDatabase" ), "=frontend",
6928 STRLENOF( "=frontend" ))) {
6930 vals[1].bv_val = NULL;
6931 memset( &ca, 0, sizeof(ConfigArgs));
6933 ca.bi = frontendDB->bd_info;
6934 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6935 rdn.bv_val = ca.log;
6936 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6937 "%s=" SLAP_X_ORDERED_FMT "%s",
6938 cfAd_database->ad_cname.bv_val, -1,
6940 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6941 &CFOC_DATABASE, ca.be->be_cf_ocs );
6942 thrctx = ldap_pvt_thread_pool_context();
6943 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6945 op->o_bd = &cfb->cb_db;
6946 op->o_tag = LDAP_REQ_ADD;
6948 op->o_dn = be->be_rootdn;
6949 op->o_ndn = be->be_rootndn;
6950 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6951 if ( rc != LDAP_SUCCESS ) {
6952 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6953 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6957 if ( ce && bi && bi->bi_tool_entry_put &&
6958 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6959 entry_put_got_frontend++;
6961 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6962 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6966 entry_put_got_frontend++;
6971 /* Create entry for config database if it does not exist already */
6972 if ( !entry_put_got_config && !isFrontend ) {
6973 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6974 STRLENOF( "olcDatabase" ))) {
6975 if ( strncmp( e->e_nname.bv_val +
6976 STRLENOF( "olcDatabase" ), "={0}config",
6977 STRLENOF( "={0}config" )) &&
6978 strncmp( e->e_nname.bv_val +
6979 STRLENOF( "olcDatabase" ), "=config",
6980 STRLENOF( "=config" )) ) {
6982 vals[1].bv_val = NULL;
6983 memset( &ca, 0, sizeof(ConfigArgs));
6984 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6985 ca.bi = ca.be->bd_info;
6986 rdn.bv_val = ca.log;
6987 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6988 "%s=" SLAP_X_ORDERED_FMT "%s",
6989 cfAd_database->ad_cname.bv_val, 0,
6991 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6994 thrctx = ldap_pvt_thread_pool_context();
6995 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6997 op->o_bd = &cfb->cb_db;
6998 op->o_tag = LDAP_REQ_ADD;
6999 op->o_dn = be->be_rootdn;
7000 op->o_ndn = be->be_rootndn;
7003 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7004 if ( rc != LDAP_SUCCESS ) {
7005 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7006 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7009 if (ce && bi && bi->bi_tool_entry_put &&
7010 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7011 entry_put_got_config++;
7013 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7014 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7018 entry_put_got_config++;
7022 if ( bi && bi->bi_tool_entry_put &&
7023 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7024 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7031 AttributeDescription **desc;
7033 { "attribute", &cfAd_attr },
7034 { "backend", &cfAd_backend },
7035 { "database", &cfAd_database },
7036 { "include", &cfAd_include },
7037 { "ldapsyntax", &cfAd_syntax },
7038 { "objectclass", &cfAd_oc },
7039 { "objectidentifier", &cfAd_om },
7040 { "overlay", &cfAd_overlay },
7045 * add / delete: all types that may be added or deleted must use an
7046 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7047 * should automatically renumber the index of any siblings as needed,
7048 * so that no gaps in the numbering sequence exist after the add/delete
7050 * What can be added:
7052 * backend objects for backend-specific config directives
7056 * delete: probably no support this time around.
7058 * modrdn: generally not done. Will be invoked automatically by add/
7059 * delete to update numbering sequence. Perform as an explicit operation
7060 * so that the renumbering effect may be replicated. Subtree rename must
7061 * be supported, since renumbering a database will affect all its child
7064 * modify: must be fully supported.
7068 config_back_initialize( BackendInfo *bi )
7070 ConfigTable *ct = config_back_cf_table;
7074 AttributeDescription *ad = NULL;
7076 static char *controls[] = {
7077 LDAP_CONTROL_MANAGEDSAIT,
7081 /* Make sure we don't exceed the bits reserved for userland */
7082 config_check_userland( CFG_LAST );
7084 bi->bi_controls = controls;
7089 bi->bi_destroy = config_back_destroy;
7091 bi->bi_db_init = config_back_db_init;
7092 bi->bi_db_config = 0;
7093 bi->bi_db_open = config_back_db_open;
7094 bi->bi_db_close = config_back_db_close;
7095 bi->bi_db_destroy = config_back_db_destroy;
7097 bi->bi_op_bind = config_back_bind;
7098 bi->bi_op_unbind = 0;
7099 bi->bi_op_search = config_back_search;
7100 bi->bi_op_compare = 0;
7101 bi->bi_op_modify = config_back_modify;
7102 bi->bi_op_modrdn = config_back_modrdn;
7103 bi->bi_op_add = config_back_add;
7104 bi->bi_op_delete = config_back_delete;
7105 bi->bi_op_abandon = 0;
7107 bi->bi_extended = 0;
7109 bi->bi_chk_referrals = 0;
7111 bi->bi_access_allowed = slap_access_allowed;
7113 bi->bi_connection_init = 0;
7114 bi->bi_connection_destroy = 0;
7116 bi->bi_entry_release_rw = config_entry_release;
7117 bi->bi_entry_get_rw = config_back_entry_get;
7119 bi->bi_tool_entry_open = config_tool_entry_open;
7120 bi->bi_tool_entry_close = config_tool_entry_close;
7121 bi->bi_tool_entry_first = config_tool_entry_first;
7122 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7123 bi->bi_tool_entry_next = config_tool_entry_next;
7124 bi->bi_tool_entry_get = config_tool_entry_get;
7125 bi->bi_tool_entry_put = config_tool_entry_put;
7128 argv[ 0 ] = "slapd";
7134 for (i=0; OidMacros[i].name; i++ ) {
7135 argv[1] = OidMacros[i].name;
7136 argv[2] = OidMacros[i].oid;
7137 parse_oidm( &ca, 0, NULL );
7140 bi->bi_cf_ocs = cf_ocs;
7142 i = config_register_schema( ct, cf_ocs );
7145 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7148 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7149 * basically, we don't care if it fails */
7150 i = slap_str2ad( "olcRootPW", &ad, &text );
7152 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7153 "warning, unable to get \"olcRootPW\" "
7154 "attribute description: %d: %s\n",
7157 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7158 ad->ad_type->sat_oid );
7161 /* set up the notable AttributeDescriptions */
7163 for (;ct->name;ct++) {
7164 if (strcmp(ct->name, ads[i].name)) continue;
7165 *ads[i].desc = ct->ad;
7167 if (!ads[i].name) break;