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
258 * OLcfgOv{Oc|At}:1 -> syncprov
259 * OLcfgOv{Oc|At}:2 -> pcache
260 * OLcfgOv{Oc|At}:3 -> chain
261 * OLcfgOv{Oc|At}:4 -> accesslog
262 * OLcfgOv{Oc|At}:5 -> valsort
263 * OLcfgOv{Oc|At}:7 -> distproc
264 * OLcfgOv{Oc|At}:8 -> dynlist
265 * OLcfgOv{Oc|At}:9 -> dds
266 * OLcfgOv{Oc|At}:10 -> unique
267 * OLcfgOv{Oc|At}:11 -> refint
268 * OLcfgOv{Oc|At}:12 -> ppolicy
269 * OLcfgOv{Oc|At}:13 -> constraint
270 * OLcfgOv{Oc|At}:14 -> translucent
271 * OLcfgOv{Oc|At}:15 -> auditlog
272 * OLcfgOv{Oc|At}:16 -> rwm
273 * OLcfgOv{Oc|At}:17 -> dyngroup
274 * OLcfgOv{Oc|At}:18 -> memberof
275 * OLcfgOv{Oc|At}:19 -> collect
276 * OLcfgOv{Oc|At}:20 -> retcode
277 * OLcfgOv{Oc|At}:21 -> sssvlv
280 /* alphabetical ordering */
282 static ConfigTable config_back_cf_table[] = {
283 /* This attr is read-only */
284 { "", "", 0, 0, 0, ARG_MAGIC,
285 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
286 "DESC 'File for slapd configuration directives' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
289 { "", "", 0, 0, 0, ARG_MAGIC,
290 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
291 "DESC 'Directory for slapd configuration backend' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
294 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
295 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
296 "DESC 'Access Control List' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
299 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
300 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
301 "DESC 'Check ACLs against content of Add ops' "
302 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
303 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
304 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
305 "DESC 'Allowed set of deprecated features' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString )", NULL, NULL },
308 { "argsfile", "file", 2, 2, 0, ARG_STRING,
309 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
310 "DESC 'File for slapd command line options' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
313 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
314 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString )", NULL, NULL },
317 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
318 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
319 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
320 "DESC 'OpenLDAP attributeTypes' "
321 "EQUALITY caseIgnoreMatch "
322 "SUBSTR caseIgnoreSubstringsMatch "
323 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
325 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
326 #ifdef SLAP_AUTH_REWRITE
327 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
331 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
332 "EQUALITY caseIgnoreMatch "
333 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
334 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
335 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
338 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
339 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
340 "EQUALITY caseIgnoreMatch "
341 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
342 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
343 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
344 "DESC 'A type of backend' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
348 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
349 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
350 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
351 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
352 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
353 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
354 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
355 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
356 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
357 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
358 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
359 "DESC 'The backend type for a database instance' "
360 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
361 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
362 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
363 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
364 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
365 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
366 "EQUALITY caseIgnoreMatch "
367 "SYNTAX OMsDirectoryString )", NULL, NULL },
368 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
369 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
370 "DESC 'OpenLDAP DIT content rules' "
371 "EQUALITY caseIgnoreMatch "
372 "SUBSTR caseIgnoreSubstringsMatch "
373 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
375 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
376 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
377 "EQUALITY caseIgnoreMatch "
378 "SYNTAX OMsDirectoryString )", NULL, NULL },
379 { "gentlehup", "on|off", 2, 2, 0,
381 ARG_ON_OFF, &global_gentlehup,
385 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
386 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
387 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
388 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
389 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
390 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
391 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
392 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
393 { "include", "file", 2, 2, 0, ARG_MAGIC,
394 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
395 "SUP labeledURI )", NULL, NULL },
396 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
397 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
398 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
399 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
400 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
401 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
402 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
403 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
404 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
405 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
406 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
407 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
408 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
409 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
410 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
411 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
412 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
413 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
414 { "ldapsyntax", "syntax", 2, 0, 0,
415 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
416 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
417 "DESC 'OpenLDAP ldapSyntax' "
418 "EQUALITY caseIgnoreMatch "
419 "SUBSTR caseIgnoreSubstringsMatch "
420 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
422 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
423 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
424 "EQUALITY caseIgnoreMatch "
425 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
426 { "listener-threads", "count", 2, 0, 0,
430 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
432 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
433 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
434 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
435 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
436 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
437 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
438 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
439 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
440 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
441 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
442 "EQUALITY caseIgnoreMatch "
443 "SYNTAX OMsDirectoryString )", NULL, NULL },
444 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
445 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
446 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
447 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
448 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
449 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
450 { "moduleload", "file", 2, 0, 0,
452 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
456 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
457 "EQUALITY caseIgnoreMatch "
458 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
459 { "modulepath", "path", 2, 2, 0,
461 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
465 "( OLcfgGlAt:31 NAME 'olcModulePath' "
466 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
467 { "monitoring", "TRUE|FALSE", 2, 2, 0,
468 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
469 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
470 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
471 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
472 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
473 "DESC 'OpenLDAP object classes' "
474 "EQUALITY caseIgnoreMatch "
475 "SUBSTR caseIgnoreSubstringsMatch "
476 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
478 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
479 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
480 "EQUALITY caseIgnoreMatch "
481 "SUBSTR caseIgnoreSubstringsMatch "
482 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
483 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
484 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
485 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
486 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
487 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
488 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
489 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
490 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
491 "EQUALITY caseIgnoreMatch "
492 "SYNTAX OMsDirectoryString )", NULL, NULL },
493 { "pidfile", "file", 2, 2, 0, ARG_STRING,
494 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
495 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
496 { "plugin", NULL, 0, 0, 0,
498 ARG_MAGIC|CFG_PLUGIN, &config_generic,
502 "( OLcfgGlAt:38 NAME 'olcPlugin' "
503 "EQUALITY caseIgnoreMatch "
504 "SYNTAX OMsDirectoryString )", NULL, NULL },
505 { "pluginlog", "filename", 2, 2, 0,
507 ARG_STRING, &slapi_log_file,
511 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
512 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
513 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
514 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
515 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
516 { "referral", "url", 2, 2, 0, ARG_MAGIC,
517 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
518 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
519 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
520 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
521 "EQUALITY caseIgnoreMatch "
522 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
523 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
524 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
525 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
526 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
527 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
528 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
529 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
530 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
531 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
532 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
533 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
534 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
535 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
536 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
537 "EQUALITY caseIgnoreMatch "
538 "SYNTAX OMsDirectoryString )", NULL, NULL },
539 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
540 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
541 "EQUALITY caseIgnoreMatch "
542 "SYNTAX OMsDirectoryString )", NULL, NULL },
543 { "reverse-lookup", "on|off", 2, 2, 0,
544 #ifdef SLAPD_RLOOKUPS
545 ARG_ON_OFF, &use_reverse_lookup,
549 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
550 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
551 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
552 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
553 "EQUALITY distinguishedNameMatch "
554 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
555 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
556 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
557 "EQUALITY caseIgnoreMatch "
558 "SYNTAX OMsDirectoryString )", NULL, NULL },
559 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
560 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
561 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
562 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
563 &config_generic, NULL, NULL, NULL },
564 { "sasl-auxprops", NULL, 2, 0, 0,
565 #ifdef HAVE_CYRUS_SASL
566 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
570 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
571 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
572 { "sasl-host", "host", 2, 2, 0,
573 #ifdef HAVE_CYRUS_SASL
574 ARG_STRING|ARG_UNIQUE, &sasl_host,
578 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
579 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
580 { "sasl-realm", "realm", 2, 2, 0,
581 #ifdef HAVE_CYRUS_SASL
582 ARG_STRING|ARG_UNIQUE, &global_realm,
586 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
587 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
588 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
589 &config_generic, NULL, NULL, NULL },
590 { "sasl-secprops", "properties", 2, 2, 0,
591 #ifdef HAVE_CYRUS_SASL
592 ARG_MAGIC|CFG_SASLSECP, &config_generic,
596 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
597 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
598 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
599 &config_generic, NULL, NULL, NULL },
600 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
601 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
602 "EQUALITY distinguishedNameMatch "
603 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
604 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
605 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
606 "EQUALITY caseIgnoreMatch "
607 "SYNTAX OMsDirectoryString )", NULL, NULL },
608 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
609 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
610 "EQUALITY caseIgnoreMatch "
611 "SYNTAX OMsDirectoryString )", NULL, NULL },
612 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
613 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
614 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
615 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
616 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
617 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
618 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
619 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
620 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
621 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
622 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
623 "DESC 'Attributes whose values will always be sorted' "
624 "EQUALITY caseIgnoreMatch "
625 "SYNTAX OMsDirectoryString )", NULL, NULL },
626 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
627 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
628 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
629 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
630 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
631 "EQUALITY distinguishedNameMatch "
632 "SYNTAX OMsDN )", NULL, NULL },
633 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
634 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
635 "DESC 'Store sync context in a subentry' "
636 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
637 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
638 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
639 "EQUALITY caseIgnoreMatch "
640 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
641 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
642 #ifndef LDAP_TCP_BUFFER
644 #else /* LDAP_TCP_BUFFER */
645 ARG_MAGIC, &config_tcp_buffer,
646 #endif /* LDAP_TCP_BUFFER */
647 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
648 "DESC 'Custom TCP buffer size' "
649 "SYNTAX OMsDirectoryString )", NULL, NULL },
650 { "threads", "count", 2, 2, 0,
654 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
656 "( OLcfgGlAt:66 NAME 'olcThreads' "
657 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
658 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
659 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
660 "SYNTAX OMsDirectoryString )", NULL, NULL },
661 { "TLSCACertificateFile", NULL, 2, 2, 0,
663 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
667 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
668 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
669 { "TLSCACertificatePath", NULL, 2, 2, 0,
671 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
675 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
676 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
677 { "TLSCertificateFile", NULL, 2, 2, 0,
679 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
683 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
684 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
685 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
687 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
691 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
692 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
693 { "TLSCipherSuite", NULL, 2, 2, 0,
695 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
699 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
700 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
701 { "TLSCRLCheck", NULL, 2, 2, 0,
702 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
703 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
707 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
708 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
709 { "TLSCRLFile", NULL, 2, 2, 0,
710 #if defined(HAVE_GNUTLS)
711 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
715 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
716 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
717 { "TLSRandFile", NULL, 2, 2, 0,
719 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
723 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
724 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
725 { "TLSVerifyClient", NULL, 2, 2, 0,
727 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
731 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
732 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
733 { "TLSDHParamFile", NULL, 2, 2, 0,
735 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
739 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
740 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
741 { "TLSProtocolMin", NULL, 2, 2, 0,
743 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
747 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
748 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
749 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
750 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
751 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
752 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
753 NULL, NULL, NULL, NULL },
754 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
755 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
756 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
757 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
758 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
759 "EQUALITY caseIgnoreMatch "
760 "SUP labeledURI )", NULL, NULL },
761 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
762 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
763 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
764 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
765 NULL, NULL, NULL, NULL }
768 /* Need to no-op this keyword for dynamic config */
769 ConfigTable olcDatabaseDummy[] = {
770 { "", "", 0, 0, 0, ARG_IGNORED,
771 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
772 "DESC 'The backend type for a database instance' "
773 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
774 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
777 /* Routines to check if a child can be added to this type */
778 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
779 cfAddBackend, cfAddModule, cfAddOverlay;
781 /* NOTE: be careful when defining array members
782 * that can be conditionally compiled */
783 #define CFOC_GLOBAL cf_ocs[1]
784 #define CFOC_SCHEMA cf_ocs[2]
785 #define CFOC_BACKEND cf_ocs[3]
786 #define CFOC_DATABASE cf_ocs[4]
787 #define CFOC_OVERLAY cf_ocs[5]
788 #define CFOC_INCLUDE cf_ocs[6]
789 #define CFOC_FRONTEND cf_ocs[7]
791 #define CFOC_MODULE cf_ocs[8]
792 #endif /* SLAPD_MODULES */
794 static ConfigOCs cf_ocs[] = {
797 "DESC 'OpenLDAP configuration object' "
798 "ABSTRACT SUP top )", Cft_Abstract, NULL },
801 "DESC 'OpenLDAP Global configuration options' "
802 "SUP olcConfig STRUCTURAL "
803 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
804 "olcAttributeOptions $ olcAuthIDRewrite $ "
805 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
806 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
807 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
808 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
809 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
810 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
811 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
812 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
813 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
815 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
816 "olcSecurity $ olcServerID $ olcSizeLimit $ "
817 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
819 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
820 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
821 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
822 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
823 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
824 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
825 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
827 "NAME 'olcSchemaConfig' "
828 "DESC 'OpenLDAP schema object' "
829 "SUP olcConfig STRUCTURAL "
830 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
831 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
832 Cft_Schema, NULL, cfAddSchema },
834 "NAME 'olcBackendConfig' "
835 "DESC 'OpenLDAP Backend-specific options' "
836 "SUP olcConfig STRUCTURAL "
837 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
839 "NAME 'olcDatabaseConfig' "
840 "DESC 'OpenLDAP Database-specific options' "
841 "SUP olcConfig STRUCTURAL "
843 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
844 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
845 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
846 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
847 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
848 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
849 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
850 "olcMonitoring $ olcExtraAttrs ) )",
851 Cft_Database, NULL, cfAddDatabase },
853 "NAME 'olcOverlayConfig' "
854 "DESC 'OpenLDAP Overlay-specific options' "
855 "SUP olcConfig STRUCTURAL "
856 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
858 "NAME 'olcIncludeFile' "
859 "DESC 'OpenLDAP configuration include file' "
860 "SUP olcConfig STRUCTURAL "
862 "MAY ( cn $ olcRootDSE ) )",
863 /* Used to be Cft_Include, that def has been removed */
864 Cft_Abstract, NULL, cfAddInclude },
865 /* This should be STRUCTURAL like all the other database classes, but
866 * that would mean inheriting all of the olcDatabaseConfig attributes,
867 * which causes them to be merged twice in config_build_entry.
870 "NAME 'olcFrontendConfig' "
871 "DESC 'OpenLDAP frontend configuration' "
873 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
874 Cft_Database, NULL, NULL },
877 "NAME 'olcModuleList' "
878 "DESC 'OpenLDAP dynamic module info' "
879 "SUP olcConfig STRUCTURAL "
880 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
881 Cft_Module, NULL, cfAddModule },
886 typedef struct ServerID {
887 struct ServerID *si_next;
888 struct berval si_url;
892 static ServerID *sid_list;
893 static ServerID *sid_set;
895 typedef struct voidList {
896 struct voidList *vl_next;
900 typedef struct ADlist {
901 struct ADlist *al_next;
902 AttributeDescription *al_desc;
905 static ADlist *sortVals;
908 config_generic(ConfigArgs *c) {
911 if ( c->op == SLAP_CONFIG_EMIT ) {
915 c->value_int = ldap_pvt_thread_get_concurrency();
918 c->value_int = connection_pool_max;
921 c->value_int = slap_tool_thread_max;
924 c->value_uint = slapd_daemon_threads;
928 c->value_string = ch_strdup( passwd_salt );
933 if ( c->be->be_limits ) {
937 for ( i=0; c->be->be_limits[i]; i++ ) {
938 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
939 if ( bv.bv_len >= sizeof( buf ) ) {
940 ber_bvarray_free_x( c->rvalue_vals, NULL );
941 c->rvalue_vals = NULL;
945 bv.bv_val = buf + bv.bv_len;
946 limits_unparse( c->be->be_limits[i], &bv,
947 sizeof( buf ) - ( bv.bv_val - buf ) );
948 bv.bv_len += bv.bv_val - buf;
950 value_add_one( &c->rvalue_vals, &bv );
953 if ( !c->rvalue_vals ) rc = 1;
956 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
959 c->value_string = ch_strdup( slap_sasl_getpolicy());
962 slap_sasl_regexp_unparse( &c->rvalue_vals );
963 if ( !c->rvalue_vals ) rc = 1;
965 #ifdef HAVE_CYRUS_SASL
967 struct berval bv = BER_BVNULL;
968 slap_sasl_secprops_unparse( &bv );
969 if ( !BER_BVISNULL( &bv )) {
970 ber_bvarray_add( &c->rvalue_vals, &bv );
978 c->value_int = c->be->be_max_deref_depth;
981 if ( SLAP_DBHIDDEN( c->be )) {
988 ConfigFile *cf = c->ca_private;
990 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
991 else if ( cf->c_om_head )
992 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
994 if ( !c->rvalue_vals )
999 ad_unparse_options( &c->rvalue_vals );
1002 ConfigFile *cf = c->ca_private;
1004 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1005 else if ( cf->c_oc_head )
1006 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1008 if ( !c->rvalue_vals )
1013 ConfigFile *cf = c->ca_private;
1015 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1016 else if ( cf->c_at_head )
1017 at_unparse( &c->rvalue_vals, cf->c_at_head,
1019 if ( !c->rvalue_vals )
1024 ConfigFile *cf = c->ca_private;
1026 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1027 else if ( cf->c_syn_head )
1028 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1029 cf->c_syn_tail, 0 );
1030 if ( !c->rvalue_vals )
1035 ConfigFile *cf = c->ca_private;
1037 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1038 else if ( cf->c_cr_head )
1039 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1041 if ( !c->rvalue_vals )
1048 char *src, *dst, ibuf[11];
1049 struct berval bv, abv;
1050 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1051 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1052 if ( abv.bv_len >= sizeof( ibuf ) ) {
1053 ber_bvarray_free_x( c->rvalue_vals, NULL );
1054 c->rvalue_vals = NULL;
1058 acl_unparse( a, &bv );
1059 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1060 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1061 /* Turn TAB / EOL into plain space */
1062 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1063 if (isspace((unsigned char)*src)) *dst++ = ' ';
1067 if (dst[-1] == ' ') {
1071 abv.bv_len = dst - abv.bv_val;
1072 ber_bvarray_add( &c->rvalue_vals, &abv );
1078 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1081 ConfigFile *cf = c->ca_private;
1082 if ( cf->c_dseFiles ) {
1083 value_add( &c->rvalue_vals, cf->c_dseFiles );
1094 for ( si = sid_list; si; si=si->si_next ) {
1095 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1096 if ( !BER_BVISEMPTY( &si->si_url )) {
1097 bv.bv_len = si->si_url.bv_len + 6;
1098 bv.bv_val = ch_malloc( bv.bv_len );
1099 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1100 si->si_url.bv_val );
1101 ber_bvarray_add( &c->rvalue_vals, &bv );
1105 bv.bv_len = sprintf( buf, "%d", si->si_num );
1106 value_add_one( &c->rvalue_vals, &bv );
1115 c->value_string = ch_strdup( logfileName );
1120 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1122 case CFG_SYNC_SUBENTRY:
1123 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1125 case CFG_MIRRORMODE:
1126 if ( SLAP_SHADOW(c->be))
1127 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1131 case CFG_MONITORING:
1132 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1134 case CFG_SSTR_IF_MAX:
1135 c->value_uint = index_substr_if_maxlen;
1137 case CFG_SSTR_IF_MIN:
1138 c->value_uint = index_substr_if_minlen;
1141 c->value_int = index_intlen;
1143 case CFG_SORTVALS: {
1146 for ( sv = sortVals; sv; sv = sv->al_next ) {
1147 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1151 #ifdef SLAPD_MODULES
1153 ModPaths *mp = c->ca_private;
1156 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1159 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1160 SLAP_X_ORDERED_FMT "%s", i,
1161 mp->mp_loads[i].bv_val );
1162 if ( bv.bv_len >= sizeof( c->log ) ) {
1163 ber_bvarray_free_x( c->rvalue_vals, NULL );
1164 c->rvalue_vals = NULL;
1167 value_add_one( &c->rvalue_vals, &bv );
1171 rc = c->rvalue_vals ? 0 : 1;
1175 ModPaths *mp = c->ca_private;
1176 if ( !BER_BVISNULL( &mp->mp_path ))
1177 value_add_one( &c->rvalue_vals, &mp->mp_path );
1179 rc = c->rvalue_vals ? 0 : 1;
1185 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1186 if ( !c->rvalue_vals ) rc = 1;
1189 #ifdef SLAP_AUTH_REWRITE
1191 if ( authz_rewrites ) {
1192 struct berval bv, idx;
1197 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1198 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1199 if ( idx.bv_len >= sizeof( ibuf ) ) {
1200 ber_bvarray_free_x( c->rvalue_vals, NULL );
1201 c->rvalue_vals = NULL;
1204 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1205 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1206 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1207 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1208 authz_rewrites[i].bv_val,
1209 authz_rewrites[i].bv_len + 1 );
1210 ber_bvarray_add( &c->rvalue_vals, &bv );
1213 if ( !c->rvalue_vals ) rc = 1;
1220 } else if ( c->op == LDAP_MOD_DELETE ) {
1223 /* single-valued attrs, no-ops */
1232 case CFG_MONITORING:
1234 case CFG_SSTR_IF_MAX:
1235 case CFG_SSTR_IF_MIN:
1237 case CFG_SYNC_SUBENTRY:
1240 /* no-ops, requires slapd restart */
1245 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1248 case CFG_MIRRORMODE:
1249 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1250 if(SLAP_SHADOW(c->be))
1251 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1255 ch_free( passwd_salt );
1260 ch_free( logfileName );
1268 case CFG_SERVERID: {
1269 ServerID *si, **sip;
1271 for ( i=0, si = sid_list, sip = &sid_list;
1272 si; si = *sip, i++ ) {
1273 if ( c->valx == -1 || i == c->valx ) {
1275 if ( sid_set == si )
1287 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1291 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1292 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1293 SLAP_INDEX_INTLEN_DEFAULT );
1297 if ( c->valx < 0 ) {
1298 acl_destroy( c->be->be_acl );
1299 c->be->be_acl = NULL;
1302 AccessControl **prev, *a;
1304 for (i=0, prev = &c->be->be_acl; i < c->valx;
1307 prev = &a->acl_next;
1310 *prev = a->acl_next;
1313 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1314 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1315 "Last explicit ACL for back-config removed. "
1316 "Using hardcoded default\n", 0, 0, 0 );
1317 c->be->be_acl = defacl_parsed;
1323 /* Can be NULL when undoing a failed add */
1324 if ( c->ca_entry ) {
1325 ce = c->ca_entry->e_private;
1326 /* can't modify the hardcoded schema */
1327 if ( ce->ce_parent->ce_type == Cft_Global )
1331 cfn = c->ca_private;
1332 if ( c->valx < 0 ) {
1335 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1337 if ( oc == cfn->c_oc_tail )
1340 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1342 ObjectClass *oc, *prev = NULL;
1344 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1349 if ( cfn->c_oc_tail == oc ) {
1350 cfn->c_oc_tail = prev;
1352 if ( cfn->c_oc_head == oc ) {
1354 cfn->c_oc_head = oc;
1361 /* Can be NULL when undoing a failed add */
1362 if ( c->ca_entry ) {
1363 ce = c->ca_entry->e_private;
1364 /* can't modify the hardcoded schema */
1365 if ( ce->ce_parent->ce_type == Cft_Global )
1369 cfn = c->ca_private;
1370 if ( c->valx < 0 ) {
1373 for( at = cfn->c_at_head; at; at_next( &at )) {
1375 if ( at == cfn->c_at_tail )
1378 cfn->c_at_head = cfn->c_at_tail = NULL;
1380 AttributeType *at, *prev = NULL;
1382 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1387 if ( cfn->c_at_tail == at ) {
1388 cfn->c_at_tail = prev;
1390 if ( cfn->c_at_head == at ) {
1392 cfn->c_at_head = at;
1399 /* Can be NULL when undoing a failed add */
1400 if ( c->ca_entry ) {
1401 ce = c->ca_entry->e_private;
1402 /* can't modify the hardcoded schema */
1403 if ( ce->ce_parent->ce_type == Cft_Global )
1407 cfn = c->ca_private;
1408 if ( c->valx < 0 ) {
1411 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1413 if ( syn == cfn->c_syn_tail )
1416 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1418 Syntax *syn, *prev = NULL;
1420 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1425 if ( cfn->c_syn_tail == syn ) {
1426 cfn->c_syn_tail = prev;
1428 if ( cfn->c_syn_head == syn ) {
1430 cfn->c_syn_head = syn;
1435 if ( c->valx < 0 ) {
1437 for ( sv = sortVals; sv; sv = sortVals ) {
1438 sortVals = sv->al_next;
1439 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1446 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1447 prev = &sv->al_next;
1450 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1451 *prev = sv->al_next;
1457 /* FIXME: there is no limits_free function */
1458 if ( c->valx < 0 ) {
1459 limits_destroy( c->be->be_limits );
1460 c->be->be_limits = NULL;
1465 if ( c->be->be_limits ) {
1466 for ( num = 0; c->be->be_limits[ num ]; num++ )
1470 if ( c->valx >= num ) {
1475 limits_destroy( c->be->be_limits );
1476 c->be->be_limits = NULL;
1479 limits_free_one( c->be->be_limits[ c->valx ] );
1481 for ( cnt = c->valx; cnt < num; cnt++ ) {
1482 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1489 /* FIXME: there is no ad_option_free function */
1491 /* FIXME: there is no way to remove attributes added by
1505 if(!(c->bi = backend_info(c->argv[1]))) {
1506 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1507 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1508 c->log, c->cr_msg, c->argv[1] );
1515 /* NOTE: config is always the first backend!
1517 if ( !strcasecmp( c->argv[1], "config" )) {
1518 c->be = LDAP_STAILQ_FIRST(&backendDB);
1519 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1522 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1524 if ( c->cr_msg[0] == 0 )
1525 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1526 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1533 ldap_pvt_thread_set_concurrency(c->value_int);
1537 if ( c->value_int < 2 ) {
1538 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1539 "threads=%d smaller than minimum value 2",
1541 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1542 c->log, c->cr_msg, 0 );
1545 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1546 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1547 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1548 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1549 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1550 c->log, c->cr_msg, 0 );
1552 if ( slapMode & SLAP_SERVER_MODE )
1553 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1554 connection_pool_max = c->value_int; /* save for reference */
1558 if ( slapMode & SLAP_TOOL_MODE )
1559 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1560 slap_tool_thread_max = c->value_int; /* save for reference */
1565 /* use a power of two */
1566 while (c->value_uint > 1) {
1567 c->value_uint >>= 1;
1571 slapd_daemon_mask = mask;
1572 slapd_daemon_threads = mask+1;
1577 if ( passwd_salt ) ch_free( passwd_salt );
1578 passwd_salt = c->value_string;
1579 lutil_salt_format(passwd_salt);
1583 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1589 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1591 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1595 ch_free(c->value_string);
1596 if (slap_sasl_setpolicy( c->argv[1] )) {
1597 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1598 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1599 c->log, c->cr_msg, c->argv[1] );
1605 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1609 #ifdef HAVE_CYRUS_SASL
1612 char *txt = slap_sasl_secprops( c->argv[1] );
1614 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1616 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1624 c->be->be_max_deref_depth = c->value_int;
1630 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1631 cfn = c->ca_private;
1632 if(parse_oidm(c, 1, &om))
1634 if (!cfn->c_om_head) cfn->c_om_head = om;
1635 cfn->c_om_tail = om;
1640 ObjectClass *oc, *prev;
1642 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1643 cfn = c->ca_private;
1644 if ( c->valx < 0 ) {
1645 prev = cfn->c_oc_tail;
1648 /* If adding anything after the first, prev is easy */
1651 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1653 if ( !oc_next( &oc ))
1657 /* If adding the first, and head exists, find its prev */
1658 if (cfn->c_oc_head) {
1659 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1664 /* else prev is NULL, append to end of global list */
1666 if(parse_oc(c, &oc, prev)) return(1);
1667 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1668 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1673 AttributeType *at, *prev;
1675 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1676 cfn = c->ca_private;
1677 if ( c->valx < 0 ) {
1678 prev = cfn->c_at_tail;
1681 /* If adding anything after the first, prev is easy */
1684 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1686 if ( !at_next( &at ))
1690 /* If adding the first, and head exists, find its prev */
1691 if (cfn->c_at_head) {
1692 for ( at_start( &at ); at != cfn->c_at_head; ) {
1697 /* else prev is NULL, append to end of global list */
1699 if(parse_at(c, &at, prev)) return(1);
1700 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1701 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1708 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1709 cfn = c->ca_private;
1710 if ( c->valx < 0 ) {
1711 prev = cfn->c_syn_tail;
1714 /* If adding anything after the first, prev is easy */
1717 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1719 if ( !syn_next( &syn ))
1723 /* If adding the first, and head exists, find its prev */
1724 if (cfn->c_syn_head) {
1725 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1730 /* else prev is NULL, append to end of global list */
1732 if ( parse_syn( c, &syn, prev ) ) return(1);
1733 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1734 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1741 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1742 cfn = c->ca_private;
1743 if(parse_cr(c, &cr)) return(1);
1744 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1745 cfn->c_cr_tail = cr;
1750 ad_define_option(NULL, NULL, 0);
1751 for(i = 1; i < c->argc; i++)
1752 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1757 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1758 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1759 else if ( c->value_int > 255 )
1761 index_intlen = c->value_int;
1762 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1766 case CFG_SORTVALS: {
1767 ADlist *svnew = NULL, *svtail, *sv;
1769 for ( i = 1; i < c->argc; i++ ) {
1770 AttributeDescription *ad = NULL;
1774 rc = slap_str2ad( c->argv[i], &ad, &text );
1776 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1779 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1780 c->log, c->cr_msg, c->argv[i] );
1781 for ( sv = svnew; sv; sv = svnew ) {
1782 svnew = sv->al_next;
1787 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1788 ad->ad_type->sat_single_value ) {
1789 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1791 goto sortval_reject;
1793 sv = ch_malloc( sizeof( ADlist ));
1798 svtail->al_next = sv;
1803 for ( sv = svnew; sv; sv = sv->al_next )
1804 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1805 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1807 sv->al_next = svnew;
1814 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
1815 c->be->be_acl = NULL;
1817 /* Don't append to the global ACL if we're on a specific DB */
1819 if ( c->valx == -1 ) {
1822 for ( a=c->be->be_acl; a; a = a->acl_next )
1825 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1826 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
1827 c->be->be_acl = defacl_parsed;
1835 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1837 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1841 if(root_dse_read_file(c->argv[1])) {
1842 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1843 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1844 c->log, c->cr_msg, c->argv[1] );
1849 ber_str2bv( c->argv[1], 0, 1, &bv );
1850 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1851 cfn = c->ca_private;
1852 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1858 ServerID *si, **sip;
1861 if (( lutil_atoi( &num, c->argv[1] ) &&
1862 lutil_atoix( &num, c->argv[1], 16 )) ||
1863 num < 0 || num > SLAP_SYNC_SID_MAX )
1865 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1866 "<%s> illegal server ID", c->argv[0] );
1867 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1868 c->log, c->cr_msg, c->argv[1] );
1871 /* only one value allowed if no URL is given */
1872 if ( c->argc > 2 ) {
1875 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1876 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1877 "<%s> only one server ID allowed now", c->argv[0] );
1878 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1879 c->log, c->cr_msg, c->argv[1] );
1883 if ( ldap_url_parse( c->argv[2], &lud )) {
1884 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1885 "<%s> invalid URL", c->argv[0] );
1886 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1887 c->log, c->cr_msg, c->argv[2] );
1890 len = strlen( c->argv[2] );
1891 si = ch_malloc( sizeof(ServerID) + len + 1 );
1892 si->si_url.bv_val = (char *)(si+1);
1893 si->si_url.bv_len = len;
1894 strcpy( si->si_url.bv_val, c->argv[2] );
1897 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1898 "<%s> unqualified server ID not allowed now", c->argv[0] );
1899 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1900 c->log, c->cr_msg, c->argv[1] );
1903 si = ch_malloc( sizeof(ServerID) );
1904 BER_BVZERO( &si->si_url );
1905 slap_serverID = num;
1906 Debug( LDAP_DEBUG_CONFIG,
1908 c->log, slap_serverID, 0 );
1913 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1916 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1917 Listener *l = config_check_my_url( c->argv[2], lud );
1920 ldap_free_urldesc( lud );
1921 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1922 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
1923 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1924 c->log, c->cr_msg, c->argv[1] );
1927 slap_serverID = si->si_num;
1928 Debug( LDAP_DEBUG_CONFIG,
1929 "%s: SID=0x%03x (listener=%s)\n",
1930 c->log, slap_serverID,
1936 ldap_free_urldesc( lud );
1940 if ( logfileName ) ch_free( logfileName );
1941 logfileName = c->value_string;
1942 logfile = fopen(logfileName, "w");
1943 if(logfile) lutil_debug_file(logfile);
1947 if(SLAP_NOLASTMODCMD(c->be)) {
1948 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1949 c->argv[0], c->be->bd_info->bi_type );
1950 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1951 c->log, c->cr_msg, 0 );
1955 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1957 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1960 case CFG_MIRRORMODE:
1961 if(c->value_int && !SLAP_SHADOW(c->be)) {
1962 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1964 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1965 c->log, c->cr_msg, 0 );
1969 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1970 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
1972 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1973 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1977 case CFG_MONITORING:
1979 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1981 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1986 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1988 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1991 case CFG_SYNC_SUBENTRY:
1993 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1995 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1998 case CFG_SSTR_IF_MAX:
1999 if (c->value_uint < index_substr_if_minlen) {
2000 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2001 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2002 c->log, c->cr_msg, c->value_int );
2005 index_substr_if_maxlen = c->value_uint;
2008 case CFG_SSTR_IF_MIN:
2009 if (c->value_uint > index_substr_if_maxlen) {
2010 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2011 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2012 c->log, c->cr_msg, c->value_int );
2015 index_substr_if_minlen = c->value_uint;
2018 #ifdef SLAPD_MODULES
2020 /* If we're just adding a module on an existing modpath,
2021 * make sure we've selected the current path.
2023 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2024 modcur = c->ca_private;
2025 /* This should never fail */
2026 if ( module_path( modcur->mp_path.bv_val )) {
2027 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2029 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2030 c->log, c->cr_msg, modcur->mp_path.bv_val );
2034 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2036 /* Record this load on the current path */
2040 if ( c->op == SLAP_CONFIG_ADD ) {
2041 ptr = c->line + STRLENOF("moduleload");
2042 while (!isspace((unsigned char) *ptr)) ptr++;
2043 while (isspace((unsigned char) *ptr)) ptr++;
2047 ber_str2bv(ptr, 0, 1, &bv);
2048 ber_bvarray_add( &modcur->mp_loads, &bv );
2050 /* Check for any new hardcoded schema */
2051 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2052 config_check_schema( NULL, &cfBackInfo );
2057 if(module_path(c->argv[1])) return(1);
2058 /* Record which path was used with each module */
2062 if (!modpaths.mp_loads) {
2065 mp = ch_malloc( sizeof( ModPaths ));
2066 modlast->mp_next = mp;
2068 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2070 mp->mp_loads = NULL;
2081 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2083 slapi_plugins_used++;
2087 #ifdef SLAP_AUTH_REWRITE
2093 if ( c->op == LDAP_MOD_ADD ) {
2097 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2101 if ( c->argc > 1 ) {
2104 /* quote all args but the first */
2105 line = ldap_charray2str( c->argv, "\" \"" );
2106 ber_str2bv( line, 0, 0, &bv );
2107 s = ber_bvchr( &bv, '"' );
2108 assert( s != NULL );
2109 /* move the trailing quote of argv[0] to the end */
2110 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2111 bv.bv_val[ bv.bv_len - 1 ] = '"';
2114 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2117 ber_bvarray_add( &authz_rewrites, &bv );
2119 if ( c->op == LDAP_MOD_ADD ) {
2129 Debug( LDAP_DEBUG_ANY,
2130 "%s: unknown CFG_TYPE %d.\n",
2131 c->log, c->type, 0 );
2140 config_fname(ConfigArgs *c) {
2141 if(c->op == SLAP_CONFIG_EMIT) {
2142 if (c->ca_private) {
2143 ConfigFile *cf = c->ca_private;
2144 value_add_one( &c->rvalue_vals, &cf->c_file );
2153 config_cfdir(ConfigArgs *c) {
2154 if(c->op == SLAP_CONFIG_EMIT) {
2155 if ( !BER_BVISEMPTY( &cfdir )) {
2156 value_add_one( &c->rvalue_vals, &cfdir );
2165 config_search_base(ConfigArgs *c) {
2166 if(c->op == SLAP_CONFIG_EMIT) {
2168 if (!BER_BVISEMPTY(&default_search_base)) {
2169 value_add_one(&c->rvalue_vals, &default_search_base);
2170 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2174 } else if( c->op == LDAP_MOD_DELETE ) {
2175 ch_free( default_search_base.bv_val );
2176 ch_free( default_search_nbase.bv_val );
2177 BER_BVZERO( &default_search_base );
2178 BER_BVZERO( &default_search_nbase );
2182 if(c->bi || c->be != frontendDB) {
2183 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2184 "prior to any backend or database definition\n",
2189 if(default_search_nbase.bv_len) {
2190 free(default_search_base.bv_val);
2191 free(default_search_nbase.bv_val);
2194 default_search_base = c->value_dn;
2195 default_search_nbase = c->value_ndn;
2199 /* For RE23 compatibility we allow this in the global entry
2200 * but we now defer it to the frontend entry to allow modules
2201 * to load new hash types.
2204 config_passwd_hash(ConfigArgs *c) {
2206 if (c->op == SLAP_CONFIG_EMIT) {
2208 /* Don't generate it in the global entry */
2209 if ( c->table == Cft_Global )
2211 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2212 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2213 value_add_one(&c->rvalue_vals, &bv);
2216 } else if ( c->op == LDAP_MOD_DELETE ) {
2217 /* Deleting from global is a no-op, only the frontendDB entry matters */
2218 if ( c->table == Cft_Global )
2220 if ( c->valx < 0 ) {
2221 ldap_charray_free( default_passwd_hash );
2222 default_passwd_hash = NULL;
2225 ch_free( default_passwd_hash[i] );
2226 for (; default_passwd_hash[i]; i++ )
2227 default_passwd_hash[i] = default_passwd_hash[i+1];
2231 for(i = 1; i < c->argc; i++) {
2232 if(!lutil_passwd_scheme(c->argv[i])) {
2233 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2234 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2235 c->log, c->cr_msg, c->argv[i]);
2237 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2240 if(!default_passwd_hash) {
2241 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2242 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2243 c->log, c->cr_msg, 0 );
2250 config_schema_dn(ConfigArgs *c) {
2251 if ( c->op == SLAP_CONFIG_EMIT ) {
2253 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2254 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2255 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2259 } else if ( c->op == LDAP_MOD_DELETE ) {
2260 ch_free( c->be->be_schemadn.bv_val );
2261 ch_free( c->be->be_schemandn.bv_val );
2262 BER_BVZERO( &c->be->be_schemadn );
2263 BER_BVZERO( &c->be->be_schemandn );
2266 ch_free( c->be->be_schemadn.bv_val );
2267 ch_free( c->be->be_schemandn.bv_val );
2268 c->be->be_schemadn = c->value_dn;
2269 c->be->be_schemandn = c->value_ndn;
2274 config_sizelimit(ConfigArgs *c) {
2276 struct slap_limits_set *lim = &c->be->be_def_limit;
2277 if (c->op == SLAP_CONFIG_EMIT) {
2282 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2283 if ( !BER_BVISEMPTY( &bv ))
2284 value_add_one( &c->rvalue_vals, &bv );
2288 } else if ( c->op == LDAP_MOD_DELETE ) {
2289 /* Reset to defaults or values from frontend */
2290 if ( c->be == frontendDB ) {
2291 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2292 lim->lms_s_hard = 0;
2293 lim->lms_s_unchecked = -1;
2295 lim->lms_s_pr_hide = 0;
2296 lim->lms_s_pr_total = 0;
2298 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2299 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2300 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2301 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2302 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2303 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2307 for(i = 1; i < c->argc; i++) {
2308 if(!strncasecmp(c->argv[i], "size", 4)) {
2309 rc = limits_parse_one(c->argv[i], lim);
2311 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2312 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2313 c->log, c->cr_msg, c->argv[i]);
2317 if(!strcasecmp(c->argv[i], "unlimited")) {
2318 lim->lms_s_soft = -1;
2320 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2321 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2322 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2323 c->log, c->cr_msg, c->argv[i]);
2327 lim->lms_s_hard = 0;
2332 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2333 /* This is a modification to the global limits apply it to
2334 * the other databases as needed */
2335 AttributeDescription *ad=NULL;
2336 const char *text = NULL;
2337 CfEntryInfo *ce = c->ca_entry->e_private;
2339 slap_str2ad(c->argv[0], &ad, &text);
2340 /* if we got here... */
2341 assert( ad != NULL );
2343 if ( ce->ce_type == Cft_Global ){
2346 for (; ce; ce=ce->ce_sibs) {
2347 Entry *dbe = ce->ce_entry;
2348 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2349 && (!attr_find(dbe->e_attrs, ad)) ) {
2350 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2351 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2352 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2353 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2354 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2355 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2363 config_timelimit(ConfigArgs *c) {
2365 struct slap_limits_set *lim = &c->be->be_def_limit;
2366 if (c->op == SLAP_CONFIG_EMIT) {
2371 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2372 if ( !BER_BVISEMPTY( &bv ))
2373 value_add_one( &c->rvalue_vals, &bv );
2377 } else if ( c->op == LDAP_MOD_DELETE ) {
2378 /* Reset to defaults or values from frontend */
2379 if ( c->be == frontendDB ) {
2380 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2381 lim->lms_t_hard = 0;
2383 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2384 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2388 for(i = 1; i < c->argc; i++) {
2389 if(!strncasecmp(c->argv[i], "time", 4)) {
2390 rc = limits_parse_one(c->argv[i], lim);
2392 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2393 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2394 c->log, c->cr_msg, c->argv[i]);
2398 if(!strcasecmp(c->argv[i], "unlimited")) {
2399 lim->lms_t_soft = -1;
2401 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2402 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2403 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2404 c->log, c->cr_msg, c->argv[i]);
2408 lim->lms_t_hard = 0;
2413 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2414 /* This is a modification to the global limits apply it to
2415 * the other databases as needed */
2416 AttributeDescription *ad=NULL;
2417 const char *text = NULL;
2418 CfEntryInfo *ce = c->ca_entry->e_private;
2420 slap_str2ad(c->argv[0], &ad, &text);
2421 /* if we got here... */
2422 assert( ad != NULL );
2424 if ( ce->ce_type == Cft_Global ){
2427 for (; ce; ce=ce->ce_sibs) {
2428 Entry *dbe = ce->ce_entry;
2429 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2430 && (!attr_find(dbe->e_attrs, ad)) ) {
2431 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2432 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2440 config_overlay(ConfigArgs *c) {
2441 if (c->op == SLAP_CONFIG_EMIT) {
2443 } else if ( c->op == LDAP_MOD_DELETE ) {
2446 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2447 c->valx, &c->bi, &c->reply)) {
2449 Debug( LDAP_DEBUG_ANY,
2450 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2451 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2453 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2460 config_subordinate(ConfigArgs *c)
2466 case SLAP_CONFIG_EMIT:
2467 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2470 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2471 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2474 value_add_one( &c->rvalue_vals, &bv );
2478 case LDAP_MOD_DELETE:
2479 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2480 glue_sub_del( c->be );
2482 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2487 case SLAP_CONFIG_ADD:
2488 if ( c->be->be_nsuffix == NULL ) {
2490 snprintf( c->cr_msg, sizeof( c->cr_msg),
2491 "subordinate configuration needs a suffix" );
2492 Debug( LDAP_DEBUG_ANY,
2494 c->log, c->cr_msg, 0 );
2499 if ( c->argc == 2 ) {
2500 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2503 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2505 snprintf( c->cr_msg, sizeof( c->cr_msg),
2506 "subordinate must be \"TRUE\" or \"advertise\"" );
2507 Debug( LDAP_DEBUG_ANY,
2508 "%s: suffix \"%s\": %s.\n",
2509 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2515 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2523 * [listener=<listener>] [{read|write}=]<size>
2526 #ifdef LDAP_TCP_BUFFER
2527 static BerVarray tcp_buffer;
2530 #define SLAP_TCP_RMEM (0x1U)
2531 #define SLAP_TCP_WMEM (0x2U)
2534 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2535 int *size, int *rw, Listener **l )
2537 int i, rc = LDAP_SUCCESS;
2538 LDAPURLDesc *lud = NULL;
2541 if ( val != NULL && argv == NULL ) {
2542 char *s = val->bv_val;
2544 argv = ldap_str2charray( s, " \t" );
2545 if ( argv == NULL ) {
2551 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2554 char *url = argv[ i ] + STRLENOF( "listener=" );
2556 if ( ldap_url_parse( url, &lud ) ) {
2557 rc = LDAP_INVALID_SYNTAX;
2561 *l = config_check_my_url( url, lud );
2563 rc = LDAP_NO_SUCH_ATTRIBUTE;
2571 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2572 *rw |= SLAP_TCP_RMEM;
2573 ptr += STRLENOF( "read=" );
2575 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2576 *rw |= SLAP_TCP_WMEM;
2577 ptr += STRLENOF( "write=" );
2580 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2583 /* accept any base */
2584 if ( lutil_atoix( size, ptr, 0 ) ) {
2585 rc = LDAP_INVALID_SYNTAX;
2590 if ( val != NULL && argv != NULL ) {
2591 ldap_charray_free( argv );
2594 if ( lud != NULL ) {
2595 ldap_free_urldesc( lud );
2602 tcp_buffer_delete_one( struct berval *val )
2605 int size = -1, rw = 0;
2608 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2615 Listener **ll = slapd_get_listeners();
2617 for ( i = 0; ll[ i ] != NULL; i++ ) {
2618 if ( ll[ i ] == l ) break;
2621 if ( ll[ i ] == NULL ) {
2622 return LDAP_NO_SUCH_ATTRIBUTE;
2625 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2626 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2628 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2629 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2630 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2634 /* NOTE: this affects listeners without a specific setting,
2635 * does not reset all listeners. If a listener without
2636 * specific settings was assigned a buffer because of
2637 * a global setting, it will not be reset. In any case,
2638 * buffer changes will only take place at restart. */
2639 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2640 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2647 tcp_buffer_delete( BerVarray vals )
2651 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2652 tcp_buffer_delete_one( &vals[ i ] );
2659 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2661 char buf[sizeof("2147483648")], *ptr;
2663 /* unparse for later use */
2664 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2666 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2669 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2670 if ( rw & SLAP_TCP_RMEM ) {
2671 val->bv_len += STRLENOF( "read=" );
2672 } else if ( rw & SLAP_TCP_WMEM ) {
2673 val->bv_len += STRLENOF( "write=" );
2677 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2682 ptr = lutil_strcopy( ptr, "listener=" );
2683 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2687 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2688 if ( rw & SLAP_TCP_RMEM ) {
2689 ptr = lutil_strcopy( ptr, "read=" );
2690 } else if ( rw & SLAP_TCP_WMEM ) {
2691 ptr = lutil_strcopy( ptr, "write=" );
2695 ptr = lutil_strcopy( ptr, buf );
2698 assert( val->bv_val + val->bv_len == ptr );
2700 return LDAP_SUCCESS;
2704 tcp_buffer_add_one( int argc, char **argv )
2707 int size = -1, rw = 0;
2713 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2718 /* unparse for later use */
2719 rc = tcp_buffer_unparse( size, rw, l, &val );
2720 if ( rc != LDAP_SUCCESS ) {
2724 /* use parsed values */
2727 Listener **ll = slapd_get_listeners();
2729 for ( i = 0; ll[ i ] != NULL; i++ ) {
2730 if ( ll[ i ] == l ) break;
2733 if ( ll[ i ] == NULL ) {
2734 return LDAP_NO_SUCH_ATTRIBUTE;
2737 /* buffer only applies to TCP listeners;
2738 * we do not do any check here, and delegate them
2739 * to setsockopt(2) */
2740 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2741 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2743 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2744 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2745 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2749 /* NOTE: this affects listeners without a specific setting,
2750 * does not set all listeners */
2751 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2752 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2755 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2757 tcp_buffer[ tcp_buffer_num ] = val;
2760 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2766 config_tcp_buffer( ConfigArgs *c )
2768 if ( c->op == SLAP_CONFIG_EMIT ) {
2769 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2772 value_add( &c->rvalue_vals, tcp_buffer );
2773 value_add( &c->rvalue_nvals, tcp_buffer );
2775 } else if ( c->op == LDAP_MOD_DELETE ) {
2777 tcp_buffer_delete( tcp_buffer );
2778 ber_bvarray_free( tcp_buffer );
2784 int size = -1, rw = 0;
2787 struct berval val = BER_BVNULL;
2791 if ( tcp_buffer_num == 0 ) {
2796 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2801 /* unparse for later use */
2802 rc = tcp_buffer_unparse( size, rw, l, &val );
2803 if ( rc != LDAP_SUCCESS ) {
2807 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2808 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2813 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2819 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2820 ber_memfree( tcp_buffer[ i ].bv_val );
2821 for ( ; i < tcp_buffer_num; i++ ) {
2822 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2827 if ( !BER_BVISNULL( &val ) ) {
2828 SLAP_FREE( val.bv_val );
2836 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2838 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2839 "<%s> unable to add value #%d",
2840 c->argv[0], tcp_buffer_num );
2841 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2842 c->log, c->cr_msg, 0 );
2849 #endif /* LDAP_TCP_BUFFER */
2852 config_suffix(ConfigArgs *c)
2855 struct berval pdn, ndn;
2856 char *notallowed = NULL;
2858 if ( c->be == frontendDB ) {
2859 notallowed = "frontend";
2861 } else if ( SLAP_MONITOR(c->be) ) {
2862 notallowed = "monitor";
2864 } else if ( SLAP_CONFIG(c->be) ) {
2865 notallowed = "config";
2868 if ( notallowed != NULL ) {
2869 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2873 case LDAP_MOD_DELETE:
2874 case LDAP_MOD_REPLACE:
2875 case LDAP_MOD_INCREMENT:
2876 case SLAP_CONFIG_ADD:
2877 if ( !BER_BVISNULL( &c->value_dn ) ) {
2878 snprintf( buf, sizeof( buf ), "<%s> ",
2879 c->value_dn.bv_val );
2882 Debug(LDAP_DEBUG_ANY,
2883 "%s: suffix %snot allowed in %s database.\n",
2884 c->log, buf, notallowed );
2887 case SLAP_CONFIG_EMIT:
2888 /* don't complain when emitting... */
2892 /* FIXME: don't know what values may be valid;
2893 * please remove assertion, or add legal values
2894 * to either block */
2902 if (c->op == SLAP_CONFIG_EMIT) {
2903 if ( c->be->be_suffix == NULL
2904 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2908 value_add( &c->rvalue_vals, c->be->be_suffix );
2909 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2912 } else if ( c->op == LDAP_MOD_DELETE ) {
2913 if ( c->valx < 0 ) {
2914 ber_bvarray_free( c->be->be_suffix );
2915 ber_bvarray_free( c->be->be_nsuffix );
2916 c->be->be_suffix = NULL;
2917 c->be->be_nsuffix = NULL;
2920 ch_free( c->be->be_suffix[i].bv_val );
2921 ch_free( c->be->be_nsuffix[i].bv_val );
2923 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2924 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2926 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2931 #ifdef SLAPD_MONITOR_DN
2932 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2933 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2935 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2936 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2941 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2942 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2943 c->argv[0], c->be->bd_info->bi_type );
2944 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2945 c->log, c->cr_msg, 0);
2952 if (SLAP_DBHIDDEN( c->be ))
2955 tbe = select_backend(&ndn, 0);
2957 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2963 BackendDB *b2 = tbe;
2965 /* Does tbe precede be? */
2966 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2969 char *type = tbe->bd_info->bi_type;
2971 if ( overlay_is_over( tbe ) ) {
2972 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2973 type = oi->oi_orig->bi_type;
2976 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2977 "already served by a preceding %s database",
2978 c->argv[0], pdn.bv_val, type );
2979 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2980 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2986 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2987 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2988 "base provided \"%s\" (assuming okay)\n",
2989 c->log, default_search_base.bv_val, 0);
2991 ber_bvarray_add(&c->be->be_suffix, &pdn);
2992 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2997 config_rootdn(ConfigArgs *c) {
2998 if (c->op == SLAP_CONFIG_EMIT) {
2999 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3000 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3001 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3006 } else if ( c->op == LDAP_MOD_DELETE ) {
3007 ch_free( c->be->be_rootdn.bv_val );
3008 ch_free( c->be->be_rootndn.bv_val );
3009 BER_BVZERO( &c->be->be_rootdn );
3010 BER_BVZERO( &c->be->be_rootndn );
3013 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3014 ch_free( c->be->be_rootdn.bv_val );
3015 ch_free( c->be->be_rootndn.bv_val );
3017 c->be->be_rootdn = c->value_dn;
3018 c->be->be_rootndn = c->value_ndn;
3023 config_rootpw(ConfigArgs *c) {
3026 if (c->op == SLAP_CONFIG_EMIT) {
3027 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3028 /* don't copy, because "rootpw" is marked
3030 c->value_bv = c->be->be_rootpw;
3034 } else if ( c->op == LDAP_MOD_DELETE ) {
3035 ch_free( c->be->be_rootpw.bv_val );
3036 BER_BVZERO( &c->be->be_rootpw );
3040 tbe = select_backend(&c->be->be_rootndn, 0);
3042 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3044 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3045 c->log, c->cr_msg, 0);
3048 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3049 ch_free( c->be->be_rootpw.bv_val );
3050 c->be->be_rootpw = c->value_bv;
3055 config_restrict(ConfigArgs *c) {
3056 slap_mask_t restrictops = 0;
3058 slap_verbmasks restrictable_ops[] = {
3059 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3060 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3061 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3062 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3063 { BER_BVC("modrdn"), 0 },
3064 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3065 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3066 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3067 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3068 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3069 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3070 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3071 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3072 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3073 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3074 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3078 if (c->op == SLAP_CONFIG_EMIT) {
3079 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3081 } else if ( c->op == LDAP_MOD_DELETE ) {
3083 c->be->be_restrictops = 0;
3085 i = verb_to_mask( c->line, restrictable_ops );
3086 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3090 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3092 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3093 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3094 c->log, c->cr_msg, c->argv[i]);
3097 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3098 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3099 c->be->be_restrictops |= restrictops;
3104 config_allows(ConfigArgs *c) {
3105 slap_mask_t allows = 0;
3107 slap_verbmasks allowable_ops[] = {
3108 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3109 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3110 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3111 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3112 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3115 if (c->op == SLAP_CONFIG_EMIT) {
3116 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3117 } else if ( c->op == LDAP_MOD_DELETE ) {
3121 i = verb_to_mask( c->line, allowable_ops );
3122 global_allows &= ~allowable_ops[i].mask;
3126 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3128 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3129 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3130 c->log, c->cr_msg, c->argv[i]);
3133 global_allows |= allows;
3138 config_disallows(ConfigArgs *c) {
3139 slap_mask_t disallows = 0;
3141 slap_verbmasks disallowable_ops[] = {
3142 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3143 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3144 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3145 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3146 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3147 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3150 if (c->op == SLAP_CONFIG_EMIT) {
3151 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3152 } else if ( c->op == LDAP_MOD_DELETE ) {
3154 global_disallows = 0;
3156 i = verb_to_mask( c->line, disallowable_ops );
3157 global_disallows &= ~disallowable_ops[i].mask;
3161 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3163 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3164 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3165 c->log, c->cr_msg, c->argv[i]);
3168 global_disallows |= disallows;
3173 config_requires(ConfigArgs *c) {
3174 slap_mask_t requires = frontendDB->be_requires;
3175 int i, argc = c->argc;
3176 char **argv = c->argv;
3178 slap_verbmasks requires_ops[] = {
3179 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3180 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3181 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3182 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3183 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3186 if (c->op == SLAP_CONFIG_EMIT) {
3187 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3188 } else if ( c->op == LDAP_MOD_DELETE ) {
3190 c->be->be_requires = 0;
3192 i = verb_to_mask( c->line, requires_ops );
3193 c->be->be_requires &= ~requires_ops[i].mask;
3197 /* "none" can only be first, to wipe out default/global values */
3198 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3203 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3205 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3206 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3207 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3208 c->log, c->cr_msg, 0);
3210 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3211 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3212 c->log, c->cr_msg, c->argv[i]);
3216 c->be->be_requires = requires;
3221 config_extra_attrs(ConfigArgs *c)
3223 assert( c->be != NULL );
3225 if ( c->op == SLAP_CONFIG_EMIT ) {
3228 if ( c->be->be_extra_anlist == NULL ) {
3232 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3233 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3236 } else if ( c->op == LDAP_MOD_DELETE ) {
3237 if ( c->be->be_extra_anlist == NULL ) {
3241 if ( c->valx < 0 ) {
3242 anlist_free( c->be->be_extra_anlist, 1, NULL );
3243 c->be->be_extra_anlist = NULL;
3248 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3251 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3255 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3257 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3258 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3263 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3264 if ( c->be->be_extra_anlist == NULL ) {
3272 static slap_verbmasks *loglevel_ops;
3275 loglevel_init( void )
3277 slap_verbmasks lo[] = {
3278 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3279 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3280 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3281 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3282 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3283 { BER_BVC("BER"), LDAP_DEBUG_BER },
3284 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3285 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3286 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3287 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3288 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3289 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3290 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3291 #if 0 /* no longer used (nor supported) */
3292 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3293 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3295 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3296 { BER_BVC("None"), LDAP_DEBUG_NONE },
3300 return slap_verbmasks_init( &loglevel_ops, lo );
3304 loglevel_destroy( void )
3306 if ( loglevel_ops ) {
3307 (void)slap_verbmasks_destroy( loglevel_ops );
3309 loglevel_ops = NULL;
3312 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3315 slap_loglevel_register( slap_mask_t m, struct berval *s )
3319 if ( loglevel_ops == NULL ) {
3323 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3326 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3334 slap_loglevel_get( struct berval *s, int *l )
3339 if ( loglevel_ops == NULL ) {
3343 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3344 m |= loglevel_ops[ i ].mask;
3347 for ( i = 1; m & i; i <<= 1 )
3354 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3357 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3368 str2loglevel( const char *s, int *l )
3372 if ( loglevel_ops == NULL ) {
3376 i = verb_to_mask( s, loglevel_ops );
3378 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3382 *l = loglevel_ops[ i ].mask;
3388 loglevel2str( int l )
3390 struct berval bv = BER_BVNULL;
3392 loglevel2bv( l, &bv );
3398 loglevel2bv( int l, struct berval *bv )
3400 if ( loglevel_ops == NULL ) {
3406 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3410 loglevel2bvarray( int l, BerVarray *bva )
3412 if ( loglevel_ops == NULL ) {
3416 return mask_to_verbs( loglevel_ops, l, bva );
3420 loglevel_print( FILE *out )
3424 if ( loglevel_ops == NULL ) {
3428 fprintf( out, "Installed log subsystems:\n\n" );
3429 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3430 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3432 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3433 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3434 loglevel_ops[ i ].word.bv_val, mask, mask );
3437 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3438 "by specific code\n\n" );
3443 static int config_syslog;
3446 config_loglevel(ConfigArgs *c) {
3449 if ( loglevel_ops == NULL ) {
3453 if (c->op == SLAP_CONFIG_EMIT) {
3454 /* Get default or commandline slapd setting */
3455 if ( ldap_syslog && !config_syslog )
3456 config_syslog = ldap_syslog;
3457 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3459 } else if ( c->op == LDAP_MOD_DELETE ) {
3463 i = verb_to_mask( c->line, loglevel_ops );
3464 config_syslog &= ~loglevel_ops[i].mask;
3466 if ( slapMode & SLAP_SERVER_MODE ) {
3467 ldap_syslog = config_syslog;
3472 for( i=1; i < c->argc; i++ ) {
3475 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3476 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3477 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3478 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3479 c->log, c->cr_msg, c->argv[i]);
3483 if ( str2loglevel( c->argv[i], &level ) ) {
3484 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3485 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3486 c->log, c->cr_msg, c->argv[i]);
3490 /* Explicitly setting a zero clears all the levels */
3492 config_syslog |= level;
3496 if ( slapMode & SLAP_SERVER_MODE ) {
3497 ldap_syslog = config_syslog;
3503 config_referral(ConfigArgs *c) {
3505 if (c->op == SLAP_CONFIG_EMIT) {
3506 if ( default_referral ) {
3507 value_add( &c->rvalue_vals, default_referral );
3512 } else if ( c->op == LDAP_MOD_DELETE ) {
3513 if ( c->valx < 0 ) {
3514 ber_bvarray_free( default_referral );
3515 default_referral = NULL;
3518 ch_free( default_referral[i].bv_val );
3519 for (; default_referral[i].bv_val; i++ )
3520 default_referral[i] = default_referral[i+1];
3524 if(validate_global_referral(c->argv[1])) {
3525 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3526 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3527 c->log, c->cr_msg, c->argv[1]);
3531 ber_str2bv(c->argv[1], 0, 0, &val);
3532 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3540 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3541 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3542 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3543 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3544 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3545 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3546 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3547 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3548 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3553 config_security(ConfigArgs *c) {
3554 slap_ssf_set_t *set = &c->be->be_ssf_set;
3557 if (c->op == SLAP_CONFIG_EMIT) {
3563 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3564 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3567 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3568 if ( bv.bv_len >= sizeof( numbuf ) ) {
3569 ber_bvarray_free_x( c->rvalue_vals, NULL );
3570 c->rvalue_vals = NULL;
3574 bv.bv_len += sec_keys[i].key.bv_len;
3575 bv.bv_val = ch_malloc( bv.bv_len + 1);
3576 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3577 strcpy( next, numbuf );
3578 ber_bvarray_add( &c->rvalue_vals, &bv );
3583 for(i = 1; i < c->argc; i++) {
3584 slap_ssf_t *tgt = NULL;
3586 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3587 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3588 sec_keys[j].key.bv_len)) {
3589 src = c->argv[i] + sec_keys[j].key.bv_len;
3590 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3595 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3596 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3597 c->log, c->cr_msg, c->argv[i]);
3601 if ( lutil_atou( tgt, src ) != 0 ) {
3602 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3603 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3604 c->log, c->cr_msg, c->argv[i]);
3612 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3616 for (; !BER_BVISNULL( &an->an_name ); an++) {
3617 /* if buflen == 0, assume the buffer size has been
3618 * already checked otherwise */
3619 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3620 if ( comma ) *ptr++ = ',';
3621 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3628 config_updatedn(ConfigArgs *c) {
3629 if (c->op == SLAP_CONFIG_EMIT) {
3630 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3631 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3632 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3636 } else if ( c->op == LDAP_MOD_DELETE ) {
3637 ch_free( c->be->be_update_ndn.bv_val );
3638 BER_BVZERO( &c->be->be_update_ndn );
3639 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3642 if(SLAP_SHADOW(c->be)) {
3643 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3644 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3645 c->log, c->cr_msg, 0);
3649 ber_memfree_x( c->value_dn.bv_val, NULL );
3650 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3651 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3653 c->be->be_update_ndn = c->value_ndn;
3654 BER_BVZERO( &c->value_dn );
3655 BER_BVZERO( &c->value_ndn );
3657 return config_slurp_shadow( c );
3661 config_shadow( ConfigArgs *c, slap_mask_t flag )
3663 char *notallowed = NULL;
3665 if ( c->be == frontendDB ) {
3666 notallowed = "frontend";
3668 } else if ( SLAP_MONITOR(c->be) ) {
3669 notallowed = "monitor";
3672 if ( notallowed != NULL ) {
3673 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3677 if ( SLAP_SHADOW(c->be) ) {
3678 /* if already shadow, only check consistency */
3679 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3680 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3686 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3687 if ( !SLAP_MULTIMASTER( c->be ))
3688 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3695 config_updateref(ConfigArgs *c) {
3697 if (c->op == SLAP_CONFIG_EMIT) {
3698 if ( c->be->be_update_refs ) {
3699 value_add( &c->rvalue_vals, c->be->be_update_refs );
3704 } else if ( c->op == LDAP_MOD_DELETE ) {
3705 if ( c->valx < 0 ) {
3706 ber_bvarray_free( c->be->be_update_refs );
3707 c->be->be_update_refs = NULL;
3710 ch_free( c->be->be_update_refs[i].bv_val );
3711 for (; c->be->be_update_refs[i].bv_val; i++)
3712 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3716 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3717 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3719 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3720 c->log, c->cr_msg, 0);
3724 if(validate_global_referral(c->argv[1])) {
3725 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3726 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3727 c->log, c->cr_msg, c->argv[1]);
3730 ber_str2bv(c->argv[1], 0, 0, &val);
3731 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3736 config_obsolete(ConfigArgs *c) {
3737 if (c->op == SLAP_CONFIG_EMIT)
3740 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3742 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3747 config_include(ConfigArgs *c) {
3748 int savelineno = c->lineno;
3751 ConfigFile *cfsave = cfn;
3752 ConfigFile *cf2 = NULL;
3754 /* Leftover from RE23. No dynamic config for include files */
3755 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3758 cf = ch_calloc( 1, sizeof(ConfigFile));
3759 if ( cfn->c_kids ) {
3760 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3766 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3767 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3768 c->lineno = savelineno - 1;
3771 if ( cf2 ) cf2->c_sibs = NULL;
3772 else cfn->c_kids = NULL;
3773 ch_free( cf->c_file.bv_val );
3783 config_tls_cleanup(ConfigArgs *c) {
3786 if ( slap_tls_ld ) {
3789 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3791 /* Force new ctx to be created */
3792 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3794 /* The ctx's refcount is bumped up here */
3795 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3796 /* This is a no-op if it's already loaded */
3797 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3804 config_tls_option(ConfigArgs *c) {
3806 LDAP *ld = slap_tls_ld;
3808 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3809 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3810 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3811 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3812 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3813 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3814 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3816 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3818 default: Debug(LDAP_DEBUG_ANY, "%s: "
3819 "unknown tls_option <0x%x>\n",
3820 c->log, c->type, 0);
3823 if (c->op == SLAP_CONFIG_EMIT) {
3824 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3825 } else if ( c->op == LDAP_MOD_DELETE ) {
3826 c->cleanup = config_tls_cleanup;
3827 return ldap_pvt_tls_set_option( ld, flag, NULL );
3829 ch_free(c->value_string);
3830 c->cleanup = config_tls_cleanup;
3831 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3834 /* FIXME: this ought to be provided by libldap */
3836 config_tls_config(ConfigArgs *c) {
3839 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3840 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3841 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3843 Debug(LDAP_DEBUG_ANY, "%s: "
3844 "unknown tls_option <0x%x>\n",
3845 c->log, c->type, 0);
3848 if (c->op == SLAP_CONFIG_EMIT) {
3849 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3850 } else if ( c->op == LDAP_MOD_DELETE ) {
3852 c->cleanup = config_tls_cleanup;
3853 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3855 ch_free( c->value_string );
3856 c->cleanup = config_tls_cleanup;
3857 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3858 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3859 Debug(LDAP_DEBUG_ANY, "%s: "
3860 "unable to parse %s \"%s\"\n",
3861 c->log, c->argv[0], c->argv[1] );
3864 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3866 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3871 static CfEntryInfo *
3872 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3882 if ( dn_match( &root->ce_entry->e_nname, dn ))
3885 c = dn->bv_val+dn->bv_len;
3886 for (;*c != ',';c--);
3890 for (--c;c>dn->bv_val && *c != ',';c--);
3894 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3896 root = root->ce_kids;
3898 for (;root;root=root->ce_sibs) {
3899 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3900 if ( cdn.bv_val == dn->bv_val ) {
3910 typedef struct setup_cookie {
3920 config_ldif_resp( Operation *op, SlapReply *rs )
3922 if ( rs->sr_type == REP_SEARCH ) {
3923 setup_cookie *sc = op->o_callback->sc_private;
3926 sc->cfb->cb_got_ldif = 1;
3927 /* Does the frontend exist? */
3928 if ( !sc->got_frontend ) {
3929 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3930 "olcDatabase", STRLENOF( "olcDatabase" )))
3932 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3933 STRLENOF( "olcDatabase" ), "={-1}frontend",
3934 STRLENOF( "={-1}frontend" )))
3938 sc->ca->be = frontendDB;
3939 sc->ca->bi = frontendDB->bd_info;
3940 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3941 rdn.bv_val = sc->ca->log;
3942 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3943 "%s=" SLAP_X_ORDERED_FMT "%s",
3944 cfAd_database->ad_cname.bv_val, -1,
3945 sc->ca->bi->bi_type);
3947 sc->frontend = config_build_entry( op, rs,
3948 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3949 sc->ca->be->be_cf_ocs );
3959 dnParent( &rs->sr_entry->e_nname, &pdn );
3961 /* Does the configDB exist? */
3962 if ( sc->got_frontend && !sc->got_config &&
3963 !strncmp( rs->sr_entry->e_nname.bv_val,
3964 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3965 dn_match( &config_rdn, &pdn ) )
3967 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3968 STRLENOF( "olcDatabase" ), "={0}config",
3969 STRLENOF( "={0}config" )))
3973 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3974 sc->ca->bi = sc->ca->be->bd_info;
3975 rdn.bv_val = sc->ca->log;
3976 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3977 "%s=" SLAP_X_ORDERED_FMT "%s",
3978 cfAd_database->ad_cname.bv_val, 0,
3979 sc->ca->bi->bi_type);
3981 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3982 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3989 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3990 if ( rs->sr_err != LDAP_SUCCESS ) {
3991 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3992 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3998 /* Configure and read the underlying back-ldif store */
4000 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4001 CfBackInfo *cfb = be->be_private;
4007 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4008 Connection conn = {0};
4009 OperationBuffer opbuf;
4011 SlapReply rs = {REP_RESULT};
4012 Filter filter = { LDAP_FILTER_PRESENT };
4013 struct berval filterstr = BER_BVC("(objectclass=*)");
4016 /* Is the config directory available? */
4017 if ( stat( dir, &st ) < 0 ) {
4018 /* No, so don't bother using the backing store.
4019 * All changes will be in-memory only.
4024 cfb->cb_db.bd_info = backend_info( "ldif" );
4025 if ( !cfb->cb_db.bd_info )
4026 return 0; /* FIXME: eventually this will be a fatal error */
4028 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4031 cfb->cb_db.be_suffix = be->be_suffix;
4032 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4034 /* The suffix is always "cn=config". The underlying DB's rootdn
4035 * is always the same as the suffix.
4037 cfb->cb_db.be_rootdn = be->be_suffix[0];
4038 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4040 ber_str2bv( dir, 0, 1, &cfdir );
4045 argv[0] = "directory";
4046 argv[1] = (char *)dir;
4051 c.table = Cft_Database;
4053 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4057 if ( config_add_vals( ct, &c ))
4060 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4064 void *thrctx = ldap_pvt_thread_pool_context();
4067 connection_fake_init( &conn, &opbuf, thrctx );
4070 filter.f_desc = slap_schema.si_ad_objectClass;
4072 op->o_tag = LDAP_REQ_SEARCH;
4074 op->ors_filter = &filter;
4075 op->ors_filterstr = filterstr;
4076 op->ors_scope = LDAP_SCOPE_SUBTREE;
4078 op->o_dn = c.be->be_rootdn;
4079 op->o_ndn = c.be->be_rootndn;
4081 op->o_req_dn = be->be_suffix[0];
4082 op->o_req_ndn = be->be_nsuffix[0];
4084 op->ors_tlimit = SLAP_NO_LIMIT;
4085 op->ors_slimit = SLAP_NO_LIMIT;
4087 op->ors_attrs = slap_anlist_all_attributes;
4088 op->ors_attrsonly = 0;
4090 op->o_callback = &cb;
4093 cb.sc_private = ≻
4094 sc.got_frontend = 0;
4099 op->o_bd = &cfb->cb_db;
4101 /* Allow unknown attrs in DNs */
4102 prev_DN_strict = slap_DN_strict;
4105 rc = op->o_bd->be_search( op, &rs );
4107 /* Restore normal DN validation */
4108 slap_DN_strict = prev_DN_strict;
4110 op->o_tag = LDAP_REQ_ADD;
4111 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4112 rs_reinit( &rs, REP_RESULT );
4113 op->ora_e = sc.frontend;
4114 rc = op->o_bd->be_add( op, &rs );
4116 if ( rc == LDAP_SUCCESS && sc.config ) {
4117 rs_reinit( &rs, REP_RESULT );
4118 op->ora_e = sc.config;
4119 rc = op->o_bd->be_add( op, &rs );
4121 ldap_pvt_thread_pool_context_reset( thrctx );
4124 /* ITS#4194 - only use if it's present, or we're converting. */
4125 if ( !readit || rc == LDAP_SUCCESS )
4126 cfb->cb_use_ldif = 1;
4132 CfOc_cmp( const void *c1, const void *c2 ) {
4133 const ConfigOCs *co1 = c1;
4134 const ConfigOCs *co2 = c2;
4136 return ber_bvcmp( co1->co_name, co2->co_name );
4140 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4143 i = init_config_attrs( ct );
4146 /* set up the objectclasses */
4147 i = init_config_ocs( ocs );
4150 for (i=0; ocs[i].co_def; i++) {
4151 if ( ocs[i].co_oc ) {
4152 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4153 if ( !ocs[i].co_table )
4154 ocs[i].co_table = ct;
4155 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4162 read_config(const char *fname, const char *dir) {
4165 const char *cfdir, *cfname;
4168 /* Setup the config backend */
4169 be = backend_db_init( "config", NULL, 0, NULL );
4173 cfb = be->be_private;
4174 be->be_dfltaccess = ACL_NONE;
4176 /* If no .conf, or a dir was specified, setup the dir */
4177 if ( !fname || dir ) {
4179 /* If explicitly given, check for existence */
4182 if ( stat( dir, &st ) < 0 ) {
4183 Debug( LDAP_DEBUG_ANY,
4184 "invalid config directory %s, error %d\n",
4190 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4192 /* if fname is defaulted, try reading .d */
4193 rc = config_setup_ldif( be, cfdir, !fname );
4196 /* It may be OK if the base object doesn't exist yet. */
4197 if ( rc != LDAP_NO_SUCH_OBJECT )
4199 /* ITS#4194: But if dir was specified and no fname,
4200 * then we were supposed to read the dir. Unless we're
4201 * trying to slapadd the dir...
4203 if ( dir && !fname ) {
4204 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4206 /* Assume it's slapadd with a config dir, let it continue */
4208 cfb->cb_got_ldif = 1;
4209 cfb->cb_use_ldif = 1;
4214 /* If we read the config from back-ldif, nothing to do here */
4215 if ( cfb->cb_got_ldif ) {
4224 cfname = SLAPD_DEFAULT_CONFIGFILE;
4226 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4229 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4232 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4233 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4234 &frontendDB->be_schemadn );
4235 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4236 if ( rc != LDAP_SUCCESS ) {
4237 Debug(LDAP_DEBUG_ANY, "read_config: "
4238 "unable to normalize default schema DN \"%s\"\n",
4239 frontendDB->be_schemadn.bv_val, 0, 0 );
4240 /* must not happen */
4244 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4245 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4246 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4247 "Check slapd -h arguments.\n", 0,0,0 );
4255 config_back_bind( Operation *op, SlapReply *rs )
4257 if ( be_isroot_pw( op ) ) {
4258 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4259 /* frontend sends result */
4260 return LDAP_SUCCESS;
4263 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4264 send_ldap_result( op, rs );
4270 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4274 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4276 rs->sr_attrs = op->ors_attrs;
4277 rs->sr_entry = ce->ce_entry;
4279 rc = send_search_entry( op, rs );
4280 if ( rc != LDAP_SUCCESS ) {
4284 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4285 if ( ce->ce_kids ) {
4286 rc = config_send( op, rs, ce->ce_kids, 1 );
4287 if ( rc ) return rc;
4290 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4291 rc = config_send( op, rs, ce, 0 );
4299 static ConfigTable *
4300 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4305 for (j=0; j<nocs; j++) {
4306 for (i=0; colst[j]->co_table[i].name; i++)
4307 if ( colst[j]->co_table[i].ad == ad ) {
4308 ca->table = colst[j]->co_type;
4309 return &colst[j]->co_table[i];
4315 /* Sort the attributes of the entry according to the order defined
4316 * in the objectclass, with required attributes occurring before
4317 * allowed attributes. For any attributes with sequencing dependencies
4318 * (e.g., rootDN must be defined after suffix) the objectclass must
4319 * list the attributes in the desired sequence.
4322 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4324 Attribute *a, *head = NULL, *tail = NULL, **prev;
4327 for (i=0; i<nocs; i++) {
4328 if ( colst[i]->co_oc->soc_required ) {
4329 AttributeType **at = colst[i]->co_oc->soc_required;
4330 for (j=0; at[j]; j++) {
4331 for (a=e->e_attrs, prev=&e->e_attrs; a;
4332 prev = &(*prev)->a_next, a=a->a_next) {
4333 if ( a->a_desc == at[j]->sat_ad ) {
4347 if ( colst[i]->co_oc->soc_allowed ) {
4348 AttributeType **at = colst[i]->co_oc->soc_allowed;
4349 for (j=0; at[j]; j++) {
4350 for (a=e->e_attrs, prev=&e->e_attrs; a;
4351 prev = &(*prev)->a_next, a=a->a_next) {
4352 if ( a->a_desc == at[j]->sat_ad ) {
4368 tail->a_next = e->e_attrs;
4374 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4376 Attribute *a = NULL;
4377 AttributeDescription *ad;
4387 Modifications *ml = ptr;
4389 vals = ml->sml_values;
4392 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4393 rc = ordered_value_sort( a, 1 );
4395 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4396 ad->ad_cname.bv_val );
4400 for ( i=0; vals[i].bv_val; i++ ) {
4401 ca->line = vals[i].bv_val;
4402 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4403 ca->line[0] == '{' ) {
4404 char *idx = strchr( ca->line, '}' );
4405 if ( idx ) ca->line = idx+1;
4407 rc = config_parse_vals( ct, ca, i );
4416 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4419 struct berval rtype, rval;
4421 AttributeDescription *ad = NULL;
4423 dnRdn( &e->e_name, rdn );
4424 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4425 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4426 rtype.bv_val = rdn->bv_val;
4427 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4430 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4431 a = attr_find( e->e_attrs, ad );
4432 if (!a ) return LDAP_NAMING_VIOLATION;
4439 config_rename_kids( CfEntryInfo *ce )
4442 struct berval rdn, nrdn;
4444 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4445 struct berval newdn, newndn;
4446 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4447 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4448 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4449 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4450 free( ce2->ce_entry->e_name.bv_val );
4451 free( ce2->ce_entry->e_nname.bv_val );
4452 ce2->ce_entry->e_name = newdn;
4453 ce2->ce_entry->e_nname = newndn;
4454 config_rename_kids( ce2 );
4459 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4460 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4461 struct berval *nnewrdn, int use_ldif )
4465 struct berval odn, ondn;
4469 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4470 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4473 free( a->a_vals[0].bv_val );
4474 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4475 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4476 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4477 strcpy( a->a_vals[0].bv_val, ptr1 );
4479 if ( a->a_nvals != a->a_vals ) {
4480 free( a->a_nvals[0].bv_val );
4481 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4482 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4483 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4484 strcpy( a->a_nvals[0].bv_val, ptr1 );
4487 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4488 BackendDB *be = op->o_bd;
4489 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4490 struct berval dn, ndn, xdn, xndn;
4492 op->o_bd = &cfb->cb_db;
4494 /* Save current rootdn; use the underlying DB's rootdn */
4498 xndn = op->o_req_ndn;
4499 op->o_dn = op->o_bd->be_rootdn;
4500 op->o_ndn = op->o_bd->be_rootndn;
4502 op->o_req_ndn = ondn;
4504 scp = op->o_callback;
4505 op->o_callback = ≻
4506 op->orr_newrdn = *newrdn;
4507 op->orr_nnewrdn = *nnewrdn;
4508 op->orr_newSup = NULL;
4509 op->orr_nnewSup = NULL;
4510 op->orr_deleteoldrdn = 1;
4511 op->orr_modlist = NULL;
4512 slap_modrdn2mods( op, rs );
4513 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4514 rc = op->o_bd->be_modrdn( op, rs );
4515 slap_mods_free( op->orr_modlist, 1 );
4518 op->o_callback = scp;
4522 op->o_req_ndn = xndn;
4525 free( ondn.bv_val );
4527 config_rename_kids( e->e_private );
4532 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4533 Entry *e, int idx, int tailindex, int use_ldif )
4535 struct berval ival, newrdn, nnewrdn;
4538 char ibuf[32], *ptr1, *ptr2 = NULL;
4541 rc = config_rename_attr( rs, e, &rdn, &a );
4542 if ( rc ) return rc;
4545 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4546 if ( ival.bv_len >= sizeof( ibuf ) ) {
4547 return LDAP_NAMING_VIOLATION;
4550 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4551 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4554 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4555 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4558 ptr2 = ber_bvchr( &rdn, '}' );
4562 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4564 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4565 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4566 a->a_desc->ad_cname.bv_len );
4568 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4569 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4573 /* Do the equivalent of ModRDN */
4574 /* Replace DN / NDN */
4575 newrdn.bv_len = ptr1 - newrdn.bv_val;
4576 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4577 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4579 free( nnewrdn.bv_val );
4580 free( newrdn.bv_val );
4585 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4586 SlapReply *rs, int *renum, int *ibase )
4589 int index = -1, gotindex = 0, nsibs, rc = 0;
4590 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4591 char *ptr1, *ptr2 = NULL;
4594 if ( renum ) *renum = 0;
4596 /* These entries don't get indexed/renumbered */
4597 if ( ce_type == Cft_Global ) return 0;
4598 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4600 if ( ce_type == Cft_Module )
4603 /* See if the rdn has an index already */
4604 dnRdn( &e->e_name, &rdn );
4605 if ( ce_type == Cft_Database ) {
4606 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4607 "frontend", STRLENOF("frontend") ))
4609 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4610 "config", STRLENOF("config") ))
4613 ptr1 = ber_bvchr( &e->e_name, '{' );
4614 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4616 ptr2 = strchr( ptr1, '}' );
4617 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4618 return LDAP_NAMING_VIOLATION;
4619 if ( ptr2-ptr1 == 1)
4620 return LDAP_NAMING_VIOLATION;
4622 index = strtol( ptr1 + 1, &next, 10 );
4623 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4624 return LDAP_NAMING_VIOLATION;
4627 /* Special case, we allow -1 for the frontendDB */
4628 if ( index != -1 || !isfrontend )
4629 return LDAP_NAMING_VIOLATION;
4631 if ( isconfig && index != 0 ){
4632 return LDAP_NAMING_VIOLATION;
4636 /* count related kids */
4637 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4638 if ( ce->ce_type == ce_type ) nsibs++;
4641 /* account for -1 frontend */
4642 if ( ce_type == Cft_Database )
4645 if ( index != nsibs ) {
4647 if ( index < nsibs ) {
4648 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4649 /* Siblings need to be renumbered */
4650 if ( index != -1 || !isfrontend )
4654 /* config DB is always "0" */
4655 if ( isconfig && index == -1 ) {
4658 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4662 /* just make index = nsibs */
4664 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4667 if ( ibase ) *ibase = index;
4668 if ( renum ) *renum = renumber;
4672 /* Insert all superior classes of the given class */
4674 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4679 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4680 if ( count_oc( *sups, copp, nocs ) ) {
4685 co.co_name = &oc->soc_cname;
4686 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4690 /* check for duplicates */
4691 for ( i = 0; i < *nocs; i++ ) {
4692 if ( *copp && (*copp)[i] == cop ) {
4698 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4699 if ( tmp == NULL ) {
4703 (*copp)[*nocs] = cop;
4711 /* Find all superior classes of the given objectclasses,
4712 * return list in order of most-subordinate first.
4714 * Special / auxiliary / Cft_Misc classes always take precedence.
4717 count_ocs( Attribute *oc_at, int *nocs )
4719 int i, j, misc = -1;
4720 ConfigOCs **colst = NULL;
4724 for ( i = oc_at->a_numvals; i--; ) {
4725 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4727 assert( oc != NULL );
4728 if ( count_oc( oc, &colst, nocs ) ) {
4738 ConfigOCs *tmp = colst[i];
4739 colst[i] = colst[j];
4741 if (tmp->co_type == Cft_Misc)
4745 /* Move misc class to front of list */
4747 ConfigOCs *tmp = colst[misc];
4748 for (i=misc; i>0; i--)
4749 colst[i] = colst[i-1];
4757 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4759 /* Leftover from RE23. Never parse this entry */
4760 return LDAP_COMPARE_TRUE;
4764 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4768 /* This entry is hardcoded, don't re-parse it */
4769 if ( p->ce_type == Cft_Global ) {
4770 cfn = p->ce_private;
4771 ca->ca_private = cfn;
4772 return LDAP_COMPARE_TRUE;
4774 if ( p->ce_type != Cft_Schema )
4775 return LDAP_CONSTRAINT_VIOLATION;
4777 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4778 ca->ca_private = cfn;
4779 cfo = p->ce_private;
4780 cfn->c_sibs = cfo->c_kids;
4782 return LDAP_SUCCESS;
4786 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4788 if ( p->ce_type != Cft_Global ) {
4789 return LDAP_CONSTRAINT_VIOLATION;
4791 /* config must be {0}, nothing else allowed */
4792 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4793 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4794 return LDAP_CONSTRAINT_VIOLATION;
4796 ca->be = frontendDB; /* just to get past check_vals */
4797 return LDAP_SUCCESS;
4801 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4803 if ( p->ce_type != Cft_Global ) {
4804 return LDAP_CONSTRAINT_VIOLATION;
4806 return LDAP_SUCCESS;
4810 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4812 if ( p->ce_type != Cft_Global ) {
4813 return LDAP_CONSTRAINT_VIOLATION;
4815 return LDAP_SUCCESS;
4819 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4821 if ( p->ce_type != Cft_Database ) {
4822 return LDAP_CONSTRAINT_VIOLATION;
4825 return LDAP_SUCCESS;
4829 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4834 AttributeDescription *ad;
4840 if ( cfn->c_cr_head ) {
4841 struct berval bv = BER_BVC("olcDitContentRules");
4843 slap_bv2ad( &bv, &ad, &text );
4844 ct = config_find_table( colst, nocs, ad, ca );
4845 config_del_vals( ct, ca );
4847 if ( cfn->c_oc_head ) {
4848 struct berval bv = BER_BVC("olcObjectClasses");
4850 slap_bv2ad( &bv, &ad, &text );
4851 ct = config_find_table( colst, nocs, ad, ca );
4852 config_del_vals( ct, ca );
4854 if ( cfn->c_at_head ) {
4855 struct berval bv = BER_BVC("olcAttributeTypes");
4857 slap_bv2ad( &bv, &ad, &text );
4858 ct = config_find_table( colst, nocs, ad, ca );
4859 config_del_vals( ct, ca );
4861 if ( cfn->c_syn_head ) {
4862 struct berval bv = BER_BVC("olcLdapSyntaxes");
4864 slap_bv2ad( &bv, &ad, &text );
4865 ct = config_find_table( colst, nocs, ad, ca );
4866 config_del_vals( ct, ca );
4868 if ( cfn->c_om_head ) {
4869 struct berval bv = BER_BVC("olcObjectIdentifier");
4871 slap_bv2ad( &bv, &ad, &text );
4872 ct = config_find_table( colst, nocs, ad, ca );
4873 config_del_vals( ct, ca );
4875 cfo = p->ce_private;
4876 cfo->c_kids = cfn->c_sibs;
4881 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4883 int rc = LDAP_CONSTRAINT_VIOLATION;
4886 if ( (*cop)->co_ldadd ) {
4887 rc = (*cop)->co_ldadd( last, e, ca );
4888 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4893 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4894 ConfigOCs co = { 0 };
4896 co.co_name = &(*ocp)->soc_cname;
4897 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4898 if ( *cop == NULL ) {
4902 rc = config_add_oc( cop, last, e, ca );
4903 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4911 /* Parse an LDAP entry into config directives */
4913 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4914 int *renum, Operation *op )
4916 CfEntryInfo *ce, *last = NULL;
4917 ConfigOCs co, *coptr, **colst;
4918 Attribute *a, *oc_at, *soc_at;
4919 int i, ibase = -1, nocs, rc = 0;
4922 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4924 memset( ca, 0, sizeof(ConfigArgs));
4926 /* Make sure parent exists and entry does not. But allow
4927 * Databases and Overlays to be inserted. Don't do any
4928 * auto-renumbering if manageDSAit control is present.
4930 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4932 if ( ( op && op->o_managedsait ) ||
4933 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4934 ce->ce_type != Cft_Module ) )
4936 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4937 "DN=\"%s\" already exists\n",
4938 log_prefix, e->e_name.bv_val, 0 );
4939 /* global schema ignores all writes */
4940 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4941 return LDAP_COMPARE_TRUE;
4942 return LDAP_ALREADY_EXISTS;
4946 dnParent( &e->e_nname, &pdn );
4948 /* If last is NULL, the new entry is the root/suffix entry,
4949 * otherwise last should be the parent.
4951 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4953 rs->sr_matched = last->ce_entry->e_name.bv_val;
4955 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4956 "DN=\"%s\" not child of DN=\"%s\"\n",
4957 log_prefix, e->e_name.bv_val,
4958 last->ce_entry->e_name.bv_val );
4959 return LDAP_NO_SUCH_OBJECT;
4963 /* No parent, must be root. This will never happen... */
4964 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4965 return LDAP_NO_SUCH_OBJECT;
4968 if ( last && !access_allowed( op, last->ce_entry,
4969 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4971 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4972 "DN=\"%s\" no write access to \"children\" of parent\n",
4973 log_prefix, e->e_name.bv_val, 0 );
4974 return LDAP_INSUFFICIENT_ACCESS;
4978 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4980 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4981 "DN=\"%s\" no objectClass\n",
4982 log_prefix, e->e_name.bv_val, 0 );
4983 return LDAP_OBJECT_CLASS_VIOLATION;
4986 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4988 ObjectClass *soc = NULL;
4989 char textbuf[ SLAP_TEXT_BUFLEN ];
4990 const char *text = textbuf;
4992 /* FIXME: check result */
4993 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4994 &text, textbuf, sizeof(textbuf), NULL );
4995 if ( rc != LDAP_SUCCESS ) {
4996 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4997 "DN=\"%s\" no structural objectClass (%s)\n",
4998 log_prefix, e->e_name.bv_val, text );
5001 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5002 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5003 if ( soc_at == NULL ) {
5004 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5005 "DN=\"%s\" no structural objectClass; "
5006 "unable to merge computed class %s\n",
5007 log_prefix, e->e_name.bv_val,
5008 soc->soc_cname.bv_val );
5009 return LDAP_OBJECT_CLASS_VIOLATION;
5012 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5013 "DN=\"%s\" no structural objectClass; "
5014 "computed objectClass %s merged\n",
5015 log_prefix, e->e_name.bv_val,
5016 soc->soc_cname.bv_val );
5019 /* Fake the coordinates based on whether we're part of an
5020 * LDAP Add or if reading the config dir
5023 ca->fname = "slapd";
5026 ca->fname = cfdir.bv_val;
5031 co.co_name = &soc_at->a_nvals[0];
5032 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5033 if ( coptr == NULL ) {
5034 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5035 "DN=\"%s\" no structural objectClass in configuration table\n",
5036 log_prefix, e->e_name.bv_val, 0 );
5037 return LDAP_OBJECT_CLASS_VIOLATION;
5040 /* Only the root can be Cft_Global, everything else must
5041 * have a parent. Only limited nesting arrangements are allowed.
5043 rc = LDAP_CONSTRAINT_VIOLATION;
5044 if ( coptr->co_type == Cft_Global && !last ) {
5045 cfn = cfb->cb_config;
5046 ca->ca_private = cfn;
5047 ca->be = frontendDB; /* just to get past check_vals */
5051 colst = count_ocs( oc_at, &nocs );
5053 /* Check whether the Add is allowed by its parent, and do
5054 * any necessary arg setup
5057 rc = config_add_oc( &coptr, last, e, ca );
5058 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5059 for ( i = 0; i<nocs; i++ ) {
5060 /* Already checked these */
5061 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5063 if ( colst[i]->co_ldadd &&
5064 ( rc = colst[i]->co_ldadd( last, e, ca ))
5065 != LDAP_CONSTRAINT_VIOLATION ) {
5071 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5072 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5073 "DN=\"%s\" no structural objectClass add function\n",
5074 log_prefix, e->e_name.bv_val, 0 );
5075 return LDAP_OBJECT_CLASS_VIOLATION;
5079 /* Add the entry but don't parse it, we already have its contents */
5080 if ( rc == LDAP_COMPARE_TRUE ) {
5085 if ( rc != LDAP_SUCCESS )
5088 /* Parse all the values and check for simple syntax errors before
5089 * performing any set actions.
5091 * If doing an LDAPadd, check for indexed names and any necessary
5092 * renaming/renumbering. Entries that don't need indexed names are
5093 * ignored. Entries that need an indexed name and arrive without one
5094 * are assigned to the end. Entries that arrive with an index may
5095 * cause the following entries to be renumbered/bumped down.
5097 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5098 * don't allow Adding an entry with an index that's already in use.
5099 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5101 * These entries can have auto-assigned indexes (appended to the end)
5102 * but only the other types support auto-renumbering of siblings.
5105 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5110 if ( renum && *renum && coptr->co_type != Cft_Database &&
5111 coptr->co_type != Cft_Overlay )
5113 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5114 "operation requires sibling renumbering" );
5115 rc = LDAP_UNWILLING_TO_PERFORM;
5120 init_config_argv( ca );
5122 /* Make sure we process attrs in the required order */
5123 sort_attrs( e, colst, nocs );
5125 for ( a = e->e_attrs; a; a = a->a_next ) {
5126 if ( a == oc_at ) continue;
5127 ct = config_find_table( colst, nocs, a->a_desc, ca );
5128 if ( !ct ) continue; /* user data? */
5129 rc = check_vals( ct, ca, a, 1 );
5130 if ( rc ) goto done_noop;
5133 /* Basic syntax checks are OK. Do the actual settings. */
5134 for ( a=e->e_attrs; a; a=a->a_next ) {
5135 if ( a == oc_at ) continue;
5136 ct = config_find_table( colst, nocs, a->a_desc, ca );
5137 if ( !ct ) continue; /* user data? */
5138 for (i=0; a->a_vals[i].bv_val; i++) {
5141 ca->line = a->a_vals[i].bv_val;
5142 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5143 ptr = strchr( ca->line, '}' );
5145 iptr = strchr( ca->line, '{' );
5149 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5151 ca->valx = strtol( iptr+1, NULL, 0 );
5156 rc = config_parse_add( ct, ca, i );
5164 /* Newly added databases and overlays need to be started up */
5165 if ( CONFIG_ONLINE_ADD( ca )) {
5166 if ( coptr->co_type == Cft_Database ) {
5167 rc = backend_startup_one( ca->be, &ca->reply );
5169 } else if ( coptr->co_type == Cft_Overlay ) {
5170 if ( ca->bi->bi_db_open ) {
5171 BackendInfo *bi_orig = ca->be->bd_info;
5172 ca->be->bd_info = ca->bi;
5173 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5174 ca->be->bd_info = bi_orig;
5176 } else if ( ca->cleanup ) {
5177 rc = ca->cleanup( ca );
5180 if (ca->cr_msg[0] == '\0')
5181 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5183 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5184 ca->log, ca->cr_msg, ca->argv[1] );
5191 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5192 ce->ce_parent = last;
5193 ce->ce_entry = entry_dup( e );
5194 ce->ce_entry->e_private = ce;
5195 ce->ce_type = coptr->co_type;
5198 ce->ce_private = ca->ca_private;
5199 ca->ca_entry = ce->ce_entry;
5202 } else if ( last->ce_kids ) {
5203 CfEntryInfo *c2, **cprev;
5205 /* Advance to first of this type */
5206 cprev = &last->ce_kids;
5207 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5208 cprev = &c2->ce_sibs;
5211 /* Account for the (-1) frontendDB entry */
5212 if ( ce->ce_type == Cft_Database ) {
5213 if ( ca->be == frontendDB )
5215 else if ( ibase != -1 )
5220 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5221 cprev = &c2->ce_sibs;
5227 for ( i=0; i<ibase; i++ ) {
5229 cprev = &c2->ce_sibs;
5232 ce->ce_sibs = *cprev;
5240 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5241 if ( ca->be != frontendDB )
5242 backend_destroy_one( ca->be, 1 );
5243 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5244 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5245 } else if ( coptr->co_type == Cft_Schema ) {
5246 schema_destroy_one( ca, colst, nocs, last );
5251 ch_free( ca->argv );
5252 if ( colst ) ch_free( colst );
5256 #define BIGTMP 10000
5258 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5259 int base, int rebase, int max, int use_ldif )
5261 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5262 ConfigType etype = ce->ce_type;
5263 int count = 0, rc = 0;
5265 /* Reverse ce list */
5266 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5267 if (ce2->ce_type != etype) {
5272 ce2->ce_sibs = cetmp;
5275 if ( max && count >= max ) {
5281 /* Move original to a temp name until increments are done */
5283 ce->ce_entry->e_private = NULL;
5284 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5285 base+BIGTMP, 0, use_ldif );
5286 ce->ce_entry->e_private = ce;
5288 /* start incrementing */
5289 for (ce2=cetmp; ce2; ce2=ce3) {
5291 ce2->ce_sibs = cerem;
5294 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5295 count+base, 0, use_ldif );
5299 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5300 base, 0, use_ldif );
5305 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5306 CfEntryInfo *ce2, int old, int use_ldif )
5310 /* Renumber original to a temp value */
5311 ce->ce_entry->e_private = NULL;
5312 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5313 old+BIGTMP, 0, use_ldif );
5314 ce->ce_entry->e_private = ce;
5316 /* start decrementing */
5317 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5318 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5319 count+old, 0, use_ldif );
5322 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5323 count+old, 0, use_ldif );
5326 /* Parse an LDAP entry into config directives, then store in underlying
5330 config_back_add( Operation *op, SlapReply *rs )
5336 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5337 NULL, ACL_WADD, NULL )) {
5338 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5343 * Check for attribute ACL
5345 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5346 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5347 rs->sr_text = "no write access to attribute";
5351 cfb = (CfBackInfo *)op->o_bd->be_private;
5353 /* add opattrs for syncprov */
5355 char textbuf[SLAP_TEXT_BUFLEN];
5356 size_t textlen = sizeof textbuf;
5357 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5358 &rs->sr_text, textbuf, sizeof( textbuf ) );
5359 if ( rs->sr_err != LDAP_SUCCESS )
5361 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5362 if ( rs->sr_err != LDAP_SUCCESS ) {
5363 Debug( LDAP_DEBUG_TRACE,
5364 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5365 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5370 if ( op->o_abandon ) {
5371 rs->sr_err = SLAPD_ABANDON;
5374 ldap_pvt_thread_pool_pause( &connection_pool );
5377 * 1) check for existence of entry
5378 * 2) check for sibling renumbering
5379 * 3) perform internal add
5380 * 4) perform any necessary renumbering
5381 * 5) store entry in underlying database
5383 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5384 if ( rs->sr_err != LDAP_SUCCESS ) {
5385 rs->sr_text = ca.cr_msg;
5390 CfEntryInfo *ce = ca.ca_entry->e_private;
5391 req_add_s addr = op->oq_add;
5392 op->o_tag = LDAP_REQ_MODRDN;
5393 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5394 op->o_tag = LDAP_REQ_ADD;
5396 if ( rs->sr_err != LDAP_SUCCESS ) {
5401 if ( cfb->cb_use_ldif ) {
5402 BackendDB *be = op->o_bd;
5403 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5404 struct berval dn, ndn;
5406 op->o_bd = &cfb->cb_db;
5408 /* Save current rootdn; use the underlying DB's rootdn */
5411 op->o_dn = op->o_bd->be_rootdn;
5412 op->o_ndn = op->o_bd->be_rootndn;
5414 scp = op->o_callback;
5415 op->o_callback = ≻
5416 op->o_bd->be_add( op, rs );
5418 op->o_callback = scp;
5424 ldap_pvt_thread_pool_resume( &connection_pool );
5427 { int repl = op->o_dont_replicate;
5428 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5429 rs->sr_text = NULL; /* Set after config_add_internal */
5430 rs->sr_err = LDAP_SUCCESS;
5431 op->o_dont_replicate = 1;
5433 send_ldap_result( op, rs );
5434 op->o_dont_replicate = repl;
5436 slap_graduate_commit_csn( op );
5440 typedef struct delrec {
5441 struct delrec *next;
5447 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5453 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5454 ca->line[0] == '{' )
5456 char *ptr = strchr( ca->line + 1, '}' );
5460 ca->valx = strtol( ca->line + 1, &next, 0 );
5461 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5467 rc = config_parse_add( ct, ca, i );
5475 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5478 int rc = LDAP_UNWILLING_TO_PERFORM;
5480 Entry *e = ce->ce_entry;
5481 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5486 delrec *dels = NULL, *deltail = NULL;
5488 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5489 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5491 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5492 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5496 colst = count_ocs( oc_at, &nocs );
5498 /* make sure add/del flags are clear; should always be true */
5499 for ( s = save_attrs; s; s = s->a_next ) {
5500 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5503 e->e_attrs = attrs_dup( e->e_attrs );
5505 init_config_argv( ca );
5508 ca->ca_private = ce->ce_private;
5510 ca->fname = "slapd";
5512 strcpy( ca->log, "back-config" );
5514 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5515 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5516 switch (ml->sml_op) {
5517 case LDAP_MOD_DELETE:
5518 case LDAP_MOD_REPLACE:
5519 case SLAP_MOD_SOFTDEL:
5521 BerVarray vals = NULL, nvals = NULL;
5523 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5525 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5526 ml->sml_desc->ad_cname.bv_val );
5529 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5530 vals = ml->sml_values;
5531 nvals = ml->sml_nvalues;
5532 ml->sml_values = NULL;
5533 ml->sml_nvalues = NULL;
5535 /* If we're deleting by values, remember the indexes of the
5536 * values we deleted.
5538 if ( ct && ml->sml_values ) {
5540 i = ml->sml_numvals;
5541 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5552 rc = modify_delete_vindex(e, &ml->sml_mod,
5553 get_permissiveModify(op),
5554 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5555 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5556 ml->sml_values = vals;
5557 ml->sml_nvalues = nvals;
5559 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5563 /* FIXME: check rc before fallthru? */
5567 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5569 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5570 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5571 && attr_find( e->e_attrs, ml->sml_desc ) )
5578 case SLAP_MOD_SOFTADD: {
5579 int mop = ml->sml_op;
5581 ml->sml_op = LDAP_MOD_ADD;
5583 if ( ct->arg_type & ARG_NO_INSERT ) {
5584 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5586 navals = a->a_numvals;
5589 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5590 if ( ml->sml_values[i].bv_val[0] == '{' &&
5593 char *next, *val = ml->sml_values[i].bv_val + 1;
5596 j = strtol( val, &next, 0 );
5597 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5599 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5600 ml->sml_desc->ad_cname.bv_val );
5604 rc = check_vals( ct, ca, ml, 0 );
5605 if ( rc ) goto out_noop;
5608 rc = modify_add_values(e, &ml->sml_mod,
5609 get_permissiveModify(op),
5610 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5612 /* If value already exists, show success here
5613 * and ignore this operation down below.
5615 if ( mop == SLAP_MOD_SOFTADD ) {
5616 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5626 case LDAP_MOD_INCREMENT: /* FIXME */
5631 if(rc != LDAP_SUCCESS) break;
5634 if ( rc == LDAP_SUCCESS) {
5635 /* check that the entry still obeys the schema */
5636 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5637 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5639 if ( rc ) goto out_noop;
5641 /* Basic syntax checks are OK. Do the actual settings. */
5642 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5643 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5644 if ( !ct ) continue;
5646 s = attr_find( save_attrs, ml->sml_desc );
5647 a = attr_find( e->e_attrs, ml->sml_desc );
5649 switch (ml->sml_op) {
5650 case LDAP_MOD_DELETE:
5651 case LDAP_MOD_REPLACE: {
5652 BerVarray vals = NULL, nvals = NULL;
5655 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5656 vals = ml->sml_values;
5657 nvals = ml->sml_nvalues;
5658 ml->sml_values = NULL;
5659 ml->sml_nvalues = NULL;
5662 if ( ml->sml_values )
5665 /* If we didn't delete the whole attribute */
5666 if ( ml->sml_values && a ) {
5667 struct berval *mvals;
5670 if ( ml->sml_nvalues )
5671 mvals = ml->sml_nvalues;
5673 mvals = ml->sml_values;
5675 /* use the indexes we saved up above */
5676 for (i=0; i < d->nidx; i++) {
5677 struct berval bv = *mvals++;
5678 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5679 bv.bv_val[0] == '{' ) {
5680 ptr = strchr( bv.bv_val, '}' ) + 1;
5681 bv.bv_len -= ptr - bv.bv_val;
5684 ca->line = bv.bv_val;
5685 ca->valx = d->idx[i];
5686 config_parse_vals(ct, ca, d->idx[i] );
5687 rc = config_del_vals( ct, ca );
5688 if ( rc != LDAP_SUCCESS ) break;
5690 s->a_flags |= SLAP_ATTR_IXDEL;
5691 for (j=i+1; j < d->nidx; j++)
5692 if ( d->idx[j] >d->idx[i] )
5699 rc = config_del_vals( ct, ca );
5700 if ( rc ) rc = LDAP_OTHER;
5702 s->a_flags |= SLAP_ATTR_IXDEL;
5704 if ( ml->sml_values ) {
5709 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5710 ml->sml_values = vals;
5711 ml->sml_nvalues = nvals;
5713 if ( !vals || rc != LDAP_SUCCESS )
5716 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5721 for (i=0; ml->sml_values[i].bv_val; i++) {
5722 ca->line = ml->sml_values[i].bv_val;
5724 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5727 a->a_flags |= SLAP_ATTR_IXADD;
5734 /* Undo for a failed operation */
5735 if ( rc != LDAP_SUCCESS ) {
5736 ConfigReply msg = ca->reply;
5737 for ( s = save_attrs; s; s = s->a_next ) {
5738 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5739 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5740 ct = config_find_table( colst, nocs, s->a_desc, ca );
5741 a = attr_find( e->e_attrs, s->a_desc );
5743 /* clear the flag so the add check below will skip it */
5744 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5748 config_del_vals( ct, ca );
5750 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5751 ca->line = s->a_vals[i].bv_val;
5753 config_modify_add( ct, ca, s->a_desc, i );
5757 for ( a = e->e_attrs; a; a = a->a_next ) {
5758 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5759 ct = config_find_table( colst, nocs, a->a_desc, ca );
5763 config_del_vals( ct, ca );
5764 s = attr_find( save_attrs, a->a_desc );
5766 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5767 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5768 ca->line = s->a_vals[i].bv_val;
5770 config_modify_add( ct, ca, s->a_desc, i );
5781 if ( rc == LDAP_SUCCESS ) {
5782 attrs_free( save_attrs );
5785 attrs_free( e->e_attrs );
5786 e->e_attrs = save_attrs;
5788 ch_free( ca->argv );
5789 if ( colst ) ch_free( colst );
5791 deltail = dels->next;
5800 config_back_modify( Operation *op, SlapReply *rs )
5803 CfEntryInfo *ce, *last;
5805 ConfigArgs ca = {0};
5808 AttributeDescription *rad = NULL;
5811 cfb = (CfBackInfo *)op->o_bd->be_private;
5813 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5816 rs->sr_matched = last->ce_entry->e_name.bv_val;
5817 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5821 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5822 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5826 /* Get type of RDN */
5827 rdn = ce->ce_entry->e_nname;
5828 ptr = strchr( rdn.bv_val, '=' );
5829 rdn.bv_len = ptr - rdn.bv_val;
5830 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5831 if ( rs->sr_err != LDAP_SUCCESS ) {
5835 /* Some basic validation... */
5836 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5837 /* Don't allow Modify of RDN; must use ModRdn for that. */
5838 if ( ml->sml_desc == rad ) {
5839 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5840 rs->sr_text = "Use modrdn to change the entry name";
5843 /* Internal update of contextCSN? */
5844 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5850 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5853 if ( op->o_abandon ) {
5854 rs->sr_err = SLAPD_ABANDON;
5857 ldap_pvt_thread_pool_pause( &connection_pool );
5861 * 1) perform the Modify on the cached Entry.
5862 * 2) verify that the Entry still satisfies the schema.
5863 * 3) perform the individual config operations.
5864 * 4) store Modified entry in underlying LDIF backend.
5866 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5868 rs->sr_text = ca.cr_msg;
5869 } else if ( cfb->cb_use_ldif ) {
5870 BackendDB *be = op->o_bd;
5871 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5872 struct berval dn, ndn;
5874 op->o_bd = &cfb->cb_db;
5878 op->o_dn = op->o_bd->be_rootdn;
5879 op->o_ndn = op->o_bd->be_rootndn;
5881 scp = op->o_callback;
5882 op->o_callback = ≻
5883 op->o_bd->be_modify( op, rs );
5885 op->o_callback = scp;
5891 ldap_pvt_thread_pool_resume( &connection_pool );
5893 send_ldap_result( op, rs );
5894 slap_graduate_commit_csn( op );
5899 config_back_modrdn( Operation *op, SlapReply *rs )
5902 CfEntryInfo *ce, *last;
5906 cfb = (CfBackInfo *)op->o_bd->be_private;
5908 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5911 rs->sr_matched = last->ce_entry->e_name.bv_val;
5912 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5915 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5916 NULL, ACL_WRITE, NULL )) {
5917 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5921 if ( ce->ce_parent )
5922 parent = ce->ce_parent->ce_entry;
5924 parent = (Entry *)&slap_entry_root;
5925 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5926 NULL, ACL_WRITE, NULL )) {
5927 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5932 /* We don't allow moving objects to new parents.
5933 * Generally we only allow reordering a set of ordered entries.
5935 if ( op->orr_newSup ) {
5936 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5940 /* If newRDN == oldRDN, quietly succeed */
5941 dnRdn( &op->o_req_ndn, &rdn );
5942 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5943 rs->sr_err = LDAP_SUCCESS;
5947 /* Current behavior, subject to change as needed:
5949 * For backends and overlays, we only allow renumbering.
5950 * For schema, we allow renaming with the same number.
5951 * Otherwise, the op is not allowed.
5954 if ( ce->ce_type == Cft_Schema ) {
5958 /* Can't alter the main cn=schema entry */
5959 if ( ce->ce_parent->ce_type == Cft_Global ) {
5960 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5961 rs->sr_text = "renaming not allowed for this entry";
5965 /* We could support this later if desired */
5966 ptr1 = ber_bvchr( &rdn, '}' );
5967 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5968 len = ptr1 - rdn.bv_val;
5969 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5970 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5971 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5972 rs->sr_text = "schema reordering not supported";
5975 } else if ( ce->ce_type == Cft_Database ||
5976 ce->ce_type == Cft_Overlay ) {
5977 char *ptr1, *ptr2, *iptr1, *iptr2;
5980 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5981 if ( *iptr2 != '{' ) {
5982 rs->sr_err = LDAP_NAMING_VIOLATION;
5983 rs->sr_text = "new ordering index is required";
5987 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5988 ptr1 = ber_bvchr( &rdn, '}' );
5989 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5991 rs->sr_err = LDAP_NAMING_VIOLATION;
5992 rs->sr_text = "new ordering index is required";
5996 len1 = ptr1 - rdn.bv_val;
5997 len2 = ptr2 - op->orr_newrdn.bv_val;
5999 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6000 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6001 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6002 rs->sr_text = "changing database/overlay type not allowed";
6005 ixold = strtol( iptr1, NULL, 0 );
6006 ixnew = strtol( iptr2, &ptr1, 0 );
6007 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6008 rs->sr_err = LDAP_NAMING_VIOLATION;
6011 /* config DB is always 0, cannot be changed */
6012 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6013 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6017 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6018 rs->sr_text = "renaming not supported for this entry";
6022 if ( op->o_abandon ) {
6023 rs->sr_err = SLAPD_ABANDON;
6026 ldap_pvt_thread_pool_pause( &connection_pool );
6028 if ( ce->ce_type == Cft_Schema ) {
6029 req_modrdn_s modr = op->oq_modrdn;
6032 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6033 if ( rs->sr_err == LDAP_SUCCESS ) {
6034 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6035 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6038 op->oq_modrdn = modr;
6040 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6041 req_modrdn_s modr = op->oq_modrdn;
6044 /* Advance to first of this type */
6045 cprev = &ce->ce_parent->ce_kids;
6046 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6047 cprev = &ce2->ce_sibs;
6050 /* Skip the -1 entry */
6051 if ( ce->ce_type == Cft_Database ) {
6052 cprev = &ce2->ce_sibs;
6058 /* Remove from old slot */
6059 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6060 cprev = &ce2->ce_sibs;
6061 *cprev = ce->ce_sibs;
6062 ceold = ce->ce_sibs;
6064 /* Insert into new slot */
6066 for ( i=0; i<ixnew; i++ ) {
6070 cprev = &ce2->ce_sibs;
6072 ce->ce_sibs = *cprev;
6077 /* NOTE: These should be encoded in the OC tables, not inline here */
6078 if ( ce->ce_type == Cft_Database )
6079 backend_db_move( ce->ce_be, ixnew );
6080 else if ( ce->ce_type == Cft_Overlay )
6081 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6083 if ( ixold < ixnew ) {
6084 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6087 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6088 ixold - ixnew, cfb->cb_use_ldif );
6090 op->oq_modrdn = modr;
6093 ldap_pvt_thread_pool_resume( &connection_pool );
6095 send_ldap_result( op, rs );
6100 config_back_delete( Operation *op, SlapReply *rs )
6102 #ifdef SLAP_CONFIG_DELETE
6104 CfEntryInfo *ce, *last, *ce2;
6106 cfb = (CfBackInfo *)op->o_bd->be_private;
6108 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6111 rs->sr_matched = last->ce_entry->e_name.bv_val;
6112 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6113 } else if ( ce->ce_kids ) {
6114 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6115 } else if ( op->o_abandon ) {
6116 rs->sr_err = SLAPD_ABANDON;
6117 } else if ( ce->ce_type == Cft_Overlay ||
6118 ce->ce_type == Cft_Database ||
6119 ce->ce_type == Cft_Misc ){
6123 ldap_pvt_thread_pool_pause( &connection_pool );
6125 if ( ce->ce_type == Cft_Overlay ){
6126 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6127 } else if ( ce->ce_type == Cft_Misc ) {
6129 * only Cft_Misc objects that have a co_lddel handler set in
6130 * the ConfigOCs struct can be deleted. This code also
6131 * assumes that the entry can be only have one objectclass
6132 * with co_type == Cft_Misc
6134 ConfigOCs co, *coptr;
6138 oc_at = attr_find( ce->ce_entry->e_attrs,
6139 slap_schema.si_ad_objectClass );
6141 rs->sr_err = LDAP_OTHER;
6142 rs->sr_text = "objectclass not found";
6143 ldap_pvt_thread_pool_resume( &connection_pool );
6146 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6147 co.co_name = &oc_at->a_nvals[i];
6148 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6149 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6152 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6153 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6154 if ( ! coptr->co_lddel ) {
6155 rs->sr_text = "No delete handler found";
6157 rs->sr_err = LDAP_OTHER;
6158 /* FIXME: We should return a helpful error message
6161 ldap_pvt_thread_pool_resume( &connection_pool );
6166 } else if (ce->ce_type == Cft_Database ) {
6167 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6168 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6169 rs->sr_text = "Cannot delete config or frontend database";
6170 ldap_pvt_thread_pool_resume( &connection_pool );
6173 if ( ce->ce_be->bd_info->bi_db_close ) {
6174 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6176 backend_destroy_one( ce->ce_be, 1);
6179 /* remove CfEntryInfo from the siblings list */
6180 if ( ce->ce_parent->ce_kids == ce ) {
6181 ce->ce_parent->ce_kids = ce->ce_sibs;
6183 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6184 if ( ce2->ce_sibs == ce ) {
6185 ce2->ce_sibs = ce->ce_sibs;
6191 /* remove from underlying database */
6192 if ( cfb->cb_use_ldif ) {
6193 BackendDB *be = op->o_bd;
6194 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6195 struct berval dn, ndn, req_dn, req_ndn;
6197 op->o_bd = &cfb->cb_db;
6201 req_dn = op->o_req_dn;
6202 req_ndn = op->o_req_ndn;
6204 op->o_dn = op->o_bd->be_rootdn;
6205 op->o_ndn = op->o_bd->be_rootndn;
6206 op->o_req_dn = ce->ce_entry->e_name;
6207 op->o_req_ndn = ce->ce_entry->e_nname;
6209 scp = op->o_callback;
6210 op->o_callback = ≻
6211 op->o_bd->be_delete( op, rs );
6213 op->o_callback = scp;
6216 op->o_req_dn = req_dn;
6217 op->o_req_ndn = req_ndn;
6220 /* renumber siblings */
6221 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6222 ixold = strtol( iptr, NULL, 0 );
6223 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6224 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6225 count+ixold, 0, cfb->cb_use_ldif );
6229 ce->ce_entry->e_private=NULL;
6230 entry_free(ce->ce_entry);
6232 ldap_pvt_thread_pool_resume( &connection_pool );
6234 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6238 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6239 #endif /* SLAP_CONFIG_DELETE */
6240 send_ldap_result( op, rs );
6245 config_back_search( Operation *op, SlapReply *rs )
6248 CfEntryInfo *ce, *last;
6251 cfb = (CfBackInfo *)op->o_bd->be_private;
6253 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6256 rs->sr_matched = last->ce_entry->e_name.bv_val;
6257 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6260 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6261 ACL_SEARCH, NULL, &mask ))
6263 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6264 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6266 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6270 switch ( op->ors_scope ) {
6271 case LDAP_SCOPE_BASE:
6272 case LDAP_SCOPE_SUBTREE:
6273 rs->sr_err = config_send( op, rs, ce, 0 );
6276 case LDAP_SCOPE_ONELEVEL:
6277 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6278 rs->sr_err = config_send( op, rs, ce, 1 );
6287 send_ldap_result( op, rs );
6291 /* no-op, we never free entries */
6292 int config_entry_release(
6297 if ( !e->e_private ) {
6300 return LDAP_SUCCESS;
6303 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6305 int config_back_entry_get(
6309 AttributeDescription *at,
6314 CfEntryInfo *ce, *last;
6315 int rc = LDAP_NO_SUCH_OBJECT;
6317 cfb = (CfBackInfo *)op->o_bd->be_private;
6319 ce = config_find_base( cfb->cb_root, ndn, &last );
6321 *ent = ce->ce_entry;
6324 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6325 rc = LDAP_NO_SUCH_ATTRIBUTE;
6335 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6336 ConfigTable *ct, ConfigArgs *c )
6340 for (; at && *at; at++) {
6341 /* Skip the naming attr */
6342 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6344 for (i=0;ct[i].name;i++) {
6345 if (ct[i].ad == (*at)->sat_ad) {
6346 rc = config_get_vals(&ct[i], c);
6347 /* NOTE: tolerate that config_get_vals()
6348 * returns success with no values */
6349 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6350 if ( c->rvalue_nvals )
6351 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6354 slap_syntax_validate_func *validate =
6355 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6358 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6359 rc = ordered_value_validate( ct[i].ad,
6360 &c->rvalue_vals[j], LDAP_MOD_ADD );
6362 Debug( LDAP_DEBUG_ANY,
6363 "config_build_attrs: error %d on %s value #%d\n",
6364 rc, ct[i].ad->ad_cname.bv_val, j );
6370 rc = attr_merge_normalize(e, ct[i].ad,
6371 c->rvalue_vals, NULL);
6373 ber_bvarray_free( c->rvalue_nvals );
6374 ber_bvarray_free( c->rvalue_vals );
6376 Debug( LDAP_DEBUG_ANY,
6377 "config_build_attrs: error %d on %s\n",
6378 rc, ct[i].ad->ad_cname.bv_val, 0 );
6389 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6392 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6393 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6395 Entry *e = entry_alloc();
6396 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6398 struct berval ad_name;
6399 AttributeDescription *ad = NULL;
6402 const char *text = "";
6406 CfEntryInfo *ceprev = NULL;
6408 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6411 ce->ce_type = main->co_type;
6412 ce->ce_parent = parent;
6414 pdn = parent->ce_entry->e_nname;
6415 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6416 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6417 ceprev->ce_type <= ce->ce_type;
6418 ceprev = ceprev->ce_sibs );
6423 ce->ce_private = c->ca_private;
6427 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6428 ber_dupbv( &e->e_nname, &e->e_name );
6430 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6431 main->co_name, NULL );
6433 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6434 extra->co_name, NULL );
6435 ptr = strchr(rdn->bv_val, '=');
6436 ad_name.bv_val = rdn->bv_val;
6437 ad_name.bv_len = ptr - rdn->bv_val;
6438 rc = slap_bv2ad( &ad_name, &ad, &text );
6443 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6444 attr_merge_normalize_one(e, ad, &val, NULL );
6447 c->table = main->co_type;
6448 if ( oc->soc_required ) {
6449 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6450 if ( rc ) goto fail;
6453 if ( oc->soc_allowed ) {
6454 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6455 if ( rc ) goto fail;
6460 c->table = extra->co_type;
6461 if ( oc->soc_required ) {
6462 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6463 if ( rc ) goto fail;
6466 if ( oc->soc_allowed ) {
6467 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6468 if ( rc ) goto fail;
6472 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6473 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6474 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6475 if ( rc != LDAP_SUCCESS ) {
6477 Debug( LDAP_DEBUG_ANY,
6478 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6479 rdn->bv_val, text, 0);
6482 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6485 op->ora_modlist = NULL;
6486 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6487 if ( !op->o_noop ) {
6488 SlapReply rs2 = {REP_RESULT};
6489 op->o_bd->be_add( op, &rs2 );
6490 rs->sr_err = rs2.sr_err;
6491 rs_assert_done( &rs2 );
6492 if ( ( rs2.sr_err != LDAP_SUCCESS )
6493 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6499 ce->ce_sibs = ceprev->ce_sibs;
6500 ceprev->ce_sibs = ce;
6501 } else if ( parent ) {
6502 ce->ce_sibs = parent->ce_kids;
6503 parent->ce_kids = ce;
6510 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6511 Operation *op, SlapReply *rs )
6514 ConfigFile *cf = c->ca_private;
6516 struct berval bv, rdn;
6518 for (; cf; cf=cf->c_sibs, c->depth++) {
6519 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6520 !cf->c_om_head && !cf->c_syn_head ) continue;
6521 c->value_dn.bv_val = c->log;
6522 LUTIL_SLASHPATH( cf->c_file.bv_val );
6523 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6528 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6530 ptr = strchr( bv.bv_val, '.' );
6532 bv.bv_len = ptr - bv.bv_val;
6533 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6534 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6535 /* FIXME: how can indicate error? */
6538 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6540 c->value_dn.bv_len += bv.bv_len;
6541 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6542 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6545 e = config_build_entry( op, rs, ceparent, c, &rdn,
6546 &CFOC_SCHEMA, NULL );
6547 ch_free( rdn.bv_val );
6550 } else if ( e && cf->c_kids ) {
6551 c->ca_private = cf->c_kids;
6552 config_build_schema_inc( c, e->e_private, op, rs );
6558 #ifdef SLAPD_MODULES
6561 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6562 Operation *op, SlapReply *rs )
6567 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6568 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6570 c->value_dn.bv_val = c->log;
6571 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6572 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6573 /* FIXME: how can indicate error? */
6577 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6586 config_check_schema(Operation *op, CfBackInfo *cfb)
6588 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6590 CfEntryInfo *ce, *last;
6593 /* If there's no root entry, we must be in the midst of converting */
6594 if ( !cfb->cb_root )
6597 /* Make sure the main schema entry exists */
6598 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6605 /* Make sure it's up to date */
6606 if ( cf_om_tail != om_sys_tail ) {
6607 a = attr_find( e->e_attrs, cfAd_om );
6609 if ( a->a_nvals != a->a_vals )
6610 ber_bvarray_free( a->a_nvals );
6611 ber_bvarray_free( a->a_vals );
6616 oidm_unparse( &bv, NULL, NULL, 1 );
6617 attr_merge_normalize( e, cfAd_om, bv, NULL );
6618 ber_bvarray_free( bv );
6619 cf_om_tail = om_sys_tail;
6621 if ( cf_at_tail != at_sys_tail ) {
6622 a = attr_find( e->e_attrs, cfAd_attr );
6624 if ( a->a_nvals != a->a_vals )
6625 ber_bvarray_free( a->a_nvals );
6626 ber_bvarray_free( a->a_vals );
6631 at_unparse( &bv, NULL, NULL, 1 );
6632 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6633 ber_bvarray_free( bv );
6634 cf_at_tail = at_sys_tail;
6636 if ( cf_oc_tail != oc_sys_tail ) {
6637 a = attr_find( e->e_attrs, cfAd_oc );
6639 if ( a->a_nvals != a->a_vals )
6640 ber_bvarray_free( a->a_nvals );
6641 ber_bvarray_free( a->a_vals );
6646 oc_unparse( &bv, NULL, NULL, 1 );
6647 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6648 ber_bvarray_free( bv );
6649 cf_oc_tail = oc_sys_tail;
6651 if ( cf_syn_tail != syn_sys_tail ) {
6652 a = attr_find( e->e_attrs, cfAd_syntax );
6654 if ( a->a_nvals != a->a_vals )
6655 ber_bvarray_free( a->a_nvals );
6656 ber_bvarray_free( a->a_vals );
6661 syn_unparse( &bv, NULL, NULL, 1 );
6662 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6663 ber_bvarray_free( bv );
6664 cf_syn_tail = syn_sys_tail;
6667 SlapReply rs = {REP_RESULT};
6668 c.ca_private = NULL;
6669 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6670 &CFOC_SCHEMA, NULL );
6675 ce->ce_private = cfb->cb_config;
6676 cf_at_tail = at_sys_tail;
6677 cf_oc_tail = oc_sys_tail;
6678 cf_om_tail = om_sys_tail;
6679 cf_syn_tail = syn_sys_tail;
6684 static const char *defacl[] = {
6685 NULL, "to", "*", "by", "*", "none", NULL
6689 config_back_db_open( BackendDB *be, ConfigReply *cr )
6691 CfBackInfo *cfb = be->be_private;
6694 CfEntryInfo *ce, *ceparent;
6698 Connection conn = {0};
6699 OperationBuffer opbuf;
6701 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6702 SlapReply rs = {REP_RESULT};
6703 void *thrctx = NULL;
6704 AccessControl *save_access;
6706 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6708 /* If we have no explicitly configured ACLs, don't just use
6709 * the global ACLs. Explicitly deny access to everything.
6711 save_access = be->bd_self->be_acl;
6712 be->bd_self->be_acl = NULL;
6713 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6714 defacl_parsed = be->bd_self->be_acl;
6715 if ( save_access ) {
6716 be->bd_self->be_acl = save_access;
6718 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6719 "No explicit ACL for back-config configured. "
6720 "Using hardcoded default\n", 0, 0, 0 );
6723 thrctx = ldap_pvt_thread_pool_context();
6724 connection_fake_init( &conn, &opbuf, thrctx );
6727 op->o_tag = LDAP_REQ_ADD;
6728 op->o_callback = &cb;
6729 op->o_bd = &cfb->cb_db;
6730 op->o_dn = op->o_bd->be_rootdn;
6731 op->o_ndn = op->o_bd->be_rootndn;
6733 if ( !cfb->cb_use_ldif ) {
6737 /* If we read the config from back-ldif, do some quick sanity checks */
6738 if ( cfb->cb_got_ldif ) {
6739 return config_check_schema( op, cfb );
6742 /* create root of tree */
6744 c.ca_private = cfb->cb_config;
6746 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6756 #ifdef SLAPD_MODULES
6757 /* Create Module nodes... */
6758 if ( modpaths.mp_loads ) {
6759 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6765 /* Create schema nodes... cn=schema will contain the hardcoded core
6766 * schema, read-only. Child objects will contain runtime loaded schema
6770 c.ca_private = NULL;
6771 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6776 ce->ce_private = cfb->cb_config;
6777 cf_at_tail = at_sys_tail;
6778 cf_oc_tail = oc_sys_tail;
6779 cf_om_tail = om_sys_tail;
6780 cf_syn_tail = syn_sys_tail;
6782 /* Create schema nodes for included schema... */
6783 if ( cfb->cb_config->c_kids ) {
6786 c.ca_private = cfb->cb_config->c_kids;
6787 rc = config_build_schema_inc( &c, ce, op, &rs );
6793 /* Create backend nodes. Skip if they don't provide a cf_table.
6794 * There usually aren't any of these.
6798 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6799 if (!bi->bi_cf_ocs) {
6800 /* If it only supports the old config mech, complain. */
6801 if ( bi->bi_config ) {
6802 Debug( LDAP_DEBUG_ANY,
6803 "WARNING: No dynamic config support for backend %s.\n",
6804 bi->bi_type, 0, 0 );
6809 if (!bi->bi_private) continue;
6812 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6813 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6814 if ( rdn.bv_len >= sizeof( c.log ) ) {
6815 /* FIXME: holler ... */ ;
6818 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6825 /* Create database nodes... */
6826 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6827 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6828 for ( i = -1, be = frontendDB ; be;
6829 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6830 slap_overinfo *oi = NULL;
6832 if ( overlay_is_over( be )) {
6833 oi = be->bd_info->bi_private;
6839 /* If this backend supports the old config mechanism, but not
6840 * the new mech, complain.
6842 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6843 Debug( LDAP_DEBUG_ANY,
6844 "WARNING: No dynamic config support for database %s.\n",
6845 bi->bi_type, 0, 0 );
6849 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6850 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6852 if ( rdn.bv_len >= sizeof( c.log ) ) {
6853 /* FIXME: holler ... */ ;
6857 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6863 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6864 rs_reinit( &rs, REP_RESULT );
6865 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6867 /* Iterate through overlays */
6872 voidList *vl, *v0 = NULL;
6874 /* overlays are in LIFO order, must reverse stack */
6875 for (on=oi->oi_list; on; on=on->on_next) {
6876 vl = ch_malloc( sizeof( voidList ));
6881 for (j=0; vl; j++,vl=v0) {
6885 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6886 Debug( LDAP_DEBUG_ANY,
6887 "WARNING: No dynamic config support for overlay %s.\n",
6888 on->on_bi.bi_type, 0, 0 );
6892 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6893 "%s=" SLAP_X_ORDERED_FMT "%s",
6894 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6895 if ( rdn.bv_len >= sizeof( c.log ) ) {
6896 /* FIXME: holler ... */ ;
6900 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6901 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6905 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6906 rs_reinit( &rs, REP_RESULT );
6907 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6913 ldap_pvt_thread_pool_context_reset( thrctx );
6915 if ( unsupp && cfb->cb_use_ldif ) {
6916 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6917 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6924 cfb_free_cffile( ConfigFile *cf )
6928 for (; cf; cf=next) {
6931 cfb_free_cffile( cf->c_kids );
6932 ch_free( cf->c_file.bv_val );
6933 ber_bvarray_free( cf->c_dseFiles );
6939 cfb_free_entries( CfEntryInfo *ce )
6943 for (; ce; ce=next) {
6946 cfb_free_entries( ce->ce_kids );
6947 ce->ce_entry->e_private = NULL;
6948 entry_free( ce->ce_entry );
6954 config_back_db_close( BackendDB *be, ConfigReply *cr )
6956 CfBackInfo *cfb = be->be_private;
6958 cfb_free_entries( cfb->cb_root );
6959 cfb->cb_root = NULL;
6961 if ( cfb->cb_db.bd_info ) {
6962 backend_shutdown( &cfb->cb_db );
6965 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
6966 acl_free( defacl_parsed );
6967 defacl_parsed = NULL;
6974 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6976 CfBackInfo *cfb = be->be_private;
6978 cfb_free_cffile( cfb->cb_config );
6980 ch_free( cfdir.bv_val );
6982 avl_free( CfOcTree, NULL );
6984 if ( cfb->cb_db.bd_info ) {
6985 cfb->cb_db.be_suffix = NULL;
6986 cfb->cb_db.be_nsuffix = NULL;
6987 BER_BVZERO( &cfb->cb_db.be_rootdn );
6988 BER_BVZERO( &cfb->cb_db.be_rootndn );
6990 backend_destroy_one( &cfb->cb_db, 0 );
6999 config_back_db_init( BackendDB *be, ConfigReply* cr )
7005 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7006 cfn = cfb->cb_config;
7007 be->be_private = cfb;
7009 ber_dupbv( &be->be_rootdn, &config_rdn );
7010 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7011 ber_dupbv( &dn, &be->be_rootdn );
7012 ber_bvarray_add( &be->be_suffix, &dn );
7013 ber_dupbv( &dn, &be->be_rootdn );
7014 ber_bvarray_add( &be->be_nsuffix, &dn );
7016 /* Hide from namingContexts */
7017 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7019 /* Check ACLs on content of Adds by default */
7020 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7026 config_back_destroy( BackendInfo *bi )
7028 ldif_must_b64_encode_release();
7033 config_tool_entry_open( BackendDB *be, int mode )
7035 CfBackInfo *cfb = be->be_private;
7036 BackendInfo *bi = cfb->cb_db.bd_info;
7038 if ( bi && bi->bi_tool_entry_open )
7039 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7046 config_tool_entry_close( BackendDB *be )
7048 CfBackInfo *cfb = be->be_private;
7049 BackendInfo *bi = cfb->cb_db.bd_info;
7051 if ( bi && bi->bi_tool_entry_close )
7052 return bi->bi_tool_entry_close( &cfb->cb_db );
7058 config_tool_entry_first( BackendDB *be )
7060 CfBackInfo *cfb = be->be_private;
7061 BackendInfo *bi = cfb->cb_db.bd_info;
7063 if ( bi && bi->bi_tool_entry_first ) {
7064 return bi->bi_tool_entry_first( &cfb->cb_db );
7066 if ( bi && bi->bi_tool_entry_first_x ) {
7067 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7068 NULL, LDAP_SCOPE_DEFAULT, NULL );
7074 config_tool_entry_first_x(
7076 struct berval *base,
7080 CfBackInfo *cfb = be->be_private;
7081 BackendInfo *bi = cfb->cb_db.bd_info;
7083 if ( bi && bi->bi_tool_entry_first_x ) {
7084 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7090 config_tool_entry_next( BackendDB *be )
7092 CfBackInfo *cfb = be->be_private;
7093 BackendInfo *bi = cfb->cb_db.bd_info;
7095 if ( bi && bi->bi_tool_entry_next )
7096 return bi->bi_tool_entry_next( &cfb->cb_db );
7102 config_tool_entry_get( BackendDB *be, ID id )
7104 CfBackInfo *cfb = be->be_private;
7105 BackendInfo *bi = cfb->cb_db.bd_info;
7107 if ( bi && bi->bi_tool_entry_get )
7108 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7113 static int entry_put_got_frontend=0;
7114 static int entry_put_got_config=0;
7116 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7118 CfBackInfo *cfb = be->be_private;
7119 BackendInfo *bi = cfb->cb_db.bd_info;
7121 struct berval rdn, vals[ 2 ];
7123 OperationBuffer opbuf;
7125 Connection conn = {0};
7126 Operation *op = NULL;
7129 int isFrontendChild = 0;
7131 /* Create entry for frontend database if it does not exist already */
7132 if ( !entry_put_got_frontend ) {
7133 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7134 STRLENOF( "olcDatabase" ))) {
7135 if ( strncmp( e->e_nname.bv_val +
7136 STRLENOF( "olcDatabase" ), "={-1}frontend",
7137 STRLENOF( "={-1}frontend" )) &&
7138 strncmp( e->e_nname.bv_val +
7139 STRLENOF( "olcDatabase" ), "=frontend",
7140 STRLENOF( "=frontend" ))) {
7142 vals[1].bv_val = NULL;
7143 memset( &ca, 0, sizeof(ConfigArgs));
7145 ca.bi = frontendDB->bd_info;
7146 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7147 rdn.bv_val = ca.log;
7148 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7149 "%s=" SLAP_X_ORDERED_FMT "%s",
7150 cfAd_database->ad_cname.bv_val, -1,
7152 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7153 &CFOC_DATABASE, ca.be->be_cf_ocs );
7154 thrctx = ldap_pvt_thread_pool_context();
7155 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7157 op->o_bd = &cfb->cb_db;
7158 op->o_tag = LDAP_REQ_ADD;
7160 op->o_dn = be->be_rootdn;
7161 op->o_ndn = be->be_rootndn;
7162 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7163 if ( rc != LDAP_SUCCESS ) {
7164 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7165 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7169 if ( ce && bi && bi->bi_tool_entry_put &&
7170 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7171 entry_put_got_frontend++;
7173 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7174 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7178 if ( !strncmp( e->e_nname.bv_val +
7179 STRLENOF( "olcDatabase" ), "=frontend",
7180 STRLENOF( "=frontend" ) ) )
7182 struct berval rdn, pdn, ndn;
7183 dnParent( &e->e_nname, &pdn );
7184 rdn.bv_val = ca.log;
7185 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7186 "%s=" SLAP_X_ORDERED_FMT "%s",
7187 cfAd_database->ad_cname.bv_val, -1,
7188 frontendDB->bd_info->bi_type );
7189 build_new_dn( &ndn, &pdn, &rdn, NULL );
7190 ber_memfree( e->e_name.bv_val );
7192 ber_bvreplace( &e->e_nname, &e->e_name );
7194 entry_put_got_frontend++;
7200 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7201 * instances, may appear before the config database entry in the ldif, skip
7202 * auto-creation of olcDatabase={0}config in such a case */
7203 if ( !entry_put_got_config &&
7204 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7206 dnParent( &e->e_nname, &pdn );
7207 while ( pdn.bv_len ) {
7208 if ( !strncmp( pdn.bv_val, "olcDatabase",
7209 STRLENOF( "olcDatabase" ))) {
7210 if ( !strncmp( pdn.bv_val +
7211 STRLENOF( "olcDatabase" ), "={-1}frontend",
7212 STRLENOF( "={-1}frontend" )) ||
7213 !strncmp( pdn.bv_val +
7214 STRLENOF( "olcDatabase" ), "=frontend",
7215 STRLENOF( "=frontend" ))) {
7217 isFrontendChild = 1;
7221 dnParent( &pdn, &pdn );
7225 /* Create entry for config database if it does not exist already */
7226 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7227 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7228 STRLENOF( "olcDatabase" ))) {
7229 if ( strncmp( e->e_nname.bv_val +
7230 STRLENOF( "olcDatabase" ), "={0}config",
7231 STRLENOF( "={0}config" )) &&
7232 strncmp( e->e_nname.bv_val +
7233 STRLENOF( "olcDatabase" ), "=config",
7234 STRLENOF( "=config" )) ) {
7236 vals[1].bv_val = NULL;
7237 memset( &ca, 0, sizeof(ConfigArgs));
7238 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7239 ca.bi = ca.be->bd_info;
7240 rdn.bv_val = ca.log;
7241 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7242 "%s=" SLAP_X_ORDERED_FMT "%s",
7243 cfAd_database->ad_cname.bv_val, 0,
7245 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7248 thrctx = ldap_pvt_thread_pool_context();
7249 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7251 op->o_bd = &cfb->cb_db;
7252 op->o_tag = LDAP_REQ_ADD;
7253 op->o_dn = be->be_rootdn;
7254 op->o_ndn = be->be_rootndn;
7257 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7258 if ( rc != LDAP_SUCCESS ) {
7259 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7260 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7263 if (ce && bi && bi->bi_tool_entry_put &&
7264 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7265 entry_put_got_config++;
7267 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7268 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7272 entry_put_got_config++;
7276 if ( bi && bi->bi_tool_entry_put &&
7277 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7278 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7285 AttributeDescription **desc;
7287 { "attribute", &cfAd_attr },
7288 { "backend", &cfAd_backend },
7289 { "database", &cfAd_database },
7290 { "include", &cfAd_include },
7291 { "ldapsyntax", &cfAd_syntax },
7292 { "objectclass", &cfAd_oc },
7293 { "objectidentifier", &cfAd_om },
7294 { "overlay", &cfAd_overlay },
7299 * add / delete: all types that may be added or deleted must use an
7300 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7301 * should automatically renumber the index of any siblings as needed,
7302 * so that no gaps in the numbering sequence exist after the add/delete
7304 * What can be added:
7306 * backend objects for backend-specific config directives
7310 * delete: probably no support this time around.
7312 * modrdn: generally not done. Will be invoked automatically by add/
7313 * delete to update numbering sequence. Perform as an explicit operation
7314 * so that the renumbering effect may be replicated. Subtree rename must
7315 * be supported, since renumbering a database will affect all its child
7318 * modify: must be fully supported.
7322 config_back_initialize( BackendInfo *bi )
7324 ConfigTable *ct = config_back_cf_table;
7328 AttributeDescription *ad = NULL;
7330 static char *controls[] = {
7331 LDAP_CONTROL_MANAGEDSAIT,
7335 /* Make sure we don't exceed the bits reserved for userland */
7336 config_check_userland( CFG_LAST );
7338 bi->bi_controls = controls;
7343 bi->bi_destroy = config_back_destroy;
7345 bi->bi_db_init = config_back_db_init;
7346 bi->bi_db_config = 0;
7347 bi->bi_db_open = config_back_db_open;
7348 bi->bi_db_close = config_back_db_close;
7349 bi->bi_db_destroy = config_back_db_destroy;
7351 bi->bi_op_bind = config_back_bind;
7352 bi->bi_op_unbind = 0;
7353 bi->bi_op_search = config_back_search;
7354 bi->bi_op_compare = 0;
7355 bi->bi_op_modify = config_back_modify;
7356 bi->bi_op_modrdn = config_back_modrdn;
7357 bi->bi_op_add = config_back_add;
7358 bi->bi_op_delete = config_back_delete;
7359 bi->bi_op_abandon = 0;
7361 bi->bi_extended = 0;
7363 bi->bi_chk_referrals = 0;
7365 bi->bi_access_allowed = slap_access_allowed;
7367 bi->bi_connection_init = 0;
7368 bi->bi_connection_destroy = 0;
7370 bi->bi_entry_release_rw = config_entry_release;
7371 bi->bi_entry_get_rw = config_back_entry_get;
7373 bi->bi_tool_entry_open = config_tool_entry_open;
7374 bi->bi_tool_entry_close = config_tool_entry_close;
7375 bi->bi_tool_entry_first = config_tool_entry_first;
7376 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7377 bi->bi_tool_entry_next = config_tool_entry_next;
7378 bi->bi_tool_entry_get = config_tool_entry_get;
7379 bi->bi_tool_entry_put = config_tool_entry_put;
7382 argv[ 0 ] = "slapd";
7388 for (i=0; OidMacros[i].name; i++ ) {
7389 argv[1] = OidMacros[i].name;
7390 argv[2] = OidMacros[i].oid;
7391 parse_oidm( &ca, 0, NULL );
7394 bi->bi_cf_ocs = cf_ocs;
7396 i = config_register_schema( ct, cf_ocs );
7399 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7402 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7403 * basically, we don't care if it fails */
7404 i = slap_str2ad( "olcRootPW", &ad, &text );
7406 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7407 "warning, unable to get \"olcRootPW\" "
7408 "attribute description: %d: %s\n",
7411 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7412 ad->ad_type->sat_oid );
7415 /* set up the notable AttributeDescriptions */
7417 for (;ct->name;ct++) {
7418 if (strcmp(ct->name, ads[i].name)) continue;
7419 *ads[i].desc = ct->ad;
7421 if (!ads[i].name) break;