1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2012 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;
87 static AccessControl *defacl_parsed = NULL;
89 static struct berval cfdir;
92 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
93 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
95 static ConfigFile *cfn;
97 static Avlnode *CfOcTree;
99 /* System schema state */
100 extern AttributeType *at_sys_tail; /* at.c */
101 extern ObjectClass *oc_sys_tail; /* oc.c */
102 extern OidMacro *om_sys_tail; /* oidm.c */
103 extern Syntax *syn_sys_tail; /* syntax.c */
104 static AttributeType *cf_at_tail;
105 static ObjectClass *cf_oc_tail;
106 static OidMacro *cf_om_tail;
107 static Syntax *cf_syn_tail;
109 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
110 SlapReply *rs, int *renumber, Operation *op );
112 static int config_check_schema( Operation *op, CfBackInfo *cfb );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_subordinate;
124 static ConfigDriver config_suffix;
125 #ifdef LDAP_TCP_BUFFER
126 static ConfigDriver config_tcp_buffer;
127 #endif /* LDAP_TCP_BUFFER */
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_extra_attrs;
140 static ConfigDriver config_include;
141 static ConfigDriver config_obsolete;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_config;
154 CFG_TLS_PROTOCOL_MIN,
205 static OidRec OidMacros[] = {
206 /* OpenLDAProot:1.12.2 */
207 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
208 { "OLcfgAt", "OLcfg:3" },
209 { "OLcfgGlAt", "OLcfgAt:0" },
210 { "OLcfgBkAt", "OLcfgAt:1" },
211 { "OLcfgDbAt", "OLcfgAt:2" },
212 { "OLcfgOvAt", "OLcfgAt:3" },
213 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
214 { "OLcfgOc", "OLcfg:4" },
215 { "OLcfgGlOc", "OLcfgOc:0" },
216 { "OLcfgBkOc", "OLcfgOc:1" },
217 { "OLcfgDbOc", "OLcfgOc:2" },
218 { "OLcfgOvOc", "OLcfgOc:3" },
219 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
221 /* Syntaxes. We should just start using the standard names and
222 * document that they are predefined and available for users
223 * to reference in their own schema. Defining schema without
224 * OID macros is for masochists...
226 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
227 { "OMsBoolean", "OMsyn:7" },
228 { "OMsDN", "OMsyn:12" },
229 { "OMsDirectoryString", "OMsyn:15" },
230 { "OMsIA5String", "OMsyn:26" },
231 { "OMsInteger", "OMsyn:27" },
232 { "OMsOID", "OMsyn:38" },
233 { "OMsOctetString", "OMsyn:40" },
238 * Backend/Database registry
240 * OLcfg{Bk|Db}{Oc|At}:0 -> common
241 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
242 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
243 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
244 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
245 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
246 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
247 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
248 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
249 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
250 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
251 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
252 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
253 * OLcfg{Bk|Db}{Oc|At}:13 -> back-meta
259 * OLcfgOv{Oc|At}:1 -> syncprov
260 * OLcfgOv{Oc|At}:2 -> pcache
261 * OLcfgOv{Oc|At}:3 -> chain
262 * OLcfgOv{Oc|At}:4 -> accesslog
263 * OLcfgOv{Oc|At}:5 -> valsort
264 * OLcfgOv{Oc|At}:7 -> distproc
265 * OLcfgOv{Oc|At}:8 -> dynlist
266 * OLcfgOv{Oc|At}:9 -> dds
267 * OLcfgOv{Oc|At}:10 -> unique
268 * OLcfgOv{Oc|At}:11 -> refint
269 * OLcfgOv{Oc|At}:12 -> ppolicy
270 * OLcfgOv{Oc|At}:13 -> constraint
271 * OLcfgOv{Oc|At}:14 -> translucent
272 * OLcfgOv{Oc|At}:15 -> auditlog
273 * OLcfgOv{Oc|At}:16 -> rwm
274 * OLcfgOv{Oc|At}:17 -> dyngroup
275 * OLcfgOv{Oc|At}:18 -> memberof
276 * OLcfgOv{Oc|At}:19 -> collect
277 * OLcfgOv{Oc|At}:20 -> retcode
278 * OLcfgOv{Oc|At}:21 -> sssvlv
281 /* alphabetical ordering */
283 static ConfigTable config_back_cf_table[] = {
284 /* This attr is read-only */
285 { "", "", 0, 0, 0, ARG_MAGIC,
286 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
287 "DESC 'File for slapd configuration directives' "
288 "EQUALITY caseIgnoreMatch "
289 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
290 { "", "", 0, 0, 0, ARG_MAGIC,
291 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
292 "DESC 'Directory for slapd configuration backend' "
293 "EQUALITY caseIgnoreMatch "
294 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
295 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
296 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
297 "DESC 'Access Control List' "
298 "EQUALITY caseIgnoreMatch "
299 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
300 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
301 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
302 "DESC 'Check ACLs against content of Add ops' "
303 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
304 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
305 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
306 "DESC 'Allowed set of deprecated features' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString )", NULL, NULL },
309 { "argsfile", "file", 2, 2, 0, ARG_STRING,
310 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
311 "DESC 'File for slapd command line options' "
312 "EQUALITY caseIgnoreMatch "
313 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
314 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
315 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
316 "EQUALITY caseIgnoreMatch "
317 "SYNTAX OMsDirectoryString )", NULL, NULL },
318 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
319 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
320 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
321 "DESC 'OpenLDAP attributeTypes' "
322 "EQUALITY caseIgnoreMatch "
323 "SUBSTR caseIgnoreSubstringsMatch "
324 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
326 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
327 #ifdef SLAP_AUTH_REWRITE
328 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
332 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
333 "EQUALITY caseIgnoreMatch "
334 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
335 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
336 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
337 "EQUALITY caseIgnoreMatch "
338 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
339 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
340 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
343 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
344 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
345 "DESC 'A type of backend' "
346 "EQUALITY caseIgnoreMatch "
347 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
349 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
350 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
351 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
352 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
353 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
354 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
355 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
356 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
357 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
358 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
359 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
360 "DESC 'The backend type for a database instance' "
361 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
362 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
363 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
364 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
365 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
366 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
367 "EQUALITY caseIgnoreMatch "
368 "SYNTAX OMsDirectoryString )", NULL, NULL },
369 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
370 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
371 "DESC 'OpenLDAP DIT content rules' "
372 "EQUALITY caseIgnoreMatch "
373 "SUBSTR caseIgnoreSubstringsMatch "
374 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
376 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
377 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
378 "EQUALITY caseIgnoreMatch "
379 "SYNTAX OMsDirectoryString )", NULL, NULL },
380 { "gentlehup", "on|off", 2, 2, 0,
382 ARG_ON_OFF, &global_gentlehup,
386 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
387 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
388 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
389 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
390 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
391 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
392 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
393 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
394 { "include", "file", 2, 2, 0, ARG_MAGIC,
395 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
396 "SUP labeledURI )", NULL, NULL },
397 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
398 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
399 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
400 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
401 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
402 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
403 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
404 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
405 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
406 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
407 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
408 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
409 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
410 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
411 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
412 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
413 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
414 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
415 { "ldapsyntax", "syntax", 2, 0, 0,
416 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
417 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
418 "DESC 'OpenLDAP ldapSyntax' "
419 "EQUALITY caseIgnoreMatch "
420 "SUBSTR caseIgnoreSubstringsMatch "
421 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
423 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
424 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
425 "EQUALITY caseIgnoreMatch "
426 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
427 { "listener-threads", "count", 2, 0, 0,
431 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
433 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
434 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
435 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
436 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
437 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
438 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
439 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
440 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
441 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
442 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
443 "EQUALITY caseIgnoreMatch "
444 "SYNTAX OMsDirectoryString )", NULL, NULL },
445 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
446 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
447 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
448 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
449 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
450 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
451 { "moduleload", "file", 2, 0, 0,
453 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
457 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
458 "EQUALITY caseIgnoreMatch "
459 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
460 { "modulepath", "path", 2, 2, 0,
462 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
466 "( OLcfgGlAt:31 NAME 'olcModulePath' "
467 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
468 { "monitoring", "TRUE|FALSE", 2, 2, 0,
469 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
470 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
471 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
472 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
473 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
474 "DESC 'OpenLDAP object classes' "
475 "EQUALITY caseIgnoreMatch "
476 "SUBSTR caseIgnoreSubstringsMatch "
477 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
479 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
480 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
481 "EQUALITY caseIgnoreMatch "
482 "SUBSTR caseIgnoreSubstringsMatch "
483 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
484 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
485 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
486 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
487 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
488 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
489 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
490 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
491 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
492 "EQUALITY caseIgnoreMatch "
493 "SYNTAX OMsDirectoryString )", NULL, NULL },
494 { "pidfile", "file", 2, 2, 0, ARG_STRING,
495 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
496 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
497 { "plugin", NULL, 0, 0, 0,
499 ARG_MAGIC|CFG_PLUGIN, &config_generic,
503 "( OLcfgGlAt:38 NAME 'olcPlugin' "
504 "EQUALITY caseIgnoreMatch "
505 "SYNTAX OMsDirectoryString )", NULL, NULL },
506 { "pluginlog", "filename", 2, 2, 0,
508 ARG_STRING, &slapi_log_file,
512 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
513 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
514 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
515 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
516 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
517 { "referral", "url", 2, 2, 0, ARG_MAGIC,
518 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
519 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
520 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
521 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
522 "EQUALITY caseIgnoreMatch "
523 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
524 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
525 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
526 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
527 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
528 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
529 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
530 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
531 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
532 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
533 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
534 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
535 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
536 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
537 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
538 "EQUALITY caseIgnoreMatch "
539 "SYNTAX OMsDirectoryString )", NULL, NULL },
540 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
541 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
542 "EQUALITY caseIgnoreMatch "
543 "SYNTAX OMsDirectoryString )", NULL, NULL },
544 { "reverse-lookup", "on|off", 2, 2, 0,
545 #ifdef SLAPD_RLOOKUPS
546 ARG_ON_OFF, &use_reverse_lookup,
550 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
551 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
552 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
553 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
554 "EQUALITY distinguishedNameMatch "
555 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
556 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
557 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
558 "EQUALITY caseIgnoreMatch "
559 "SYNTAX OMsDirectoryString )", NULL, NULL },
560 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
561 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
562 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
563 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
564 &config_generic, NULL, NULL, NULL },
565 { "sasl-auxprops", NULL, 2, 0, 0,
566 #ifdef HAVE_CYRUS_SASL
567 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
571 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "sasl-host", "host", 2, 2, 0,
574 #ifdef HAVE_CYRUS_SASL
575 ARG_STRING|ARG_UNIQUE, &sasl_host,
579 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
580 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
581 { "sasl-realm", "realm", 2, 2, 0,
582 #ifdef HAVE_CYRUS_SASL
583 ARG_STRING|ARG_UNIQUE, &global_realm,
587 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
588 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
589 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
590 &config_generic, NULL, NULL, NULL },
591 { "sasl-secprops", "properties", 2, 2, 0,
592 #ifdef HAVE_CYRUS_SASL
593 ARG_MAGIC|CFG_SASLSECP, &config_generic,
597 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
598 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
599 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
600 &config_generic, NULL, NULL, NULL },
601 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
602 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
603 "EQUALITY distinguishedNameMatch "
604 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
605 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
606 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
607 "EQUALITY caseIgnoreMatch "
608 "SYNTAX OMsDirectoryString )", NULL, NULL },
609 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
610 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
611 "EQUALITY caseIgnoreMatch "
612 "SYNTAX OMsDirectoryString )", NULL, NULL },
613 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
614 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
615 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
616 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
617 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
618 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
619 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
620 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
621 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
622 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
623 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
624 "DESC 'Attributes whose values will always be sorted' "
625 "EQUALITY caseIgnoreMatch "
626 "SYNTAX OMsDirectoryString )", NULL, NULL },
627 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
628 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
629 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
630 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
631 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
632 "EQUALITY distinguishedNameMatch "
633 "SYNTAX OMsDN )", NULL, NULL },
634 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
635 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
636 "DESC 'Store sync context in a subentry' "
637 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
638 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
639 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
640 "EQUALITY caseIgnoreMatch "
641 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
642 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
643 #ifndef LDAP_TCP_BUFFER
645 #else /* LDAP_TCP_BUFFER */
646 ARG_MAGIC, &config_tcp_buffer,
647 #endif /* LDAP_TCP_BUFFER */
648 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
649 "DESC 'Custom TCP buffer size' "
650 "SYNTAX OMsDirectoryString )", NULL, NULL },
651 { "threads", "count", 2, 2, 0,
655 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
657 "( OLcfgGlAt:66 NAME 'olcThreads' "
658 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
659 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
660 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
661 "SYNTAX OMsDirectoryString )", NULL, NULL },
662 { "TLSCACertificateFile", NULL, 2, 2, 0,
664 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
668 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
669 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
670 { "TLSCACertificatePath", NULL, 2, 2, 0,
672 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
676 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
677 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
678 { "TLSCertificateFile", NULL, 2, 2, 0,
680 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
684 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
685 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
686 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
688 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
692 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
693 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
694 { "TLSCipherSuite", NULL, 2, 2, 0,
696 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
700 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
701 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
702 { "TLSCRLCheck", NULL, 2, 2, 0,
703 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
704 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
708 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
709 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
710 { "TLSCRLFile", NULL, 2, 2, 0,
711 #if defined(HAVE_GNUTLS)
712 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
716 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
717 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
718 { "TLSRandFile", NULL, 2, 2, 0,
720 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
724 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
725 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
726 { "TLSVerifyClient", NULL, 2, 2, 0,
728 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
732 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
733 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
734 { "TLSDHParamFile", NULL, 2, 2, 0,
736 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
740 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
741 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
742 { "TLSProtocolMin", NULL, 2, 2, 0,
744 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
748 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
749 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
750 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
751 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
752 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
753 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
754 NULL, NULL, NULL, NULL },
755 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
756 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
757 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
758 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
759 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
760 "EQUALITY caseIgnoreMatch "
761 "SUP labeledURI )", NULL, NULL },
762 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
763 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
764 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
765 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
766 NULL, NULL, NULL, NULL }
769 /* Need to no-op this keyword for dynamic config */
770 ConfigTable olcDatabaseDummy[] = {
771 { "", "", 0, 0, 0, ARG_IGNORED,
772 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
773 "DESC 'The backend type for a database instance' "
774 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
775 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
778 /* Routines to check if a child can be added to this type */
779 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
780 cfAddBackend, cfAddModule, cfAddOverlay;
782 /* NOTE: be careful when defining array members
783 * that can be conditionally compiled */
784 #define CFOC_GLOBAL cf_ocs[1]
785 #define CFOC_SCHEMA cf_ocs[2]
786 #define CFOC_BACKEND cf_ocs[3]
787 #define CFOC_DATABASE cf_ocs[4]
788 #define CFOC_OVERLAY cf_ocs[5]
789 #define CFOC_INCLUDE cf_ocs[6]
790 #define CFOC_FRONTEND cf_ocs[7]
792 #define CFOC_MODULE cf_ocs[8]
793 #endif /* SLAPD_MODULES */
795 static ConfigOCs cf_ocs[] = {
798 "DESC 'OpenLDAP configuration object' "
799 "ABSTRACT SUP top )", Cft_Abstract, NULL },
802 "DESC 'OpenLDAP Global configuration options' "
803 "SUP olcConfig STRUCTURAL "
804 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
805 "olcAttributeOptions $ olcAuthIDRewrite $ "
806 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
807 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
808 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
809 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
810 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
811 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
812 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
813 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
814 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
816 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
817 "olcSecurity $ olcServerID $ olcSizeLimit $ "
818 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
820 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
821 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
822 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
823 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
824 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
825 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
826 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
828 "NAME 'olcSchemaConfig' "
829 "DESC 'OpenLDAP schema object' "
830 "SUP olcConfig STRUCTURAL "
831 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
832 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
833 Cft_Schema, NULL, cfAddSchema },
835 "NAME 'olcBackendConfig' "
836 "DESC 'OpenLDAP Backend-specific options' "
837 "SUP olcConfig STRUCTURAL "
838 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
840 "NAME 'olcDatabaseConfig' "
841 "DESC 'OpenLDAP Database-specific options' "
842 "SUP olcConfig STRUCTURAL "
844 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
845 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
846 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
847 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
848 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
849 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
850 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
851 "olcMonitoring $ olcExtraAttrs ) )",
852 Cft_Database, NULL, cfAddDatabase },
854 "NAME 'olcOverlayConfig' "
855 "DESC 'OpenLDAP Overlay-specific options' "
856 "SUP olcConfig STRUCTURAL "
857 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
859 "NAME 'olcIncludeFile' "
860 "DESC 'OpenLDAP configuration include file' "
861 "SUP olcConfig STRUCTURAL "
863 "MAY ( cn $ olcRootDSE ) )",
864 /* Used to be Cft_Include, that def has been removed */
865 Cft_Abstract, NULL, cfAddInclude },
866 /* This should be STRUCTURAL like all the other database classes, but
867 * that would mean inheriting all of the olcDatabaseConfig attributes,
868 * which causes them to be merged twice in config_build_entry.
871 "NAME 'olcFrontendConfig' "
872 "DESC 'OpenLDAP frontend configuration' "
874 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
875 Cft_Database, NULL, NULL },
878 "NAME 'olcModuleList' "
879 "DESC 'OpenLDAP dynamic module info' "
880 "SUP olcConfig STRUCTURAL "
881 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
882 Cft_Module, NULL, cfAddModule },
887 typedef struct ServerID {
888 struct ServerID *si_next;
889 struct berval si_url;
893 static ServerID *sid_list;
894 static ServerID *sid_set;
896 typedef struct voidList {
897 struct voidList *vl_next;
901 typedef struct ADlist {
902 struct ADlist *al_next;
903 AttributeDescription *al_desc;
906 static ADlist *sortVals;
909 config_generic(ConfigArgs *c) {
912 if ( c->op == SLAP_CONFIG_EMIT ) {
916 c->value_int = ldap_pvt_thread_get_concurrency();
919 c->value_int = connection_pool_max;
922 c->value_int = slap_tool_thread_max;
925 c->value_uint = slapd_daemon_threads;
929 c->value_string = ch_strdup( passwd_salt );
934 if ( c->be->be_limits ) {
938 for ( i=0; c->be->be_limits[i]; i++ ) {
939 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
940 if ( bv.bv_len >= sizeof( buf ) ) {
941 ber_bvarray_free_x( c->rvalue_vals, NULL );
942 c->rvalue_vals = NULL;
946 bv.bv_val = buf + bv.bv_len;
947 limits_unparse( c->be->be_limits[i], &bv,
948 sizeof( buf ) - ( bv.bv_val - buf ) );
949 bv.bv_len += bv.bv_val - buf;
951 value_add_one( &c->rvalue_vals, &bv );
954 if ( !c->rvalue_vals ) rc = 1;
957 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
960 c->value_string = ch_strdup( slap_sasl_getpolicy());
963 slap_sasl_regexp_unparse( &c->rvalue_vals );
964 if ( !c->rvalue_vals ) rc = 1;
966 #ifdef HAVE_CYRUS_SASL
968 struct berval bv = BER_BVNULL;
969 slap_sasl_secprops_unparse( &bv );
970 if ( !BER_BVISNULL( &bv )) {
971 ber_bvarray_add( &c->rvalue_vals, &bv );
979 c->value_int = c->be->be_max_deref_depth;
982 if ( SLAP_DBHIDDEN( c->be )) {
989 ConfigFile *cf = c->ca_private;
991 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
992 else if ( cf->c_om_head )
993 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
995 if ( !c->rvalue_vals )
1000 ad_unparse_options( &c->rvalue_vals );
1003 ConfigFile *cf = c->ca_private;
1005 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1006 else if ( cf->c_oc_head )
1007 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1009 if ( !c->rvalue_vals )
1014 ConfigFile *cf = c->ca_private;
1016 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1017 else if ( cf->c_at_head )
1018 at_unparse( &c->rvalue_vals, cf->c_at_head,
1020 if ( !c->rvalue_vals )
1025 ConfigFile *cf = c->ca_private;
1027 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1028 else if ( cf->c_syn_head )
1029 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1030 cf->c_syn_tail, 0 );
1031 if ( !c->rvalue_vals )
1036 ConfigFile *cf = c->ca_private;
1038 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1039 else if ( cf->c_cr_head )
1040 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1042 if ( !c->rvalue_vals )
1049 char *src, *dst, ibuf[11];
1050 struct berval bv, abv;
1051 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1052 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1053 if ( abv.bv_len >= sizeof( ibuf ) ) {
1054 ber_bvarray_free_x( c->rvalue_vals, NULL );
1055 c->rvalue_vals = NULL;
1059 acl_unparse( a, &bv );
1060 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1061 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1062 /* Turn TAB / EOL into plain space */
1063 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1064 if (isspace((unsigned char)*src)) *dst++ = ' ';
1068 if (dst[-1] == ' ') {
1072 abv.bv_len = dst - abv.bv_val;
1073 ber_bvarray_add( &c->rvalue_vals, &abv );
1079 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1082 ConfigFile *cf = c->ca_private;
1083 if ( cf->c_dseFiles ) {
1084 value_add( &c->rvalue_vals, cf->c_dseFiles );
1095 for ( si = sid_list; si; si=si->si_next ) {
1096 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1097 if ( !BER_BVISEMPTY( &si->si_url )) {
1098 bv.bv_len = si->si_url.bv_len + 6;
1099 bv.bv_val = ch_malloc( bv.bv_len );
1100 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1101 si->si_url.bv_val );
1102 ber_bvarray_add( &c->rvalue_vals, &bv );
1106 bv.bv_len = sprintf( buf, "%d", si->si_num );
1107 value_add_one( &c->rvalue_vals, &bv );
1116 c->value_string = ch_strdup( logfileName );
1121 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1123 case CFG_SYNC_SUBENTRY:
1124 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1126 case CFG_MIRRORMODE:
1127 if ( SLAP_SHADOW(c->be))
1128 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1132 case CFG_MONITORING:
1133 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1135 case CFG_SSTR_IF_MAX:
1136 c->value_uint = index_substr_if_maxlen;
1138 case CFG_SSTR_IF_MIN:
1139 c->value_uint = index_substr_if_minlen;
1142 c->value_int = index_intlen;
1144 case CFG_SORTVALS: {
1147 for ( sv = sortVals; sv; sv = sv->al_next ) {
1148 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1152 #ifdef SLAPD_MODULES
1154 ModPaths *mp = c->ca_private;
1157 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1160 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1161 SLAP_X_ORDERED_FMT "%s", i,
1162 mp->mp_loads[i].bv_val );
1163 if ( bv.bv_len >= sizeof( c->log ) ) {
1164 ber_bvarray_free_x( c->rvalue_vals, NULL );
1165 c->rvalue_vals = NULL;
1168 value_add_one( &c->rvalue_vals, &bv );
1172 rc = c->rvalue_vals ? 0 : 1;
1176 ModPaths *mp = c->ca_private;
1177 if ( !BER_BVISNULL( &mp->mp_path ))
1178 value_add_one( &c->rvalue_vals, &mp->mp_path );
1180 rc = c->rvalue_vals ? 0 : 1;
1186 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1187 if ( !c->rvalue_vals ) rc = 1;
1190 #ifdef SLAP_AUTH_REWRITE
1192 if ( authz_rewrites ) {
1193 struct berval bv, idx;
1198 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1199 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1200 if ( idx.bv_len >= sizeof( ibuf ) ) {
1201 ber_bvarray_free_x( c->rvalue_vals, NULL );
1202 c->rvalue_vals = NULL;
1205 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1206 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1207 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1208 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1209 authz_rewrites[i].bv_val,
1210 authz_rewrites[i].bv_len + 1 );
1211 ber_bvarray_add( &c->rvalue_vals, &bv );
1214 if ( !c->rvalue_vals ) rc = 1;
1221 } else if ( c->op == LDAP_MOD_DELETE ) {
1224 /* single-valued attrs, no-ops */
1233 case CFG_MONITORING:
1235 case CFG_SSTR_IF_MAX:
1236 case CFG_SSTR_IF_MIN:
1238 case CFG_SYNC_SUBENTRY:
1241 /* no-ops, requires slapd restart */
1246 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1249 case CFG_MIRRORMODE:
1250 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1251 if(SLAP_SHADOW(c->be))
1252 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1256 ch_free( passwd_salt );
1261 ch_free( logfileName );
1269 case CFG_SERVERID: {
1270 ServerID *si, **sip;
1272 for ( i=0, si = sid_list, sip = &sid_list;
1273 si; si = *sip, i++ ) {
1274 if ( c->valx == -1 || i == c->valx ) {
1276 if ( sid_set == si )
1288 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1292 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1293 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1294 SLAP_INDEX_INTLEN_DEFAULT );
1298 if ( c->valx < 0 ) {
1299 acl_destroy( c->be->be_acl );
1300 c->be->be_acl = NULL;
1303 AccessControl **prev, *a;
1305 for (i=0, prev = &c->be->be_acl; i < c->valx;
1308 prev = &a->acl_next;
1311 *prev = a->acl_next;
1314 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1315 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1316 "Last explicit ACL for back-config removed. "
1317 "Using hardcoded default\n", 0, 0, 0 );
1318 c->be->be_acl = defacl_parsed;
1324 /* Can be NULL when undoing a failed add */
1325 if ( c->ca_entry ) {
1326 ce = c->ca_entry->e_private;
1327 /* can't modify the hardcoded schema */
1328 if ( ce->ce_parent->ce_type == Cft_Global )
1332 cfn = c->ca_private;
1333 if ( c->valx < 0 ) {
1336 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1338 if ( oc == cfn->c_oc_tail )
1341 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1343 ObjectClass *oc, *prev = NULL;
1345 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1350 if ( cfn->c_oc_tail == oc ) {
1351 cfn->c_oc_tail = prev;
1353 if ( cfn->c_oc_head == oc ) {
1355 cfn->c_oc_head = oc;
1362 /* Can be NULL when undoing a failed add */
1363 if ( c->ca_entry ) {
1364 ce = c->ca_entry->e_private;
1365 /* can't modify the hardcoded schema */
1366 if ( ce->ce_parent->ce_type == Cft_Global )
1370 cfn = c->ca_private;
1371 if ( c->valx < 0 ) {
1374 for( at = cfn->c_at_head; at; at_next( &at )) {
1376 if ( at == cfn->c_at_tail )
1379 cfn->c_at_head = cfn->c_at_tail = NULL;
1381 AttributeType *at, *prev = NULL;
1383 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1388 if ( cfn->c_at_tail == at ) {
1389 cfn->c_at_tail = prev;
1391 if ( cfn->c_at_head == at ) {
1393 cfn->c_at_head = at;
1400 /* Can be NULL when undoing a failed add */
1401 if ( c->ca_entry ) {
1402 ce = c->ca_entry->e_private;
1403 /* can't modify the hardcoded schema */
1404 if ( ce->ce_parent->ce_type == Cft_Global )
1408 cfn = c->ca_private;
1409 if ( c->valx < 0 ) {
1412 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1414 if ( syn == cfn->c_syn_tail )
1417 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1419 Syntax *syn, *prev = NULL;
1421 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1426 if ( cfn->c_syn_tail == syn ) {
1427 cfn->c_syn_tail = prev;
1429 if ( cfn->c_syn_head == syn ) {
1431 cfn->c_syn_head = syn;
1436 if ( c->valx < 0 ) {
1438 for ( sv = sortVals; sv; sv = sortVals ) {
1439 sortVals = sv->al_next;
1440 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1447 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1448 prev = &sv->al_next;
1451 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1452 *prev = sv->al_next;
1458 /* FIXME: there is no limits_free function */
1459 if ( c->valx < 0 ) {
1460 limits_destroy( c->be->be_limits );
1461 c->be->be_limits = NULL;
1466 if ( c->be->be_limits ) {
1467 for ( num = 0; c->be->be_limits[ num ]; num++ )
1471 if ( c->valx >= num ) {
1476 limits_destroy( c->be->be_limits );
1477 c->be->be_limits = NULL;
1480 limits_free_one( c->be->be_limits[ c->valx ] );
1482 for ( cnt = c->valx; cnt < num; cnt++ ) {
1483 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1490 /* FIXME: there is no ad_option_free function */
1492 /* FIXME: there is no way to remove attributes added by
1506 if(!(c->bi = backend_info(c->argv[1]))) {
1507 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1508 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1509 c->log, c->cr_msg, c->argv[1] );
1516 /* NOTE: config is always the first backend!
1518 if ( !strcasecmp( c->argv[1], "config" )) {
1519 c->be = LDAP_STAILQ_FIRST(&backendDB);
1520 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1523 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1525 if ( c->cr_msg[0] == 0 )
1526 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1527 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1534 ldap_pvt_thread_set_concurrency(c->value_int);
1538 if ( c->value_int < 2 ) {
1539 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1540 "threads=%d smaller than minimum value 2",
1542 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1543 c->log, c->cr_msg, 0 );
1546 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1547 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1548 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1549 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1550 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1551 c->log, c->cr_msg, 0 );
1553 if ( slapMode & SLAP_SERVER_MODE )
1554 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1555 connection_pool_max = c->value_int; /* save for reference */
1559 if ( slapMode & SLAP_TOOL_MODE )
1560 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1561 slap_tool_thread_max = c->value_int; /* save for reference */
1566 /* use a power of two */
1567 while (c->value_uint > 1) {
1568 c->value_uint >>= 1;
1572 slapd_daemon_mask = mask;
1573 slapd_daemon_threads = mask+1;
1578 if ( passwd_salt ) ch_free( passwd_salt );
1579 passwd_salt = c->value_string;
1580 lutil_salt_format(passwd_salt);
1584 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1590 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1592 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1596 ch_free(c->value_string);
1597 if (slap_sasl_setpolicy( c->argv[1] )) {
1598 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1599 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1600 c->log, c->cr_msg, c->argv[1] );
1606 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1610 #ifdef HAVE_CYRUS_SASL
1613 char *txt = slap_sasl_secprops( c->argv[1] );
1615 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1617 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1625 c->be->be_max_deref_depth = c->value_int;
1631 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1632 cfn = c->ca_private;
1633 if(parse_oidm(c, 1, &om))
1635 if (!cfn->c_om_head) cfn->c_om_head = om;
1636 cfn->c_om_tail = om;
1641 ObjectClass *oc, *prev;
1643 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1644 cfn = c->ca_private;
1645 if ( c->valx < 0 ) {
1646 prev = cfn->c_oc_tail;
1649 /* If adding anything after the first, prev is easy */
1652 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1654 if ( !oc_next( &oc ))
1658 /* If adding the first, and head exists, find its prev */
1659 if (cfn->c_oc_head) {
1660 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1665 /* else prev is NULL, append to end of global list */
1667 if(parse_oc(c, &oc, prev)) return(1);
1668 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1669 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1674 AttributeType *at, *prev;
1676 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1677 cfn = c->ca_private;
1678 if ( c->valx < 0 ) {
1679 prev = cfn->c_at_tail;
1682 /* If adding anything after the first, prev is easy */
1685 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1687 if ( !at_next( &at ))
1691 /* If adding the first, and head exists, find its prev */
1692 if (cfn->c_at_head) {
1693 for ( at_start( &at ); at != cfn->c_at_head; ) {
1698 /* else prev is NULL, append to end of global list */
1700 if(parse_at(c, &at, prev)) return(1);
1701 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1702 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1709 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1710 cfn = c->ca_private;
1711 if ( c->valx < 0 ) {
1712 prev = cfn->c_syn_tail;
1715 /* If adding anything after the first, prev is easy */
1718 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1720 if ( !syn_next( &syn ))
1724 /* If adding the first, and head exists, find its prev */
1725 if (cfn->c_syn_head) {
1726 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1731 /* else prev is NULL, append to end of global list */
1733 if ( parse_syn( c, &syn, prev ) ) return(1);
1734 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1735 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1742 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1743 cfn = c->ca_private;
1744 if(parse_cr(c, &cr)) return(1);
1745 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1746 cfn->c_cr_tail = cr;
1751 ad_define_option(NULL, NULL, 0);
1752 for(i = 1; i < c->argc; i++)
1753 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1758 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1759 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1760 else if ( c->value_int > 255 )
1762 index_intlen = c->value_int;
1763 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1767 case CFG_SORTVALS: {
1768 ADlist *svnew = NULL, *svtail, *sv;
1770 for ( i = 1; i < c->argc; i++ ) {
1771 AttributeDescription *ad = NULL;
1775 rc = slap_str2ad( c->argv[i], &ad, &text );
1777 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1780 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1781 c->log, c->cr_msg, c->argv[i] );
1782 for ( sv = svnew; sv; sv = svnew ) {
1783 svnew = sv->al_next;
1788 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1789 ad->ad_type->sat_single_value ) {
1790 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1792 goto sortval_reject;
1794 sv = ch_malloc( sizeof( ADlist ));
1799 svtail->al_next = sv;
1804 for ( sv = svnew; sv; sv = sv->al_next )
1805 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1806 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1808 sv->al_next = svnew;
1815 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
1816 c->be->be_acl = NULL;
1818 /* Don't append to the global ACL if we're on a specific DB */
1820 if ( c->valx == -1 ) {
1823 for ( a=c->be->be_acl; a; a = a->acl_next )
1826 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1827 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
1828 c->be->be_acl = defacl_parsed;
1836 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1838 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1842 if(root_dse_read_file(c->argv[1])) {
1843 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1844 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1845 c->log, c->cr_msg, c->argv[1] );
1850 ber_str2bv( c->argv[1], 0, 1, &bv );
1851 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1852 cfn = c->ca_private;
1853 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1859 ServerID *si, **sip;
1862 if (( lutil_atoi( &num, c->argv[1] ) &&
1863 lutil_atoix( &num, c->argv[1], 16 )) ||
1864 num < 0 || num > SLAP_SYNC_SID_MAX )
1866 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1867 "<%s> illegal server ID", c->argv[0] );
1868 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1869 c->log, c->cr_msg, c->argv[1] );
1872 /* only one value allowed if no URL is given */
1873 if ( c->argc > 2 ) {
1876 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1877 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1878 "<%s> only one server ID allowed now", c->argv[0] );
1879 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1880 c->log, c->cr_msg, c->argv[1] );
1884 if ( ldap_url_parse( c->argv[2], &lud )) {
1885 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1886 "<%s> invalid URL", c->argv[0] );
1887 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1888 c->log, c->cr_msg, c->argv[2] );
1891 len = strlen( c->argv[2] );
1892 si = ch_malloc( sizeof(ServerID) + len + 1 );
1893 si->si_url.bv_val = (char *)(si+1);
1894 si->si_url.bv_len = len;
1895 strcpy( si->si_url.bv_val, c->argv[2] );
1898 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1899 "<%s> unqualified server ID not allowed now", c->argv[0] );
1900 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1901 c->log, c->cr_msg, c->argv[1] );
1904 si = ch_malloc( sizeof(ServerID) );
1905 BER_BVZERO( &si->si_url );
1906 slap_serverID = num;
1907 Debug( LDAP_DEBUG_CONFIG,
1909 c->log, slap_serverID, 0 );
1914 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1917 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1918 Listener *l = config_check_my_url( c->argv[2], lud );
1921 ldap_free_urldesc( lud );
1922 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1923 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
1924 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1925 c->log, c->cr_msg, c->argv[1] );
1928 slap_serverID = si->si_num;
1929 Debug( LDAP_DEBUG_CONFIG,
1930 "%s: SID=0x%03x (listener=%s)\n",
1931 c->log, slap_serverID,
1937 ldap_free_urldesc( lud );
1941 if ( logfileName ) ch_free( logfileName );
1942 logfileName = c->value_string;
1943 logfile = fopen(logfileName, "w");
1944 if(logfile) lutil_debug_file(logfile);
1948 if(SLAP_NOLASTMODCMD(c->be)) {
1949 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1950 c->argv[0], c->be->bd_info->bi_type );
1951 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1952 c->log, c->cr_msg, 0 );
1956 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1958 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1961 case CFG_MIRRORMODE:
1962 if(c->value_int && !SLAP_SHADOW(c->be)) {
1963 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1965 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1966 c->log, c->cr_msg, 0 );
1970 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1971 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
1973 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1974 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1978 case CFG_MONITORING:
1980 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1982 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1987 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1989 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1992 case CFG_SYNC_SUBENTRY:
1994 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1996 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1999 case CFG_SSTR_IF_MAX:
2000 if (c->value_uint < index_substr_if_minlen) {
2001 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2002 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2003 c->log, c->cr_msg, c->value_int );
2006 index_substr_if_maxlen = c->value_uint;
2009 case CFG_SSTR_IF_MIN:
2010 if (c->value_uint > index_substr_if_maxlen) {
2011 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2012 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2013 c->log, c->cr_msg, c->value_int );
2016 index_substr_if_minlen = c->value_uint;
2019 #ifdef SLAPD_MODULES
2021 /* If we're just adding a module on an existing modpath,
2022 * make sure we've selected the current path.
2024 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2025 modcur = c->ca_private;
2026 /* This should never fail */
2027 if ( module_path( modcur->mp_path.bv_val )) {
2028 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2030 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2031 c->log, c->cr_msg, modcur->mp_path.bv_val );
2035 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2037 /* Record this load on the current path */
2041 if ( c->op == SLAP_CONFIG_ADD ) {
2042 ptr = c->line + STRLENOF("moduleload");
2043 while (!isspace((unsigned char) *ptr)) ptr++;
2044 while (isspace((unsigned char) *ptr)) ptr++;
2048 ber_str2bv(ptr, 0, 1, &bv);
2049 ber_bvarray_add( &modcur->mp_loads, &bv );
2051 /* Check for any new hardcoded schema */
2052 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2053 config_check_schema( NULL, &cfBackInfo );
2058 if(module_path(c->argv[1])) return(1);
2059 /* Record which path was used with each module */
2063 if (!modpaths.mp_loads) {
2066 mp = ch_malloc( sizeof( ModPaths ));
2067 modlast->mp_next = mp;
2069 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2071 mp->mp_loads = NULL;
2082 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2084 slapi_plugins_used++;
2088 #ifdef SLAP_AUTH_REWRITE
2094 if ( c->op == LDAP_MOD_ADD ) {
2098 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2102 if ( c->argc > 1 ) {
2105 /* quote all args but the first */
2106 line = ldap_charray2str( c->argv, "\" \"" );
2107 ber_str2bv( line, 0, 0, &bv );
2108 s = ber_bvchr( &bv, '"' );
2109 assert( s != NULL );
2110 /* move the trailing quote of argv[0] to the end */
2111 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2112 bv.bv_val[ bv.bv_len - 1 ] = '"';
2115 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2118 ber_bvarray_add( &authz_rewrites, &bv );
2120 if ( c->op == LDAP_MOD_ADD ) {
2130 Debug( LDAP_DEBUG_ANY,
2131 "%s: unknown CFG_TYPE %d.\n",
2132 c->log, c->type, 0 );
2141 config_fname(ConfigArgs *c) {
2142 if(c->op == SLAP_CONFIG_EMIT) {
2143 if (c->ca_private) {
2144 ConfigFile *cf = c->ca_private;
2145 value_add_one( &c->rvalue_vals, &cf->c_file );
2154 config_cfdir(ConfigArgs *c) {
2155 if(c->op == SLAP_CONFIG_EMIT) {
2156 if ( !BER_BVISEMPTY( &cfdir )) {
2157 value_add_one( &c->rvalue_vals, &cfdir );
2166 config_search_base(ConfigArgs *c) {
2167 if(c->op == SLAP_CONFIG_EMIT) {
2169 if (!BER_BVISEMPTY(&default_search_base)) {
2170 value_add_one(&c->rvalue_vals, &default_search_base);
2171 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2175 } else if( c->op == LDAP_MOD_DELETE ) {
2176 ch_free( default_search_base.bv_val );
2177 ch_free( default_search_nbase.bv_val );
2178 BER_BVZERO( &default_search_base );
2179 BER_BVZERO( &default_search_nbase );
2183 if(c->bi || c->be != frontendDB) {
2184 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2185 "prior to any backend or database definition\n",
2190 if(default_search_nbase.bv_len) {
2191 free(default_search_base.bv_val);
2192 free(default_search_nbase.bv_val);
2195 default_search_base = c->value_dn;
2196 default_search_nbase = c->value_ndn;
2200 /* For RE23 compatibility we allow this in the global entry
2201 * but we now defer it to the frontend entry to allow modules
2202 * to load new hash types.
2205 config_passwd_hash(ConfigArgs *c) {
2207 if (c->op == SLAP_CONFIG_EMIT) {
2209 /* Don't generate it in the global entry */
2210 if ( c->table == Cft_Global )
2212 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2213 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2214 value_add_one(&c->rvalue_vals, &bv);
2217 } else if ( c->op == LDAP_MOD_DELETE ) {
2218 /* Deleting from global is a no-op, only the frontendDB entry matters */
2219 if ( c->table == Cft_Global )
2221 if ( c->valx < 0 ) {
2222 ldap_charray_free( default_passwd_hash );
2223 default_passwd_hash = NULL;
2226 ch_free( default_passwd_hash[i] );
2227 for (; default_passwd_hash[i]; i++ )
2228 default_passwd_hash[i] = default_passwd_hash[i+1];
2232 for(i = 1; i < c->argc; i++) {
2233 if(!lutil_passwd_scheme(c->argv[i])) {
2234 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2235 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2236 c->log, c->cr_msg, c->argv[i]);
2238 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2241 if(!default_passwd_hash) {
2242 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2243 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2244 c->log, c->cr_msg, 0 );
2251 config_schema_dn(ConfigArgs *c) {
2252 if ( c->op == SLAP_CONFIG_EMIT ) {
2254 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2255 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2256 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2260 } else if ( c->op == LDAP_MOD_DELETE ) {
2261 ch_free( c->be->be_schemadn.bv_val );
2262 ch_free( c->be->be_schemandn.bv_val );
2263 BER_BVZERO( &c->be->be_schemadn );
2264 BER_BVZERO( &c->be->be_schemandn );
2267 ch_free( c->be->be_schemadn.bv_val );
2268 ch_free( c->be->be_schemandn.bv_val );
2269 c->be->be_schemadn = c->value_dn;
2270 c->be->be_schemandn = c->value_ndn;
2275 config_sizelimit(ConfigArgs *c) {
2277 struct slap_limits_set *lim = &c->be->be_def_limit;
2278 if (c->op == SLAP_CONFIG_EMIT) {
2283 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2284 if ( !BER_BVISEMPTY( &bv ))
2285 value_add_one( &c->rvalue_vals, &bv );
2289 } else if ( c->op == LDAP_MOD_DELETE ) {
2290 /* Reset to defaults or values from frontend */
2291 if ( c->be == frontendDB ) {
2292 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2293 lim->lms_s_hard = 0;
2294 lim->lms_s_unchecked = -1;
2296 lim->lms_s_pr_hide = 0;
2297 lim->lms_s_pr_total = 0;
2299 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2300 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2301 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2302 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2303 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2304 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2308 for(i = 1; i < c->argc; i++) {
2309 if(!strncasecmp(c->argv[i], "size", 4)) {
2310 rc = limits_parse_one(c->argv[i], lim);
2312 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2313 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2314 c->log, c->cr_msg, c->argv[i]);
2318 if(!strcasecmp(c->argv[i], "unlimited")) {
2319 lim->lms_s_soft = -1;
2321 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2322 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2323 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2324 c->log, c->cr_msg, c->argv[i]);
2328 lim->lms_s_hard = 0;
2333 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2334 /* This is a modification to the global limits apply it to
2335 * the other databases as needed */
2336 AttributeDescription *ad=NULL;
2337 const char *text = NULL;
2338 CfEntryInfo *ce = c->ca_entry->e_private;
2340 slap_str2ad(c->argv[0], &ad, &text);
2341 /* if we got here... */
2342 assert( ad != NULL );
2344 if ( ce->ce_type == Cft_Global ){
2347 for (; ce; ce=ce->ce_sibs) {
2348 Entry *dbe = ce->ce_entry;
2349 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2350 && (!attr_find(dbe->e_attrs, ad)) ) {
2351 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2352 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2353 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2354 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2355 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2356 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2364 config_timelimit(ConfigArgs *c) {
2366 struct slap_limits_set *lim = &c->be->be_def_limit;
2367 if (c->op == SLAP_CONFIG_EMIT) {
2372 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2373 if ( !BER_BVISEMPTY( &bv ))
2374 value_add_one( &c->rvalue_vals, &bv );
2378 } else if ( c->op == LDAP_MOD_DELETE ) {
2379 /* Reset to defaults or values from frontend */
2380 if ( c->be == frontendDB ) {
2381 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2382 lim->lms_t_hard = 0;
2384 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2385 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2389 for(i = 1; i < c->argc; i++) {
2390 if(!strncasecmp(c->argv[i], "time", 4)) {
2391 rc = limits_parse_one(c->argv[i], lim);
2393 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2394 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2395 c->log, c->cr_msg, c->argv[i]);
2399 if(!strcasecmp(c->argv[i], "unlimited")) {
2400 lim->lms_t_soft = -1;
2402 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2403 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2404 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2405 c->log, c->cr_msg, c->argv[i]);
2409 lim->lms_t_hard = 0;
2414 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2415 /* This is a modification to the global limits apply it to
2416 * the other databases as needed */
2417 AttributeDescription *ad=NULL;
2418 const char *text = NULL;
2419 CfEntryInfo *ce = c->ca_entry->e_private;
2421 slap_str2ad(c->argv[0], &ad, &text);
2422 /* if we got here... */
2423 assert( ad != NULL );
2425 if ( ce->ce_type == Cft_Global ){
2428 for (; ce; ce=ce->ce_sibs) {
2429 Entry *dbe = ce->ce_entry;
2430 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2431 && (!attr_find(dbe->e_attrs, ad)) ) {
2432 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2433 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2441 config_overlay(ConfigArgs *c) {
2442 if (c->op == SLAP_CONFIG_EMIT) {
2444 } else if ( c->op == LDAP_MOD_DELETE ) {
2447 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2448 c->valx, &c->bi, &c->reply)) {
2450 Debug( LDAP_DEBUG_ANY,
2451 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2452 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2454 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2461 config_subordinate(ConfigArgs *c)
2467 case SLAP_CONFIG_EMIT:
2468 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2471 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2472 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2475 value_add_one( &c->rvalue_vals, &bv );
2479 case LDAP_MOD_DELETE:
2480 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2481 glue_sub_del( c->be );
2483 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2488 case SLAP_CONFIG_ADD:
2489 if ( c->be->be_nsuffix == NULL ) {
2491 snprintf( c->cr_msg, sizeof( c->cr_msg),
2492 "subordinate configuration needs a suffix" );
2493 Debug( LDAP_DEBUG_ANY,
2495 c->log, c->cr_msg, 0 );
2500 if ( c->argc == 2 ) {
2501 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2504 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2506 snprintf( c->cr_msg, sizeof( c->cr_msg),
2507 "subordinate must be \"TRUE\" or \"advertise\"" );
2508 Debug( LDAP_DEBUG_ANY,
2509 "%s: suffix \"%s\": %s.\n",
2510 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2516 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2524 * [listener=<listener>] [{read|write}=]<size>
2527 #ifdef LDAP_TCP_BUFFER
2528 static BerVarray tcp_buffer;
2531 #define SLAP_TCP_RMEM (0x1U)
2532 #define SLAP_TCP_WMEM (0x2U)
2535 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2536 int *size, int *rw, Listener **l )
2538 int i, rc = LDAP_SUCCESS;
2539 LDAPURLDesc *lud = NULL;
2542 if ( val != NULL && argv == NULL ) {
2543 char *s = val->bv_val;
2545 argv = ldap_str2charray( s, " \t" );
2546 if ( argv == NULL ) {
2552 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2555 char *url = argv[ i ] + STRLENOF( "listener=" );
2557 if ( ldap_url_parse( url, &lud ) ) {
2558 rc = LDAP_INVALID_SYNTAX;
2562 *l = config_check_my_url( url, lud );
2564 rc = LDAP_NO_SUCH_ATTRIBUTE;
2572 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2573 *rw |= SLAP_TCP_RMEM;
2574 ptr += STRLENOF( "read=" );
2576 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2577 *rw |= SLAP_TCP_WMEM;
2578 ptr += STRLENOF( "write=" );
2581 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2584 /* accept any base */
2585 if ( lutil_atoix( size, ptr, 0 ) ) {
2586 rc = LDAP_INVALID_SYNTAX;
2591 if ( val != NULL && argv != NULL ) {
2592 ldap_charray_free( argv );
2595 if ( lud != NULL ) {
2596 ldap_free_urldesc( lud );
2603 tcp_buffer_delete_one( struct berval *val )
2606 int size = -1, rw = 0;
2609 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2616 Listener **ll = slapd_get_listeners();
2618 for ( i = 0; ll[ i ] != NULL; i++ ) {
2619 if ( ll[ i ] == l ) break;
2622 if ( ll[ i ] == NULL ) {
2623 return LDAP_NO_SUCH_ATTRIBUTE;
2626 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2627 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2629 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2630 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2631 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2635 /* NOTE: this affects listeners without a specific setting,
2636 * does not reset all listeners. If a listener without
2637 * specific settings was assigned a buffer because of
2638 * a global setting, it will not be reset. In any case,
2639 * buffer changes will only take place at restart. */
2640 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2641 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2648 tcp_buffer_delete( BerVarray vals )
2652 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2653 tcp_buffer_delete_one( &vals[ i ] );
2660 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2662 char buf[sizeof("2147483648")], *ptr;
2664 /* unparse for later use */
2665 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2667 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2670 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2671 if ( rw & SLAP_TCP_RMEM ) {
2672 val->bv_len += STRLENOF( "read=" );
2673 } else if ( rw & SLAP_TCP_WMEM ) {
2674 val->bv_len += STRLENOF( "write=" );
2678 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2683 ptr = lutil_strcopy( ptr, "listener=" );
2684 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2688 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2689 if ( rw & SLAP_TCP_RMEM ) {
2690 ptr = lutil_strcopy( ptr, "read=" );
2691 } else if ( rw & SLAP_TCP_WMEM ) {
2692 ptr = lutil_strcopy( ptr, "write=" );
2696 ptr = lutil_strcopy( ptr, buf );
2699 assert( val->bv_val + val->bv_len == ptr );
2701 return LDAP_SUCCESS;
2705 tcp_buffer_add_one( int argc, char **argv )
2708 int size = -1, rw = 0;
2714 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2719 /* unparse for later use */
2720 rc = tcp_buffer_unparse( size, rw, l, &val );
2721 if ( rc != LDAP_SUCCESS ) {
2725 /* use parsed values */
2728 Listener **ll = slapd_get_listeners();
2730 for ( i = 0; ll[ i ] != NULL; i++ ) {
2731 if ( ll[ i ] == l ) break;
2734 if ( ll[ i ] == NULL ) {
2735 return LDAP_NO_SUCH_ATTRIBUTE;
2738 /* buffer only applies to TCP listeners;
2739 * we do not do any check here, and delegate them
2740 * to setsockopt(2) */
2741 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2742 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2744 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2745 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2746 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2750 /* NOTE: this affects listeners without a specific setting,
2751 * does not set all listeners */
2752 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2753 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2756 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2758 tcp_buffer[ tcp_buffer_num ] = val;
2761 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2767 config_tcp_buffer( ConfigArgs *c )
2769 if ( c->op == SLAP_CONFIG_EMIT ) {
2770 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2773 value_add( &c->rvalue_vals, tcp_buffer );
2774 value_add( &c->rvalue_nvals, tcp_buffer );
2776 } else if ( c->op == LDAP_MOD_DELETE ) {
2778 tcp_buffer_delete( tcp_buffer );
2779 ber_bvarray_free( tcp_buffer );
2785 int size = -1, rw = 0;
2788 struct berval val = BER_BVNULL;
2792 if ( tcp_buffer_num == 0 ) {
2797 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2802 /* unparse for later use */
2803 rc = tcp_buffer_unparse( size, rw, l, &val );
2804 if ( rc != LDAP_SUCCESS ) {
2808 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2809 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2814 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2820 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2821 ber_memfree( tcp_buffer[ i ].bv_val );
2822 for ( ; i < tcp_buffer_num; i++ ) {
2823 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2828 if ( !BER_BVISNULL( &val ) ) {
2829 SLAP_FREE( val.bv_val );
2837 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2839 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2840 "<%s> unable to add value #%d",
2841 c->argv[0], tcp_buffer_num );
2842 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2843 c->log, c->cr_msg, 0 );
2850 #endif /* LDAP_TCP_BUFFER */
2853 config_suffix(ConfigArgs *c)
2856 struct berval pdn, ndn;
2857 char *notallowed = NULL;
2859 if ( c->be == frontendDB ) {
2860 notallowed = "frontend";
2862 } else if ( SLAP_MONITOR(c->be) ) {
2863 notallowed = "monitor";
2865 } else if ( SLAP_CONFIG(c->be) ) {
2866 notallowed = "config";
2869 if ( notallowed != NULL ) {
2870 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2874 case LDAP_MOD_DELETE:
2875 case LDAP_MOD_REPLACE:
2876 case LDAP_MOD_INCREMENT:
2877 case SLAP_CONFIG_ADD:
2878 if ( !BER_BVISNULL( &c->value_dn ) ) {
2879 snprintf( buf, sizeof( buf ), "<%s> ",
2880 c->value_dn.bv_val );
2883 Debug(LDAP_DEBUG_ANY,
2884 "%s: suffix %snot allowed in %s database.\n",
2885 c->log, buf, notallowed );
2888 case SLAP_CONFIG_EMIT:
2889 /* don't complain when emitting... */
2893 /* FIXME: don't know what values may be valid;
2894 * please remove assertion, or add legal values
2895 * to either block */
2903 if (c->op == SLAP_CONFIG_EMIT) {
2904 if ( c->be->be_suffix == NULL
2905 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2909 value_add( &c->rvalue_vals, c->be->be_suffix );
2910 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2913 } else if ( c->op == LDAP_MOD_DELETE ) {
2914 if ( c->valx < 0 ) {
2915 ber_bvarray_free( c->be->be_suffix );
2916 ber_bvarray_free( c->be->be_nsuffix );
2917 c->be->be_suffix = NULL;
2918 c->be->be_nsuffix = NULL;
2921 ch_free( c->be->be_suffix[i].bv_val );
2922 ch_free( c->be->be_nsuffix[i].bv_val );
2924 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2925 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2927 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2932 #ifdef SLAPD_MONITOR_DN
2933 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2934 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2936 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2937 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2942 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
2943 !BER_BVISNULL( &c->be->be_suffix[0] )) {
2944 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2945 c->argv[0], c->be->bd_info->bi_type );
2946 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2947 c->log, c->cr_msg, 0);
2954 if (SLAP_DBHIDDEN( c->be ))
2957 tbe = select_backend(&ndn, 0);
2959 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2965 BackendDB *b2 = tbe;
2967 /* Does tbe precede be? */
2968 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2971 char *type = tbe->bd_info->bi_type;
2973 if ( overlay_is_over( tbe ) ) {
2974 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2975 type = oi->oi_orig->bi_type;
2978 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2979 "already served by a preceding %s database",
2980 c->argv[0], pdn.bv_val, type );
2981 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2982 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2988 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2989 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2990 "base provided \"%s\" (assuming okay)\n",
2991 c->log, default_search_base.bv_val, 0);
2993 ber_bvarray_add(&c->be->be_suffix, &pdn);
2994 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2999 config_rootdn(ConfigArgs *c) {
3000 if (c->op == SLAP_CONFIG_EMIT) {
3001 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3002 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3003 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3008 } else if ( c->op == LDAP_MOD_DELETE ) {
3009 ch_free( c->be->be_rootdn.bv_val );
3010 ch_free( c->be->be_rootndn.bv_val );
3011 BER_BVZERO( &c->be->be_rootdn );
3012 BER_BVZERO( &c->be->be_rootndn );
3015 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3016 ch_free( c->be->be_rootdn.bv_val );
3017 ch_free( c->be->be_rootndn.bv_val );
3019 c->be->be_rootdn = c->value_dn;
3020 c->be->be_rootndn = c->value_ndn;
3025 config_rootpw(ConfigArgs *c) {
3028 if (c->op == SLAP_CONFIG_EMIT) {
3029 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3030 /* don't copy, because "rootpw" is marked
3032 c->value_bv = c->be->be_rootpw;
3036 } else if ( c->op == LDAP_MOD_DELETE ) {
3037 ch_free( c->be->be_rootpw.bv_val );
3038 BER_BVZERO( &c->be->be_rootpw );
3042 tbe = select_backend(&c->be->be_rootndn, 0);
3044 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3046 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3047 c->log, c->cr_msg, 0);
3050 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3051 ch_free( c->be->be_rootpw.bv_val );
3052 c->be->be_rootpw = c->value_bv;
3057 config_restrict(ConfigArgs *c) {
3058 slap_mask_t restrictops = 0;
3060 slap_verbmasks restrictable_ops[] = {
3061 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3062 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3063 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3064 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3065 { BER_BVC("modrdn"), 0 },
3066 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3067 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3068 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3069 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3070 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3071 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3072 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3073 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3074 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3075 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3076 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3080 if (c->op == SLAP_CONFIG_EMIT) {
3081 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3083 } else if ( c->op == LDAP_MOD_DELETE ) {
3085 c->be->be_restrictops = 0;
3087 i = verb_to_mask( c->line, restrictable_ops );
3088 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3092 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3094 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3095 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3096 c->log, c->cr_msg, c->argv[i]);
3099 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3100 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3101 c->be->be_restrictops |= restrictops;
3106 config_allows(ConfigArgs *c) {
3107 slap_mask_t allows = 0;
3109 slap_verbmasks allowable_ops[] = {
3110 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3111 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3112 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3113 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3114 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3117 if (c->op == SLAP_CONFIG_EMIT) {
3118 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3119 } else if ( c->op == LDAP_MOD_DELETE ) {
3123 i = verb_to_mask( c->line, allowable_ops );
3124 global_allows &= ~allowable_ops[i].mask;
3128 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3130 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3131 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3132 c->log, c->cr_msg, c->argv[i]);
3135 global_allows |= allows;
3140 config_disallows(ConfigArgs *c) {
3141 slap_mask_t disallows = 0;
3143 slap_verbmasks disallowable_ops[] = {
3144 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3145 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3146 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3147 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3148 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3149 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3152 if (c->op == SLAP_CONFIG_EMIT) {
3153 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3154 } else if ( c->op == LDAP_MOD_DELETE ) {
3156 global_disallows = 0;
3158 i = verb_to_mask( c->line, disallowable_ops );
3159 global_disallows &= ~disallowable_ops[i].mask;
3163 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3165 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3166 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3167 c->log, c->cr_msg, c->argv[i]);
3170 global_disallows |= disallows;
3175 config_requires(ConfigArgs *c) {
3176 slap_mask_t requires = frontendDB->be_requires;
3177 int i, argc = c->argc;
3178 char **argv = c->argv;
3180 slap_verbmasks requires_ops[] = {
3181 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3182 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3183 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3184 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3185 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3188 if (c->op == SLAP_CONFIG_EMIT) {
3189 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3190 } else if ( c->op == LDAP_MOD_DELETE ) {
3192 c->be->be_requires = 0;
3194 i = verb_to_mask( c->line, requires_ops );
3195 c->be->be_requires &= ~requires_ops[i].mask;
3199 /* "none" can only be first, to wipe out default/global values */
3200 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3205 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3207 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3208 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3209 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3210 c->log, c->cr_msg, 0);
3212 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3213 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3214 c->log, c->cr_msg, c->argv[i]);
3218 c->be->be_requires = requires;
3223 config_extra_attrs(ConfigArgs *c)
3225 assert( c->be != NULL );
3227 if ( c->op == SLAP_CONFIG_EMIT ) {
3230 if ( c->be->be_extra_anlist == NULL ) {
3234 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3235 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3238 } else if ( c->op == LDAP_MOD_DELETE ) {
3239 if ( c->be->be_extra_anlist == NULL ) {
3243 if ( c->valx < 0 ) {
3244 anlist_free( c->be->be_extra_anlist, 1, NULL );
3245 c->be->be_extra_anlist = NULL;
3250 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3253 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3257 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3259 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3260 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3265 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3266 if ( c->be->be_extra_anlist == NULL ) {
3274 static slap_verbmasks *loglevel_ops;
3277 loglevel_init( void )
3279 slap_verbmasks lo[] = {
3280 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3281 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3282 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3283 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3284 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3285 { BER_BVC("BER"), LDAP_DEBUG_BER },
3286 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3287 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3288 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3289 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3290 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3291 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3292 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3293 #if 0 /* no longer used (nor supported) */
3294 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3295 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3297 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3298 { BER_BVC("None"), LDAP_DEBUG_NONE },
3302 return slap_verbmasks_init( &loglevel_ops, lo );
3306 loglevel_destroy( void )
3308 if ( loglevel_ops ) {
3309 (void)slap_verbmasks_destroy( loglevel_ops );
3311 loglevel_ops = NULL;
3314 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3317 slap_loglevel_register( slap_mask_t m, struct berval *s )
3321 if ( loglevel_ops == NULL ) {
3325 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3328 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3336 slap_loglevel_get( struct berval *s, int *l )
3341 if ( loglevel_ops == NULL ) {
3345 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3346 m |= loglevel_ops[ i ].mask;
3349 for ( i = 1; m & i; i <<= 1 )
3356 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3359 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3370 str2loglevel( const char *s, int *l )
3374 if ( loglevel_ops == NULL ) {
3378 i = verb_to_mask( s, loglevel_ops );
3380 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3384 *l = loglevel_ops[ i ].mask;
3390 loglevel2str( int l )
3392 struct berval bv = BER_BVNULL;
3394 loglevel2bv( l, &bv );
3400 loglevel2bv( int l, struct berval *bv )
3402 if ( loglevel_ops == NULL ) {
3408 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3412 loglevel2bvarray( int l, BerVarray *bva )
3414 if ( loglevel_ops == NULL ) {
3418 return mask_to_verbs( loglevel_ops, l, bva );
3422 loglevel_print( FILE *out )
3426 if ( loglevel_ops == NULL ) {
3430 fprintf( out, "Installed log subsystems:\n\n" );
3431 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3432 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3434 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3435 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3436 loglevel_ops[ i ].word.bv_val, mask, mask );
3439 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3440 "by specific code\n\n" );
3445 static int config_syslog;
3448 config_loglevel(ConfigArgs *c) {
3451 if ( loglevel_ops == NULL ) {
3455 if (c->op == SLAP_CONFIG_EMIT) {
3456 /* Get default or commandline slapd setting */
3457 if ( ldap_syslog && !config_syslog )
3458 config_syslog = ldap_syslog;
3459 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3461 } else if ( c->op == LDAP_MOD_DELETE ) {
3465 i = verb_to_mask( c->line, loglevel_ops );
3466 config_syslog &= ~loglevel_ops[i].mask;
3468 if ( slapMode & SLAP_SERVER_MODE ) {
3469 ldap_syslog = config_syslog;
3474 for( i=1; i < c->argc; i++ ) {
3477 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3478 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3479 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3480 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3481 c->log, c->cr_msg, c->argv[i]);
3485 if ( str2loglevel( c->argv[i], &level ) ) {
3486 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3487 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3488 c->log, c->cr_msg, c->argv[i]);
3492 /* Explicitly setting a zero clears all the levels */
3494 config_syslog |= level;
3498 if ( slapMode & SLAP_SERVER_MODE ) {
3499 ldap_syslog = config_syslog;
3505 config_referral(ConfigArgs *c) {
3507 if (c->op == SLAP_CONFIG_EMIT) {
3508 if ( default_referral ) {
3509 value_add( &c->rvalue_vals, default_referral );
3514 } else if ( c->op == LDAP_MOD_DELETE ) {
3515 if ( c->valx < 0 ) {
3516 ber_bvarray_free( default_referral );
3517 default_referral = NULL;
3520 ch_free( default_referral[i].bv_val );
3521 for (; default_referral[i].bv_val; i++ )
3522 default_referral[i] = default_referral[i+1];
3526 if(validate_global_referral(c->argv[1])) {
3527 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3528 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3529 c->log, c->cr_msg, c->argv[1]);
3533 ber_str2bv(c->argv[1], 0, 0, &val);
3534 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3542 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3543 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3544 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3545 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3546 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3547 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3548 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3549 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3550 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3555 config_security(ConfigArgs *c) {
3556 slap_ssf_set_t *set = &c->be->be_ssf_set;
3559 if (c->op == SLAP_CONFIG_EMIT) {
3565 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3566 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3569 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3570 if ( bv.bv_len >= sizeof( numbuf ) ) {
3571 ber_bvarray_free_x( c->rvalue_vals, NULL );
3572 c->rvalue_vals = NULL;
3576 bv.bv_len += sec_keys[i].key.bv_len;
3577 bv.bv_val = ch_malloc( bv.bv_len + 1);
3578 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3579 strcpy( next, numbuf );
3580 ber_bvarray_add( &c->rvalue_vals, &bv );
3585 for(i = 1; i < c->argc; i++) {
3586 slap_ssf_t *tgt = NULL;
3588 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3589 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3590 sec_keys[j].key.bv_len)) {
3591 src = c->argv[i] + sec_keys[j].key.bv_len;
3592 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3597 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3598 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3599 c->log, c->cr_msg, c->argv[i]);
3603 if ( lutil_atou( tgt, src ) != 0 ) {
3604 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3605 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3606 c->log, c->cr_msg, c->argv[i]);
3614 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3618 for (; !BER_BVISNULL( &an->an_name ); an++) {
3619 /* if buflen == 0, assume the buffer size has been
3620 * already checked otherwise */
3621 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3622 if ( comma ) *ptr++ = ',';
3623 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3630 config_updatedn(ConfigArgs *c) {
3631 if (c->op == SLAP_CONFIG_EMIT) {
3632 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3633 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3634 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3638 } else if ( c->op == LDAP_MOD_DELETE ) {
3639 ch_free( c->be->be_update_ndn.bv_val );
3640 BER_BVZERO( &c->be->be_update_ndn );
3641 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3644 if(SLAP_SHADOW(c->be)) {
3645 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3646 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3647 c->log, c->cr_msg, 0);
3651 ber_memfree_x( c->value_dn.bv_val, NULL );
3652 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3653 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3655 c->be->be_update_ndn = c->value_ndn;
3656 BER_BVZERO( &c->value_dn );
3657 BER_BVZERO( &c->value_ndn );
3659 return config_slurp_shadow( c );
3663 config_shadow( ConfigArgs *c, slap_mask_t flag )
3665 char *notallowed = NULL;
3667 if ( c->be == frontendDB ) {
3668 notallowed = "frontend";
3670 } else if ( SLAP_MONITOR(c->be) ) {
3671 notallowed = "monitor";
3674 if ( notallowed != NULL ) {
3675 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3679 if ( SLAP_SHADOW(c->be) ) {
3680 /* if already shadow, only check consistency */
3681 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3682 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3688 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3689 if ( !SLAP_MULTIMASTER( c->be ))
3690 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3697 config_updateref(ConfigArgs *c) {
3699 if (c->op == SLAP_CONFIG_EMIT) {
3700 if ( c->be->be_update_refs ) {
3701 value_add( &c->rvalue_vals, c->be->be_update_refs );
3706 } else if ( c->op == LDAP_MOD_DELETE ) {
3707 if ( c->valx < 0 ) {
3708 ber_bvarray_free( c->be->be_update_refs );
3709 c->be->be_update_refs = NULL;
3712 ch_free( c->be->be_update_refs[i].bv_val );
3713 for (; c->be->be_update_refs[i].bv_val; i++)
3714 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3718 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3719 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3721 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3722 c->log, c->cr_msg, 0);
3726 if(validate_global_referral(c->argv[1])) {
3727 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3728 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3729 c->log, c->cr_msg, c->argv[1]);
3732 ber_str2bv(c->argv[1], 0, 0, &val);
3733 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3738 config_obsolete(ConfigArgs *c) {
3739 if (c->op == SLAP_CONFIG_EMIT)
3742 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3744 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3749 config_include(ConfigArgs *c) {
3750 int savelineno = c->lineno;
3753 ConfigFile *cfsave = cfn;
3754 ConfigFile *cf2 = NULL;
3756 /* Leftover from RE23. No dynamic config for include files */
3757 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3760 cf = ch_calloc( 1, sizeof(ConfigFile));
3761 if ( cfn->c_kids ) {
3762 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3768 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3769 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3770 c->lineno = savelineno - 1;
3773 if ( cf2 ) cf2->c_sibs = NULL;
3774 else cfn->c_kids = NULL;
3775 ch_free( cf->c_file.bv_val );
3785 config_tls_cleanup(ConfigArgs *c) {
3788 if ( slap_tls_ld ) {
3791 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3793 /* Force new ctx to be created */
3794 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3796 /* The ctx's refcount is bumped up here */
3797 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3798 /* This is a no-op if it's already loaded */
3799 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3806 config_tls_option(ConfigArgs *c) {
3808 LDAP *ld = slap_tls_ld;
3810 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3811 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3812 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3813 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3814 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3815 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3816 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3818 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3820 default: Debug(LDAP_DEBUG_ANY, "%s: "
3821 "unknown tls_option <0x%x>\n",
3822 c->log, c->type, 0);
3825 if (c->op == SLAP_CONFIG_EMIT) {
3826 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3827 } else if ( c->op == LDAP_MOD_DELETE ) {
3828 c->cleanup = config_tls_cleanup;
3829 return ldap_pvt_tls_set_option( ld, flag, NULL );
3831 ch_free(c->value_string);
3832 c->cleanup = config_tls_cleanup;
3833 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3836 /* FIXME: this ought to be provided by libldap */
3838 config_tls_config(ConfigArgs *c) {
3841 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3842 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3843 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3845 Debug(LDAP_DEBUG_ANY, "%s: "
3846 "unknown tls_option <0x%x>\n",
3847 c->log, c->type, 0);
3850 if (c->op == SLAP_CONFIG_EMIT) {
3851 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3852 } else if ( c->op == LDAP_MOD_DELETE ) {
3854 c->cleanup = config_tls_cleanup;
3855 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3857 ch_free( c->value_string );
3858 c->cleanup = config_tls_cleanup;
3859 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3860 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3861 Debug(LDAP_DEBUG_ANY, "%s: "
3862 "unable to parse %s \"%s\"\n",
3863 c->log, c->argv[0], c->argv[1] );
3866 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3868 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3873 static CfEntryInfo *
3874 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3884 if ( dn_match( &root->ce_entry->e_nname, dn ))
3887 c = dn->bv_val+dn->bv_len;
3888 for (;*c != ',';c--);
3892 for (--c;c>dn->bv_val && *c != ',';c--);
3896 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3898 root = root->ce_kids;
3900 for (;root;root=root->ce_sibs) {
3901 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3902 if ( cdn.bv_val == dn->bv_val ) {
3912 typedef struct setup_cookie {
3922 config_ldif_resp( Operation *op, SlapReply *rs )
3924 if ( rs->sr_type == REP_SEARCH ) {
3925 setup_cookie *sc = op->o_callback->sc_private;
3928 sc->cfb->cb_got_ldif = 1;
3929 /* Does the frontend exist? */
3930 if ( !sc->got_frontend ) {
3931 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3932 "olcDatabase", STRLENOF( "olcDatabase" )))
3934 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3935 STRLENOF( "olcDatabase" ), "={-1}frontend",
3936 STRLENOF( "={-1}frontend" )))
3940 sc->ca->be = frontendDB;
3941 sc->ca->bi = frontendDB->bd_info;
3942 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3943 rdn.bv_val = sc->ca->log;
3944 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3945 "%s=" SLAP_X_ORDERED_FMT "%s",
3946 cfAd_database->ad_cname.bv_val, -1,
3947 sc->ca->bi->bi_type);
3949 sc->frontend = config_build_entry( op, rs,
3950 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3951 sc->ca->be->be_cf_ocs );
3961 dnParent( &rs->sr_entry->e_nname, &pdn );
3963 /* Does the configDB exist? */
3964 if ( sc->got_frontend && !sc->got_config &&
3965 !strncmp( rs->sr_entry->e_nname.bv_val,
3966 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3967 dn_match( &config_rdn, &pdn ) )
3969 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3970 STRLENOF( "olcDatabase" ), "={0}config",
3971 STRLENOF( "={0}config" )))
3975 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3976 sc->ca->bi = sc->ca->be->bd_info;
3977 rdn.bv_val = sc->ca->log;
3978 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3979 "%s=" SLAP_X_ORDERED_FMT "%s",
3980 cfAd_database->ad_cname.bv_val, 0,
3981 sc->ca->bi->bi_type);
3983 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3984 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3991 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3992 if ( rs->sr_err != LDAP_SUCCESS ) {
3993 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3994 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4000 /* Configure and read the underlying back-ldif store */
4002 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4003 CfBackInfo *cfb = be->be_private;
4009 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4010 Connection conn = {0};
4011 OperationBuffer opbuf;
4013 SlapReply rs = {REP_RESULT};
4014 Filter filter = { LDAP_FILTER_PRESENT };
4015 struct berval filterstr = BER_BVC("(objectclass=*)");
4018 /* Is the config directory available? */
4019 if ( stat( dir, &st ) < 0 ) {
4020 /* No, so don't bother using the backing store.
4021 * All changes will be in-memory only.
4026 cfb->cb_db.bd_info = backend_info( "ldif" );
4027 if ( !cfb->cb_db.bd_info )
4028 return 0; /* FIXME: eventually this will be a fatal error */
4030 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4033 cfb->cb_db.be_suffix = be->be_suffix;
4034 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4036 /* The suffix is always "cn=config". The underlying DB's rootdn
4037 * is always the same as the suffix.
4039 cfb->cb_db.be_rootdn = be->be_suffix[0];
4040 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4042 ber_str2bv( dir, 0, 1, &cfdir );
4047 argv[0] = "directory";
4048 argv[1] = (char *)dir;
4053 c.table = Cft_Database;
4055 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4059 if ( config_add_vals( ct, &c ))
4062 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4066 void *thrctx = ldap_pvt_thread_pool_context();
4069 connection_fake_init( &conn, &opbuf, thrctx );
4072 filter.f_desc = slap_schema.si_ad_objectClass;
4074 op->o_tag = LDAP_REQ_SEARCH;
4076 op->ors_filter = &filter;
4077 op->ors_filterstr = filterstr;
4078 op->ors_scope = LDAP_SCOPE_SUBTREE;
4080 op->o_dn = c.be->be_rootdn;
4081 op->o_ndn = c.be->be_rootndn;
4083 op->o_req_dn = be->be_suffix[0];
4084 op->o_req_ndn = be->be_nsuffix[0];
4086 op->ors_tlimit = SLAP_NO_LIMIT;
4087 op->ors_slimit = SLAP_NO_LIMIT;
4089 op->ors_attrs = slap_anlist_all_attributes;
4090 op->ors_attrsonly = 0;
4092 op->o_callback = &cb;
4095 cb.sc_private = ≻
4096 sc.got_frontend = 0;
4101 op->o_bd = &cfb->cb_db;
4103 /* Allow unknown attrs in DNs */
4104 prev_DN_strict = slap_DN_strict;
4107 rc = op->o_bd->be_search( op, &rs );
4109 /* Restore normal DN validation */
4110 slap_DN_strict = prev_DN_strict;
4112 op->o_tag = LDAP_REQ_ADD;
4113 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4114 rs_reinit( &rs, REP_RESULT );
4115 op->ora_e = sc.frontend;
4116 rc = op->o_bd->be_add( op, &rs );
4118 if ( rc == LDAP_SUCCESS && sc.config ) {
4119 rs_reinit( &rs, REP_RESULT );
4120 op->ora_e = sc.config;
4121 rc = op->o_bd->be_add( op, &rs );
4123 ldap_pvt_thread_pool_context_reset( thrctx );
4126 /* ITS#4194 - only use if it's present, or we're converting. */
4127 if ( !readit || rc == LDAP_SUCCESS )
4128 cfb->cb_use_ldif = 1;
4134 CfOc_cmp( const void *c1, const void *c2 ) {
4135 const ConfigOCs *co1 = c1;
4136 const ConfigOCs *co2 = c2;
4138 return ber_bvcmp( co1->co_name, co2->co_name );
4142 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4145 i = init_config_attrs( ct );
4148 /* set up the objectclasses */
4149 i = init_config_ocs( ocs );
4152 for (i=0; ocs[i].co_def; i++) {
4153 if ( ocs[i].co_oc ) {
4154 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4155 if ( !ocs[i].co_table )
4156 ocs[i].co_table = ct;
4157 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4164 read_config(const char *fname, const char *dir) {
4167 const char *cfdir, *cfname;
4170 /* Setup the config backend */
4171 be = backend_db_init( "config", NULL, 0, NULL );
4175 cfb = be->be_private;
4176 be->be_dfltaccess = ACL_NONE;
4178 /* If no .conf, or a dir was specified, setup the dir */
4179 if ( !fname || dir ) {
4181 /* If explicitly given, check for existence */
4184 if ( stat( dir, &st ) < 0 ) {
4185 Debug( LDAP_DEBUG_ANY,
4186 "invalid config directory %s, error %d\n",
4192 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4194 /* if fname is defaulted, try reading .d */
4195 rc = config_setup_ldif( be, cfdir, !fname );
4198 /* It may be OK if the base object doesn't exist yet. */
4199 if ( rc != LDAP_NO_SUCH_OBJECT )
4201 /* ITS#4194: But if dir was specified and no fname,
4202 * then we were supposed to read the dir. Unless we're
4203 * trying to slapadd the dir...
4205 if ( dir && !fname ) {
4206 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4208 /* Assume it's slapadd with a config dir, let it continue */
4210 cfb->cb_got_ldif = 1;
4211 cfb->cb_use_ldif = 1;
4216 /* If we read the config from back-ldif, nothing to do here */
4217 if ( cfb->cb_got_ldif ) {
4226 cfname = SLAPD_DEFAULT_CONFIGFILE;
4228 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4231 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4234 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4235 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4236 &frontendDB->be_schemadn );
4237 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4238 if ( rc != LDAP_SUCCESS ) {
4239 Debug(LDAP_DEBUG_ANY, "read_config: "
4240 "unable to normalize default schema DN \"%s\"\n",
4241 frontendDB->be_schemadn.bv_val, 0, 0 );
4242 /* must not happen */
4246 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4247 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4248 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4249 "Check slapd -h arguments.\n", 0,0,0 );
4257 config_back_bind( Operation *op, SlapReply *rs )
4259 if ( be_isroot_pw( op ) ) {
4260 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4261 /* frontend sends result */
4262 return LDAP_SUCCESS;
4265 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4266 send_ldap_result( op, rs );
4272 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4276 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4278 rs->sr_attrs = op->ors_attrs;
4279 rs->sr_entry = ce->ce_entry;
4281 rc = send_search_entry( op, rs );
4282 if ( rc != LDAP_SUCCESS ) {
4286 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4287 if ( ce->ce_kids ) {
4288 rc = config_send( op, rs, ce->ce_kids, 1 );
4289 if ( rc ) return rc;
4292 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4293 rc = config_send( op, rs, ce, 0 );
4301 static ConfigTable *
4302 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4307 for (j=0; j<nocs; j++) {
4308 for (i=0; colst[j]->co_table[i].name; i++)
4309 if ( colst[j]->co_table[i].ad == ad ) {
4310 ca->table = colst[j]->co_type;
4311 return &colst[j]->co_table[i];
4317 /* Sort the attributes of the entry according to the order defined
4318 * in the objectclass, with required attributes occurring before
4319 * allowed attributes. For any attributes with sequencing dependencies
4320 * (e.g., rootDN must be defined after suffix) the objectclass must
4321 * list the attributes in the desired sequence.
4324 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4326 Attribute *a, *head = NULL, *tail = NULL, **prev;
4329 for (i=0; i<nocs; i++) {
4330 if ( colst[i]->co_oc->soc_required ) {
4331 AttributeType **at = colst[i]->co_oc->soc_required;
4332 for (j=0; at[j]; j++) {
4333 for (a=e->e_attrs, prev=&e->e_attrs; a;
4334 prev = &(*prev)->a_next, a=a->a_next) {
4335 if ( a->a_desc == at[j]->sat_ad ) {
4349 if ( colst[i]->co_oc->soc_allowed ) {
4350 AttributeType **at = colst[i]->co_oc->soc_allowed;
4351 for (j=0; at[j]; j++) {
4352 for (a=e->e_attrs, prev=&e->e_attrs; a;
4353 prev = &(*prev)->a_next, a=a->a_next) {
4354 if ( a->a_desc == at[j]->sat_ad ) {
4370 tail->a_next = e->e_attrs;
4376 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4378 Attribute *a = NULL;
4379 AttributeDescription *ad;
4389 Modifications *ml = ptr;
4391 vals = ml->sml_values;
4394 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4395 rc = ordered_value_sort( a, 1 );
4397 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4398 ad->ad_cname.bv_val );
4402 for ( i=0; vals[i].bv_val; i++ ) {
4403 ca->line = vals[i].bv_val;
4404 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4405 ca->line[0] == '{' ) {
4406 char *idx = strchr( ca->line, '}' );
4407 if ( idx ) ca->line = idx+1;
4409 rc = config_parse_vals( ct, ca, i );
4418 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4421 struct berval rtype, rval;
4423 AttributeDescription *ad = NULL;
4425 dnRdn( &e->e_name, rdn );
4426 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4427 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4428 rtype.bv_val = rdn->bv_val;
4429 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4432 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4433 a = attr_find( e->e_attrs, ad );
4434 if (!a ) return LDAP_NAMING_VIOLATION;
4441 config_rename_kids( CfEntryInfo *ce )
4444 struct berval rdn, nrdn;
4446 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4447 struct berval newdn, newndn;
4448 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4449 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4450 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4451 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4452 free( ce2->ce_entry->e_name.bv_val );
4453 free( ce2->ce_entry->e_nname.bv_val );
4454 ce2->ce_entry->e_name = newdn;
4455 ce2->ce_entry->e_nname = newndn;
4456 config_rename_kids( ce2 );
4461 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4462 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4463 struct berval *nnewrdn, int use_ldif )
4467 struct berval odn, ondn;
4471 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4472 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4475 free( a->a_vals[0].bv_val );
4476 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4477 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4478 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4479 strcpy( a->a_vals[0].bv_val, ptr1 );
4481 if ( a->a_nvals != a->a_vals ) {
4482 free( a->a_nvals[0].bv_val );
4483 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4484 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4485 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4486 strcpy( a->a_nvals[0].bv_val, ptr1 );
4489 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4490 BackendDB *be = op->o_bd;
4491 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4492 struct berval dn, ndn, xdn, xndn;
4494 op->o_bd = &cfb->cb_db;
4496 /* Save current rootdn; use the underlying DB's rootdn */
4500 xndn = op->o_req_ndn;
4501 op->o_dn = op->o_bd->be_rootdn;
4502 op->o_ndn = op->o_bd->be_rootndn;
4504 op->o_req_ndn = ondn;
4506 scp = op->o_callback;
4507 op->o_callback = ≻
4508 op->orr_newrdn = *newrdn;
4509 op->orr_nnewrdn = *nnewrdn;
4510 op->orr_newSup = NULL;
4511 op->orr_nnewSup = NULL;
4512 op->orr_deleteoldrdn = 1;
4513 op->orr_modlist = NULL;
4514 slap_modrdn2mods( op, rs );
4515 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4516 rc = op->o_bd->be_modrdn( op, rs );
4517 slap_mods_free( op->orr_modlist, 1 );
4520 op->o_callback = scp;
4524 op->o_req_ndn = xndn;
4527 free( ondn.bv_val );
4529 config_rename_kids( e->e_private );
4534 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4535 Entry *e, int idx, int tailindex, int use_ldif )
4537 struct berval ival, newrdn, nnewrdn;
4540 char ibuf[32], *ptr1, *ptr2 = NULL;
4543 rc = config_rename_attr( rs, e, &rdn, &a );
4544 if ( rc ) return rc;
4547 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4548 if ( ival.bv_len >= sizeof( ibuf ) ) {
4549 return LDAP_NAMING_VIOLATION;
4552 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4553 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4556 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4557 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4560 ptr2 = ber_bvchr( &rdn, '}' );
4564 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4566 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4567 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4568 a->a_desc->ad_cname.bv_len );
4570 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4571 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4575 /* Do the equivalent of ModRDN */
4576 /* Replace DN / NDN */
4577 newrdn.bv_len = ptr1 - newrdn.bv_val;
4578 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4579 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4581 free( nnewrdn.bv_val );
4582 free( newrdn.bv_val );
4587 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4588 SlapReply *rs, int *renum, int *ibase )
4591 int index = -1, gotindex = 0, nsibs, rc = 0;
4592 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4593 char *ptr1, *ptr2 = NULL;
4596 if ( renum ) *renum = 0;
4598 /* These entries don't get indexed/renumbered */
4599 if ( ce_type == Cft_Global ) return 0;
4600 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4602 if ( ce_type == Cft_Module )
4605 /* See if the rdn has an index already */
4606 dnRdn( &e->e_name, &rdn );
4607 if ( ce_type == Cft_Database ) {
4608 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4609 "frontend", STRLENOF("frontend") ))
4611 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4612 "config", STRLENOF("config") ))
4615 ptr1 = ber_bvchr( &e->e_name, '{' );
4616 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4618 ptr2 = strchr( ptr1, '}' );
4619 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4620 return LDAP_NAMING_VIOLATION;
4621 if ( ptr2-ptr1 == 1)
4622 return LDAP_NAMING_VIOLATION;
4624 index = strtol( ptr1 + 1, &next, 10 );
4625 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4626 return LDAP_NAMING_VIOLATION;
4629 /* Special case, we allow -1 for the frontendDB */
4630 if ( index != -1 || !isfrontend )
4631 return LDAP_NAMING_VIOLATION;
4633 if ( isconfig && index != 0 ){
4634 return LDAP_NAMING_VIOLATION;
4638 /* count related kids.
4639 * For entries of type Cft_Misc, only count siblings with same RDN type
4641 if ( ce_type == Cft_Misc ) {
4642 rdn.bv_val = e->e_nname.bv_val;
4643 ptr1 = strchr( rdn.bv_val, '=' );
4644 assert( ptr1 != NULL );
4646 rdn.bv_len = ptr1 - rdn.bv_val;
4648 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4650 if ( ce->ce_type != ce_type )
4653 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4655 ptr1 = strchr( rdn2.bv_val, '=' );
4656 assert( ptr1 != NULL );
4658 rdn2.bv_len = ptr1 - rdn2.bv_val;
4659 if ( bvmatch( &rdn, &rdn2 ))
4663 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4664 if ( ce->ce_type == ce_type ) nsibs++;
4668 /* account for -1 frontend */
4669 if ( ce_type == Cft_Database )
4672 if ( index != nsibs ) {
4674 if ( index < nsibs ) {
4675 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4676 /* Siblings need to be renumbered */
4677 if ( index != -1 || !isfrontend )
4681 /* config DB is always "0" */
4682 if ( isconfig && index == -1 ) {
4685 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4689 /* just make index = nsibs */
4691 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4694 if ( ibase ) *ibase = index;
4695 if ( renum ) *renum = renumber;
4699 /* Insert all superior classes of the given class */
4701 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4706 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4707 if ( count_oc( *sups, copp, nocs ) ) {
4712 co.co_name = &oc->soc_cname;
4713 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4717 /* check for duplicates */
4718 for ( i = 0; i < *nocs; i++ ) {
4719 if ( *copp && (*copp)[i] == cop ) {
4725 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4726 if ( tmp == NULL ) {
4730 (*copp)[*nocs] = cop;
4738 /* Find all superior classes of the given objectclasses,
4739 * return list in order of most-subordinate first.
4741 * Special / auxiliary / Cft_Misc classes always take precedence.
4744 count_ocs( Attribute *oc_at, int *nocs )
4746 int i, j, misc = -1;
4747 ConfigOCs **colst = NULL;
4751 for ( i = oc_at->a_numvals; i--; ) {
4752 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4754 assert( oc != NULL );
4755 if ( count_oc( oc, &colst, nocs ) ) {
4765 ConfigOCs *tmp = colst[i];
4766 colst[i] = colst[j];
4768 if (tmp->co_type == Cft_Misc)
4772 /* Move misc class to front of list */
4774 ConfigOCs *tmp = colst[misc];
4775 for (i=misc; i>0; i--)
4776 colst[i] = colst[i-1];
4784 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4786 /* Leftover from RE23. Never parse this entry */
4787 return LDAP_COMPARE_TRUE;
4791 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4795 /* This entry is hardcoded, don't re-parse it */
4796 if ( p->ce_type == Cft_Global ) {
4797 cfn = p->ce_private;
4798 ca->ca_private = cfn;
4799 return LDAP_COMPARE_TRUE;
4801 if ( p->ce_type != Cft_Schema )
4802 return LDAP_CONSTRAINT_VIOLATION;
4804 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4805 ca->ca_private = cfn;
4806 cfo = p->ce_private;
4807 cfn->c_sibs = cfo->c_kids;
4809 return LDAP_SUCCESS;
4813 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4815 if ( p->ce_type != Cft_Global ) {
4816 return LDAP_CONSTRAINT_VIOLATION;
4818 /* config must be {0}, nothing else allowed */
4819 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4820 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4821 return LDAP_CONSTRAINT_VIOLATION;
4823 ca->be = frontendDB; /* just to get past check_vals */
4824 return LDAP_SUCCESS;
4828 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4830 if ( p->ce_type != Cft_Global ) {
4831 return LDAP_CONSTRAINT_VIOLATION;
4833 return LDAP_SUCCESS;
4837 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4839 if ( p->ce_type != Cft_Global ) {
4840 return LDAP_CONSTRAINT_VIOLATION;
4842 return LDAP_SUCCESS;
4846 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4848 if ( p->ce_type != Cft_Database ) {
4849 return LDAP_CONSTRAINT_VIOLATION;
4852 return LDAP_SUCCESS;
4856 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4861 AttributeDescription *ad;
4867 if ( cfn->c_cr_head ) {
4868 struct berval bv = BER_BVC("olcDitContentRules");
4870 slap_bv2ad( &bv, &ad, &text );
4871 ct = config_find_table( colst, nocs, ad, ca );
4872 config_del_vals( ct, ca );
4874 if ( cfn->c_oc_head ) {
4875 struct berval bv = BER_BVC("olcObjectClasses");
4877 slap_bv2ad( &bv, &ad, &text );
4878 ct = config_find_table( colst, nocs, ad, ca );
4879 config_del_vals( ct, ca );
4881 if ( cfn->c_at_head ) {
4882 struct berval bv = BER_BVC("olcAttributeTypes");
4884 slap_bv2ad( &bv, &ad, &text );
4885 ct = config_find_table( colst, nocs, ad, ca );
4886 config_del_vals( ct, ca );
4888 if ( cfn->c_syn_head ) {
4889 struct berval bv = BER_BVC("olcLdapSyntaxes");
4891 slap_bv2ad( &bv, &ad, &text );
4892 ct = config_find_table( colst, nocs, ad, ca );
4893 config_del_vals( ct, ca );
4895 if ( cfn->c_om_head ) {
4896 struct berval bv = BER_BVC("olcObjectIdentifier");
4898 slap_bv2ad( &bv, &ad, &text );
4899 ct = config_find_table( colst, nocs, ad, ca );
4900 config_del_vals( ct, ca );
4902 cfo = p->ce_private;
4903 cfo->c_kids = cfn->c_sibs;
4908 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4910 int rc = LDAP_CONSTRAINT_VIOLATION;
4913 if ( (*cop)->co_ldadd ) {
4914 rc = (*cop)->co_ldadd( last, e, ca );
4915 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4920 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4921 ConfigOCs co = { 0 };
4923 co.co_name = &(*ocp)->soc_cname;
4924 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4925 if ( *cop == NULL ) {
4929 rc = config_add_oc( cop, last, e, ca );
4930 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4938 /* Parse an LDAP entry into config directives */
4940 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4941 int *renum, Operation *op )
4943 CfEntryInfo *ce, *last = NULL;
4944 ConfigOCs co, *coptr, **colst;
4945 Attribute *a, *oc_at, *soc_at;
4946 int i, ibase = -1, nocs, rc = 0;
4949 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4951 memset( ca, 0, sizeof(ConfigArgs));
4953 /* Make sure parent exists and entry does not. But allow
4954 * Databases and Overlays to be inserted. Don't do any
4955 * auto-renumbering if manageDSAit control is present.
4957 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4959 if ( ( op && op->o_managedsait ) ||
4960 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4961 ce->ce_type != Cft_Module ) )
4963 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4964 "DN=\"%s\" already exists\n",
4965 log_prefix, e->e_name.bv_val, 0 );
4966 /* global schema ignores all writes */
4967 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4968 return LDAP_COMPARE_TRUE;
4969 return LDAP_ALREADY_EXISTS;
4973 dnParent( &e->e_nname, &pdn );
4975 /* If last is NULL, the new entry is the root/suffix entry,
4976 * otherwise last should be the parent.
4978 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4980 rs->sr_matched = last->ce_entry->e_name.bv_val;
4982 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4983 "DN=\"%s\" not child of DN=\"%s\"\n",
4984 log_prefix, e->e_name.bv_val,
4985 last->ce_entry->e_name.bv_val );
4986 return LDAP_NO_SUCH_OBJECT;
4990 /* No parent, must be root. This will never happen... */
4991 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4992 return LDAP_NO_SUCH_OBJECT;
4995 if ( last && !access_allowed( op, last->ce_entry,
4996 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4998 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4999 "DN=\"%s\" no write access to \"children\" of parent\n",
5000 log_prefix, e->e_name.bv_val, 0 );
5001 return LDAP_INSUFFICIENT_ACCESS;
5005 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5007 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5008 "DN=\"%s\" no objectClass\n",
5009 log_prefix, e->e_name.bv_val, 0 );
5010 return LDAP_OBJECT_CLASS_VIOLATION;
5013 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5015 ObjectClass *soc = NULL;
5016 char textbuf[ SLAP_TEXT_BUFLEN ];
5017 const char *text = textbuf;
5019 /* FIXME: check result */
5020 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5021 &text, textbuf, sizeof(textbuf), NULL );
5022 if ( rc != LDAP_SUCCESS ) {
5023 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5024 "DN=\"%s\" no structural objectClass (%s)\n",
5025 log_prefix, e->e_name.bv_val, text );
5028 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5029 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5030 if ( soc_at == NULL ) {
5031 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5032 "DN=\"%s\" no structural objectClass; "
5033 "unable to merge computed class %s\n",
5034 log_prefix, e->e_name.bv_val,
5035 soc->soc_cname.bv_val );
5036 return LDAP_OBJECT_CLASS_VIOLATION;
5039 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5040 "DN=\"%s\" no structural objectClass; "
5041 "computed objectClass %s merged\n",
5042 log_prefix, e->e_name.bv_val,
5043 soc->soc_cname.bv_val );
5046 /* Fake the coordinates based on whether we're part of an
5047 * LDAP Add or if reading the config dir
5050 ca->fname = "slapd";
5053 ca->fname = cfdir.bv_val;
5058 co.co_name = &soc_at->a_nvals[0];
5059 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5060 if ( coptr == NULL ) {
5061 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5062 "DN=\"%s\" no structural objectClass in configuration table\n",
5063 log_prefix, e->e_name.bv_val, 0 );
5064 return LDAP_OBJECT_CLASS_VIOLATION;
5067 /* Only the root can be Cft_Global, everything else must
5068 * have a parent. Only limited nesting arrangements are allowed.
5070 rc = LDAP_CONSTRAINT_VIOLATION;
5071 if ( coptr->co_type == Cft_Global && !last ) {
5072 cfn = cfb->cb_config;
5073 ca->ca_private = cfn;
5074 ca->be = frontendDB; /* just to get past check_vals */
5078 colst = count_ocs( oc_at, &nocs );
5080 /* Check whether the Add is allowed by its parent, and do
5081 * any necessary arg setup
5084 rc = config_add_oc( &coptr, last, e, ca );
5085 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5086 for ( i = 0; i<nocs; i++ ) {
5087 /* Already checked these */
5088 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5090 if ( colst[i]->co_ldadd &&
5091 ( rc = colst[i]->co_ldadd( last, e, ca ))
5092 != LDAP_CONSTRAINT_VIOLATION ) {
5098 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5099 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5100 "DN=\"%s\" no structural objectClass add function\n",
5101 log_prefix, e->e_name.bv_val, 0 );
5102 return LDAP_OBJECT_CLASS_VIOLATION;
5106 /* Add the entry but don't parse it, we already have its contents */
5107 if ( rc == LDAP_COMPARE_TRUE ) {
5112 if ( rc != LDAP_SUCCESS )
5115 /* Parse all the values and check for simple syntax errors before
5116 * performing any set actions.
5118 * If doing an LDAPadd, check for indexed names and any necessary
5119 * renaming/renumbering. Entries that don't need indexed names are
5120 * ignored. Entries that need an indexed name and arrive without one
5121 * are assigned to the end. Entries that arrive with an index may
5122 * cause the following entries to be renumbered/bumped down.
5124 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5125 * don't allow Adding an entry with an index that's already in use.
5126 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5128 * These entries can have auto-assigned indexes (appended to the end)
5129 * but only the other types support auto-renumbering of siblings.
5132 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5137 if ( renum && *renum && coptr->co_type != Cft_Database &&
5138 coptr->co_type != Cft_Overlay )
5140 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5141 "operation requires sibling renumbering" );
5142 rc = LDAP_UNWILLING_TO_PERFORM;
5147 init_config_argv( ca );
5149 /* Make sure we process attrs in the required order */
5150 sort_attrs( e, colst, nocs );
5152 for ( a = e->e_attrs; a; a = a->a_next ) {
5153 if ( a == oc_at ) continue;
5154 ct = config_find_table( colst, nocs, a->a_desc, ca );
5155 if ( !ct ) continue; /* user data? */
5156 rc = check_vals( ct, ca, a, 1 );
5157 if ( rc ) goto done_noop;
5160 /* Basic syntax checks are OK. Do the actual settings. */
5161 for ( a=e->e_attrs; a; a=a->a_next ) {
5162 if ( a == oc_at ) continue;
5163 ct = config_find_table( colst, nocs, a->a_desc, ca );
5164 if ( !ct ) continue; /* user data? */
5165 for (i=0; a->a_vals[i].bv_val; i++) {
5168 ca->line = a->a_vals[i].bv_val;
5169 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5170 ptr = strchr( ca->line, '}' );
5172 iptr = strchr( ca->line, '{' );
5176 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5178 ca->valx = strtol( iptr+1, NULL, 0 );
5183 rc = config_parse_add( ct, ca, i );
5191 /* Newly added databases and overlays need to be started up */
5192 if ( CONFIG_ONLINE_ADD( ca )) {
5193 if ( coptr->co_type == Cft_Database ) {
5194 rc = backend_startup_one( ca->be, &ca->reply );
5196 } else if ( coptr->co_type == Cft_Overlay ) {
5197 if ( ca->bi->bi_db_open ) {
5198 BackendInfo *bi_orig = ca->be->bd_info;
5199 ca->be->bd_info = ca->bi;
5200 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5201 ca->be->bd_info = bi_orig;
5203 } else if ( ca->cleanup ) {
5204 rc = ca->cleanup( ca );
5207 if (ca->cr_msg[0] == '\0')
5208 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5210 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5211 ca->log, ca->cr_msg, ca->argv[1] );
5218 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5219 ce->ce_parent = last;
5220 ce->ce_entry = entry_dup( e );
5221 ce->ce_entry->e_private = ce;
5222 ce->ce_type = coptr->co_type;
5225 ce->ce_private = ca->ca_private;
5226 ca->ca_entry = ce->ce_entry;
5229 } else if ( last->ce_kids ) {
5230 CfEntryInfo *c2, **cprev;
5232 /* Advance to first of this type */
5233 cprev = &last->ce_kids;
5234 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5235 cprev = &c2->ce_sibs;
5238 /* Account for the (-1) frontendDB entry */
5239 if ( ce->ce_type == Cft_Database ) {
5240 if ( ca->be == frontendDB )
5242 else if ( ibase != -1 )
5247 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5248 cprev = &c2->ce_sibs;
5254 for ( i=0; i<ibase; i++ ) {
5256 cprev = &c2->ce_sibs;
5259 ce->ce_sibs = *cprev;
5267 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5268 if ( ca->be != frontendDB )
5269 backend_destroy_one( ca->be, 1 );
5270 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5271 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5272 } else if ( coptr->co_type == Cft_Schema ) {
5273 schema_destroy_one( ca, colst, nocs, last );
5278 ch_free( ca->argv );
5279 if ( colst ) ch_free( colst );
5283 #define BIGTMP 10000
5285 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5286 int base, int rebase, int max, int use_ldif )
5288 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5289 ConfigType etype = ce->ce_type;
5290 int count = 0, rc = 0;
5292 /* Reverse ce list */
5293 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5294 if (ce2->ce_type != etype) {
5299 ce2->ce_sibs = cetmp;
5302 if ( max && count >= max ) {
5308 /* Move original to a temp name until increments are done */
5310 ce->ce_entry->e_private = NULL;
5311 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5312 base+BIGTMP, 0, use_ldif );
5313 ce->ce_entry->e_private = ce;
5315 /* start incrementing */
5316 for (ce2=cetmp; ce2; ce2=ce3) {
5318 ce2->ce_sibs = cerem;
5321 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5322 count+base, 0, use_ldif );
5326 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5327 base, 0, use_ldif );
5332 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5333 CfEntryInfo *ce2, int old, int use_ldif )
5337 /* Renumber original to a temp value */
5338 ce->ce_entry->e_private = NULL;
5339 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5340 old+BIGTMP, 0, use_ldif );
5341 ce->ce_entry->e_private = ce;
5343 /* start decrementing */
5344 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5345 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5346 count+old, 0, use_ldif );
5349 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5350 count+old, 0, use_ldif );
5353 /* Parse an LDAP entry into config directives, then store in underlying
5357 config_back_add( Operation *op, SlapReply *rs )
5363 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5364 NULL, ACL_WADD, NULL )) {
5365 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5370 * Check for attribute ACL
5372 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5373 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5374 rs->sr_text = "no write access to attribute";
5378 cfb = (CfBackInfo *)op->o_bd->be_private;
5380 /* add opattrs for syncprov */
5382 char textbuf[SLAP_TEXT_BUFLEN];
5383 size_t textlen = sizeof textbuf;
5384 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5385 &rs->sr_text, textbuf, sizeof( textbuf ) );
5386 if ( rs->sr_err != LDAP_SUCCESS )
5388 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5389 if ( rs->sr_err != LDAP_SUCCESS ) {
5390 Debug( LDAP_DEBUG_TRACE,
5391 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5392 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5397 if ( op->o_abandon ) {
5398 rs->sr_err = SLAPD_ABANDON;
5401 ldap_pvt_thread_pool_pause( &connection_pool );
5404 * 1) check for existence of entry
5405 * 2) check for sibling renumbering
5406 * 3) perform internal add
5407 * 4) perform any necessary renumbering
5408 * 5) store entry in underlying database
5410 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5411 if ( rs->sr_err != LDAP_SUCCESS ) {
5412 rs->sr_text = ca.cr_msg;
5417 CfEntryInfo *ce = ca.ca_entry->e_private;
5418 req_add_s addr = op->oq_add;
5419 op->o_tag = LDAP_REQ_MODRDN;
5420 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5421 op->o_tag = LDAP_REQ_ADD;
5423 if ( rs->sr_err != LDAP_SUCCESS ) {
5428 if ( cfb->cb_use_ldif ) {
5429 BackendDB *be = op->o_bd;
5430 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5431 struct berval dn, ndn;
5433 op->o_bd = &cfb->cb_db;
5435 /* Save current rootdn; use the underlying DB's rootdn */
5438 op->o_dn = op->o_bd->be_rootdn;
5439 op->o_ndn = op->o_bd->be_rootndn;
5441 scp = op->o_callback;
5442 op->o_callback = ≻
5443 op->o_bd->be_add( op, rs );
5445 op->o_callback = scp;
5451 ldap_pvt_thread_pool_resume( &connection_pool );
5454 { int repl = op->o_dont_replicate;
5455 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5456 rs->sr_text = NULL; /* Set after config_add_internal */
5457 rs->sr_err = LDAP_SUCCESS;
5458 op->o_dont_replicate = 1;
5460 send_ldap_result( op, rs );
5461 op->o_dont_replicate = repl;
5463 slap_graduate_commit_csn( op );
5467 typedef struct delrec {
5468 struct delrec *next;
5474 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5480 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5481 ca->line[0] == '{' )
5483 char *ptr = strchr( ca->line + 1, '}' );
5487 ca->valx = strtol( ca->line + 1, &next, 0 );
5488 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5494 rc = config_parse_add( ct, ca, i );
5502 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5505 int rc = LDAP_UNWILLING_TO_PERFORM;
5507 Entry *e = ce->ce_entry;
5508 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5513 delrec *dels = NULL, *deltail = NULL;
5515 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5516 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5518 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5519 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5523 colst = count_ocs( oc_at, &nocs );
5525 /* make sure add/del flags are clear; should always be true */
5526 for ( s = save_attrs; s; s = s->a_next ) {
5527 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5530 e->e_attrs = attrs_dup( e->e_attrs );
5532 init_config_argv( ca );
5535 ca->ca_private = ce->ce_private;
5537 ca->fname = "slapd";
5539 strcpy( ca->log, "back-config" );
5541 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5542 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5543 switch (ml->sml_op) {
5544 case LDAP_MOD_DELETE:
5545 case LDAP_MOD_REPLACE:
5546 case SLAP_MOD_SOFTDEL:
5548 BerVarray vals = NULL, nvals = NULL;
5550 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5552 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5553 ml->sml_desc->ad_cname.bv_val );
5556 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5557 vals = ml->sml_values;
5558 nvals = ml->sml_nvalues;
5559 ml->sml_values = NULL;
5560 ml->sml_nvalues = NULL;
5562 /* If we're deleting by values, remember the indexes of the
5563 * values we deleted.
5565 if ( ct && ml->sml_values ) {
5567 i = ml->sml_numvals;
5568 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5579 rc = modify_delete_vindex(e, &ml->sml_mod,
5580 get_permissiveModify(op),
5581 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5582 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5583 ml->sml_values = vals;
5584 ml->sml_nvalues = nvals;
5586 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5590 /* FIXME: check rc before fallthru? */
5594 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5596 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5597 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5598 && attr_find( e->e_attrs, ml->sml_desc ) )
5605 case SLAP_MOD_SOFTADD: {
5606 int mop = ml->sml_op;
5608 ml->sml_op = LDAP_MOD_ADD;
5610 if ( ct->arg_type & ARG_NO_INSERT ) {
5611 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5613 navals = a->a_numvals;
5616 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5617 if ( ml->sml_values[i].bv_val[0] == '{' &&
5620 char *next, *val = ml->sml_values[i].bv_val + 1;
5623 j = strtol( val, &next, 0 );
5624 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5626 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5627 ml->sml_desc->ad_cname.bv_val );
5631 rc = check_vals( ct, ca, ml, 0 );
5632 if ( rc ) goto out_noop;
5635 rc = modify_add_values(e, &ml->sml_mod,
5636 get_permissiveModify(op),
5637 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5639 /* If value already exists, show success here
5640 * and ignore this operation down below.
5642 if ( mop == SLAP_MOD_SOFTADD ) {
5643 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5653 case LDAP_MOD_INCREMENT: /* FIXME */
5658 if(rc != LDAP_SUCCESS) break;
5661 if ( rc == LDAP_SUCCESS) {
5662 /* check that the entry still obeys the schema */
5663 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5664 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5666 if ( rc ) goto out_noop;
5668 /* Basic syntax checks are OK. Do the actual settings. */
5669 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5670 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5671 if ( !ct ) continue;
5673 s = attr_find( save_attrs, ml->sml_desc );
5674 a = attr_find( e->e_attrs, ml->sml_desc );
5676 switch (ml->sml_op) {
5677 case LDAP_MOD_DELETE:
5678 case LDAP_MOD_REPLACE: {
5679 BerVarray vals = NULL, nvals = NULL;
5682 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5683 vals = ml->sml_values;
5684 nvals = ml->sml_nvalues;
5685 ml->sml_values = NULL;
5686 ml->sml_nvalues = NULL;
5689 if ( ml->sml_values )
5692 /* If we didn't delete the whole attribute */
5693 if ( ml->sml_values && a ) {
5694 struct berval *mvals;
5697 if ( ml->sml_nvalues )
5698 mvals = ml->sml_nvalues;
5700 mvals = ml->sml_values;
5702 /* use the indexes we saved up above */
5703 for (i=0; i < d->nidx; i++) {
5704 struct berval bv = *mvals++;
5705 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5706 bv.bv_val[0] == '{' ) {
5707 ptr = strchr( bv.bv_val, '}' ) + 1;
5708 bv.bv_len -= ptr - bv.bv_val;
5711 ca->line = bv.bv_val;
5712 ca->valx = d->idx[i];
5713 config_parse_vals(ct, ca, d->idx[i] );
5714 rc = config_del_vals( ct, ca );
5715 if ( rc != LDAP_SUCCESS ) break;
5717 s->a_flags |= SLAP_ATTR_IXDEL;
5718 for (j=i+1; j < d->nidx; j++)
5719 if ( d->idx[j] >d->idx[i] )
5726 rc = config_del_vals( ct, ca );
5727 if ( rc ) rc = LDAP_OTHER;
5729 s->a_flags |= SLAP_ATTR_IXDEL;
5731 if ( ml->sml_values ) {
5736 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5737 ml->sml_values = vals;
5738 ml->sml_nvalues = nvals;
5740 if ( !vals || rc != LDAP_SUCCESS )
5743 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5748 for (i=0; ml->sml_values[i].bv_val; i++) {
5749 ca->line = ml->sml_values[i].bv_val;
5751 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5754 a->a_flags |= SLAP_ATTR_IXADD;
5761 /* Undo for a failed operation */
5762 if ( rc != LDAP_SUCCESS ) {
5763 ConfigReply msg = ca->reply;
5764 for ( s = save_attrs; s; s = s->a_next ) {
5765 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5766 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5767 ct = config_find_table( colst, nocs, s->a_desc, ca );
5768 a = attr_find( e->e_attrs, s->a_desc );
5770 /* clear the flag so the add check below will skip it */
5771 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5775 config_del_vals( ct, ca );
5777 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5778 ca->line = s->a_vals[i].bv_val;
5780 config_modify_add( ct, ca, s->a_desc, i );
5784 for ( a = e->e_attrs; a; a = a->a_next ) {
5785 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5786 ct = config_find_table( colst, nocs, a->a_desc, ca );
5790 config_del_vals( ct, ca );
5791 s = attr_find( save_attrs, a->a_desc );
5793 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5794 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5795 ca->line = s->a_vals[i].bv_val;
5797 config_modify_add( ct, ca, s->a_desc, i );
5808 if ( rc == LDAP_SUCCESS ) {
5809 attrs_free( save_attrs );
5812 attrs_free( e->e_attrs );
5813 e->e_attrs = save_attrs;
5815 ch_free( ca->argv );
5816 if ( colst ) ch_free( colst );
5818 deltail = dels->next;
5827 config_back_modify( Operation *op, SlapReply *rs )
5830 CfEntryInfo *ce, *last;
5832 ConfigArgs ca = {0};
5835 AttributeDescription *rad = NULL;
5838 cfb = (CfBackInfo *)op->o_bd->be_private;
5840 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5843 rs->sr_matched = last->ce_entry->e_name.bv_val;
5844 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5848 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5849 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5853 /* Get type of RDN */
5854 rdn = ce->ce_entry->e_nname;
5855 ptr = strchr( rdn.bv_val, '=' );
5856 rdn.bv_len = ptr - rdn.bv_val;
5857 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5858 if ( rs->sr_err != LDAP_SUCCESS ) {
5862 /* Some basic validation... */
5863 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5864 /* Don't allow Modify of RDN; must use ModRdn for that. */
5865 if ( ml->sml_desc == rad ) {
5866 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5867 rs->sr_text = "Use modrdn to change the entry name";
5870 /* Internal update of contextCSN? */
5871 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5877 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5880 if ( op->o_abandon ) {
5881 rs->sr_err = SLAPD_ABANDON;
5884 ldap_pvt_thread_pool_pause( &connection_pool );
5888 * 1) perform the Modify on the cached Entry.
5889 * 2) verify that the Entry still satisfies the schema.
5890 * 3) perform the individual config operations.
5891 * 4) store Modified entry in underlying LDIF backend.
5893 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5895 rs->sr_text = ca.cr_msg;
5896 } else if ( cfb->cb_use_ldif ) {
5897 BackendDB *be = op->o_bd;
5898 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5899 struct berval dn, ndn;
5901 op->o_bd = &cfb->cb_db;
5905 op->o_dn = op->o_bd->be_rootdn;
5906 op->o_ndn = op->o_bd->be_rootndn;
5908 scp = op->o_callback;
5909 op->o_callback = ≻
5910 op->o_bd->be_modify( op, rs );
5912 op->o_callback = scp;
5918 ldap_pvt_thread_pool_resume( &connection_pool );
5920 send_ldap_result( op, rs );
5921 slap_graduate_commit_csn( op );
5926 config_back_modrdn( Operation *op, SlapReply *rs )
5929 CfEntryInfo *ce, *last;
5933 cfb = (CfBackInfo *)op->o_bd->be_private;
5935 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5938 rs->sr_matched = last->ce_entry->e_name.bv_val;
5939 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5942 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5943 NULL, ACL_WRITE, NULL )) {
5944 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5948 if ( ce->ce_parent )
5949 parent = ce->ce_parent->ce_entry;
5951 parent = (Entry *)&slap_entry_root;
5952 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5953 NULL, ACL_WRITE, NULL )) {
5954 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5959 /* We don't allow moving objects to new parents.
5960 * Generally we only allow reordering a set of ordered entries.
5962 if ( op->orr_newSup ) {
5963 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5967 /* If newRDN == oldRDN, quietly succeed */
5968 dnRdn( &op->o_req_ndn, &rdn );
5969 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5970 rs->sr_err = LDAP_SUCCESS;
5974 /* Current behavior, subject to change as needed:
5976 * For backends and overlays, we only allow renumbering.
5977 * For schema, we allow renaming with the same number.
5978 * Otherwise, the op is not allowed.
5981 if ( ce->ce_type == Cft_Schema ) {
5985 /* Can't alter the main cn=schema entry */
5986 if ( ce->ce_parent->ce_type == Cft_Global ) {
5987 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5988 rs->sr_text = "renaming not allowed for this entry";
5992 /* We could support this later if desired */
5993 ptr1 = ber_bvchr( &rdn, '}' );
5994 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5995 len = ptr1 - rdn.bv_val;
5996 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5997 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5998 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5999 rs->sr_text = "schema reordering not supported";
6002 } else if ( ce->ce_type == Cft_Database ||
6003 ce->ce_type == Cft_Overlay ) {
6004 char *ptr1, *ptr2, *iptr1, *iptr2;
6007 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6008 if ( *iptr2 != '{' ) {
6009 rs->sr_err = LDAP_NAMING_VIOLATION;
6010 rs->sr_text = "new ordering index is required";
6014 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6015 ptr1 = ber_bvchr( &rdn, '}' );
6016 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6018 rs->sr_err = LDAP_NAMING_VIOLATION;
6019 rs->sr_text = "new ordering index is required";
6023 len1 = ptr1 - rdn.bv_val;
6024 len2 = ptr2 - op->orr_newrdn.bv_val;
6026 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6027 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6028 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6029 rs->sr_text = "changing database/overlay type not allowed";
6032 ixold = strtol( iptr1, NULL, 0 );
6033 ixnew = strtol( iptr2, &ptr1, 0 );
6034 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6035 rs->sr_err = LDAP_NAMING_VIOLATION;
6038 /* config DB is always 0, cannot be changed */
6039 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6040 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6044 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6045 rs->sr_text = "renaming not supported for this entry";
6049 if ( op->o_abandon ) {
6050 rs->sr_err = SLAPD_ABANDON;
6053 ldap_pvt_thread_pool_pause( &connection_pool );
6055 if ( ce->ce_type == Cft_Schema ) {
6056 req_modrdn_s modr = op->oq_modrdn;
6059 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6060 if ( rs->sr_err == LDAP_SUCCESS ) {
6061 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6062 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6065 op->oq_modrdn = modr;
6067 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6068 req_modrdn_s modr = op->oq_modrdn;
6071 /* Advance to first of this type */
6072 cprev = &ce->ce_parent->ce_kids;
6073 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6074 cprev = &ce2->ce_sibs;
6077 /* Skip the -1 entry */
6078 if ( ce->ce_type == Cft_Database ) {
6079 cprev = &ce2->ce_sibs;
6085 /* Remove from old slot */
6086 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6087 cprev = &ce2->ce_sibs;
6088 *cprev = ce->ce_sibs;
6089 ceold = ce->ce_sibs;
6091 /* Insert into new slot */
6093 for ( i=0; i<ixnew; i++ ) {
6097 cprev = &ce2->ce_sibs;
6099 ce->ce_sibs = *cprev;
6104 /* NOTE: These should be encoded in the OC tables, not inline here */
6105 if ( ce->ce_type == Cft_Database )
6106 backend_db_move( ce->ce_be, ixnew );
6107 else if ( ce->ce_type == Cft_Overlay )
6108 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6110 if ( ixold < ixnew ) {
6111 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6114 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6115 ixold - ixnew, cfb->cb_use_ldif );
6117 op->oq_modrdn = modr;
6120 ldap_pvt_thread_pool_resume( &connection_pool );
6122 send_ldap_result( op, rs );
6127 config_back_delete( Operation *op, SlapReply *rs )
6129 #ifdef SLAP_CONFIG_DELETE
6131 CfEntryInfo *ce, *last, *ce2;
6133 cfb = (CfBackInfo *)op->o_bd->be_private;
6135 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6138 rs->sr_matched = last->ce_entry->e_name.bv_val;
6139 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6140 } else if ( ce->ce_kids ) {
6141 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6142 } else if ( op->o_abandon ) {
6143 rs->sr_err = SLAPD_ABANDON;
6144 } else if ( ce->ce_type == Cft_Overlay ||
6145 ce->ce_type == Cft_Database ||
6146 ce->ce_type == Cft_Misc ){
6150 ldap_pvt_thread_pool_pause( &connection_pool );
6152 if ( ce->ce_type == Cft_Overlay ){
6153 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6154 } else if ( ce->ce_type == Cft_Misc ) {
6156 * only Cft_Misc objects that have a co_lddel handler set in
6157 * the ConfigOCs struct can be deleted. This code also
6158 * assumes that the entry can be only have one objectclass
6159 * with co_type == Cft_Misc
6161 ConfigOCs co, *coptr;
6165 oc_at = attr_find( ce->ce_entry->e_attrs,
6166 slap_schema.si_ad_objectClass );
6168 rs->sr_err = LDAP_OTHER;
6169 rs->sr_text = "objectclass not found";
6170 ldap_pvt_thread_pool_resume( &connection_pool );
6173 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6174 co.co_name = &oc_at->a_nvals[i];
6175 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6176 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6179 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6180 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6181 if ( ! coptr->co_lddel ) {
6182 rs->sr_text = "No delete handler found";
6184 rs->sr_err = LDAP_OTHER;
6185 /* FIXME: We should return a helpful error message
6188 ldap_pvt_thread_pool_resume( &connection_pool );
6193 } else if (ce->ce_type == Cft_Database ) {
6194 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6195 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6196 rs->sr_text = "Cannot delete config or frontend database";
6197 ldap_pvt_thread_pool_resume( &connection_pool );
6200 if ( ce->ce_be->bd_info->bi_db_close ) {
6201 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6203 backend_destroy_one( ce->ce_be, 1);
6206 /* remove CfEntryInfo from the siblings list */
6207 if ( ce->ce_parent->ce_kids == ce ) {
6208 ce->ce_parent->ce_kids = ce->ce_sibs;
6210 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6211 if ( ce2->ce_sibs == ce ) {
6212 ce2->ce_sibs = ce->ce_sibs;
6218 /* remove from underlying database */
6219 if ( cfb->cb_use_ldif ) {
6220 BackendDB *be = op->o_bd;
6221 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6222 struct berval dn, ndn, req_dn, req_ndn;
6224 op->o_bd = &cfb->cb_db;
6228 req_dn = op->o_req_dn;
6229 req_ndn = op->o_req_ndn;
6231 op->o_dn = op->o_bd->be_rootdn;
6232 op->o_ndn = op->o_bd->be_rootndn;
6233 op->o_req_dn = ce->ce_entry->e_name;
6234 op->o_req_ndn = ce->ce_entry->e_nname;
6236 scp = op->o_callback;
6237 op->o_callback = ≻
6238 op->o_bd->be_delete( op, rs );
6240 op->o_callback = scp;
6243 op->o_req_dn = req_dn;
6244 op->o_req_ndn = req_ndn;
6247 /* renumber siblings */
6248 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6249 ixold = strtol( iptr, NULL, 0 );
6250 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6251 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6252 count+ixold, 0, cfb->cb_use_ldif );
6256 ce->ce_entry->e_private=NULL;
6257 entry_free(ce->ce_entry);
6259 ldap_pvt_thread_pool_resume( &connection_pool );
6261 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6265 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6266 #endif /* SLAP_CONFIG_DELETE */
6267 send_ldap_result( op, rs );
6272 config_back_search( Operation *op, SlapReply *rs )
6275 CfEntryInfo *ce, *last;
6278 cfb = (CfBackInfo *)op->o_bd->be_private;
6280 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6283 rs->sr_matched = last->ce_entry->e_name.bv_val;
6284 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6287 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6288 ACL_SEARCH, NULL, &mask ))
6290 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6291 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6293 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6297 switch ( op->ors_scope ) {
6298 case LDAP_SCOPE_BASE:
6299 case LDAP_SCOPE_SUBTREE:
6300 rs->sr_err = config_send( op, rs, ce, 0 );
6303 case LDAP_SCOPE_ONELEVEL:
6304 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6305 rs->sr_err = config_send( op, rs, ce, 1 );
6314 send_ldap_result( op, rs );
6318 /* no-op, we never free entries */
6319 int config_entry_release(
6324 if ( !e->e_private ) {
6327 return LDAP_SUCCESS;
6330 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6332 int config_back_entry_get(
6336 AttributeDescription *at,
6341 CfEntryInfo *ce, *last;
6342 int rc = LDAP_NO_SUCH_OBJECT;
6344 cfb = (CfBackInfo *)op->o_bd->be_private;
6346 ce = config_find_base( cfb->cb_root, ndn, &last );
6348 *ent = ce->ce_entry;
6351 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6352 rc = LDAP_NO_SUCH_ATTRIBUTE;
6362 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6363 ConfigTable *ct, ConfigArgs *c )
6367 for (; at && *at; at++) {
6368 /* Skip the naming attr */
6369 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6371 for (i=0;ct[i].name;i++) {
6372 if (ct[i].ad == (*at)->sat_ad) {
6373 rc = config_get_vals(&ct[i], c);
6374 /* NOTE: tolerate that config_get_vals()
6375 * returns success with no values */
6376 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6377 if ( c->rvalue_nvals )
6378 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6381 slap_syntax_validate_func *validate =
6382 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6385 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6386 rc = ordered_value_validate( ct[i].ad,
6387 &c->rvalue_vals[j], LDAP_MOD_ADD );
6389 Debug( LDAP_DEBUG_ANY,
6390 "config_build_attrs: error %d on %s value #%d\n",
6391 rc, ct[i].ad->ad_cname.bv_val, j );
6397 rc = attr_merge_normalize(e, ct[i].ad,
6398 c->rvalue_vals, NULL);
6400 ber_bvarray_free( c->rvalue_nvals );
6401 ber_bvarray_free( c->rvalue_vals );
6403 Debug( LDAP_DEBUG_ANY,
6404 "config_build_attrs: error %d on %s\n",
6405 rc, ct[i].ad->ad_cname.bv_val, 0 );
6416 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6419 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6420 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6422 Entry *e = entry_alloc();
6423 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6425 struct berval ad_name;
6426 AttributeDescription *ad = NULL;
6429 const char *text = "";
6433 CfEntryInfo *ceprev = NULL;
6435 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6438 ce->ce_type = main->co_type;
6439 ce->ce_parent = parent;
6441 pdn = parent->ce_entry->e_nname;
6442 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6443 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6444 ceprev->ce_type <= ce->ce_type;
6445 ceprev = ceprev->ce_sibs );
6450 ce->ce_private = c->ca_private;
6454 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6455 ber_dupbv( &e->e_nname, &e->e_name );
6457 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6458 main->co_name, NULL );
6460 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6461 extra->co_name, NULL );
6462 ptr = strchr(rdn->bv_val, '=');
6463 ad_name.bv_val = rdn->bv_val;
6464 ad_name.bv_len = ptr - rdn->bv_val;
6465 rc = slap_bv2ad( &ad_name, &ad, &text );
6470 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6471 attr_merge_normalize_one(e, ad, &val, NULL );
6474 c->table = main->co_type;
6475 if ( oc->soc_required ) {
6476 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6477 if ( rc ) goto fail;
6480 if ( oc->soc_allowed ) {
6481 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6482 if ( rc ) goto fail;
6487 c->table = extra->co_type;
6488 if ( oc->soc_required ) {
6489 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6490 if ( rc ) goto fail;
6493 if ( oc->soc_allowed ) {
6494 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6495 if ( rc ) goto fail;
6499 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6500 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6501 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6502 if ( rc != LDAP_SUCCESS ) {
6504 Debug( LDAP_DEBUG_ANY,
6505 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6506 rdn->bv_val, text, 0);
6509 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6512 op->ora_modlist = NULL;
6513 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6514 if ( !op->o_noop ) {
6515 SlapReply rs2 = {REP_RESULT};
6516 op->o_bd->be_add( op, &rs2 );
6517 rs->sr_err = rs2.sr_err;
6518 rs_assert_done( &rs2 );
6519 if ( ( rs2.sr_err != LDAP_SUCCESS )
6520 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6526 ce->ce_sibs = ceprev->ce_sibs;
6527 ceprev->ce_sibs = ce;
6528 } else if ( parent ) {
6529 ce->ce_sibs = parent->ce_kids;
6530 parent->ce_kids = ce;
6537 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6538 Operation *op, SlapReply *rs )
6541 ConfigFile *cf = c->ca_private;
6543 struct berval bv, rdn;
6545 for (; cf; cf=cf->c_sibs, c->depth++) {
6546 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6547 !cf->c_om_head && !cf->c_syn_head ) continue;
6548 c->value_dn.bv_val = c->log;
6549 LUTIL_SLASHPATH( cf->c_file.bv_val );
6550 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6555 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6557 ptr = strchr( bv.bv_val, '.' );
6559 bv.bv_len = ptr - bv.bv_val;
6560 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6561 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6562 /* FIXME: how can indicate error? */
6565 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6567 c->value_dn.bv_len += bv.bv_len;
6568 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6569 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6572 e = config_build_entry( op, rs, ceparent, c, &rdn,
6573 &CFOC_SCHEMA, NULL );
6574 ch_free( rdn.bv_val );
6577 } else if ( e && cf->c_kids ) {
6578 c->ca_private = cf->c_kids;
6579 config_build_schema_inc( c, e->e_private, op, rs );
6585 #ifdef SLAPD_MODULES
6588 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6589 Operation *op, SlapReply *rs )
6594 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6595 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6597 c->value_dn.bv_val = c->log;
6598 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6599 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6600 /* FIXME: how can indicate error? */
6604 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6613 config_check_schema(Operation *op, CfBackInfo *cfb)
6615 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6617 CfEntryInfo *ce, *last;
6620 /* If there's no root entry, we must be in the midst of converting */
6621 if ( !cfb->cb_root )
6624 /* Make sure the main schema entry exists */
6625 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6632 /* Make sure it's up to date */
6633 if ( cf_om_tail != om_sys_tail ) {
6634 a = attr_find( e->e_attrs, cfAd_om );
6636 if ( a->a_nvals != a->a_vals )
6637 ber_bvarray_free( a->a_nvals );
6638 ber_bvarray_free( a->a_vals );
6643 oidm_unparse( &bv, NULL, NULL, 1 );
6644 attr_merge_normalize( e, cfAd_om, bv, NULL );
6645 ber_bvarray_free( bv );
6646 cf_om_tail = om_sys_tail;
6648 if ( cf_at_tail != at_sys_tail ) {
6649 a = attr_find( e->e_attrs, cfAd_attr );
6651 if ( a->a_nvals != a->a_vals )
6652 ber_bvarray_free( a->a_nvals );
6653 ber_bvarray_free( a->a_vals );
6658 at_unparse( &bv, NULL, NULL, 1 );
6659 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6660 ber_bvarray_free( bv );
6661 cf_at_tail = at_sys_tail;
6663 if ( cf_oc_tail != oc_sys_tail ) {
6664 a = attr_find( e->e_attrs, cfAd_oc );
6666 if ( a->a_nvals != a->a_vals )
6667 ber_bvarray_free( a->a_nvals );
6668 ber_bvarray_free( a->a_vals );
6673 oc_unparse( &bv, NULL, NULL, 1 );
6674 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6675 ber_bvarray_free( bv );
6676 cf_oc_tail = oc_sys_tail;
6678 if ( cf_syn_tail != syn_sys_tail ) {
6679 a = attr_find( e->e_attrs, cfAd_syntax );
6681 if ( a->a_nvals != a->a_vals )
6682 ber_bvarray_free( a->a_nvals );
6683 ber_bvarray_free( a->a_vals );
6688 syn_unparse( &bv, NULL, NULL, 1 );
6689 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6690 ber_bvarray_free( bv );
6691 cf_syn_tail = syn_sys_tail;
6694 SlapReply rs = {REP_RESULT};
6695 c.ca_private = NULL;
6696 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6697 &CFOC_SCHEMA, NULL );
6702 ce->ce_private = cfb->cb_config;
6703 cf_at_tail = at_sys_tail;
6704 cf_oc_tail = oc_sys_tail;
6705 cf_om_tail = om_sys_tail;
6706 cf_syn_tail = syn_sys_tail;
6711 static const char *defacl[] = {
6712 NULL, "to", "*", "by", "*", "none", NULL
6716 config_back_db_open( BackendDB *be, ConfigReply *cr )
6718 CfBackInfo *cfb = be->be_private;
6721 CfEntryInfo *ce, *ceparent;
6725 Connection conn = {0};
6726 OperationBuffer opbuf;
6728 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6729 SlapReply rs = {REP_RESULT};
6730 void *thrctx = NULL;
6731 AccessControl *save_access;
6733 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6735 /* If we have no explicitly configured ACLs, don't just use
6736 * the global ACLs. Explicitly deny access to everything.
6738 save_access = be->bd_self->be_acl;
6739 be->bd_self->be_acl = NULL;
6740 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6741 defacl_parsed = be->bd_self->be_acl;
6742 if ( save_access ) {
6743 be->bd_self->be_acl = save_access;
6745 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6746 "No explicit ACL for back-config configured. "
6747 "Using hardcoded default\n", 0, 0, 0 );
6750 thrctx = ldap_pvt_thread_pool_context();
6751 connection_fake_init( &conn, &opbuf, thrctx );
6754 op->o_tag = LDAP_REQ_ADD;
6755 op->o_callback = &cb;
6756 op->o_bd = &cfb->cb_db;
6757 op->o_dn = op->o_bd->be_rootdn;
6758 op->o_ndn = op->o_bd->be_rootndn;
6760 if ( !cfb->cb_use_ldif ) {
6764 /* If we read the config from back-ldif, do some quick sanity checks */
6765 if ( cfb->cb_got_ldif ) {
6766 return config_check_schema( op, cfb );
6769 /* create root of tree */
6771 c.ca_private = cfb->cb_config;
6773 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6783 #ifdef SLAPD_MODULES
6784 /* Create Module nodes... */
6785 if ( modpaths.mp_loads ) {
6786 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6792 /* Create schema nodes... cn=schema will contain the hardcoded core
6793 * schema, read-only. Child objects will contain runtime loaded schema
6797 c.ca_private = NULL;
6798 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6803 ce->ce_private = cfb->cb_config;
6804 cf_at_tail = at_sys_tail;
6805 cf_oc_tail = oc_sys_tail;
6806 cf_om_tail = om_sys_tail;
6807 cf_syn_tail = syn_sys_tail;
6809 /* Create schema nodes for included schema... */
6810 if ( cfb->cb_config->c_kids ) {
6813 c.ca_private = cfb->cb_config->c_kids;
6814 rc = config_build_schema_inc( &c, ce, op, &rs );
6820 /* Create backend nodes. Skip if they don't provide a cf_table.
6821 * There usually aren't any of these.
6825 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6826 if (!bi->bi_cf_ocs) {
6827 /* If it only supports the old config mech, complain. */
6828 if ( bi->bi_config ) {
6829 Debug( LDAP_DEBUG_ANY,
6830 "WARNING: No dynamic config support for backend %s.\n",
6831 bi->bi_type, 0, 0 );
6836 if (!bi->bi_private) continue;
6839 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6840 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6841 if ( rdn.bv_len >= sizeof( c.log ) ) {
6842 /* FIXME: holler ... */ ;
6845 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6852 /* Create database nodes... */
6853 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6854 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6855 for ( i = -1, be = frontendDB ; be;
6856 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6857 slap_overinfo *oi = NULL;
6859 if ( overlay_is_over( be )) {
6860 oi = be->bd_info->bi_private;
6866 /* If this backend supports the old config mechanism, but not
6867 * the new mech, complain.
6869 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6870 Debug( LDAP_DEBUG_ANY,
6871 "WARNING: No dynamic config support for database %s.\n",
6872 bi->bi_type, 0, 0 );
6876 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6877 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6879 if ( rdn.bv_len >= sizeof( c.log ) ) {
6880 /* FIXME: holler ... */ ;
6884 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6890 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6891 rs_reinit( &rs, REP_RESULT );
6892 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6894 /* Iterate through overlays */
6899 voidList *vl, *v0 = NULL;
6901 /* overlays are in LIFO order, must reverse stack */
6902 for (on=oi->oi_list; on; on=on->on_next) {
6903 vl = ch_malloc( sizeof( voidList ));
6908 for (j=0; vl; j++,vl=v0) {
6912 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6913 Debug( LDAP_DEBUG_ANY,
6914 "WARNING: No dynamic config support for overlay %s.\n",
6915 on->on_bi.bi_type, 0, 0 );
6919 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6920 "%s=" SLAP_X_ORDERED_FMT "%s",
6921 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6922 if ( rdn.bv_len >= sizeof( c.log ) ) {
6923 /* FIXME: holler ... */ ;
6927 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6928 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6932 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6933 rs_reinit( &rs, REP_RESULT );
6934 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6940 ldap_pvt_thread_pool_context_reset( thrctx );
6942 if ( unsupp && cfb->cb_use_ldif ) {
6943 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6944 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6951 cfb_free_cffile( ConfigFile *cf )
6955 for (; cf; cf=next) {
6958 cfb_free_cffile( cf->c_kids );
6959 ch_free( cf->c_file.bv_val );
6960 ber_bvarray_free( cf->c_dseFiles );
6966 cfb_free_entries( CfEntryInfo *ce )
6970 for (; ce; ce=next) {
6973 cfb_free_entries( ce->ce_kids );
6974 ce->ce_entry->e_private = NULL;
6975 entry_free( ce->ce_entry );
6981 config_back_db_close( BackendDB *be, ConfigReply *cr )
6983 CfBackInfo *cfb = be->be_private;
6985 cfb_free_entries( cfb->cb_root );
6986 cfb->cb_root = NULL;
6988 if ( cfb->cb_db.bd_info ) {
6989 backend_shutdown( &cfb->cb_db );
6992 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
6993 acl_free( defacl_parsed );
6994 defacl_parsed = NULL;
7001 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7003 CfBackInfo *cfb = be->be_private;
7005 cfb_free_cffile( cfb->cb_config );
7007 ch_free( cfdir.bv_val );
7009 avl_free( CfOcTree, NULL );
7011 if ( cfb->cb_db.bd_info ) {
7012 cfb->cb_db.be_suffix = NULL;
7013 cfb->cb_db.be_nsuffix = NULL;
7014 BER_BVZERO( &cfb->cb_db.be_rootdn );
7015 BER_BVZERO( &cfb->cb_db.be_rootndn );
7017 backend_destroy_one( &cfb->cb_db, 0 );
7026 config_back_db_init( BackendDB *be, ConfigReply* cr )
7032 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7033 cfn = cfb->cb_config;
7034 be->be_private = cfb;
7036 ber_dupbv( &be->be_rootdn, &config_rdn );
7037 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7038 ber_dupbv( &dn, &be->be_rootdn );
7039 ber_bvarray_add( &be->be_suffix, &dn );
7040 ber_dupbv( &dn, &be->be_rootdn );
7041 ber_bvarray_add( &be->be_nsuffix, &dn );
7043 /* Hide from namingContexts */
7044 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7046 /* Check ACLs on content of Adds by default */
7047 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7053 config_back_destroy( BackendInfo *bi )
7055 ldif_must_b64_encode_release();
7060 config_tool_entry_open( BackendDB *be, int mode )
7062 CfBackInfo *cfb = be->be_private;
7063 BackendInfo *bi = cfb->cb_db.bd_info;
7065 if ( bi && bi->bi_tool_entry_open )
7066 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7073 config_tool_entry_close( BackendDB *be )
7075 CfBackInfo *cfb = be->be_private;
7076 BackendInfo *bi = cfb->cb_db.bd_info;
7078 if ( bi && bi->bi_tool_entry_close )
7079 return bi->bi_tool_entry_close( &cfb->cb_db );
7085 config_tool_entry_first( BackendDB *be )
7087 CfBackInfo *cfb = be->be_private;
7088 BackendInfo *bi = cfb->cb_db.bd_info;
7090 if ( bi && bi->bi_tool_entry_first ) {
7091 return bi->bi_tool_entry_first( &cfb->cb_db );
7093 if ( bi && bi->bi_tool_entry_first_x ) {
7094 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7095 NULL, LDAP_SCOPE_DEFAULT, NULL );
7101 config_tool_entry_first_x(
7103 struct berval *base,
7107 CfBackInfo *cfb = be->be_private;
7108 BackendInfo *bi = cfb->cb_db.bd_info;
7110 if ( bi && bi->bi_tool_entry_first_x ) {
7111 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7117 config_tool_entry_next( BackendDB *be )
7119 CfBackInfo *cfb = be->be_private;
7120 BackendInfo *bi = cfb->cb_db.bd_info;
7122 if ( bi && bi->bi_tool_entry_next )
7123 return bi->bi_tool_entry_next( &cfb->cb_db );
7129 config_tool_entry_get( BackendDB *be, ID id )
7131 CfBackInfo *cfb = be->be_private;
7132 BackendInfo *bi = cfb->cb_db.bd_info;
7134 if ( bi && bi->bi_tool_entry_get )
7135 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7140 static int entry_put_got_frontend=0;
7141 static int entry_put_got_config=0;
7143 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7145 CfBackInfo *cfb = be->be_private;
7146 BackendInfo *bi = cfb->cb_db.bd_info;
7148 struct berval rdn, vals[ 2 ];
7150 OperationBuffer opbuf;
7152 Connection conn = {0};
7153 Operation *op = NULL;
7156 int isFrontendChild = 0;
7158 /* Create entry for frontend database if it does not exist already */
7159 if ( !entry_put_got_frontend ) {
7160 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7161 STRLENOF( "olcDatabase" ))) {
7162 if ( strncmp( e->e_nname.bv_val +
7163 STRLENOF( "olcDatabase" ), "={-1}frontend",
7164 STRLENOF( "={-1}frontend" )) &&
7165 strncmp( e->e_nname.bv_val +
7166 STRLENOF( "olcDatabase" ), "=frontend",
7167 STRLENOF( "=frontend" ))) {
7169 vals[1].bv_val = NULL;
7170 memset( &ca, 0, sizeof(ConfigArgs));
7172 ca.bi = frontendDB->bd_info;
7173 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7174 rdn.bv_val = ca.log;
7175 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7176 "%s=" SLAP_X_ORDERED_FMT "%s",
7177 cfAd_database->ad_cname.bv_val, -1,
7179 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7180 &CFOC_DATABASE, ca.be->be_cf_ocs );
7181 thrctx = ldap_pvt_thread_pool_context();
7182 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7184 op->o_bd = &cfb->cb_db;
7185 op->o_tag = LDAP_REQ_ADD;
7187 op->o_dn = be->be_rootdn;
7188 op->o_ndn = be->be_rootndn;
7189 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7190 if ( rc != LDAP_SUCCESS ) {
7191 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7192 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7196 if ( ce && bi && bi->bi_tool_entry_put &&
7197 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7198 entry_put_got_frontend++;
7200 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7201 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7205 if ( !strncmp( e->e_nname.bv_val +
7206 STRLENOF( "olcDatabase" ), "=frontend",
7207 STRLENOF( "=frontend" ) ) )
7209 struct berval rdn, pdn, ndn;
7210 dnParent( &e->e_nname, &pdn );
7211 rdn.bv_val = ca.log;
7212 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7213 "%s=" SLAP_X_ORDERED_FMT "%s",
7214 cfAd_database->ad_cname.bv_val, -1,
7215 frontendDB->bd_info->bi_type );
7216 build_new_dn( &ndn, &pdn, &rdn, NULL );
7217 ber_memfree( e->e_name.bv_val );
7219 ber_bvreplace( &e->e_nname, &e->e_name );
7221 entry_put_got_frontend++;
7227 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7228 * instances, may appear before the config database entry in the ldif, skip
7229 * auto-creation of olcDatabase={0}config in such a case */
7230 if ( !entry_put_got_config &&
7231 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7233 dnParent( &e->e_nname, &pdn );
7234 while ( pdn.bv_len ) {
7235 if ( !strncmp( pdn.bv_val, "olcDatabase",
7236 STRLENOF( "olcDatabase" ))) {
7237 if ( !strncmp( pdn.bv_val +
7238 STRLENOF( "olcDatabase" ), "={-1}frontend",
7239 STRLENOF( "={-1}frontend" )) ||
7240 !strncmp( pdn.bv_val +
7241 STRLENOF( "olcDatabase" ), "=frontend",
7242 STRLENOF( "=frontend" ))) {
7244 isFrontendChild = 1;
7248 dnParent( &pdn, &pdn );
7252 /* Create entry for config database if it does not exist already */
7253 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7254 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7255 STRLENOF( "olcDatabase" ))) {
7256 if ( strncmp( e->e_nname.bv_val +
7257 STRLENOF( "olcDatabase" ), "={0}config",
7258 STRLENOF( "={0}config" )) &&
7259 strncmp( e->e_nname.bv_val +
7260 STRLENOF( "olcDatabase" ), "=config",
7261 STRLENOF( "=config" )) ) {
7263 vals[1].bv_val = NULL;
7264 memset( &ca, 0, sizeof(ConfigArgs));
7265 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7266 ca.bi = ca.be->bd_info;
7267 rdn.bv_val = ca.log;
7268 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7269 "%s=" SLAP_X_ORDERED_FMT "%s",
7270 cfAd_database->ad_cname.bv_val, 0,
7272 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7275 thrctx = ldap_pvt_thread_pool_context();
7276 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7278 op->o_bd = &cfb->cb_db;
7279 op->o_tag = LDAP_REQ_ADD;
7280 op->o_dn = be->be_rootdn;
7281 op->o_ndn = be->be_rootndn;
7284 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7285 if ( rc != LDAP_SUCCESS ) {
7286 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7287 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7290 if (ce && bi && bi->bi_tool_entry_put &&
7291 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7292 entry_put_got_config++;
7294 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7295 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7299 entry_put_got_config++;
7303 if ( bi && bi->bi_tool_entry_put &&
7304 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7305 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7312 AttributeDescription **desc;
7314 { "attribute", &cfAd_attr },
7315 { "backend", &cfAd_backend },
7316 { "database", &cfAd_database },
7317 { "include", &cfAd_include },
7318 { "ldapsyntax", &cfAd_syntax },
7319 { "objectclass", &cfAd_oc },
7320 { "objectidentifier", &cfAd_om },
7321 { "overlay", &cfAd_overlay },
7326 * add / delete: all types that may be added or deleted must use an
7327 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7328 * should automatically renumber the index of any siblings as needed,
7329 * so that no gaps in the numbering sequence exist after the add/delete
7331 * What can be added:
7333 * backend objects for backend-specific config directives
7337 * delete: probably no support this time around.
7339 * modrdn: generally not done. Will be invoked automatically by add/
7340 * delete to update numbering sequence. Perform as an explicit operation
7341 * so that the renumbering effect may be replicated. Subtree rename must
7342 * be supported, since renumbering a database will affect all its child
7345 * modify: must be fully supported.
7349 config_back_initialize( BackendInfo *bi )
7351 ConfigTable *ct = config_back_cf_table;
7355 AttributeDescription *ad = NULL;
7357 static char *controls[] = {
7358 LDAP_CONTROL_MANAGEDSAIT,
7362 /* Make sure we don't exceed the bits reserved for userland */
7363 config_check_userland( CFG_LAST );
7365 bi->bi_controls = controls;
7370 bi->bi_destroy = config_back_destroy;
7372 bi->bi_db_init = config_back_db_init;
7373 bi->bi_db_config = 0;
7374 bi->bi_db_open = config_back_db_open;
7375 bi->bi_db_close = config_back_db_close;
7376 bi->bi_db_destroy = config_back_db_destroy;
7378 bi->bi_op_bind = config_back_bind;
7379 bi->bi_op_unbind = 0;
7380 bi->bi_op_search = config_back_search;
7381 bi->bi_op_compare = 0;
7382 bi->bi_op_modify = config_back_modify;
7383 bi->bi_op_modrdn = config_back_modrdn;
7384 bi->bi_op_add = config_back_add;
7385 bi->bi_op_delete = config_back_delete;
7386 bi->bi_op_abandon = 0;
7388 bi->bi_extended = 0;
7390 bi->bi_chk_referrals = 0;
7392 bi->bi_access_allowed = slap_access_allowed;
7394 bi->bi_connection_init = 0;
7395 bi->bi_connection_destroy = 0;
7397 bi->bi_entry_release_rw = config_entry_release;
7398 bi->bi_entry_get_rw = config_back_entry_get;
7400 bi->bi_tool_entry_open = config_tool_entry_open;
7401 bi->bi_tool_entry_close = config_tool_entry_close;
7402 bi->bi_tool_entry_first = config_tool_entry_first;
7403 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7404 bi->bi_tool_entry_next = config_tool_entry_next;
7405 bi->bi_tool_entry_get = config_tool_entry_get;
7406 bi->bi_tool_entry_put = config_tool_entry_put;
7409 argv[ 0 ] = "slapd";
7415 for (i=0; OidMacros[i].name; i++ ) {
7416 argv[1] = OidMacros[i].name;
7417 argv[2] = OidMacros[i].oid;
7418 parse_oidm( &ca, 0, NULL );
7421 bi->bi_cf_ocs = cf_ocs;
7423 i = config_register_schema( ct, cf_ocs );
7426 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7429 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7430 * basically, we don't care if it fails */
7431 i = slap_str2ad( "olcRootPW", &ad, &text );
7433 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7434 "warning, unable to get \"olcRootPW\" "
7435 "attribute description: %d: %s\n",
7438 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7439 ad->ad_type->sat_oid );
7442 /* set up the notable AttributeDescriptions */
7444 for (;ct->name;ct++) {
7445 if (strcmp(ct->name, ads[i].name)) continue;
7446 *ads[i].desc = ct->ad;
7448 if (!ads[i].name) break;