1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2011 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
88 static struct berval cfdir;
91 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
92 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
94 static ConfigFile *cfn;
96 static Avlnode *CfOcTree;
98 /* System schema state */
99 extern AttributeType *at_sys_tail; /* at.c */
100 extern ObjectClass *oc_sys_tail; /* oc.c */
101 extern OidMacro *om_sys_tail; /* oidm.c */
102 extern Syntax *syn_sys_tail; /* syntax.c */
103 static AttributeType *cf_at_tail;
104 static ObjectClass *cf_oc_tail;
105 static OidMacro *cf_om_tail;
106 static Syntax *cf_syn_tail;
108 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
109 SlapReply *rs, int *renumber, Operation *op );
111 static int config_check_schema( Operation *op, CfBackInfo *cfb );
113 static ConfigDriver config_fname;
114 static ConfigDriver config_cfdir;
115 static ConfigDriver config_generic;
116 static ConfigDriver config_search_base;
117 static ConfigDriver config_passwd_hash;
118 static ConfigDriver config_schema_dn;
119 static ConfigDriver config_sizelimit;
120 static ConfigDriver config_timelimit;
121 static ConfigDriver config_overlay;
122 static ConfigDriver config_subordinate;
123 static ConfigDriver config_suffix;
124 #ifdef LDAP_TCP_BUFFER
125 static ConfigDriver config_tcp_buffer;
126 #endif /* LDAP_TCP_BUFFER */
127 static ConfigDriver config_rootdn;
128 static ConfigDriver config_rootpw;
129 static ConfigDriver config_restrict;
130 static ConfigDriver config_allows;
131 static ConfigDriver config_disallows;
132 static ConfigDriver config_requires;
133 static ConfigDriver config_security;
134 static ConfigDriver config_referral;
135 static ConfigDriver config_loglevel;
136 static ConfigDriver config_updatedn;
137 static ConfigDriver config_updateref;
138 static ConfigDriver config_include;
139 static ConfigDriver config_obsolete;
141 static ConfigDriver config_tls_option;
142 static ConfigDriver config_tls_config;
144 extern ConfigDriver syncrepl_config;
152 CFG_TLS_PROTOCOL_MIN,
203 static OidRec OidMacros[] = {
204 /* OpenLDAProot:1.12.2 */
205 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
206 { "OLcfgAt", "OLcfg:3" },
207 { "OLcfgGlAt", "OLcfgAt:0" },
208 { "OLcfgBkAt", "OLcfgAt:1" },
209 { "OLcfgDbAt", "OLcfgAt:2" },
210 { "OLcfgOvAt", "OLcfgAt:3" },
211 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
212 { "OLcfgOc", "OLcfg:4" },
213 { "OLcfgGlOc", "OLcfgOc:0" },
214 { "OLcfgBkOc", "OLcfgOc:1" },
215 { "OLcfgDbOc", "OLcfgOc:2" },
216 { "OLcfgOvOc", "OLcfgOc:3" },
217 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
219 /* Syntaxes. We should just start using the standard names and
220 * document that they are predefined and available for users
221 * to reference in their own schema. Defining schema without
222 * OID macros is for masochists...
224 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
225 { "OMsBoolean", "OMsyn:7" },
226 { "OMsDN", "OMsyn:12" },
227 { "OMsDirectoryString", "OMsyn:15" },
228 { "OMsIA5String", "OMsyn:26" },
229 { "OMsInteger", "OMsyn:27" },
230 { "OMsOID", "OMsyn:38" },
231 { "OMsOctetString", "OMsyn:40" },
236 * Backend/Database registry
238 * OLcfg{Bk|Db}{Oc|At}:0 -> common
239 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
240 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
241 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
242 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
243 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
244 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
245 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
246 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
252 * OLcfgOv{Oc|At}:1 -> syncprov
253 * OLcfgOv{Oc|At}:2 -> pcache
254 * OLcfgOv{Oc|At}:3 -> chain
255 * OLcfgOv{Oc|At}:4 -> accesslog
256 * OLcfgOv{Oc|At}:5 -> valsort
257 * OLcfgOv{Oc|At}:7 -> distproc
258 * OLcfgOv{Oc|At}:8 -> dynlist
259 * OLcfgOv{Oc|At}:9 -> dds
260 * OLcfgOv{Oc|At}:10 -> unique
261 * OLcfgOv{Oc|At}:11 -> refint
262 * OLcfgOv{Oc|At}:12 -> ppolicy
263 * OLcfgOv{Oc|At}:13 -> constraint
264 * OLcfgOv{Oc|At}:14 -> translucent
265 * OLcfgOv{Oc|At}:15 -> auditlog
266 * OLcfgOv{Oc|At}:16 -> rwm
267 * OLcfgOv{Oc|At}:17 -> dyngroup
268 * OLcfgOv{Oc|At}:18 -> memberof
269 * OLcfgOv{Oc|At}:19 -> collect
270 * OLcfgOv{Oc|At}:20 -> retcode
271 * OLcfgOv{Oc|At}:21 -> sssvlv
274 /* alphabetical ordering */
276 static ConfigTable config_back_cf_table[] = {
277 /* This attr is read-only */
278 { "", "", 0, 0, 0, ARG_MAGIC,
279 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
280 "DESC 'File for slapd configuration directives' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
283 { "", "", 0, 0, 0, ARG_MAGIC,
284 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
285 "DESC 'Directory for slapd configuration backend' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
288 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
289 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
290 "DESC 'Access Control List' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
293 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
294 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
295 "DESC 'Check ACLs against content of Add ops' "
296 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
297 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
298 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
299 "DESC 'Allowed set of deprecated features' "
300 "EQUALITY caseIgnoreMatch "
301 "SYNTAX OMsDirectoryString )", NULL, NULL },
302 { "argsfile", "file", 2, 2, 0, ARG_STRING,
303 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
304 "DESC 'File for slapd command line options' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
307 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
308 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
309 "EQUALITY caseIgnoreMatch "
310 "SYNTAX OMsDirectoryString )", NULL, NULL },
311 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
312 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
313 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
314 "DESC 'OpenLDAP attributeTypes' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
318 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
319 #ifdef SLAP_AUTH_REWRITE
320 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
324 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
325 "EQUALITY caseIgnoreMatch "
326 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
327 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
328 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
329 "EQUALITY caseIgnoreMatch "
330 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
331 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
332 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
333 "EQUALITY caseIgnoreMatch "
334 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
335 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
336 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
337 "DESC 'A type of backend' "
338 "EQUALITY caseIgnoreMatch "
339 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
341 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
342 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
343 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
344 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
345 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
346 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
347 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
348 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
349 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
350 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
351 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
352 "DESC 'The backend type for a database instance' "
353 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
354 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
355 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
356 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
357 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
358 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
359 "EQUALITY caseIgnoreMatch "
360 "SYNTAX OMsDirectoryString )", NULL, NULL },
361 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
362 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
363 "DESC 'OpenLDAP DIT content rules' "
364 "EQUALITY caseIgnoreMatch "
365 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
367 { "gentlehup", "on|off", 2, 2, 0,
369 ARG_ON_OFF, &global_gentlehup,
373 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
374 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
375 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
376 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
377 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
378 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
379 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
380 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
381 { "include", "file", 2, 2, 0, ARG_MAGIC,
382 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
383 "SUP labeledURI )", NULL, NULL },
384 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
385 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
386 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
387 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
388 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
389 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
390 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
391 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
392 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
393 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
394 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
395 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
396 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
397 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
398 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
399 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
400 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
401 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
402 { "ldapsyntax", "syntax", 2, 0, 0,
403 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
404 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
405 "DESC 'OpenLDAP ldapSyntax' "
406 "EQUALITY caseIgnoreMatch "
407 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
409 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
410 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
411 "EQUALITY caseIgnoreMatch "
412 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
413 { "listener-threads", "count", 2, 0, 0,
417 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
419 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
420 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
421 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
422 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
423 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
424 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
425 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
426 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
427 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
428 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
429 "EQUALITY caseIgnoreMatch "
430 "SYNTAX OMsDirectoryString )", NULL, NULL },
431 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
432 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
433 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
434 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
435 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
436 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
437 { "moduleload", "file", 2, 0, 0,
439 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
443 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
444 "EQUALITY caseIgnoreMatch "
445 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
446 { "modulepath", "path", 2, 2, 0,
448 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
452 "( OLcfgGlAt:31 NAME 'olcModulePath' "
453 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
454 { "monitoring", "TRUE|FALSE", 2, 2, 0,
455 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
456 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
457 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
458 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
459 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
460 "DESC 'OpenLDAP object classes' "
461 "EQUALITY caseIgnoreMatch "
462 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
464 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
465 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
466 "EQUALITY caseIgnoreMatch "
467 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
468 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
469 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
470 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
471 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
472 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
473 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
474 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
475 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
476 "EQUALITY caseIgnoreMatch "
477 "SYNTAX OMsDirectoryString )", NULL, NULL },
478 { "pidfile", "file", 2, 2, 0, ARG_STRING,
479 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
480 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
481 { "plugin", NULL, 0, 0, 0,
483 ARG_MAGIC|CFG_PLUGIN, &config_generic,
487 "( OLcfgGlAt:38 NAME 'olcPlugin' "
488 "EQUALITY caseIgnoreMatch "
489 "SYNTAX OMsDirectoryString )", NULL, NULL },
490 { "pluginlog", "filename", 2, 2, 0,
492 ARG_STRING, &slapi_log_file,
496 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
497 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
498 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
499 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
500 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
501 { "referral", "url", 2, 2, 0, ARG_MAGIC,
502 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
503 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
504 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
505 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
506 "EQUALITY caseIgnoreMatch "
507 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
508 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
509 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
510 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
511 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
512 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
513 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
514 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
515 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
516 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
517 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
518 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
519 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
520 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
521 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
522 "EQUALITY caseIgnoreMatch "
523 "SYNTAX OMsDirectoryString )", NULL, NULL },
524 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
525 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
526 "EQUALITY caseIgnoreMatch "
527 "SYNTAX OMsDirectoryString )", NULL, NULL },
528 { "reverse-lookup", "on|off", 2, 2, 0,
529 #ifdef SLAPD_RLOOKUPS
530 ARG_ON_OFF, &use_reverse_lookup,
534 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
535 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
536 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
537 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
538 "EQUALITY distinguishedNameMatch "
539 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
540 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
541 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
542 "EQUALITY caseIgnoreMatch "
543 "SYNTAX OMsDirectoryString )", NULL, NULL },
544 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
545 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
546 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
547 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
548 &config_generic, NULL, NULL, NULL },
549 { "sasl-auxprops", NULL, 2, 0, 0,
550 #ifdef HAVE_CYRUS_SASL
551 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
555 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
556 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
557 { "sasl-host", "host", 2, 2, 0,
558 #ifdef HAVE_CYRUS_SASL
559 ARG_STRING|ARG_UNIQUE, &sasl_host,
563 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
564 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
565 { "sasl-realm", "realm", 2, 2, 0,
566 #ifdef HAVE_CYRUS_SASL
567 ARG_STRING|ARG_UNIQUE, &global_realm,
571 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
574 &config_generic, NULL, NULL, NULL },
575 { "sasl-secprops", "properties", 2, 2, 0,
576 #ifdef HAVE_CYRUS_SASL
577 ARG_MAGIC|CFG_SASLSECP, &config_generic,
581 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
582 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
583 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
584 &config_generic, NULL, NULL, NULL },
585 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
586 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
587 "EQUALITY distinguishedNameMatch "
588 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
589 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
590 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
591 "EQUALITY caseIgnoreMatch "
592 "SYNTAX OMsDirectoryString )", NULL, NULL },
593 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
594 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
595 "EQUALITY caseIgnoreMatch "
596 "SYNTAX OMsDirectoryString )", NULL, NULL },
597 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
598 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
599 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
600 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
601 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
602 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
603 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
604 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
605 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
606 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
607 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
608 "DESC 'Attributes whose values will always be sorted' "
609 "EQUALITY caseIgnoreMatch "
610 "SYNTAX OMsDirectoryString )", NULL, NULL },
611 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
612 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
613 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
614 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
615 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
616 "EQUALITY distinguishedNameMatch "
617 "SYNTAX OMsDN )", NULL, NULL },
618 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
619 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
620 "DESC 'Store sync context in a subentry' "
621 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
622 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
623 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
624 "EQUALITY caseIgnoreMatch "
625 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
626 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
627 #ifndef LDAP_TCP_BUFFER
629 #else /* LDAP_TCP_BUFFER */
630 ARG_MAGIC, &config_tcp_buffer,
631 #endif /* LDAP_TCP_BUFFER */
632 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
633 "DESC 'Custom TCP buffer size' "
634 "SYNTAX OMsDirectoryString )", NULL, NULL },
635 { "threads", "count", 2, 2, 0,
639 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
641 "( OLcfgGlAt:66 NAME 'olcThreads' "
642 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
643 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
644 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
645 "SYNTAX OMsDirectoryString )", NULL, NULL },
646 { "TLSCACertificateFile", NULL, 0, 0, 0,
648 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
652 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
653 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
654 { "TLSCACertificatePath", NULL, 0, 0, 0,
656 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
660 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
661 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
662 { "TLSCertificateFile", NULL, 0, 0, 0,
664 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
668 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
669 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
670 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
672 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
676 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
677 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
678 { "TLSCipherSuite", NULL, 0, 0, 0,
680 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
684 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
685 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
686 { "TLSCRLCheck", NULL, 0, 0, 0,
687 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
688 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
692 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
693 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
694 { "TLSCRLFile", NULL, 0, 0, 0,
695 #if defined(HAVE_GNUTLS)
696 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
700 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
701 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
702 { "TLSRandFile", NULL, 0, 0, 0,
704 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
708 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
709 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
710 { "TLSVerifyClient", NULL, 0, 0, 0,
712 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
716 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
717 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
718 { "TLSDHParamFile", NULL, 0, 0, 0,
720 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
724 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
725 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
726 { "TLSProtocolMin", NULL, 0, 0, 0,
728 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
732 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
733 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
734 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
735 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
736 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
737 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
738 NULL, NULL, NULL, NULL },
739 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
740 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
741 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
742 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
743 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
744 "EQUALITY caseIgnoreMatch "
745 "SUP labeledURI )", NULL, NULL },
746 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
747 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
748 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
749 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
750 NULL, NULL, NULL, NULL }
753 /* Need to no-op this keyword for dynamic config */
754 ConfigTable olcDatabaseDummy[] = {
755 { "", "", 0, 0, 0, ARG_IGNORED,
756 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
757 "DESC 'The backend type for a database instance' "
758 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
759 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
762 /* Routines to check if a child can be added to this type */
763 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
764 cfAddBackend, cfAddModule, cfAddOverlay;
766 /* NOTE: be careful when defining array members
767 * that can be conditionally compiled */
768 #define CFOC_GLOBAL cf_ocs[1]
769 #define CFOC_SCHEMA cf_ocs[2]
770 #define CFOC_BACKEND cf_ocs[3]
771 #define CFOC_DATABASE cf_ocs[4]
772 #define CFOC_OVERLAY cf_ocs[5]
773 #define CFOC_INCLUDE cf_ocs[6]
774 #define CFOC_FRONTEND cf_ocs[7]
776 #define CFOC_MODULE cf_ocs[8]
777 #endif /* SLAPD_MODULES */
779 static ConfigOCs cf_ocs[] = {
782 "DESC 'OpenLDAP configuration object' "
783 "ABSTRACT SUP top )", Cft_Abstract, NULL },
786 "DESC 'OpenLDAP Global configuration options' "
787 "SUP olcConfig STRUCTURAL "
788 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
789 "olcAttributeOptions $ olcAuthIDRewrite $ "
790 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
791 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
792 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
793 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
794 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
795 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
796 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
797 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
798 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
800 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
801 "olcSecurity $ olcServerID $ olcSizeLimit $ "
802 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
804 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
805 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
806 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
807 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
808 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
809 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
810 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
812 "NAME 'olcSchemaConfig' "
813 "DESC 'OpenLDAP schema object' "
814 "SUP olcConfig STRUCTURAL "
815 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
816 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
817 Cft_Schema, NULL, cfAddSchema },
819 "NAME 'olcBackendConfig' "
820 "DESC 'OpenLDAP Backend-specific options' "
821 "SUP olcConfig STRUCTURAL "
822 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
824 "NAME 'olcDatabaseConfig' "
825 "DESC 'OpenLDAP Database-specific options' "
826 "SUP olcConfig STRUCTURAL "
828 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
829 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
830 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
831 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
832 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
833 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
834 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
836 Cft_Database, NULL, cfAddDatabase },
838 "NAME 'olcOverlayConfig' "
839 "DESC 'OpenLDAP Overlay-specific options' "
840 "SUP olcConfig STRUCTURAL "
841 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
843 "NAME 'olcIncludeFile' "
844 "DESC 'OpenLDAP configuration include file' "
845 "SUP olcConfig STRUCTURAL "
847 "MAY ( cn $ olcRootDSE ) )",
848 /* Used to be Cft_Include, that def has been removed */
849 Cft_Abstract, NULL, cfAddInclude },
850 /* This should be STRUCTURAL like all the other database classes, but
851 * that would mean inheriting all of the olcDatabaseConfig attributes,
852 * which causes them to be merged twice in config_build_entry.
855 "NAME 'olcFrontendConfig' "
856 "DESC 'OpenLDAP frontend configuration' "
858 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
859 Cft_Database, NULL, NULL },
862 "NAME 'olcModuleList' "
863 "DESC 'OpenLDAP dynamic module info' "
864 "SUP olcConfig STRUCTURAL "
865 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
866 Cft_Module, NULL, cfAddModule },
871 typedef struct ServerID {
872 struct ServerID *si_next;
873 struct berval si_url;
877 static ServerID *sid_list;
879 typedef struct voidList {
880 struct voidList *vl_next;
884 typedef struct ADlist {
885 struct ADlist *al_next;
886 AttributeDescription *al_desc;
889 static ADlist *sortVals;
892 config_generic(ConfigArgs *c) {
895 if ( c->op == SLAP_CONFIG_EMIT ) {
899 c->value_int = ldap_pvt_thread_get_concurrency();
902 c->value_int = connection_pool_max;
905 c->value_int = slap_tool_thread_max;
908 c->value_uint = slapd_daemon_threads;
912 c->value_string = ch_strdup( passwd_salt );
917 if ( c->be->be_limits ) {
921 for ( i=0; c->be->be_limits[i]; i++ ) {
922 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
923 if ( bv.bv_len >= sizeof( buf ) ) {
924 ber_bvarray_free_x( c->rvalue_vals, NULL );
925 c->rvalue_vals = NULL;
929 bv.bv_val = buf + bv.bv_len;
930 limits_unparse( c->be->be_limits[i], &bv,
931 sizeof( buf ) - ( bv.bv_val - buf ) );
932 bv.bv_len += bv.bv_val - buf;
934 value_add_one( &c->rvalue_vals, &bv );
937 if ( !c->rvalue_vals ) rc = 1;
940 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
943 c->value_string = ch_strdup( slap_sasl_getpolicy());
946 slap_sasl_regexp_unparse( &c->rvalue_vals );
947 if ( !c->rvalue_vals ) rc = 1;
949 #ifdef HAVE_CYRUS_SASL
951 struct berval bv = BER_BVNULL;
952 slap_sasl_secprops_unparse( &bv );
953 if ( !BER_BVISNULL( &bv )) {
954 ber_bvarray_add( &c->rvalue_vals, &bv );
962 c->value_int = c->be->be_max_deref_depth;
965 if ( SLAP_DBHIDDEN( c->be )) {
972 ConfigFile *cf = c->ca_private;
974 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
975 else if ( cf->c_om_head )
976 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
978 if ( !c->rvalue_vals )
983 ad_unparse_options( &c->rvalue_vals );
986 ConfigFile *cf = c->ca_private;
988 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
989 else if ( cf->c_oc_head )
990 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
992 if ( !c->rvalue_vals )
997 ConfigFile *cf = c->ca_private;
999 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1000 else if ( cf->c_at_head )
1001 at_unparse( &c->rvalue_vals, cf->c_at_head,
1003 if ( !c->rvalue_vals )
1008 ConfigFile *cf = c->ca_private;
1010 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1011 else if ( cf->c_syn_head )
1012 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1013 cf->c_syn_tail, 0 );
1014 if ( !c->rvalue_vals )
1019 ConfigFile *cf = c->ca_private;
1021 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1022 else if ( cf->c_cr_head )
1023 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1025 if ( !c->rvalue_vals )
1032 char *src, *dst, ibuf[11];
1033 struct berval bv, abv;
1034 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1035 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1036 if ( abv.bv_len >= sizeof( ibuf ) ) {
1037 ber_bvarray_free_x( c->rvalue_vals, NULL );
1038 c->rvalue_vals = NULL;
1042 acl_unparse( a, &bv );
1043 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1044 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1045 /* Turn TAB / EOL into plain space */
1046 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1047 if (isspace((unsigned char)*src)) *dst++ = ' ';
1051 if (dst[-1] == ' ') {
1055 abv.bv_len = dst - abv.bv_val;
1056 ber_bvarray_add( &c->rvalue_vals, &abv );
1062 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1065 ConfigFile *cf = c->ca_private;
1066 if ( cf->c_dseFiles ) {
1067 value_add( &c->rvalue_vals, cf->c_dseFiles );
1078 for ( si = sid_list; si; si=si->si_next ) {
1079 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1080 if ( !BER_BVISEMPTY( &si->si_url )) {
1081 bv.bv_len = si->si_url.bv_len + 6;
1082 bv.bv_val = ch_malloc( bv.bv_len );
1083 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1084 si->si_url.bv_val );
1085 ber_bvarray_add( &c->rvalue_vals, &bv );
1089 bv.bv_len = sprintf( buf, "%d", si->si_num );
1090 value_add_one( &c->rvalue_vals, &bv );
1099 c->value_string = ch_strdup( logfileName );
1104 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1106 case CFG_SYNC_SUBENTRY:
1107 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1109 case CFG_MIRRORMODE:
1110 if ( SLAP_SHADOW(c->be))
1111 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1115 case CFG_MONITORING:
1116 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1118 case CFG_SSTR_IF_MAX:
1119 c->value_uint = index_substr_if_maxlen;
1121 case CFG_SSTR_IF_MIN:
1122 c->value_uint = index_substr_if_minlen;
1125 c->value_int = index_intlen;
1127 case CFG_SORTVALS: {
1130 for ( sv = sortVals; sv; sv = sv->al_next ) {
1131 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1135 #ifdef SLAPD_MODULES
1137 ModPaths *mp = c->ca_private;
1140 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1143 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1144 SLAP_X_ORDERED_FMT "%s", i,
1145 mp->mp_loads[i].bv_val );
1146 if ( bv.bv_len >= sizeof( c->log ) ) {
1147 ber_bvarray_free_x( c->rvalue_vals, NULL );
1148 c->rvalue_vals = NULL;
1151 value_add_one( &c->rvalue_vals, &bv );
1155 rc = c->rvalue_vals ? 0 : 1;
1159 ModPaths *mp = c->ca_private;
1160 if ( !BER_BVISNULL( &mp->mp_path ))
1161 value_add_one( &c->rvalue_vals, &mp->mp_path );
1163 rc = c->rvalue_vals ? 0 : 1;
1169 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1170 if ( !c->rvalue_vals ) rc = 1;
1173 #ifdef SLAP_AUTH_REWRITE
1175 if ( authz_rewrites ) {
1176 struct berval bv, idx;
1181 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1182 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1183 if ( idx.bv_len >= sizeof( ibuf ) ) {
1184 ber_bvarray_free_x( c->rvalue_vals, NULL );
1185 c->rvalue_vals = NULL;
1188 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1189 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1190 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1191 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1192 authz_rewrites[i].bv_val,
1193 authz_rewrites[i].bv_len + 1 );
1194 ber_bvarray_add( &c->rvalue_vals, &bv );
1197 if ( !c->rvalue_vals ) rc = 1;
1204 } else if ( c->op == LDAP_MOD_DELETE ) {
1207 /* single-valued attrs, no-ops */
1216 case CFG_MIRRORMODE:
1217 case CFG_MONITORING:
1219 case CFG_SSTR_IF_MAX:
1220 case CFG_SSTR_IF_MIN:
1222 case CFG_SYNC_SUBENTRY:
1225 /* no-ops, requires slapd restart */
1230 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1234 ch_free( passwd_salt );
1239 ch_free( logfileName );
1247 case CFG_SERVERID: {
1248 ServerID *si, **sip;
1250 for ( i=0, si = sid_list, sip = &sid_list;
1251 si; si = *sip, i++ ) {
1252 if ( c->valx == -1 || i == c->valx ) {
1264 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1268 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1269 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1270 SLAP_INDEX_INTLEN_DEFAULT );
1274 if ( c->valx < 0 ) {
1275 acl_destroy( c->be->be_acl );
1276 c->be->be_acl = NULL;
1279 AccessControl **prev, *a;
1281 for (i=0, prev = &c->be->be_acl; i < c->valx;
1284 prev = &a->acl_next;
1287 *prev = a->acl_next;
1294 /* Can be NULL when undoing a failed add */
1295 if ( c->ca_entry ) {
1296 ce = c->ca_entry->e_private;
1297 /* can't modify the hardcoded schema */
1298 if ( ce->ce_parent->ce_type == Cft_Global )
1302 cfn = c->ca_private;
1303 if ( c->valx < 0 ) {
1306 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1308 if ( oc == cfn->c_oc_tail )
1311 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1313 ObjectClass *oc, *prev = NULL;
1315 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1320 if ( cfn->c_oc_tail == oc ) {
1321 cfn->c_oc_tail = prev;
1323 if ( cfn->c_oc_head == oc ) {
1325 cfn->c_oc_head = oc;
1332 /* Can be NULL when undoing a failed add */
1333 if ( c->ca_entry ) {
1334 ce = c->ca_entry->e_private;
1335 /* can't modify the hardcoded schema */
1336 if ( ce->ce_parent->ce_type == Cft_Global )
1340 cfn = c->ca_private;
1341 if ( c->valx < 0 ) {
1344 for( at = cfn->c_at_head; at; at_next( &at )) {
1346 if ( at == cfn->c_at_tail )
1349 cfn->c_at_head = cfn->c_at_tail = NULL;
1351 AttributeType *at, *prev = NULL;
1353 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1358 if ( cfn->c_at_tail == at ) {
1359 cfn->c_at_tail = prev;
1361 if ( cfn->c_at_head == at ) {
1363 cfn->c_at_head = at;
1370 /* Can be NULL when undoing a failed add */
1371 if ( c->ca_entry ) {
1372 ce = c->ca_entry->e_private;
1373 /* can't modify the hardcoded schema */
1374 if ( ce->ce_parent->ce_type == Cft_Global )
1378 cfn = c->ca_private;
1379 if ( c->valx < 0 ) {
1382 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1384 if ( syn == cfn->c_syn_tail )
1387 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1389 Syntax *syn, *prev = NULL;
1391 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1396 if ( cfn->c_syn_tail == syn ) {
1397 cfn->c_syn_tail = prev;
1399 if ( cfn->c_syn_head == syn ) {
1401 cfn->c_syn_head = syn;
1406 if ( c->valx < 0 ) {
1408 for ( sv = sortVals; sv; sv = sortVals ) {
1409 sortVals = sv->al_next;
1410 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1417 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1418 prev = &sv->al_next;
1421 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1422 *prev = sv->al_next;
1428 /* FIXME: there is no limits_free function */
1429 if ( c->valx < 0 ) {
1430 limits_destroy( c->be->be_limits );
1431 c->be->be_limits = NULL;
1436 if ( c->be->be_limits ) {
1437 for ( num = 0; c->be->be_limits[ num ]; num++ )
1441 if ( c->valx >= num ) {
1446 limits_destroy( c->be->be_limits );
1447 c->be->be_limits = NULL;
1450 limits_free_one( c->be->be_limits[ c->valx ] );
1452 for ( cnt = c->valx; cnt < num; cnt++ ) {
1453 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1460 /* FIXME: there is no ad_option_free function */
1462 /* FIXME: there is no way to remove attributes added by
1476 if(!(c->bi = backend_info(c->argv[1]))) {
1477 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1478 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1479 c->log, c->cr_msg, c->argv[1] );
1486 /* NOTE: config is always the first backend!
1488 if ( !strcasecmp( c->argv[1], "config" )) {
1489 c->be = LDAP_STAILQ_FIRST(&backendDB);
1490 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1493 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1495 if ( c->cr_msg[0] == 0 )
1496 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1497 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1504 ldap_pvt_thread_set_concurrency(c->value_int);
1508 if ( c->value_int < 2 ) {
1509 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1510 "threads=%d smaller than minimum value 2",
1512 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1513 c->log, c->cr_msg, 0 );
1516 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1517 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1518 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1519 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1520 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1521 c->log, c->cr_msg, 0 );
1523 if ( slapMode & SLAP_SERVER_MODE )
1524 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1525 connection_pool_max = c->value_int; /* save for reference */
1529 if ( slapMode & SLAP_TOOL_MODE )
1530 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1531 slap_tool_thread_max = c->value_int; /* save for reference */
1536 /* use a power of two */
1537 while (c->value_uint > 1) {
1538 c->value_uint >>= 1;
1542 slapd_daemon_mask = mask;
1543 slapd_daemon_threads = mask+1;
1548 if ( passwd_salt ) ch_free( passwd_salt );
1549 passwd_salt = c->value_string;
1550 lutil_salt_format(passwd_salt);
1554 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1560 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1562 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1566 ch_free(c->value_string);
1567 if (slap_sasl_setpolicy( c->argv[1] )) {
1568 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1569 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1570 c->log, c->cr_msg, c->argv[1] );
1576 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1580 #ifdef HAVE_CYRUS_SASL
1583 char *txt = slap_sasl_secprops( c->argv[1] );
1585 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1587 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1595 c->be->be_max_deref_depth = c->value_int;
1601 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1602 cfn = c->ca_private;
1603 if(parse_oidm(c, 1, &om))
1605 if (!cfn->c_om_head) cfn->c_om_head = om;
1606 cfn->c_om_tail = om;
1611 ObjectClass *oc, *prev;
1613 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1614 cfn = c->ca_private;
1615 if ( c->valx < 0 ) {
1616 prev = cfn->c_oc_tail;
1619 /* If adding anything after the first, prev is easy */
1622 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1627 /* If adding the first, and head exists, find its prev */
1628 if (cfn->c_oc_head) {
1629 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1634 /* else prev is NULL, append to end of global list */
1636 if(parse_oc(c, &oc, prev)) return(1);
1637 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1638 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1643 AttributeType *at, *prev;
1645 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1646 cfn = c->ca_private;
1647 if ( c->valx < 0 ) {
1648 prev = cfn->c_at_tail;
1651 /* If adding anything after the first, prev is easy */
1654 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1659 /* If adding the first, and head exists, find its prev */
1660 if (cfn->c_at_head) {
1661 for ( at_start( &at ); at != cfn->c_at_head; ) {
1666 /* else prev is NULL, append to end of global list */
1668 if(parse_at(c, &at, prev)) return(1);
1669 if (!cfn->c_at_head) cfn->c_at_head = at;
1670 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1677 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1678 cfn = c->ca_private;
1679 if ( c->valx < 0 ) {
1680 prev = cfn->c_syn_tail;
1683 /* If adding anything after the first, prev is easy */
1686 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1691 /* If adding the first, and head exists, find its prev */
1692 if (cfn->c_syn_head) {
1693 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1698 /* else prev is NULL, append to end of global list */
1700 if ( parse_syn( c, &syn, prev ) ) return(1);
1701 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1702 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1709 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1710 cfn = c->ca_private;
1711 if(parse_cr(c, &cr)) return(1);
1712 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1713 cfn->c_cr_tail = cr;
1718 ad_define_option(NULL, NULL, 0);
1719 for(i = 1; i < c->argc; i++)
1720 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1725 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1726 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1727 else if ( c->value_int > 255 )
1729 index_intlen = c->value_int;
1730 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1734 case CFG_SORTVALS: {
1735 ADlist *svnew = NULL, *svtail, *sv;
1737 for ( i = 1; i < c->argc; i++ ) {
1738 AttributeDescription *ad = NULL;
1742 rc = slap_str2ad( c->argv[i], &ad, &text );
1744 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1747 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1748 c->log, c->cr_msg, c->argv[i] );
1749 for ( sv = svnew; sv; sv = svnew ) {
1750 svnew = sv->al_next;
1755 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1756 ad->ad_type->sat_single_value ) {
1757 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1759 goto sortval_reject;
1761 sv = ch_malloc( sizeof( ADlist ));
1766 svtail->al_next = sv;
1771 for ( sv = svnew; sv; sv = sv->al_next )
1772 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1773 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1775 sv->al_next = svnew;
1782 /* Don't append to the global ACL if we're on a specific DB */
1784 if ( c->valx == -1 ) {
1787 for ( a=c->be->be_acl; a; a = a->acl_next )
1790 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1797 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1799 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1803 if(root_dse_read_file(c->argv[1])) {
1804 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1805 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1806 c->log, c->cr_msg, c->argv[1] );
1811 ber_str2bv( c->argv[1], 0, 1, &bv );
1812 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1813 cfn = c->ca_private;
1814 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1820 ServerID *si, **sip;
1823 if (( lutil_atoi( &num, c->argv[1] ) &&
1824 lutil_atoix( &num, c->argv[1], 16 )) ||
1825 num < 0 || num > SLAP_SYNC_SID_MAX )
1827 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1828 "<%s> illegal server ID", c->argv[0] );
1829 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1830 c->log, c->cr_msg, c->argv[1] );
1833 /* only one value allowed if no URL is given */
1834 if ( c->argc > 2 ) {
1837 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1838 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1839 "<%s> only one server ID allowed now", c->argv[0] );
1840 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1841 c->log, c->cr_msg, c->argv[1] );
1845 if ( ldap_url_parse( c->argv[2], &lud )) {
1846 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1847 "<%s> invalid URL", c->argv[0] );
1848 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1849 c->log, c->cr_msg, c->argv[2] );
1852 len = strlen( c->argv[2] );
1853 si = ch_malloc( sizeof(ServerID) + len + 1 );
1854 si->si_url.bv_val = (char *)(si+1);
1855 si->si_url.bv_len = len;
1856 strcpy( si->si_url.bv_val, c->argv[2] );
1859 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1860 "<%s> unqualified server ID not allowed now", c->argv[0] );
1861 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1862 c->log, c->cr_msg, c->argv[1] );
1865 si = ch_malloc( sizeof(ServerID) );
1866 BER_BVZERO( &si->si_url );
1867 slap_serverID = num;
1868 Debug( LDAP_DEBUG_CONFIG,
1870 c->log, slap_serverID, 0 );
1874 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1877 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1878 Listener *l = config_check_my_url( c->argv[2], lud );
1880 slap_serverID = si->si_num;
1881 Debug( LDAP_DEBUG_CONFIG,
1882 "%s: SID=0x%03x (listener=%s)\n",
1883 c->log, slap_serverID,
1888 ldap_free_urldesc( lud );
1892 if ( logfileName ) ch_free( logfileName );
1893 logfileName = c->value_string;
1894 logfile = fopen(logfileName, "w");
1895 if(logfile) lutil_debug_file(logfile);
1899 if(SLAP_NOLASTMODCMD(c->be)) {
1900 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1901 c->argv[0], c->be->bd_info->bi_type );
1902 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1903 c->log, c->cr_msg, 0 );
1907 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1909 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1912 case CFG_MIRRORMODE:
1913 if(c->value_int && !SLAP_SHADOW(c->be)) {
1914 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1916 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1917 c->log, c->cr_msg, 0 );
1921 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1923 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1926 case CFG_MONITORING:
1928 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1930 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1935 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1937 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1940 case CFG_SYNC_SUBENTRY:
1942 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1944 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1947 case CFG_SSTR_IF_MAX:
1948 if (c->value_uint < index_substr_if_minlen) {
1949 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1950 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1951 c->log, c->cr_msg, c->value_int );
1954 index_substr_if_maxlen = c->value_uint;
1957 case CFG_SSTR_IF_MIN:
1958 if (c->value_uint > index_substr_if_maxlen) {
1959 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1960 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1961 c->log, c->cr_msg, c->value_int );
1964 index_substr_if_minlen = c->value_uint;
1967 #ifdef SLAPD_MODULES
1969 /* If we're just adding a module on an existing modpath,
1970 * make sure we've selected the current path.
1972 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1973 modcur = c->ca_private;
1974 /* This should never fail */
1975 if ( module_path( modcur->mp_path.bv_val )) {
1976 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1978 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1979 c->log, c->cr_msg, modcur->mp_path.bv_val );
1983 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1985 /* Record this load on the current path */
1989 if ( c->op == SLAP_CONFIG_ADD ) {
1990 ptr = c->line + STRLENOF("moduleload");
1991 while (!isspace((unsigned char) *ptr)) ptr++;
1992 while (isspace((unsigned char) *ptr)) ptr++;
1996 ber_str2bv(ptr, 0, 1, &bv);
1997 ber_bvarray_add( &modcur->mp_loads, &bv );
1999 /* Check for any new hardcoded schema */
2000 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2001 config_check_schema( NULL, &cfBackInfo );
2006 if(module_path(c->argv[1])) return(1);
2007 /* Record which path was used with each module */
2011 if (!modpaths.mp_loads) {
2014 mp = ch_malloc( sizeof( ModPaths ));
2015 modlast->mp_next = mp;
2017 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2019 mp->mp_loads = NULL;
2030 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2032 slapi_plugins_used++;
2036 #ifdef SLAP_AUTH_REWRITE
2042 if ( c->op == LDAP_MOD_ADD ) {
2046 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2050 if ( c->argc > 1 ) {
2053 /* quote all args but the first */
2054 line = ldap_charray2str( c->argv, "\" \"" );
2055 ber_str2bv( line, 0, 0, &bv );
2056 s = ber_bvchr( &bv, '"' );
2057 assert( s != NULL );
2058 /* move the trailing quote of argv[0] to the end */
2059 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2060 bv.bv_val[ bv.bv_len - 1 ] = '"';
2063 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2066 ber_bvarray_add( &authz_rewrites, &bv );
2068 if ( c->op == LDAP_MOD_ADD ) {
2078 Debug( LDAP_DEBUG_ANY,
2079 "%s: unknown CFG_TYPE %d.\n",
2080 c->log, c->type, 0 );
2089 config_fname(ConfigArgs *c) {
2090 if(c->op == SLAP_CONFIG_EMIT) {
2091 if (c->ca_private) {
2092 ConfigFile *cf = c->ca_private;
2093 value_add_one( &c->rvalue_vals, &cf->c_file );
2102 config_cfdir(ConfigArgs *c) {
2103 if(c->op == SLAP_CONFIG_EMIT) {
2104 if ( !BER_BVISEMPTY( &cfdir )) {
2105 value_add_one( &c->rvalue_vals, &cfdir );
2114 config_search_base(ConfigArgs *c) {
2115 if(c->op == SLAP_CONFIG_EMIT) {
2117 if (!BER_BVISEMPTY(&default_search_base)) {
2118 value_add_one(&c->rvalue_vals, &default_search_base);
2119 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2123 } else if( c->op == LDAP_MOD_DELETE ) {
2124 ch_free( default_search_base.bv_val );
2125 ch_free( default_search_nbase.bv_val );
2126 BER_BVZERO( &default_search_base );
2127 BER_BVZERO( &default_search_nbase );
2131 if(c->bi || c->be != frontendDB) {
2132 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2133 "prior to any backend or database definition\n",
2138 if(default_search_nbase.bv_len) {
2139 free(default_search_base.bv_val);
2140 free(default_search_nbase.bv_val);
2143 default_search_base = c->value_dn;
2144 default_search_nbase = c->value_ndn;
2148 /* For RE23 compatibility we allow this in the global entry
2149 * but we now defer it to the frontend entry to allow modules
2150 * to load new hash types.
2153 config_passwd_hash(ConfigArgs *c) {
2155 if (c->op == SLAP_CONFIG_EMIT) {
2157 /* Don't generate it in the global entry */
2158 if ( c->table == Cft_Global )
2160 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2161 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2162 value_add_one(&c->rvalue_vals, &bv);
2165 } else if ( c->op == LDAP_MOD_DELETE ) {
2166 /* Deleting from global is a no-op, only the frontendDB entry matters */
2167 if ( c->table == Cft_Global )
2169 if ( c->valx < 0 ) {
2170 ldap_charray_free( default_passwd_hash );
2171 default_passwd_hash = NULL;
2174 ch_free( default_passwd_hash[i] );
2175 for (; default_passwd_hash[i]; i++ )
2176 default_passwd_hash[i] = default_passwd_hash[i+1];
2180 for(i = 1; i < c->argc; i++) {
2181 if(!lutil_passwd_scheme(c->argv[i])) {
2182 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2183 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2184 c->log, c->cr_msg, c->argv[i]);
2186 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2189 if(!default_passwd_hash) {
2190 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2191 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2192 c->log, c->cr_msg, 0 );
2199 config_schema_dn(ConfigArgs *c) {
2200 if ( c->op == SLAP_CONFIG_EMIT ) {
2202 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2203 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2204 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2208 } else if ( c->op == LDAP_MOD_DELETE ) {
2209 ch_free( c->be->be_schemadn.bv_val );
2210 ch_free( c->be->be_schemandn.bv_val );
2211 BER_BVZERO( &c->be->be_schemadn );
2212 BER_BVZERO( &c->be->be_schemandn );
2215 ch_free( c->be->be_schemadn.bv_val );
2216 ch_free( c->be->be_schemandn.bv_val );
2217 c->be->be_schemadn = c->value_dn;
2218 c->be->be_schemandn = c->value_ndn;
2223 config_sizelimit(ConfigArgs *c) {
2225 struct slap_limits_set *lim = &c->be->be_def_limit;
2226 if (c->op == SLAP_CONFIG_EMIT) {
2231 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2232 if ( !BER_BVISEMPTY( &bv ))
2233 value_add_one( &c->rvalue_vals, &bv );
2237 } else if ( c->op == LDAP_MOD_DELETE ) {
2238 /* Reset to defaults or values from frontend */
2239 if ( c->be == frontendDB ) {
2240 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2241 lim->lms_s_hard = 0;
2242 lim->lms_s_unchecked = -1;
2244 lim->lms_s_pr_hide = 0;
2245 lim->lms_s_pr_total = 0;
2247 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2248 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2249 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2250 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2251 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2252 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2256 for(i = 1; i < c->argc; i++) {
2257 if(!strncasecmp(c->argv[i], "size", 4)) {
2258 rc = limits_parse_one(c->argv[i], lim);
2260 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2261 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2262 c->log, c->cr_msg, c->argv[i]);
2266 if(!strcasecmp(c->argv[i], "unlimited")) {
2267 lim->lms_s_soft = -1;
2269 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2270 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2271 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2272 c->log, c->cr_msg, c->argv[i]);
2276 lim->lms_s_hard = 0;
2281 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2282 /* This is a modification to the global limits apply it to
2283 * the other databases as needed */
2284 AttributeDescription *ad=NULL;
2285 const char *text = NULL;
2286 CfEntryInfo *ce = c->ca_entry->e_private;
2288 slap_str2ad(c->argv[0], &ad, &text);
2289 /* if we got here... */
2290 assert( ad != NULL );
2292 if ( ce->ce_type == Cft_Global ){
2295 for (; ce; ce=ce->ce_sibs) {
2296 Entry *dbe = ce->ce_entry;
2297 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2298 && (!attr_find(dbe->e_attrs, ad)) ) {
2299 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2300 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2301 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2302 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2303 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2304 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2312 config_timelimit(ConfigArgs *c) {
2314 struct slap_limits_set *lim = &c->be->be_def_limit;
2315 if (c->op == SLAP_CONFIG_EMIT) {
2320 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2321 if ( !BER_BVISEMPTY( &bv ))
2322 value_add_one( &c->rvalue_vals, &bv );
2326 } else if ( c->op == LDAP_MOD_DELETE ) {
2327 /* Reset to defaults or values from frontend */
2328 if ( c->be == frontendDB ) {
2329 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2330 lim->lms_t_hard = 0;
2332 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2333 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2337 for(i = 1; i < c->argc; i++) {
2338 if(!strncasecmp(c->argv[i], "time", 4)) {
2339 rc = limits_parse_one(c->argv[i], lim);
2341 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2342 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2343 c->log, c->cr_msg, c->argv[i]);
2347 if(!strcasecmp(c->argv[i], "unlimited")) {
2348 lim->lms_t_soft = -1;
2350 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2351 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2352 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2353 c->log, c->cr_msg, c->argv[i]);
2357 lim->lms_t_hard = 0;
2362 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2363 /* This is a modification to the global limits apply it to
2364 * the other databases as needed */
2365 AttributeDescription *ad=NULL;
2366 const char *text = NULL;
2367 CfEntryInfo *ce = c->ca_entry->e_private;
2369 slap_str2ad(c->argv[0], &ad, &text);
2370 /* if we got here... */
2371 assert( ad != NULL );
2373 if ( ce->ce_type == Cft_Global ){
2376 for (; ce; ce=ce->ce_sibs) {
2377 Entry *dbe = ce->ce_entry;
2378 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2379 && (!attr_find(dbe->e_attrs, ad)) ) {
2380 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2381 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2389 config_overlay(ConfigArgs *c) {
2390 if (c->op == SLAP_CONFIG_EMIT) {
2392 } else if ( c->op == LDAP_MOD_DELETE ) {
2395 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2396 c->valx, &c->bi, &c->reply)) {
2398 Debug( LDAP_DEBUG_ANY,
2399 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2400 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2402 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2409 config_subordinate(ConfigArgs *c)
2415 case SLAP_CONFIG_EMIT:
2416 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2419 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2420 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2423 value_add_one( &c->rvalue_vals, &bv );
2427 case LDAP_MOD_DELETE:
2428 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2429 glue_sub_del( c->be );
2431 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2436 case SLAP_CONFIG_ADD:
2437 if ( c->be->be_nsuffix == NULL ) {
2439 snprintf( c->cr_msg, sizeof( c->cr_msg),
2440 "subordinate configuration needs a suffix" );
2441 Debug( LDAP_DEBUG_ANY,
2443 c->log, c->cr_msg, 0 );
2448 if ( c->argc == 2 ) {
2449 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2452 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2454 snprintf( c->cr_msg, sizeof( c->cr_msg),
2455 "subordinate must be \"TRUE\" or \"advertise\"" );
2456 Debug( LDAP_DEBUG_ANY,
2457 "%s: suffix \"%s\": %s.\n",
2458 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2464 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2472 * [listener=<listener>] [{read|write}=]<size>
2475 #ifdef LDAP_TCP_BUFFER
2476 static BerVarray tcp_buffer;
2479 #define SLAP_TCP_RMEM (0x1U)
2480 #define SLAP_TCP_WMEM (0x2U)
2483 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2484 int *size, int *rw, Listener **l )
2486 int i, rc = LDAP_SUCCESS;
2487 LDAPURLDesc *lud = NULL;
2490 if ( val != NULL && argv == NULL ) {
2491 char *s = val->bv_val;
2493 argv = ldap_str2charray( s, " \t" );
2494 if ( argv == NULL ) {
2500 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2503 char *url = argv[ i ] + STRLENOF( "listener=" );
2505 if ( ldap_url_parse( url, &lud ) ) {
2506 rc = LDAP_INVALID_SYNTAX;
2510 *l = config_check_my_url( url, lud );
2512 rc = LDAP_NO_SUCH_ATTRIBUTE;
2520 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2521 *rw |= SLAP_TCP_RMEM;
2522 ptr += STRLENOF( "read=" );
2524 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2525 *rw |= SLAP_TCP_WMEM;
2526 ptr += STRLENOF( "write=" );
2529 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2532 /* accept any base */
2533 if ( lutil_atoix( size, ptr, 0 ) ) {
2534 rc = LDAP_INVALID_SYNTAX;
2539 if ( val != NULL && argv != NULL ) {
2540 ldap_charray_free( argv );
2543 if ( lud != NULL ) {
2544 ldap_free_urldesc( lud );
2551 tcp_buffer_delete_one( struct berval *val )
2554 int size = -1, rw = 0;
2557 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2564 Listener **ll = slapd_get_listeners();
2566 for ( i = 0; ll[ i ] != NULL; i++ ) {
2567 if ( ll[ i ] == l ) break;
2570 if ( ll[ i ] == NULL ) {
2571 return LDAP_NO_SUCH_ATTRIBUTE;
2574 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2575 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2577 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2578 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2579 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2583 /* NOTE: this affects listeners without a specific setting,
2584 * does not reset all listeners. If a listener without
2585 * specific settings was assigned a buffer because of
2586 * a global setting, it will not be reset. In any case,
2587 * buffer changes will only take place at restart. */
2588 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2589 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2596 tcp_buffer_delete( BerVarray vals )
2600 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2601 tcp_buffer_delete_one( &vals[ i ] );
2608 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2610 char buf[sizeof("2147483648")], *ptr;
2612 /* unparse for later use */
2613 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2615 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2618 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2619 if ( rw & SLAP_TCP_RMEM ) {
2620 val->bv_len += STRLENOF( "read=" );
2621 } else if ( rw & SLAP_TCP_WMEM ) {
2622 val->bv_len += STRLENOF( "write=" );
2626 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2631 ptr = lutil_strcopy( ptr, "listener=" );
2632 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2636 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2637 if ( rw & SLAP_TCP_RMEM ) {
2638 ptr = lutil_strcopy( ptr, "read=" );
2639 } else if ( rw & SLAP_TCP_WMEM ) {
2640 ptr = lutil_strcopy( ptr, "write=" );
2644 ptr = lutil_strcopy( ptr, buf );
2647 assert( val->bv_val + val->bv_len == ptr );
2649 return LDAP_SUCCESS;
2653 tcp_buffer_add_one( int argc, char **argv )
2656 int size = -1, rw = 0;
2662 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2667 /* unparse for later use */
2668 rc = tcp_buffer_unparse( size, rw, l, &val );
2669 if ( rc != LDAP_SUCCESS ) {
2673 /* use parsed values */
2676 Listener **ll = slapd_get_listeners();
2678 for ( i = 0; ll[ i ] != NULL; i++ ) {
2679 if ( ll[ i ] == l ) break;
2682 if ( ll[ i ] == NULL ) {
2683 return LDAP_NO_SUCH_ATTRIBUTE;
2686 /* buffer only applies to TCP listeners;
2687 * we do not do any check here, and delegate them
2688 * to setsockopt(2) */
2689 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2690 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2692 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2693 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2694 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2698 /* NOTE: this affects listeners without a specific setting,
2699 * does not set all listeners */
2700 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2701 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2704 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2706 tcp_buffer[ tcp_buffer_num ] = val;
2709 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2715 config_tcp_buffer( ConfigArgs *c )
2717 if ( c->op == SLAP_CONFIG_EMIT ) {
2718 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2721 value_add( &c->rvalue_vals, tcp_buffer );
2722 value_add( &c->rvalue_nvals, tcp_buffer );
2724 } else if ( c->op == LDAP_MOD_DELETE ) {
2726 tcp_buffer_delete( tcp_buffer );
2727 ber_bvarray_free( tcp_buffer );
2733 int size = -1, rw = 0;
2736 struct berval val = BER_BVNULL;
2740 if ( tcp_buffer_num == 0 ) {
2745 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2750 /* unparse for later use */
2751 rc = tcp_buffer_unparse( size, rw, l, &val );
2752 if ( rc != LDAP_SUCCESS ) {
2756 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2757 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2762 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2768 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2769 ber_memfree( tcp_buffer[ i ].bv_val );
2770 for ( ; i < tcp_buffer_num; i++ ) {
2771 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2776 if ( !BER_BVISNULL( &val ) ) {
2777 SLAP_FREE( val.bv_val );
2785 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2787 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2788 "<%s> unable to add value #%d",
2789 c->argv[0], tcp_buffer_num );
2790 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2791 c->log, c->cr_msg, 0 );
2798 #endif /* LDAP_TCP_BUFFER */
2801 config_suffix(ConfigArgs *c)
2804 struct berval pdn, ndn;
2805 char *notallowed = NULL;
2807 if ( c->be == frontendDB ) {
2808 notallowed = "frontend";
2810 } else if ( SLAP_MONITOR(c->be) ) {
2811 notallowed = "monitor";
2813 } else if ( SLAP_CONFIG(c->be) ) {
2814 notallowed = "config";
2817 if ( notallowed != NULL ) {
2818 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2822 case LDAP_MOD_DELETE:
2823 case LDAP_MOD_REPLACE:
2824 case LDAP_MOD_INCREMENT:
2825 case SLAP_CONFIG_ADD:
2826 if ( !BER_BVISNULL( &c->value_dn ) ) {
2827 snprintf( buf, sizeof( buf ), "<%s> ",
2828 c->value_dn.bv_val );
2831 Debug(LDAP_DEBUG_ANY,
2832 "%s: suffix %snot allowed in %s database.\n",
2833 c->log, buf, notallowed );
2836 case SLAP_CONFIG_EMIT:
2837 /* don't complain when emitting... */
2841 /* FIXME: don't know what values may be valid;
2842 * please remove assertion, or add legal values
2843 * to either block */
2851 if (c->op == SLAP_CONFIG_EMIT) {
2852 if ( c->be->be_suffix == NULL
2853 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2857 value_add( &c->rvalue_vals, c->be->be_suffix );
2858 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2861 } else if ( c->op == LDAP_MOD_DELETE ) {
2862 if ( c->valx < 0 ) {
2863 ber_bvarray_free( c->be->be_suffix );
2864 ber_bvarray_free( c->be->be_nsuffix );
2865 c->be->be_suffix = NULL;
2866 c->be->be_nsuffix = NULL;
2869 ch_free( c->be->be_suffix[i].bv_val );
2870 ch_free( c->be->be_nsuffix[i].bv_val );
2872 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2873 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2875 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2880 #ifdef SLAPD_MONITOR_DN
2881 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2882 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2884 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2885 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2890 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2891 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2892 c->argv[0], c->be->bd_info->bi_type );
2893 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2894 c->log, c->cr_msg, 0);
2901 if (SLAP_DBHIDDEN( c->be ))
2904 tbe = select_backend(&ndn, 0);
2906 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2912 BackendDB *b2 = tbe;
2914 /* Does tbe precede be? */
2915 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2918 char *type = tbe->bd_info->bi_type;
2920 if ( overlay_is_over( tbe ) ) {
2921 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2922 type = oi->oi_orig->bi_type;
2925 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2926 "already served by a preceding %s database",
2927 c->argv[0], pdn.bv_val, type );
2928 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2929 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2935 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2936 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2937 "base provided \"%s\" (assuming okay)\n",
2938 c->log, default_search_base.bv_val, 0);
2940 ber_bvarray_add(&c->be->be_suffix, &pdn);
2941 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2946 config_rootdn(ConfigArgs *c) {
2947 if (c->op == SLAP_CONFIG_EMIT) {
2948 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2949 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2950 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2955 } else if ( c->op == LDAP_MOD_DELETE ) {
2956 ch_free( c->be->be_rootdn.bv_val );
2957 ch_free( c->be->be_rootndn.bv_val );
2958 BER_BVZERO( &c->be->be_rootdn );
2959 BER_BVZERO( &c->be->be_rootndn );
2962 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2963 ch_free( c->be->be_rootdn.bv_val );
2964 ch_free( c->be->be_rootndn.bv_val );
2966 c->be->be_rootdn = c->value_dn;
2967 c->be->be_rootndn = c->value_ndn;
2972 config_rootpw(ConfigArgs *c) {
2975 if (c->op == SLAP_CONFIG_EMIT) {
2976 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2977 /* don't copy, because "rootpw" is marked
2979 c->value_bv = c->be->be_rootpw;
2983 } else if ( c->op == LDAP_MOD_DELETE ) {
2984 ch_free( c->be->be_rootpw.bv_val );
2985 BER_BVZERO( &c->be->be_rootpw );
2989 tbe = select_backend(&c->be->be_rootndn, 0);
2991 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2993 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2994 c->log, c->cr_msg, 0);
2997 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2998 ch_free( c->be->be_rootpw.bv_val );
2999 c->be->be_rootpw = c->value_bv;
3004 config_restrict(ConfigArgs *c) {
3005 slap_mask_t restrictops = 0;
3007 slap_verbmasks restrictable_ops[] = {
3008 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3009 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3010 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3011 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3012 { BER_BVC("modrdn"), 0 },
3013 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3014 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3015 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3016 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3017 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3018 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3019 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3020 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3021 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3022 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3023 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3027 if (c->op == SLAP_CONFIG_EMIT) {
3028 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3030 } else if ( c->op == LDAP_MOD_DELETE ) {
3032 c->be->be_restrictops = 0;
3034 restrictops = verb_to_mask( c->line, restrictable_ops );
3035 c->be->be_restrictops ^= restrictops;
3039 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3041 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3042 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3043 c->log, c->cr_msg, c->argv[i]);
3046 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3047 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3048 c->be->be_restrictops |= restrictops;
3053 config_allows(ConfigArgs *c) {
3054 slap_mask_t allows = 0;
3056 slap_verbmasks allowable_ops[] = {
3057 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3058 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3059 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3060 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3061 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3064 if (c->op == SLAP_CONFIG_EMIT) {
3065 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3066 } else if ( c->op == LDAP_MOD_DELETE ) {
3070 allows = verb_to_mask( c->line, allowable_ops );
3071 global_allows ^= allows;
3075 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3077 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3078 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3079 c->log, c->cr_msg, c->argv[i]);
3082 global_allows |= allows;
3087 config_disallows(ConfigArgs *c) {
3088 slap_mask_t disallows = 0;
3090 slap_verbmasks disallowable_ops[] = {
3091 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3092 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3093 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3094 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3095 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3096 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3099 if (c->op == SLAP_CONFIG_EMIT) {
3100 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3101 } else if ( c->op == LDAP_MOD_DELETE ) {
3103 global_disallows = 0;
3105 disallows = verb_to_mask( c->line, disallowable_ops );
3106 global_disallows ^= disallows;
3110 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3112 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3113 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3114 c->log, c->cr_msg, c->argv[i]);
3117 global_disallows |= disallows;
3122 config_requires(ConfigArgs *c) {
3123 slap_mask_t requires = frontendDB->be_requires;
3124 int i, argc = c->argc;
3125 char **argv = c->argv;
3127 slap_verbmasks requires_ops[] = {
3128 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3129 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3130 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3131 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3132 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3135 if (c->op == SLAP_CONFIG_EMIT) {
3136 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3137 } else if ( c->op == LDAP_MOD_DELETE ) {
3139 c->be->be_requires = 0;
3141 requires = verb_to_mask( c->line, requires_ops );
3142 c->be->be_requires ^= requires;
3146 /* "none" can only be first, to wipe out default/global values */
3147 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3152 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3154 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3155 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3156 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3157 c->log, c->cr_msg, 0);
3159 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3160 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3161 c->log, c->cr_msg, c->argv[i]);
3165 c->be->be_requires = requires;
3169 static slap_verbmasks *loglevel_ops;
3172 loglevel_init( void )
3174 slap_verbmasks lo[] = {
3175 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3176 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3177 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3178 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3179 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3180 { BER_BVC("BER"), LDAP_DEBUG_BER },
3181 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3182 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3183 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3184 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3185 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3186 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3187 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3188 #if 0 /* no longer used (nor supported) */
3189 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3190 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3192 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3193 { BER_BVC("None"), LDAP_DEBUG_NONE },
3197 return slap_verbmasks_init( &loglevel_ops, lo );
3201 loglevel_destroy( void )
3203 if ( loglevel_ops ) {
3204 (void)slap_verbmasks_destroy( loglevel_ops );
3206 loglevel_ops = NULL;
3209 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3212 slap_loglevel_register( slap_mask_t m, struct berval *s )
3216 if ( loglevel_ops == NULL ) {
3220 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3223 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3231 slap_loglevel_get( struct berval *s, int *l )
3236 if ( loglevel_ops == NULL ) {
3240 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3241 m |= loglevel_ops[ i ].mask;
3244 for ( i = 1; m & i; i <<= 1 )
3251 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3254 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3265 str2loglevel( const char *s, int *l )
3269 if ( loglevel_ops == NULL ) {
3273 i = verb_to_mask( s, loglevel_ops );
3275 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3279 *l = loglevel_ops[ i ].mask;
3285 loglevel2str( int l )
3287 struct berval bv = BER_BVNULL;
3289 loglevel2bv( l, &bv );
3295 loglevel2bv( int l, struct berval *bv )
3297 if ( loglevel_ops == NULL ) {
3303 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3307 loglevel2bvarray( int l, BerVarray *bva )
3309 if ( loglevel_ops == NULL ) {
3313 return mask_to_verbs( loglevel_ops, l, bva );
3317 loglevel_print( FILE *out )
3321 if ( loglevel_ops == NULL ) {
3325 fprintf( out, "Installed log subsystems:\n\n" );
3326 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3327 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3329 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3330 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3331 loglevel_ops[ i ].word.bv_val, mask, mask );
3334 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3335 "by specific code\n\n" );
3340 static int config_syslog;
3343 config_loglevel(ConfigArgs *c) {
3346 if ( loglevel_ops == NULL ) {
3350 if (c->op == SLAP_CONFIG_EMIT) {
3351 /* Get default or commandline slapd setting */
3352 if ( ldap_syslog && !config_syslog )
3353 config_syslog = ldap_syslog;
3354 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3356 } else if ( c->op == LDAP_MOD_DELETE ) {
3360 int level = verb_to_mask( c->line, loglevel_ops );
3361 config_syslog ^= level;
3363 if ( slapMode & SLAP_SERVER_MODE ) {
3364 ldap_syslog = config_syslog;
3369 for( i=1; i < c->argc; i++ ) {
3372 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3373 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3374 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3375 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3376 c->log, c->cr_msg, c->argv[i]);
3380 if ( str2loglevel( c->argv[i], &level ) ) {
3381 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3382 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3383 c->log, c->cr_msg, c->argv[i]);
3387 /* Explicitly setting a zero clears all the levels */
3389 config_syslog |= level;
3393 if ( slapMode & SLAP_SERVER_MODE ) {
3394 ldap_syslog = config_syslog;
3400 config_referral(ConfigArgs *c) {
3402 if (c->op == SLAP_CONFIG_EMIT) {
3403 if ( default_referral ) {
3404 value_add( &c->rvalue_vals, default_referral );
3409 } else if ( c->op == LDAP_MOD_DELETE ) {
3410 if ( c->valx < 0 ) {
3411 ber_bvarray_free( default_referral );
3412 default_referral = NULL;
3415 ch_free( default_referral[i].bv_val );
3416 for (; default_referral[i].bv_val; i++ )
3417 default_referral[i] = default_referral[i+1];
3421 if(validate_global_referral(c->argv[1])) {
3422 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3423 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3424 c->log, c->cr_msg, c->argv[1]);
3428 ber_str2bv(c->argv[1], 0, 0, &val);
3429 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3437 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3438 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3439 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3440 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3441 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3442 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3443 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3444 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3445 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3450 config_security(ConfigArgs *c) {
3451 slap_ssf_set_t *set = &c->be->be_ssf_set;
3454 if (c->op == SLAP_CONFIG_EMIT) {
3460 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3461 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3464 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3465 if ( bv.bv_len >= sizeof( numbuf ) ) {
3466 ber_bvarray_free_x( c->rvalue_vals, NULL );
3467 c->rvalue_vals = NULL;
3471 bv.bv_len += sec_keys[i].key.bv_len;
3472 bv.bv_val = ch_malloc( bv.bv_len + 1);
3473 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3474 strcpy( next, numbuf );
3475 ber_bvarray_add( &c->rvalue_vals, &bv );
3480 for(i = 1; i < c->argc; i++) {
3481 slap_ssf_t *tgt = NULL;
3483 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3484 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3485 sec_keys[j].key.bv_len)) {
3486 src = c->argv[i] + sec_keys[j].key.bv_len;
3487 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3492 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3493 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3494 c->log, c->cr_msg, c->argv[i]);
3498 if ( lutil_atou( tgt, src ) != 0 ) {
3499 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3500 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3501 c->log, c->cr_msg, c->argv[i]);
3509 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3513 for (; !BER_BVISNULL( &an->an_name ); an++) {
3514 /* if buflen == 0, assume the buffer size has been
3515 * already checked otherwise */
3516 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3517 if ( comma ) *ptr++ = ',';
3518 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3525 config_updatedn(ConfigArgs *c) {
3526 if (c->op == SLAP_CONFIG_EMIT) {
3527 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3528 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3529 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3533 } else if ( c->op == LDAP_MOD_DELETE ) {
3534 ch_free( c->be->be_update_ndn.bv_val );
3535 BER_BVZERO( &c->be->be_update_ndn );
3536 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3539 if(SLAP_SHADOW(c->be)) {
3540 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3541 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3542 c->log, c->cr_msg, 0);
3546 ber_memfree_x( c->value_dn.bv_val, NULL );
3547 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3548 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3550 c->be->be_update_ndn = c->value_ndn;
3551 BER_BVZERO( &c->value_dn );
3552 BER_BVZERO( &c->value_ndn );
3554 return config_slurp_shadow( c );
3558 config_shadow( ConfigArgs *c, slap_mask_t flag )
3560 char *notallowed = NULL;
3562 if ( c->be == frontendDB ) {
3563 notallowed = "frontend";
3565 } else if ( SLAP_MONITOR(c->be) ) {
3566 notallowed = "monitor";
3569 if ( notallowed != NULL ) {
3570 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3574 if ( SLAP_SHADOW(c->be) ) {
3575 /* if already shadow, only check consistency */
3576 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3577 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3583 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3590 config_updateref(ConfigArgs *c) {
3592 if (c->op == SLAP_CONFIG_EMIT) {
3593 if ( c->be->be_update_refs ) {
3594 value_add( &c->rvalue_vals, c->be->be_update_refs );
3599 } else if ( c->op == LDAP_MOD_DELETE ) {
3600 if ( c->valx < 0 ) {
3601 ber_bvarray_free( c->be->be_update_refs );
3602 c->be->be_update_refs = NULL;
3605 ch_free( c->be->be_update_refs[i].bv_val );
3606 for (; c->be->be_update_refs[i].bv_val; i++)
3607 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3611 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3612 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3614 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3615 c->log, c->cr_msg, 0);
3619 if(validate_global_referral(c->argv[1])) {
3620 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3621 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3622 c->log, c->cr_msg, c->argv[1]);
3625 ber_str2bv(c->argv[1], 0, 0, &val);
3626 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3631 config_obsolete(ConfigArgs *c) {
3632 if (c->op == SLAP_CONFIG_EMIT)
3635 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3637 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3642 config_include(ConfigArgs *c) {
3643 int savelineno = c->lineno;
3646 ConfigFile *cfsave = cfn;
3647 ConfigFile *cf2 = NULL;
3649 /* Leftover from RE23. No dynamic config for include files */
3650 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3653 cf = ch_calloc( 1, sizeof(ConfigFile));
3654 if ( cfn->c_kids ) {
3655 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3661 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3662 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3663 c->lineno = savelineno - 1;
3666 if ( cf2 ) cf2->c_sibs = NULL;
3667 else cfn->c_kids = NULL;
3668 ch_free( cf->c_file.bv_val );
3678 config_tls_cleanup(ConfigArgs *c) {
3681 if ( slap_tls_ld ) {
3684 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3686 /* Force new ctx to be created */
3687 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3689 /* The ctx's refcount is bumped up here */
3690 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3691 /* This is a no-op if it's already loaded */
3692 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3699 config_tls_option(ConfigArgs *c) {
3701 LDAP *ld = slap_tls_ld;
3703 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3704 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3705 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3706 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3707 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3708 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3709 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3711 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3713 default: Debug(LDAP_DEBUG_ANY, "%s: "
3714 "unknown tls_option <0x%x>\n",
3715 c->log, c->type, 0);
3718 if (c->op == SLAP_CONFIG_EMIT) {
3719 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3720 } else if ( c->op == LDAP_MOD_DELETE ) {
3721 c->cleanup = config_tls_cleanup;
3722 return ldap_pvt_tls_set_option( ld, flag, NULL );
3724 ch_free(c->value_string);
3725 c->cleanup = config_tls_cleanup;
3726 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3729 /* FIXME: this ought to be provided by libldap */
3731 config_tls_config(ConfigArgs *c) {
3734 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3735 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3736 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3738 Debug(LDAP_DEBUG_ANY, "%s: "
3739 "unknown tls_option <0x%x>\n",
3740 c->log, c->type, 0);
3743 if (c->op == SLAP_CONFIG_EMIT) {
3744 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3745 } else if ( c->op == LDAP_MOD_DELETE ) {
3747 c->cleanup = config_tls_cleanup;
3748 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3750 ch_free( c->value_string );
3751 c->cleanup = config_tls_cleanup;
3752 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3753 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3754 Debug(LDAP_DEBUG_ANY, "%s: "
3755 "unable to parse %s \"%s\"\n",
3756 c->log, c->argv[0], c->argv[1] );
3759 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3761 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3766 static CfEntryInfo *
3767 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3777 if ( dn_match( &root->ce_entry->e_nname, dn ))
3780 c = dn->bv_val+dn->bv_len;
3781 for (;*c != ',';c--);
3785 for (--c;c>dn->bv_val && *c != ',';c--);
3789 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3791 root = root->ce_kids;
3793 for (;root;root=root->ce_sibs) {
3794 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3795 if ( cdn.bv_val == dn->bv_val ) {
3805 typedef struct setup_cookie {
3815 config_ldif_resp( Operation *op, SlapReply *rs )
3817 if ( rs->sr_type == REP_SEARCH ) {
3818 setup_cookie *sc = op->o_callback->sc_private;
3821 sc->cfb->cb_got_ldif = 1;
3822 /* Does the frontend exist? */
3823 if ( !sc->got_frontend ) {
3824 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3825 "olcDatabase", STRLENOF( "olcDatabase" )))
3827 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3828 STRLENOF( "olcDatabase" ), "={-1}frontend",
3829 STRLENOF( "={-1}frontend" )))
3833 sc->ca->be = frontendDB;
3834 sc->ca->bi = frontendDB->bd_info;
3835 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3836 rdn.bv_val = sc->ca->log;
3837 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3838 "%s=" SLAP_X_ORDERED_FMT "%s",
3839 cfAd_database->ad_cname.bv_val, -1,
3840 sc->ca->bi->bi_type);
3842 sc->frontend = config_build_entry( op, rs,
3843 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3844 sc->ca->be->be_cf_ocs );
3854 dnParent( &rs->sr_entry->e_nname, &pdn );
3856 /* Does the configDB exist? */
3857 if ( sc->got_frontend && !sc->got_config &&
3858 !strncmp( rs->sr_entry->e_nname.bv_val,
3859 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3860 dn_match( &config_rdn, &pdn ) )
3862 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3863 STRLENOF( "olcDatabase" ), "={0}config",
3864 STRLENOF( "={0}config" )))
3868 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3869 sc->ca->bi = sc->ca->be->bd_info;
3870 rdn.bv_val = sc->ca->log;
3871 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3872 "%s=" SLAP_X_ORDERED_FMT "%s",
3873 cfAd_database->ad_cname.bv_val, 0,
3874 sc->ca->bi->bi_type);
3876 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3877 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3884 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3885 if ( rs->sr_err != LDAP_SUCCESS ) {
3886 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3887 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3893 /* Configure and read the underlying back-ldif store */
3895 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3896 CfBackInfo *cfb = be->be_private;
3902 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3903 Connection conn = {0};
3904 OperationBuffer opbuf;
3906 SlapReply rs = {REP_RESULT};
3907 Filter filter = { LDAP_FILTER_PRESENT };
3908 struct berval filterstr = BER_BVC("(objectclass=*)");
3911 /* Is the config directory available? */
3912 if ( stat( dir, &st ) < 0 ) {
3913 /* No, so don't bother using the backing store.
3914 * All changes will be in-memory only.
3919 cfb->cb_db.bd_info = backend_info( "ldif" );
3920 if ( !cfb->cb_db.bd_info )
3921 return 0; /* FIXME: eventually this will be a fatal error */
3923 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3926 cfb->cb_db.be_suffix = be->be_suffix;
3927 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3929 /* The suffix is always "cn=config". The underlying DB's rootdn
3930 * is always the same as the suffix.
3932 cfb->cb_db.be_rootdn = be->be_suffix[0];
3933 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3935 ber_str2bv( dir, 0, 1, &cfdir );
3940 argv[0] = "directory";
3941 argv[1] = (char *)dir;
3946 c.table = Cft_Database;
3948 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3952 if ( config_add_vals( ct, &c ))
3955 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3959 void *thrctx = ldap_pvt_thread_pool_context();
3962 connection_fake_init( &conn, &opbuf, thrctx );
3965 filter.f_desc = slap_schema.si_ad_objectClass;
3967 op->o_tag = LDAP_REQ_SEARCH;
3969 op->ors_filter = &filter;
3970 op->ors_filterstr = filterstr;
3971 op->ors_scope = LDAP_SCOPE_SUBTREE;
3973 op->o_dn = c.be->be_rootdn;
3974 op->o_ndn = c.be->be_rootndn;
3976 op->o_req_dn = be->be_suffix[0];
3977 op->o_req_ndn = be->be_nsuffix[0];
3979 op->ors_tlimit = SLAP_NO_LIMIT;
3980 op->ors_slimit = SLAP_NO_LIMIT;
3982 op->ors_attrs = slap_anlist_all_attributes;
3983 op->ors_attrsonly = 0;
3985 op->o_callback = &cb;
3988 cb.sc_private = ≻
3989 sc.got_frontend = 0;
3994 op->o_bd = &cfb->cb_db;
3996 /* Allow unknown attrs in DNs */
3997 prev_DN_strict = slap_DN_strict;
4000 rc = op->o_bd->be_search( op, &rs );
4002 /* Restore normal DN validation */
4003 slap_DN_strict = prev_DN_strict;
4005 op->o_tag = LDAP_REQ_ADD;
4006 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4007 rs_reinit( &rs, REP_RESULT );
4008 op->ora_e = sc.frontend;
4009 rc = op->o_bd->be_add( op, &rs );
4011 if ( rc == LDAP_SUCCESS && sc.config ) {
4012 rs_reinit( &rs, REP_RESULT );
4013 op->ora_e = sc.config;
4014 rc = op->o_bd->be_add( op, &rs );
4016 ldap_pvt_thread_pool_context_reset( thrctx );
4019 /* ITS#4194 - only use if it's present, or we're converting. */
4020 if ( !readit || rc == LDAP_SUCCESS )
4021 cfb->cb_use_ldif = 1;
4027 CfOc_cmp( const void *c1, const void *c2 ) {
4028 const ConfigOCs *co1 = c1;
4029 const ConfigOCs *co2 = c2;
4031 return ber_bvcmp( co1->co_name, co2->co_name );
4035 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4038 i = init_config_attrs( ct );
4041 /* set up the objectclasses */
4042 i = init_config_ocs( ocs );
4045 for (i=0; ocs[i].co_def; i++) {
4046 if ( ocs[i].co_oc ) {
4047 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4048 if ( !ocs[i].co_table )
4049 ocs[i].co_table = ct;
4050 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4057 read_config(const char *fname, const char *dir) {
4060 const char *cfdir, *cfname;
4063 /* Setup the config backend */
4064 be = backend_db_init( "config", NULL, 0, NULL );
4068 cfb = be->be_private;
4069 be->be_dfltaccess = ACL_NONE;
4071 /* If no .conf, or a dir was specified, setup the dir */
4072 if ( !fname || dir ) {
4074 /* If explicitly given, check for existence */
4077 if ( stat( dir, &st ) < 0 ) {
4078 Debug( LDAP_DEBUG_ANY,
4079 "invalid config directory %s, error %d\n",
4085 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4087 /* if fname is defaulted, try reading .d */
4088 rc = config_setup_ldif( be, cfdir, !fname );
4091 /* It may be OK if the base object doesn't exist yet. */
4092 if ( rc != LDAP_NO_SUCH_OBJECT )
4094 /* ITS#4194: But if dir was specified and no fname,
4095 * then we were supposed to read the dir. Unless we're
4096 * trying to slapadd the dir...
4098 if ( dir && !fname ) {
4099 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4101 /* Assume it's slapadd with a config dir, let it continue */
4103 cfb->cb_got_ldif = 1;
4104 cfb->cb_use_ldif = 1;
4109 /* If we read the config from back-ldif, nothing to do here */
4110 if ( cfb->cb_got_ldif ) {
4119 cfname = SLAPD_DEFAULT_CONFIGFILE;
4121 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4124 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4127 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4128 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4129 &frontendDB->be_schemadn );
4130 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4131 if ( rc != LDAP_SUCCESS ) {
4132 Debug(LDAP_DEBUG_ANY, "read_config: "
4133 "unable to normalize default schema DN \"%s\"\n",
4134 frontendDB->be_schemadn.bv_val, 0, 0 );
4135 /* must not happen */
4143 config_back_bind( Operation *op, SlapReply *rs )
4145 if ( be_isroot_pw( op ) ) {
4146 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4147 /* frontend sends result */
4148 return LDAP_SUCCESS;
4151 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4152 send_ldap_result( op, rs );
4158 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4162 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4164 rs->sr_attrs = op->ors_attrs;
4165 rs->sr_entry = ce->ce_entry;
4167 rc = send_search_entry( op, rs );
4168 if ( rc != LDAP_SUCCESS ) {
4172 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4173 if ( ce->ce_kids ) {
4174 rc = config_send( op, rs, ce->ce_kids, 1 );
4175 if ( rc ) return rc;
4178 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4179 rc = config_send( op, rs, ce, 0 );
4187 static ConfigTable *
4188 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4193 for (j=0; j<nocs; j++) {
4194 for (i=0; colst[j]->co_table[i].name; i++)
4195 if ( colst[j]->co_table[i].ad == ad ) {
4196 ca->table = colst[j]->co_type;
4197 return &colst[j]->co_table[i];
4203 /* Sort the attributes of the entry according to the order defined
4204 * in the objectclass, with required attributes occurring before
4205 * allowed attributes. For any attributes with sequencing dependencies
4206 * (e.g., rootDN must be defined after suffix) the objectclass must
4207 * list the attributes in the desired sequence.
4210 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4212 Attribute *a, *head = NULL, *tail = NULL, **prev;
4215 for (i=0; i<nocs; i++) {
4216 if ( colst[i]->co_oc->soc_required ) {
4217 AttributeType **at = colst[i]->co_oc->soc_required;
4218 for (j=0; at[j]; j++) {
4219 for (a=e->e_attrs, prev=&e->e_attrs; a;
4220 prev = &(*prev)->a_next, a=a->a_next) {
4221 if ( a->a_desc == at[j]->sat_ad ) {
4235 if ( colst[i]->co_oc->soc_allowed ) {
4236 AttributeType **at = colst[i]->co_oc->soc_allowed;
4237 for (j=0; at[j]; j++) {
4238 for (a=e->e_attrs, prev=&e->e_attrs; a;
4239 prev = &(*prev)->a_next, a=a->a_next) {
4240 if ( a->a_desc == at[j]->sat_ad ) {
4256 tail->a_next = e->e_attrs;
4262 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4264 Attribute *a = NULL;
4265 AttributeDescription *ad;
4275 Modifications *ml = ptr;
4277 vals = ml->sml_values;
4280 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4281 rc = ordered_value_sort( a, 1 );
4283 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4284 ad->ad_cname.bv_val );
4288 for ( i=0; vals[i].bv_val; i++ ) {
4289 ca->line = vals[i].bv_val;
4290 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4291 ca->line[0] == '{' ) {
4292 char *idx = strchr( ca->line, '}' );
4293 if ( idx ) ca->line = idx+1;
4295 rc = config_parse_vals( ct, ca, i );
4304 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4307 struct berval rtype, rval;
4309 AttributeDescription *ad = NULL;
4311 dnRdn( &e->e_name, rdn );
4312 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4313 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4314 rtype.bv_val = rdn->bv_val;
4315 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4318 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4319 a = attr_find( e->e_attrs, ad );
4320 if (!a ) return LDAP_NAMING_VIOLATION;
4327 config_rename_kids( CfEntryInfo *ce )
4330 struct berval rdn, nrdn;
4332 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4333 struct berval newdn, newndn;
4334 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4335 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4336 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4337 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4338 free( ce2->ce_entry->e_name.bv_val );
4339 free( ce2->ce_entry->e_nname.bv_val );
4340 ce2->ce_entry->e_name = newdn;
4341 ce2->ce_entry->e_nname = newndn;
4342 config_rename_kids( ce2 );
4347 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4348 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4349 struct berval *nnewrdn, int use_ldif )
4353 struct berval odn, ondn;
4357 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4358 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4361 free( a->a_vals[0].bv_val );
4362 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4363 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4364 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4365 strcpy( a->a_vals[0].bv_val, ptr1 );
4367 if ( a->a_nvals != a->a_vals ) {
4368 free( a->a_nvals[0].bv_val );
4369 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4370 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4371 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4372 strcpy( a->a_nvals[0].bv_val, ptr1 );
4375 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4376 BackendDB *be = op->o_bd;
4377 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4378 struct berval dn, ndn, xdn, xndn;
4380 op->o_bd = &cfb->cb_db;
4382 /* Save current rootdn; use the underlying DB's rootdn */
4386 xndn = op->o_req_ndn;
4387 op->o_dn = op->o_bd->be_rootdn;
4388 op->o_ndn = op->o_bd->be_rootndn;
4390 op->o_req_ndn = ondn;
4392 scp = op->o_callback;
4393 op->o_callback = ≻
4394 op->orr_newrdn = *newrdn;
4395 op->orr_nnewrdn = *nnewrdn;
4396 op->orr_newSup = NULL;
4397 op->orr_nnewSup = NULL;
4398 op->orr_deleteoldrdn = 1;
4399 op->orr_modlist = NULL;
4400 slap_modrdn2mods( op, rs );
4401 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4402 rc = op->o_bd->be_modrdn( op, rs );
4403 slap_mods_free( op->orr_modlist, 1 );
4406 op->o_callback = scp;
4410 op->o_req_ndn = xndn;
4413 free( ondn.bv_val );
4415 config_rename_kids( e->e_private );
4420 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4421 Entry *e, int idx, int tailindex, int use_ldif )
4423 struct berval ival, newrdn, nnewrdn;
4426 char ibuf[32], *ptr1, *ptr2 = NULL;
4429 rc = config_rename_attr( rs, e, &rdn, &a );
4430 if ( rc ) return rc;
4433 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4434 if ( ival.bv_len >= sizeof( ibuf ) ) {
4435 return LDAP_NAMING_VIOLATION;
4438 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4439 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4442 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4443 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4446 ptr2 = ber_bvchr( &rdn, '}' );
4450 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4452 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4453 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4454 a->a_desc->ad_cname.bv_len );
4456 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4457 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4461 /* Do the equivalent of ModRDN */
4462 /* Replace DN / NDN */
4463 newrdn.bv_len = ptr1 - newrdn.bv_val;
4464 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4465 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4467 free( nnewrdn.bv_val );
4468 free( newrdn.bv_val );
4473 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4474 SlapReply *rs, int *renum, int *ibase )
4477 int index = -1, gotindex = 0, nsibs, rc = 0;
4478 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4479 char *ptr1, *ptr2 = NULL;
4482 if ( renum ) *renum = 0;
4484 /* These entries don't get indexed/renumbered */
4485 if ( ce_type == Cft_Global ) return 0;
4486 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4488 if ( ce_type == Cft_Module )
4491 /* See if the rdn has an index already */
4492 dnRdn( &e->e_name, &rdn );
4493 if ( ce_type == Cft_Database ) {
4494 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4495 "frontend", STRLENOF("frontend") ))
4497 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4498 "config", STRLENOF("config") ))
4501 ptr1 = ber_bvchr( &e->e_name, '{' );
4502 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4504 ptr2 = strchr( ptr1, '}' );
4505 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4506 return LDAP_NAMING_VIOLATION;
4507 if ( ptr2-ptr1 == 1)
4508 return LDAP_NAMING_VIOLATION;
4510 index = strtol( ptr1 + 1, &next, 10 );
4511 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4512 return LDAP_NAMING_VIOLATION;
4515 /* Special case, we allow -1 for the frontendDB */
4516 if ( index != -1 || !isfrontend )
4517 return LDAP_NAMING_VIOLATION;
4519 if ( isconfig && index != 0 ){
4520 return LDAP_NAMING_VIOLATION;
4524 /* count related kids */
4525 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4526 if ( ce->ce_type == ce_type ) nsibs++;
4529 /* account for -1 frontend */
4530 if ( ce_type == Cft_Database )
4533 if ( index != nsibs ) {
4535 if ( index < nsibs ) {
4536 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4537 /* Siblings need to be renumbered */
4538 if ( index != -1 || !isfrontend )
4542 /* config DB is always "0" */
4543 if ( isconfig && index == -1 ) {
4546 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4550 /* just make index = nsibs */
4552 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4555 if ( ibase ) *ibase = index;
4556 if ( renum ) *renum = renumber;
4561 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4566 co.co_name = &oc->soc_cname;
4567 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4571 /* check for duplicates */
4572 for ( i = 0; i < *nocs; i++ ) {
4573 if ( *copp && (*copp)[i] == cop ) {
4579 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4580 if ( tmp == NULL ) {
4584 (*copp)[*nocs] = cop;
4589 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4590 if ( count_oc( *sups, copp, nocs ) ) {
4599 count_ocs( Attribute *oc_at, int *nocs )
4602 ConfigOCs **colst = NULL;
4606 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4610 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4612 assert( oc != NULL );
4613 if ( count_oc( oc, &colst, nocs ) ) {
4623 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4625 /* Leftover from RE23. Never parse this entry */
4626 return LDAP_COMPARE_TRUE;
4630 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4634 /* This entry is hardcoded, don't re-parse it */
4635 if ( p->ce_type == Cft_Global ) {
4636 cfn = p->ce_private;
4637 ca->ca_private = cfn;
4638 return LDAP_COMPARE_TRUE;
4640 if ( p->ce_type != Cft_Schema )
4641 return LDAP_CONSTRAINT_VIOLATION;
4643 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4644 ca->ca_private = cfn;
4645 cfo = p->ce_private;
4646 cfn->c_sibs = cfo->c_kids;
4648 return LDAP_SUCCESS;
4652 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4654 if ( p->ce_type != Cft_Global ) {
4655 return LDAP_CONSTRAINT_VIOLATION;
4657 /* config must be {0}, nothing else allowed */
4658 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4659 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4660 return LDAP_CONSTRAINT_VIOLATION;
4662 ca->be = frontendDB; /* just to get past check_vals */
4663 return LDAP_SUCCESS;
4667 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4669 if ( p->ce_type != Cft_Global ) {
4670 return LDAP_CONSTRAINT_VIOLATION;
4672 return LDAP_SUCCESS;
4676 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4678 if ( p->ce_type != Cft_Global ) {
4679 return LDAP_CONSTRAINT_VIOLATION;
4681 return LDAP_SUCCESS;
4685 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4687 if ( p->ce_type != Cft_Database ) {
4688 return LDAP_CONSTRAINT_VIOLATION;
4691 return LDAP_SUCCESS;
4695 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4700 AttributeDescription *ad;
4706 if ( cfn->c_cr_head ) {
4707 struct berval bv = BER_BVC("olcDitContentRules");
4709 slap_bv2ad( &bv, &ad, &text );
4710 ct = config_find_table( colst, nocs, ad, ca );
4711 config_del_vals( ct, ca );
4713 if ( cfn->c_oc_head ) {
4714 struct berval bv = BER_BVC("olcObjectClasses");
4716 slap_bv2ad( &bv, &ad, &text );
4717 ct = config_find_table( colst, nocs, ad, ca );
4718 config_del_vals( ct, ca );
4720 if ( cfn->c_at_head ) {
4721 struct berval bv = BER_BVC("olcAttributeTypes");
4723 slap_bv2ad( &bv, &ad, &text );
4724 ct = config_find_table( colst, nocs, ad, ca );
4725 config_del_vals( ct, ca );
4727 if ( cfn->c_syn_head ) {
4728 struct berval bv = BER_BVC("olcLdapSyntaxes");
4730 slap_bv2ad( &bv, &ad, &text );
4731 ct = config_find_table( colst, nocs, ad, ca );
4732 config_del_vals( ct, ca );
4734 if ( cfn->c_om_head ) {
4735 struct berval bv = BER_BVC("olcObjectIdentifier");
4737 slap_bv2ad( &bv, &ad, &text );
4738 ct = config_find_table( colst, nocs, ad, ca );
4739 config_del_vals( ct, ca );
4741 cfo = p->ce_private;
4742 cfo->c_kids = cfn->c_sibs;
4747 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4749 int rc = LDAP_CONSTRAINT_VIOLATION;
4752 if ( (*cop)->co_ldadd ) {
4753 rc = (*cop)->co_ldadd( last, e, ca );
4754 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4759 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4760 ConfigOCs co = { 0 };
4762 co.co_name = &(*ocp)->soc_cname;
4763 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4764 if ( *cop == NULL ) {
4768 rc = config_add_oc( cop, last, e, ca );
4769 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4777 /* Parse an LDAP entry into config directives */
4779 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4780 int *renum, Operation *op )
4782 CfEntryInfo *ce, *last = NULL;
4783 ConfigOCs co, *coptr, **colst;
4784 Attribute *a, *oc_at, *soc_at;
4785 int i, ibase = -1, nocs, rc = 0;
4788 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4790 memset( ca, 0, sizeof(ConfigArgs));
4792 /* Make sure parent exists and entry does not. But allow
4793 * Databases and Overlays to be inserted. Don't do any
4794 * auto-renumbering if manageDSAit control is present.
4796 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4798 if ( ( op && op->o_managedsait ) ||
4799 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4800 ce->ce_type != Cft_Module ) )
4802 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4803 "DN=\"%s\" already exists\n",
4804 log_prefix, e->e_name.bv_val, 0 );
4805 /* global schema ignores all writes */
4806 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4807 return LDAP_COMPARE_TRUE;
4808 return LDAP_ALREADY_EXISTS;
4812 dnParent( &e->e_nname, &pdn );
4814 /* If last is NULL, the new entry is the root/suffix entry,
4815 * otherwise last should be the parent.
4817 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4819 rs->sr_matched = last->ce_entry->e_name.bv_val;
4821 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4822 "DN=\"%s\" not child of DN=\"%s\"\n",
4823 log_prefix, e->e_name.bv_val,
4824 last->ce_entry->e_name.bv_val );
4825 return LDAP_NO_SUCH_OBJECT;
4829 /* No parent, must be root. This will never happen... */
4830 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4831 return LDAP_NO_SUCH_OBJECT;
4834 if ( last && !access_allowed( op, last->ce_entry,
4835 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4837 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4838 "DN=\"%s\" no write access to \"children\" of parent\n",
4839 log_prefix, e->e_name.bv_val, 0 );
4840 return LDAP_INSUFFICIENT_ACCESS;
4844 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4846 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4847 "DN=\"%s\" no objectClass\n",
4848 log_prefix, e->e_name.bv_val, 0 );
4849 return LDAP_OBJECT_CLASS_VIOLATION;
4852 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4854 ObjectClass *soc = NULL;
4855 char textbuf[ SLAP_TEXT_BUFLEN ];
4856 const char *text = textbuf;
4858 /* FIXME: check result */
4859 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4860 &text, textbuf, sizeof(textbuf), NULL );
4861 if ( rc != LDAP_SUCCESS ) {
4862 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4863 "DN=\"%s\" no structural objectClass (%s)\n",
4864 log_prefix, e->e_name.bv_val, text );
4867 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4868 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4869 if ( soc_at == NULL ) {
4870 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4871 "DN=\"%s\" no structural objectClass; "
4872 "unable to merge computed class %s\n",
4873 log_prefix, e->e_name.bv_val,
4874 soc->soc_cname.bv_val );
4875 return LDAP_OBJECT_CLASS_VIOLATION;
4878 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4879 "DN=\"%s\" no structural objectClass; "
4880 "computed objectClass %s merged\n",
4881 log_prefix, e->e_name.bv_val,
4882 soc->soc_cname.bv_val );
4885 /* Fake the coordinates based on whether we're part of an
4886 * LDAP Add or if reading the config dir
4889 ca->fname = "slapd";
4892 ca->fname = cfdir.bv_val;
4897 co.co_name = &soc_at->a_nvals[0];
4898 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4899 if ( coptr == NULL ) {
4900 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4901 "DN=\"%s\" no structural objectClass in configuration table\n",
4902 log_prefix, e->e_name.bv_val, 0 );
4903 return LDAP_OBJECT_CLASS_VIOLATION;
4906 /* Only the root can be Cft_Global, everything else must
4907 * have a parent. Only limited nesting arrangements are allowed.
4909 rc = LDAP_CONSTRAINT_VIOLATION;
4910 if ( coptr->co_type == Cft_Global && !last ) {
4911 cfn = cfb->cb_config;
4912 ca->ca_private = cfn;
4913 ca->be = frontendDB; /* just to get past check_vals */
4917 colst = count_ocs( oc_at, &nocs );
4919 /* Check whether the Add is allowed by its parent, and do
4920 * any necessary arg setup
4923 rc = config_add_oc( &coptr, last, e, ca );
4924 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4925 for ( i = 0; i<nocs; i++ ) {
4926 /* Already checked these */
4927 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4929 if ( colst[i]->co_ldadd &&
4930 ( rc = colst[i]->co_ldadd( last, e, ca ))
4931 != LDAP_CONSTRAINT_VIOLATION ) {
4937 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4938 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4939 "DN=\"%s\" no structural objectClass add function\n",
4940 log_prefix, e->e_name.bv_val, 0 );
4941 return LDAP_OBJECT_CLASS_VIOLATION;
4945 /* Add the entry but don't parse it, we already have its contents */
4946 if ( rc == LDAP_COMPARE_TRUE ) {
4951 if ( rc != LDAP_SUCCESS )
4954 /* Parse all the values and check for simple syntax errors before
4955 * performing any set actions.
4957 * If doing an LDAPadd, check for indexed names and any necessary
4958 * renaming/renumbering. Entries that don't need indexed names are
4959 * ignored. Entries that need an indexed name and arrive without one
4960 * are assigned to the end. Entries that arrive with an index may
4961 * cause the following entries to be renumbered/bumped down.
4963 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4964 * don't allow Adding an entry with an index that's already in use.
4965 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4967 * These entries can have auto-assigned indexes (appended to the end)
4968 * but only the other types support auto-renumbering of siblings.
4971 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4976 if ( renum && *renum && coptr->co_type != Cft_Database &&
4977 coptr->co_type != Cft_Overlay )
4979 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4980 "operation requires sibling renumbering" );
4981 rc = LDAP_UNWILLING_TO_PERFORM;
4986 init_config_argv( ca );
4988 /* Make sure we process attrs in the required order */
4989 sort_attrs( e, colst, nocs );
4991 for ( a = e->e_attrs; a; a = a->a_next ) {
4992 if ( a == oc_at ) continue;
4993 ct = config_find_table( colst, nocs, a->a_desc, ca );
4994 if ( !ct ) continue; /* user data? */
4995 rc = check_vals( ct, ca, a, 1 );
4996 if ( rc ) goto done_noop;
4999 /* Basic syntax checks are OK. Do the actual settings. */
5000 for ( a=e->e_attrs; a; a=a->a_next ) {
5001 if ( a == oc_at ) continue;
5002 ct = config_find_table( colst, nocs, a->a_desc, ca );
5003 if ( !ct ) continue; /* user data? */
5004 for (i=0; a->a_vals[i].bv_val; i++) {
5007 ca->line = a->a_vals[i].bv_val;
5008 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5009 ptr = strchr( ca->line, '}' );
5011 iptr = strchr( ca->line, '{' );
5015 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5017 ca->valx = strtol( iptr+1, NULL, 0 );
5022 rc = config_parse_add( ct, ca, i );
5030 /* Newly added databases and overlays need to be started up */
5031 if ( CONFIG_ONLINE_ADD( ca )) {
5032 if ( coptr->co_type == Cft_Database ) {
5033 rc = backend_startup_one( ca->be, &ca->reply );
5035 } else if ( coptr->co_type == Cft_Overlay ) {
5036 if ( ca->bi->bi_db_open ) {
5037 BackendInfo *bi_orig = ca->be->bd_info;
5038 ca->be->bd_info = ca->bi;
5039 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5040 ca->be->bd_info = bi_orig;
5042 } else if ( ca->cleanup ) {
5043 rc = ca->cleanup( ca );
5046 if (ca->cr_msg[0] == '\0')
5047 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5049 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5050 ca->log, ca->cr_msg, ca->argv[1] );
5057 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5058 ce->ce_parent = last;
5059 ce->ce_entry = entry_dup( e );
5060 ce->ce_entry->e_private = ce;
5061 ce->ce_type = coptr->co_type;
5064 ce->ce_private = ca->ca_private;
5065 ca->ca_entry = ce->ce_entry;
5068 } else if ( last->ce_kids ) {
5069 CfEntryInfo *c2, **cprev;
5071 /* Advance to first of this type */
5072 cprev = &last->ce_kids;
5073 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5074 cprev = &c2->ce_sibs;
5077 /* Account for the (-1) frontendDB entry */
5078 if ( ce->ce_type == Cft_Database ) {
5079 if ( ca->be == frontendDB )
5081 else if ( ibase != -1 )
5086 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5087 cprev = &c2->ce_sibs;
5093 for ( i=0; i<ibase; i++ ) {
5095 cprev = &c2->ce_sibs;
5098 ce->ce_sibs = *cprev;
5106 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5107 if ( ca->be != frontendDB )
5108 backend_destroy_one( ca->be, 1 );
5109 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5110 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5111 } else if ( coptr->co_type == Cft_Schema ) {
5112 schema_destroy_one( ca, colst, nocs, last );
5117 ch_free( ca->argv );
5118 if ( colst ) ch_free( colst );
5122 #define BIGTMP 10000
5124 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5125 int base, int rebase, int max, int use_ldif )
5127 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5128 ConfigType etype = ce->ce_type;
5129 int count = 0, rc = 0;
5131 /* Reverse ce list */
5132 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5133 if (ce2->ce_type != etype) {
5138 ce2->ce_sibs = cetmp;
5141 if ( max && count >= max ) {
5147 /* Move original to a temp name until increments are done */
5149 ce->ce_entry->e_private = NULL;
5150 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5151 base+BIGTMP, 0, use_ldif );
5152 ce->ce_entry->e_private = ce;
5154 /* start incrementing */
5155 for (ce2=cetmp; ce2; ce2=ce3) {
5157 ce2->ce_sibs = cerem;
5160 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5161 count+base, 0, use_ldif );
5165 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5166 base, 0, use_ldif );
5171 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5172 CfEntryInfo *ce2, int old, int use_ldif )
5176 /* Renumber original to a temp value */
5177 ce->ce_entry->e_private = NULL;
5178 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5179 old+BIGTMP, 0, use_ldif );
5180 ce->ce_entry->e_private = ce;
5182 /* start decrementing */
5183 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5184 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5185 count+old, 0, use_ldif );
5188 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5189 count+old, 0, use_ldif );
5192 /* Parse an LDAP entry into config directives, then store in underlying
5196 config_back_add( Operation *op, SlapReply *rs )
5202 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5203 NULL, ACL_WADD, NULL )) {
5204 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5209 * Check for attribute ACL
5211 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5212 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5213 rs->sr_text = "no write access to attribute";
5217 cfb = (CfBackInfo *)op->o_bd->be_private;
5219 /* add opattrs for syncprov */
5221 char textbuf[SLAP_TEXT_BUFLEN];
5222 size_t textlen = sizeof textbuf;
5223 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5224 &rs->sr_text, textbuf, sizeof( textbuf ) );
5225 if ( rs->sr_err != LDAP_SUCCESS )
5227 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5228 if ( rs->sr_err != LDAP_SUCCESS ) {
5229 Debug( LDAP_DEBUG_TRACE,
5230 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5231 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5236 if ( op->o_abandon ) {
5237 rs->sr_err = SLAPD_ABANDON;
5240 ldap_pvt_thread_pool_pause( &connection_pool );
5243 * 1) check for existence of entry
5244 * 2) check for sibling renumbering
5245 * 3) perform internal add
5246 * 4) perform any necessary renumbering
5247 * 5) store entry in underlying database
5249 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5250 if ( rs->sr_err != LDAP_SUCCESS ) {
5251 rs->sr_text = ca.cr_msg;
5256 CfEntryInfo *ce = ca.ca_entry->e_private;
5257 req_add_s addr = op->oq_add;
5258 op->o_tag = LDAP_REQ_MODRDN;
5259 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5260 op->o_tag = LDAP_REQ_ADD;
5262 if ( rs->sr_err != LDAP_SUCCESS ) {
5267 if ( cfb->cb_use_ldif ) {
5268 BackendDB *be = op->o_bd;
5269 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5270 struct berval dn, ndn;
5272 op->o_bd = &cfb->cb_db;
5274 /* Save current rootdn; use the underlying DB's rootdn */
5277 op->o_dn = op->o_bd->be_rootdn;
5278 op->o_ndn = op->o_bd->be_rootndn;
5280 scp = op->o_callback;
5281 op->o_callback = ≻
5282 op->o_bd->be_add( op, rs );
5284 op->o_callback = scp;
5290 ldap_pvt_thread_pool_resume( &connection_pool );
5293 { int repl = op->o_dont_replicate;
5294 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5295 rs->sr_text = NULL; /* Set after config_add_internal */
5296 rs->sr_err = LDAP_SUCCESS;
5297 op->o_dont_replicate = 1;
5299 send_ldap_result( op, rs );
5300 op->o_dont_replicate = repl;
5302 slap_graduate_commit_csn( op );
5306 typedef struct delrec {
5307 struct delrec *next;
5313 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5319 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5320 ca->line[0] == '{' )
5322 char *ptr = strchr( ca->line + 1, '}' );
5326 ca->valx = strtol( ca->line + 1, &next, 0 );
5327 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5333 rc = config_parse_add( ct, ca, i );
5341 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5344 int rc = LDAP_UNWILLING_TO_PERFORM;
5346 Entry *e = ce->ce_entry;
5347 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5352 delrec *dels = NULL, *deltail = NULL;
5354 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5355 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5357 colst = count_ocs( oc_at, &nocs );
5359 /* make sure add/del flags are clear; should always be true */
5360 for ( s = save_attrs; s; s = s->a_next ) {
5361 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5364 e->e_attrs = attrs_dup( e->e_attrs );
5366 init_config_argv( ca );
5369 ca->ca_private = ce->ce_private;
5371 ca->fname = "slapd";
5373 strcpy( ca->log, "back-config" );
5375 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5376 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5377 switch (ml->sml_op) {
5378 case LDAP_MOD_DELETE:
5379 case LDAP_MOD_REPLACE: {
5380 BerVarray vals = NULL, nvals = NULL;
5382 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5384 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5385 ml->sml_desc->ad_cname.bv_val );
5388 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5389 vals = ml->sml_values;
5390 nvals = ml->sml_nvalues;
5391 ml->sml_values = NULL;
5392 ml->sml_nvalues = NULL;
5394 /* If we're deleting by values, remember the indexes of the
5395 * values we deleted.
5397 if ( ct && ml->sml_values ) {
5399 i = ml->sml_numvals;
5400 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5411 rc = modify_delete_vindex(e, &ml->sml_mod,
5412 get_permissiveModify(op),
5413 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5414 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5415 ml->sml_values = vals;
5416 ml->sml_nvalues = nvals;
5421 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5424 case SLAP_MOD_SOFTADD: {
5425 int mop = ml->sml_op;
5427 ml->sml_op = LDAP_MOD_ADD;
5429 if ( ct->arg_type & ARG_NO_INSERT ) {
5430 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5432 navals = a->a_numvals;
5435 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5436 if ( ml->sml_values[i].bv_val[0] == '{' &&
5439 char *next, *val = ml->sml_values[i].bv_val + 1;
5442 j = strtol( val, &next, 0 );
5443 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5445 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5446 ml->sml_desc->ad_cname.bv_val );
5450 rc = check_vals( ct, ca, ml, 0 );
5451 if ( rc ) goto out_noop;
5454 rc = modify_add_values(e, &ml->sml_mod,
5455 get_permissiveModify(op),
5456 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5458 /* If value already exists, show success here
5459 * and ignore this operation down below.
5461 if ( mop == SLAP_MOD_SOFTADD ) {
5462 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5472 case LDAP_MOD_INCREMENT: /* FIXME */
5477 if(rc != LDAP_SUCCESS) break;
5480 if ( rc == LDAP_SUCCESS) {
5481 /* check that the entry still obeys the schema */
5482 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5483 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5485 if ( rc ) goto out_noop;
5487 /* Basic syntax checks are OK. Do the actual settings. */
5488 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5489 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5490 if ( !ct ) continue;
5492 s = attr_find( save_attrs, ml->sml_desc );
5493 a = attr_find( e->e_attrs, ml->sml_desc );
5495 switch (ml->sml_op) {
5496 case LDAP_MOD_DELETE:
5497 case LDAP_MOD_REPLACE: {
5498 BerVarray vals = NULL, nvals = NULL;
5501 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5502 vals = ml->sml_values;
5503 nvals = ml->sml_nvalues;
5504 ml->sml_values = NULL;
5505 ml->sml_nvalues = NULL;
5508 if ( ml->sml_values )
5511 /* If we didn't delete the whole attribute */
5512 if ( ml->sml_values && a ) {
5513 struct berval *mvals;
5516 if ( ml->sml_nvalues )
5517 mvals = ml->sml_nvalues;
5519 mvals = ml->sml_values;
5521 /* use the indexes we saved up above */
5522 for (i=0; i < d->nidx; i++) {
5523 struct berval bv = *mvals++;
5524 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5525 bv.bv_val[0] == '{' ) {
5526 ptr = strchr( bv.bv_val, '}' ) + 1;
5527 bv.bv_len -= ptr - bv.bv_val;
5530 ca->line = bv.bv_val;
5531 ca->valx = d->idx[i];
5532 config_parse_vals(ct, ca, d->idx[i] );
5533 rc = config_del_vals( ct, ca );
5534 if ( rc != LDAP_SUCCESS ) break;
5536 s->a_flags |= SLAP_ATTR_IXDEL;
5537 for (j=i+1; j < d->nidx; j++)
5538 if ( d->idx[j] >d->idx[i] )
5545 rc = config_del_vals( ct, ca );
5546 if ( rc ) rc = LDAP_OTHER;
5548 s->a_flags |= SLAP_ATTR_IXDEL;
5550 if ( ml->sml_values ) {
5555 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5556 ml->sml_values = vals;
5557 ml->sml_nvalues = nvals;
5559 if ( !vals || rc != LDAP_SUCCESS )
5562 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5565 for (i=0; ml->sml_values[i].bv_val; i++) {
5566 ca->line = ml->sml_values[i].bv_val;
5568 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5571 a->a_flags |= SLAP_ATTR_IXADD;
5578 /* Undo for a failed operation */
5579 if ( rc != LDAP_SUCCESS ) {
5580 ConfigReply msg = ca->reply;
5581 for ( s = save_attrs; s; s = s->a_next ) {
5582 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5583 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5584 ct = config_find_table( colst, nocs, s->a_desc, ca );
5585 a = attr_find( e->e_attrs, s->a_desc );
5587 /* clear the flag so the add check below will skip it */
5588 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5592 config_del_vals( ct, ca );
5594 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5595 ca->line = s->a_vals[i].bv_val;
5597 config_modify_add( ct, ca, s->a_desc, i );
5601 for ( a = e->e_attrs; a; a = a->a_next ) {
5602 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5603 ct = config_find_table( colst, nocs, a->a_desc, ca );
5607 config_del_vals( ct, ca );
5608 s = attr_find( save_attrs, a->a_desc );
5610 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5611 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5612 ca->line = s->a_vals[i].bv_val;
5614 config_modify_add( ct, ca, s->a_desc, i );
5625 if ( rc == LDAP_SUCCESS ) {
5626 attrs_free( save_attrs );
5629 attrs_free( e->e_attrs );
5630 e->e_attrs = save_attrs;
5632 ch_free( ca->argv );
5633 if ( colst ) ch_free( colst );
5635 deltail = dels->next;
5644 config_back_modify( Operation *op, SlapReply *rs )
5647 CfEntryInfo *ce, *last;
5649 ConfigArgs ca = {0};
5652 AttributeDescription *rad = NULL;
5655 cfb = (CfBackInfo *)op->o_bd->be_private;
5657 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5660 rs->sr_matched = last->ce_entry->e_name.bv_val;
5661 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5665 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5666 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5670 /* Get type of RDN */
5671 rdn = ce->ce_entry->e_nname;
5672 ptr = strchr( rdn.bv_val, '=' );
5673 rdn.bv_len = ptr - rdn.bv_val;
5674 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5675 if ( rs->sr_err != LDAP_SUCCESS ) {
5679 /* Some basic validation... */
5680 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5681 /* Don't allow Modify of RDN; must use ModRdn for that. */
5682 if ( ml->sml_desc == rad ) {
5683 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5684 rs->sr_text = "Use modrdn to change the entry name";
5687 /* Internal update of contextCSN? */
5688 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5694 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5697 if ( op->o_abandon ) {
5698 rs->sr_err = SLAPD_ABANDON;
5701 ldap_pvt_thread_pool_pause( &connection_pool );
5705 * 1) perform the Modify on the cached Entry.
5706 * 2) verify that the Entry still satisfies the schema.
5707 * 3) perform the individual config operations.
5708 * 4) store Modified entry in underlying LDIF backend.
5710 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5712 rs->sr_text = ca.cr_msg;
5713 } else if ( cfb->cb_use_ldif ) {
5714 BackendDB *be = op->o_bd;
5715 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5716 struct berval dn, ndn;
5718 op->o_bd = &cfb->cb_db;
5722 op->o_dn = op->o_bd->be_rootdn;
5723 op->o_ndn = op->o_bd->be_rootndn;
5725 scp = op->o_callback;
5726 op->o_callback = ≻
5727 op->o_bd->be_modify( op, rs );
5729 op->o_callback = scp;
5735 ldap_pvt_thread_pool_resume( &connection_pool );
5737 send_ldap_result( op, rs );
5738 slap_graduate_commit_csn( op );
5743 config_back_modrdn( Operation *op, SlapReply *rs )
5746 CfEntryInfo *ce, *last;
5750 cfb = (CfBackInfo *)op->o_bd->be_private;
5752 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5755 rs->sr_matched = last->ce_entry->e_name.bv_val;
5756 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5759 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5760 NULL, ACL_WRITE, NULL )) {
5761 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5765 if ( ce->ce_parent )
5766 parent = ce->ce_parent->ce_entry;
5768 parent = (Entry *)&slap_entry_root;
5769 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5770 NULL, ACL_WRITE, NULL )) {
5771 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5776 /* We don't allow moving objects to new parents.
5777 * Generally we only allow reordering a set of ordered entries.
5779 if ( op->orr_newSup ) {
5780 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5784 /* If newRDN == oldRDN, quietly succeed */
5785 dnRdn( &op->o_req_ndn, &rdn );
5786 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5787 rs->sr_err = LDAP_SUCCESS;
5791 /* Current behavior, subject to change as needed:
5793 * For backends and overlays, we only allow renumbering.
5794 * For schema, we allow renaming with the same number.
5795 * Otherwise, the op is not allowed.
5798 if ( ce->ce_type == Cft_Schema ) {
5802 /* Can't alter the main cn=schema entry */
5803 if ( ce->ce_parent->ce_type == Cft_Global ) {
5804 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5805 rs->sr_text = "renaming not allowed for this entry";
5809 /* We could support this later if desired */
5810 ptr1 = ber_bvchr( &rdn, '}' );
5811 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5812 len = ptr1 - rdn.bv_val;
5813 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5814 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5815 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5816 rs->sr_text = "schema reordering not supported";
5819 } else if ( ce->ce_type == Cft_Database ||
5820 ce->ce_type == Cft_Overlay ) {
5821 char *ptr1, *ptr2, *iptr1, *iptr2;
5824 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5825 if ( *iptr2 != '{' ) {
5826 rs->sr_err = LDAP_NAMING_VIOLATION;
5827 rs->sr_text = "new ordering index is required";
5831 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5832 ptr1 = ber_bvchr( &rdn, '}' );
5833 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5835 rs->sr_err = LDAP_NAMING_VIOLATION;
5836 rs->sr_text = "new ordering index is required";
5840 len1 = ptr1 - rdn.bv_val;
5841 len2 = ptr2 - op->orr_newrdn.bv_val;
5843 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5844 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5845 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5846 rs->sr_text = "changing database/overlay type not allowed";
5849 ixold = strtol( iptr1, NULL, 0 );
5850 ixnew = strtol( iptr2, &ptr1, 0 );
5851 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5852 rs->sr_err = LDAP_NAMING_VIOLATION;
5855 /* config DB is always 0, cannot be changed */
5856 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5857 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5861 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5862 rs->sr_text = "renaming not supported for this entry";
5866 if ( op->o_abandon ) {
5867 rs->sr_err = SLAPD_ABANDON;
5870 ldap_pvt_thread_pool_pause( &connection_pool );
5872 if ( ce->ce_type == Cft_Schema ) {
5873 req_modrdn_s modr = op->oq_modrdn;
5876 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5877 if ( rs->sr_err == LDAP_SUCCESS ) {
5878 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5879 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5882 op->oq_modrdn = modr;
5884 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5885 req_modrdn_s modr = op->oq_modrdn;
5888 /* Advance to first of this type */
5889 cprev = &ce->ce_parent->ce_kids;
5890 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5891 cprev = &ce2->ce_sibs;
5894 /* Skip the -1 entry */
5895 if ( ce->ce_type == Cft_Database ) {
5896 cprev = &ce2->ce_sibs;
5902 /* Remove from old slot */
5903 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5904 cprev = &ce2->ce_sibs;
5905 *cprev = ce->ce_sibs;
5906 ceold = ce->ce_sibs;
5908 /* Insert into new slot */
5910 for ( i=0; i<ixnew; i++ ) {
5914 cprev = &ce2->ce_sibs;
5916 ce->ce_sibs = *cprev;
5921 /* NOTE: These should be encoded in the OC tables, not inline here */
5922 if ( ce->ce_type == Cft_Database )
5923 backend_db_move( ce->ce_be, ixnew );
5924 else if ( ce->ce_type == Cft_Overlay )
5925 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5927 if ( ixold < ixnew ) {
5928 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5931 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5932 ixold - ixnew, cfb->cb_use_ldif );
5934 op->oq_modrdn = modr;
5937 ldap_pvt_thread_pool_resume( &connection_pool );
5939 send_ldap_result( op, rs );
5944 config_back_delete( Operation *op, SlapReply *rs )
5946 #ifdef SLAP_CONFIG_DELETE
5948 CfEntryInfo *ce, *last, *ce2;
5950 cfb = (CfBackInfo *)op->o_bd->be_private;
5952 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5955 rs->sr_matched = last->ce_entry->e_name.bv_val;
5956 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5957 } else if ( ce->ce_kids ) {
5958 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5959 } else if ( op->o_abandon ) {
5960 rs->sr_err = SLAPD_ABANDON;
5961 } else if ( ce->ce_type == Cft_Overlay ){
5965 ldap_pvt_thread_pool_pause( &connection_pool );
5967 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5969 /* remove CfEntryInfo from the siblings list */
5970 if ( ce->ce_parent->ce_kids == ce ) {
5971 ce->ce_parent->ce_kids = ce->ce_sibs;
5973 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5974 if ( ce2->ce_sibs == ce ) {
5975 ce2->ce_sibs = ce->ce_sibs;
5981 /* remove from underlying database */
5982 if ( cfb->cb_use_ldif ) {
5983 BackendDB *be = op->o_bd;
5984 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5985 struct berval dn, ndn, req_dn, req_ndn;
5987 op->o_bd = &cfb->cb_db;
5991 req_dn = op->o_req_dn;
5992 req_ndn = op->o_req_ndn;
5994 op->o_dn = op->o_bd->be_rootdn;
5995 op->o_ndn = op->o_bd->be_rootndn;
5996 op->o_req_dn = ce->ce_entry->e_name;
5997 op->o_req_ndn = ce->ce_entry->e_nname;
5999 scp = op->o_callback;
6000 op->o_callback = ≻
6001 op->o_bd->be_delete( op, rs );
6003 op->o_callback = scp;
6006 op->o_req_dn = req_dn;
6007 op->o_req_ndn = req_ndn;
6010 /* renumber siblings */
6011 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6012 ixold = strtol( iptr, NULL, 0 );
6013 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6014 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6015 count+ixold, 0, cfb->cb_use_ldif );
6019 ce->ce_entry->e_private=NULL;
6020 entry_free(ce->ce_entry);
6022 ldap_pvt_thread_pool_resume( &connection_pool );
6024 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6027 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6028 #endif /* SLAP_CONFIG_DELETE */
6029 send_ldap_result( op, rs );
6034 config_back_search( Operation *op, SlapReply *rs )
6037 CfEntryInfo *ce, *last;
6040 cfb = (CfBackInfo *)op->o_bd->be_private;
6042 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6045 rs->sr_matched = last->ce_entry->e_name.bv_val;
6046 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6049 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6050 ACL_SEARCH, NULL, &mask ))
6052 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6053 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6055 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6059 switch ( op->ors_scope ) {
6060 case LDAP_SCOPE_BASE:
6061 case LDAP_SCOPE_SUBTREE:
6062 rs->sr_err = config_send( op, rs, ce, 0 );
6065 case LDAP_SCOPE_ONELEVEL:
6066 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6067 rs->sr_err = config_send( op, rs, ce, 1 );
6076 send_ldap_result( op, rs );
6080 /* no-op, we never free entries */
6081 int config_entry_release(
6086 if ( !e->e_private ) {
6089 return LDAP_SUCCESS;
6092 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6094 int config_back_entry_get(
6098 AttributeDescription *at,
6103 CfEntryInfo *ce, *last;
6104 int rc = LDAP_NO_SUCH_OBJECT;
6106 cfb = (CfBackInfo *)op->o_bd->be_private;
6108 ce = config_find_base( cfb->cb_root, ndn, &last );
6110 *ent = ce->ce_entry;
6113 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6114 rc = LDAP_NO_SUCH_ATTRIBUTE;
6124 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6125 ConfigTable *ct, ConfigArgs *c )
6129 for (; at && *at; at++) {
6130 /* Skip the naming attr */
6131 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6133 for (i=0;ct[i].name;i++) {
6134 if (ct[i].ad == (*at)->sat_ad) {
6135 rc = config_get_vals(&ct[i], c);
6136 /* NOTE: tolerate that config_get_vals()
6137 * returns success with no values */
6138 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6139 if ( c->rvalue_nvals )
6140 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6143 slap_syntax_validate_func *validate =
6144 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6147 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6148 rc = ordered_value_validate( ct[i].ad,
6149 &c->rvalue_vals[j], LDAP_MOD_ADD );
6151 Debug( LDAP_DEBUG_ANY,
6152 "config_build_attrs: error %d on %s value #%d\n",
6153 rc, ct[i].ad->ad_cname.bv_val, j );
6159 rc = attr_merge_normalize(e, ct[i].ad,
6160 c->rvalue_vals, NULL);
6162 ber_bvarray_free( c->rvalue_nvals );
6163 ber_bvarray_free( c->rvalue_vals );
6165 Debug( LDAP_DEBUG_ANY,
6166 "config_build_attrs: error %d on %s\n",
6167 rc, ct[i].ad->ad_cname.bv_val, 0 );
6178 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6181 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6182 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6184 Entry *e = entry_alloc();
6185 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6187 struct berval ad_name;
6188 AttributeDescription *ad = NULL;
6191 const char *text = "";
6195 CfEntryInfo *ceprev = NULL;
6197 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6200 ce->ce_type = main->co_type;
6201 ce->ce_parent = parent;
6203 pdn = parent->ce_entry->e_nname;
6204 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6205 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6206 ceprev->ce_type <= ce->ce_type;
6207 ceprev = ceprev->ce_sibs );
6212 ce->ce_private = c->ca_private;
6216 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6217 ber_dupbv( &e->e_nname, &e->e_name );
6219 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6220 main->co_name, NULL );
6222 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6223 extra->co_name, NULL );
6224 ptr = strchr(rdn->bv_val, '=');
6225 ad_name.bv_val = rdn->bv_val;
6226 ad_name.bv_len = ptr - rdn->bv_val;
6227 rc = slap_bv2ad( &ad_name, &ad, &text );
6232 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6233 attr_merge_normalize_one(e, ad, &val, NULL );
6236 c->table = main->co_type;
6237 if ( oc->soc_required ) {
6238 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6239 if ( rc ) goto fail;
6242 if ( oc->soc_allowed ) {
6243 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6244 if ( rc ) goto fail;
6249 c->table = extra->co_type;
6250 if ( oc->soc_required ) {
6251 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6252 if ( rc ) goto fail;
6255 if ( oc->soc_allowed ) {
6256 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6257 if ( rc ) goto fail;
6261 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6262 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6263 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6264 if ( rc != LDAP_SUCCESS ) {
6266 Debug( LDAP_DEBUG_ANY,
6267 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6268 rdn->bv_val, text, 0);
6271 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6274 op->ora_modlist = NULL;
6275 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6276 if ( !op->o_noop ) {
6277 SlapReply rs2 = {REP_RESULT};
6278 op->o_bd->be_add( op, &rs2 );
6279 rs->sr_err = rs2.sr_err;
6280 rs_assert_done( &rs2 );
6281 if ( ( rs2.sr_err != LDAP_SUCCESS )
6282 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6288 ce->ce_sibs = ceprev->ce_sibs;
6289 ceprev->ce_sibs = ce;
6290 } else if ( parent ) {
6291 ce->ce_sibs = parent->ce_kids;
6292 parent->ce_kids = ce;
6299 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6300 Operation *op, SlapReply *rs )
6303 ConfigFile *cf = c->ca_private;
6305 struct berval bv, rdn;
6307 for (; cf; cf=cf->c_sibs, c->depth++) {
6308 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6309 !cf->c_om_head && !cf->c_syn_head ) continue;
6310 c->value_dn.bv_val = c->log;
6311 LUTIL_SLASHPATH( cf->c_file.bv_val );
6312 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6317 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6319 ptr = strchr( bv.bv_val, '.' );
6321 bv.bv_len = ptr - bv.bv_val;
6322 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6323 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6324 /* FIXME: how can indicate error? */
6327 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6329 c->value_dn.bv_len += bv.bv_len;
6330 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6334 e = config_build_entry( op, rs, ceparent, c, &rdn,
6335 &CFOC_SCHEMA, NULL );
6338 } else if ( e && cf->c_kids ) {
6339 c->ca_private = cf->c_kids;
6340 config_build_schema_inc( c, e->e_private, op, rs );
6346 #ifdef SLAPD_MODULES
6349 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6350 Operation *op, SlapReply *rs )
6355 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6356 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6358 c->value_dn.bv_val = c->log;
6359 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6360 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6361 /* FIXME: how can indicate error? */
6365 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6374 config_check_schema(Operation *op, CfBackInfo *cfb)
6376 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6378 CfEntryInfo *ce, *last;
6381 /* If there's no root entry, we must be in the midst of converting */
6382 if ( !cfb->cb_root )
6385 /* Make sure the main schema entry exists */
6386 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6393 /* Make sure it's up to date */
6394 if ( cf_om_tail != om_sys_tail ) {
6395 a = attr_find( e->e_attrs, cfAd_om );
6397 if ( a->a_nvals != a->a_vals )
6398 ber_bvarray_free( a->a_nvals );
6399 ber_bvarray_free( a->a_vals );
6404 oidm_unparse( &bv, NULL, NULL, 1 );
6405 attr_merge_normalize( e, cfAd_om, bv, NULL );
6406 ber_bvarray_free( bv );
6407 cf_om_tail = om_sys_tail;
6409 if ( cf_at_tail != at_sys_tail ) {
6410 a = attr_find( e->e_attrs, cfAd_attr );
6412 if ( a->a_nvals != a->a_vals )
6413 ber_bvarray_free( a->a_nvals );
6414 ber_bvarray_free( a->a_vals );
6419 at_unparse( &bv, NULL, NULL, 1 );
6420 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6421 ber_bvarray_free( bv );
6422 cf_at_tail = at_sys_tail;
6424 if ( cf_oc_tail != oc_sys_tail ) {
6425 a = attr_find( e->e_attrs, cfAd_oc );
6427 if ( a->a_nvals != a->a_vals )
6428 ber_bvarray_free( a->a_nvals );
6429 ber_bvarray_free( a->a_vals );
6434 oc_unparse( &bv, NULL, NULL, 1 );
6435 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6436 ber_bvarray_free( bv );
6437 cf_oc_tail = oc_sys_tail;
6439 if ( cf_syn_tail != syn_sys_tail ) {
6440 a = attr_find( e->e_attrs, cfAd_syntax );
6442 if ( a->a_nvals != a->a_vals )
6443 ber_bvarray_free( a->a_nvals );
6444 ber_bvarray_free( a->a_vals );
6449 syn_unparse( &bv, NULL, NULL, 1 );
6450 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6451 ber_bvarray_free( bv );
6452 cf_syn_tail = syn_sys_tail;
6455 SlapReply rs = {REP_RESULT};
6456 c.ca_private = NULL;
6457 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6458 &CFOC_SCHEMA, NULL );
6463 ce->ce_private = cfb->cb_config;
6464 cf_at_tail = at_sys_tail;
6465 cf_oc_tail = oc_sys_tail;
6466 cf_om_tail = om_sys_tail;
6467 cf_syn_tail = syn_sys_tail;
6472 static const char *defacl[] = {
6473 NULL, "to", "*", "by", "*", "none", NULL
6477 config_back_db_open( BackendDB *be, ConfigReply *cr )
6479 CfBackInfo *cfb = be->be_private;
6482 CfEntryInfo *ce, *ceparent;
6486 Connection conn = {0};
6487 OperationBuffer opbuf;
6489 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6490 SlapReply rs = {REP_RESULT};
6491 void *thrctx = NULL;
6493 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6495 /* If we have no explicitly configured ACLs, don't just use
6496 * the global ACLs. Explicitly deny access to everything.
6498 if ( !be->bd_self->be_acl ) {
6499 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6502 thrctx = ldap_pvt_thread_pool_context();
6503 connection_fake_init( &conn, &opbuf, thrctx );
6506 op->o_tag = LDAP_REQ_ADD;
6507 op->o_callback = &cb;
6508 op->o_bd = &cfb->cb_db;
6509 op->o_dn = op->o_bd->be_rootdn;
6510 op->o_ndn = op->o_bd->be_rootndn;
6512 if ( !cfb->cb_use_ldif ) {
6516 /* If we read the config from back-ldif, do some quick sanity checks */
6517 if ( cfb->cb_got_ldif ) {
6518 return config_check_schema( op, cfb );
6521 /* create root of tree */
6523 c.ca_private = cfb->cb_config;
6525 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6535 #ifdef SLAPD_MODULES
6536 /* Create Module nodes... */
6537 if ( modpaths.mp_loads ) {
6538 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6544 /* Create schema nodes... cn=schema will contain the hardcoded core
6545 * schema, read-only. Child objects will contain runtime loaded schema
6549 c.ca_private = NULL;
6550 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6555 ce->ce_private = cfb->cb_config;
6556 cf_at_tail = at_sys_tail;
6557 cf_oc_tail = oc_sys_tail;
6558 cf_om_tail = om_sys_tail;
6559 cf_syn_tail = syn_sys_tail;
6561 /* Create schema nodes for included schema... */
6562 if ( cfb->cb_config->c_kids ) {
6565 c.ca_private = cfb->cb_config->c_kids;
6566 rc = config_build_schema_inc( &c, ce, op, &rs );
6572 /* Create backend nodes. Skip if they don't provide a cf_table.
6573 * There usually aren't any of these.
6577 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6578 if (!bi->bi_cf_ocs) {
6579 /* If it only supports the old config mech, complain. */
6580 if ( bi->bi_config ) {
6581 Debug( LDAP_DEBUG_ANY,
6582 "WARNING: No dynamic config support for backend %s.\n",
6583 bi->bi_type, 0, 0 );
6588 if (!bi->bi_private) continue;
6591 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6592 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6593 if ( rdn.bv_len >= sizeof( c.log ) ) {
6594 /* FIXME: holler ... */ ;
6597 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6604 /* Create database nodes... */
6605 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6606 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6607 for ( i = -1, be = frontendDB ; be;
6608 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6609 slap_overinfo *oi = NULL;
6611 if ( overlay_is_over( be )) {
6612 oi = be->bd_info->bi_private;
6618 /* If this backend supports the old config mechanism, but not
6619 * the new mech, complain.
6621 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6622 Debug( LDAP_DEBUG_ANY,
6623 "WARNING: No dynamic config support for database %s.\n",
6624 bi->bi_type, 0, 0 );
6628 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6629 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6631 if ( rdn.bv_len >= sizeof( c.log ) ) {
6632 /* FIXME: holler ... */ ;
6636 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6642 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6643 rs_reinit( &rs, REP_RESULT );
6644 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6646 /* Iterate through overlays */
6651 voidList *vl, *v0 = NULL;
6653 /* overlays are in LIFO order, must reverse stack */
6654 for (on=oi->oi_list; on; on=on->on_next) {
6655 vl = ch_malloc( sizeof( voidList ));
6660 for (j=0; vl; j++,vl=v0) {
6664 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6665 Debug( LDAP_DEBUG_ANY,
6666 "WARNING: No dynamic config support for overlay %s.\n",
6667 on->on_bi.bi_type, 0, 0 );
6671 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6672 "%s=" SLAP_X_ORDERED_FMT "%s",
6673 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6674 if ( rdn.bv_len >= sizeof( c.log ) ) {
6675 /* FIXME: holler ... */ ;
6679 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6680 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6684 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6685 rs_reinit( &rs, REP_RESULT );
6686 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6692 ldap_pvt_thread_pool_context_reset( thrctx );
6694 if ( unsupp && cfb->cb_use_ldif ) {
6695 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6696 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6703 cfb_free_cffile( ConfigFile *cf )
6707 for (; cf; cf=next) {
6710 cfb_free_cffile( cf->c_kids );
6711 ch_free( cf->c_file.bv_val );
6712 ber_bvarray_free( cf->c_dseFiles );
6718 cfb_free_entries( CfEntryInfo *ce )
6722 for (; ce; ce=next) {
6725 cfb_free_entries( ce->ce_kids );
6726 ce->ce_entry->e_private = NULL;
6727 entry_free( ce->ce_entry );
6733 config_back_db_close( BackendDB *be, ConfigReply *cr )
6735 CfBackInfo *cfb = be->be_private;
6737 cfb_free_entries( cfb->cb_root );
6738 cfb->cb_root = NULL;
6740 if ( cfb->cb_db.bd_info ) {
6741 backend_shutdown( &cfb->cb_db );
6748 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6750 CfBackInfo *cfb = be->be_private;
6752 cfb_free_cffile( cfb->cb_config );
6754 ch_free( cfdir.bv_val );
6756 avl_free( CfOcTree, NULL );
6758 if ( cfb->cb_db.bd_info ) {
6759 cfb->cb_db.be_suffix = NULL;
6760 cfb->cb_db.be_nsuffix = NULL;
6761 BER_BVZERO( &cfb->cb_db.be_rootdn );
6762 BER_BVZERO( &cfb->cb_db.be_rootndn );
6764 backend_destroy_one( &cfb->cb_db, 0 );
6773 config_back_db_init( BackendDB *be, ConfigReply* cr )
6779 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6780 cfn = cfb->cb_config;
6781 be->be_private = cfb;
6783 ber_dupbv( &be->be_rootdn, &config_rdn );
6784 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6785 ber_dupbv( &dn, &be->be_rootdn );
6786 ber_bvarray_add( &be->be_suffix, &dn );
6787 ber_dupbv( &dn, &be->be_rootdn );
6788 ber_bvarray_add( &be->be_nsuffix, &dn );
6790 /* Hide from namingContexts */
6791 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6793 /* Check ACLs on content of Adds by default */
6794 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6800 config_back_destroy( BackendInfo *bi )
6802 ldif_must_b64_encode_release();
6807 config_tool_entry_open( BackendDB *be, int mode )
6809 CfBackInfo *cfb = be->be_private;
6810 BackendInfo *bi = cfb->cb_db.bd_info;
6812 if ( bi && bi->bi_tool_entry_open )
6813 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6820 config_tool_entry_close( BackendDB *be )
6822 CfBackInfo *cfb = be->be_private;
6823 BackendInfo *bi = cfb->cb_db.bd_info;
6825 if ( bi && bi->bi_tool_entry_close )
6826 return bi->bi_tool_entry_close( &cfb->cb_db );
6832 config_tool_entry_first( BackendDB *be )
6834 CfBackInfo *cfb = be->be_private;
6835 BackendInfo *bi = cfb->cb_db.bd_info;
6837 if ( bi && bi->bi_tool_entry_first ) {
6838 return bi->bi_tool_entry_first( &cfb->cb_db );
6840 if ( bi && bi->bi_tool_entry_first_x ) {
6841 return bi->bi_tool_entry_first_x( &cfb->cb_db,
6842 NULL, LDAP_SCOPE_DEFAULT, NULL );
6848 config_tool_entry_first_x(
6850 struct berval *base,
6854 CfBackInfo *cfb = be->be_private;
6855 BackendInfo *bi = cfb->cb_db.bd_info;
6857 if ( bi && bi->bi_tool_entry_first_x ) {
6858 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
6864 config_tool_entry_next( BackendDB *be )
6866 CfBackInfo *cfb = be->be_private;
6867 BackendInfo *bi = cfb->cb_db.bd_info;
6869 if ( bi && bi->bi_tool_entry_next )
6870 return bi->bi_tool_entry_next( &cfb->cb_db );
6876 config_tool_entry_get( BackendDB *be, ID id )
6878 CfBackInfo *cfb = be->be_private;
6879 BackendInfo *bi = cfb->cb_db.bd_info;
6881 if ( bi && bi->bi_tool_entry_get )
6882 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6887 static int entry_put_got_frontend=0;
6888 static int entry_put_got_config=0;
6890 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6892 CfBackInfo *cfb = be->be_private;
6893 BackendInfo *bi = cfb->cb_db.bd_info;
6895 struct berval rdn, vals[ 2 ];
6897 OperationBuffer opbuf;
6899 Connection conn = {0};
6900 Operation *op = NULL;
6904 /* Create entry for frontend database if it does not exist already */
6905 if ( !entry_put_got_frontend ) {
6906 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6907 STRLENOF( "olcDatabase" ))) {
6908 if ( strncmp( e->e_nname.bv_val +
6909 STRLENOF( "olcDatabase" ), "={-1}frontend",
6910 STRLENOF( "={-1}frontend" )) &&
6911 strncmp( e->e_nname.bv_val +
6912 STRLENOF( "olcDatabase" ), "=frontend",
6913 STRLENOF( "=frontend" ))) {
6915 vals[1].bv_val = NULL;
6916 memset( &ca, 0, sizeof(ConfigArgs));
6918 ca.bi = frontendDB->bd_info;
6919 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6920 rdn.bv_val = ca.log;
6921 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6922 "%s=" SLAP_X_ORDERED_FMT "%s",
6923 cfAd_database->ad_cname.bv_val, -1,
6925 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6926 &CFOC_DATABASE, ca.be->be_cf_ocs );
6927 thrctx = ldap_pvt_thread_pool_context();
6928 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6930 op->o_bd = &cfb->cb_db;
6931 op->o_tag = LDAP_REQ_ADD;
6933 op->o_dn = be->be_rootdn;
6934 op->o_ndn = be->be_rootndn;
6935 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6936 if ( rc != LDAP_SUCCESS ) {
6937 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6938 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6942 if ( ce && bi && bi->bi_tool_entry_put &&
6943 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6944 entry_put_got_frontend++;
6946 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6947 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6951 entry_put_got_frontend++;
6956 /* Create entry for config database if it does not exist already */
6957 if ( !entry_put_got_config && !isFrontend ) {
6958 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6959 STRLENOF( "olcDatabase" ))) {
6960 if ( strncmp( e->e_nname.bv_val +
6961 STRLENOF( "olcDatabase" ), "={0}config",
6962 STRLENOF( "={0}config" )) &&
6963 strncmp( e->e_nname.bv_val +
6964 STRLENOF( "olcDatabase" ), "=config",
6965 STRLENOF( "=config" )) ) {
6967 vals[1].bv_val = NULL;
6968 memset( &ca, 0, sizeof(ConfigArgs));
6969 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6970 ca.bi = ca.be->bd_info;
6971 rdn.bv_val = ca.log;
6972 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6973 "%s=" SLAP_X_ORDERED_FMT "%s",
6974 cfAd_database->ad_cname.bv_val, 0,
6976 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6979 thrctx = ldap_pvt_thread_pool_context();
6980 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6982 op->o_bd = &cfb->cb_db;
6983 op->o_tag = LDAP_REQ_ADD;
6984 op->o_dn = be->be_rootdn;
6985 op->o_ndn = be->be_rootndn;
6988 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6989 if ( rc != LDAP_SUCCESS ) {
6990 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6991 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6994 if (ce && bi && bi->bi_tool_entry_put &&
6995 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6996 entry_put_got_config++;
6998 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6999 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7003 entry_put_got_config++;
7007 if ( bi && bi->bi_tool_entry_put &&
7008 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7009 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7016 AttributeDescription **desc;
7018 { "attribute", &cfAd_attr },
7019 { "backend", &cfAd_backend },
7020 { "database", &cfAd_database },
7021 { "include", &cfAd_include },
7022 { "ldapsyntax", &cfAd_syntax },
7023 { "objectclass", &cfAd_oc },
7024 { "objectidentifier", &cfAd_om },
7025 { "overlay", &cfAd_overlay },
7030 * add / delete: all types that may be added or deleted must use an
7031 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7032 * should automatically renumber the index of any siblings as needed,
7033 * so that no gaps in the numbering sequence exist after the add/delete
7035 * What can be added:
7037 * backend objects for backend-specific config directives
7041 * delete: probably no support this time around.
7043 * modrdn: generally not done. Will be invoked automatically by add/
7044 * delete to update numbering sequence. Perform as an explicit operation
7045 * so that the renumbering effect may be replicated. Subtree rename must
7046 * be supported, since renumbering a database will affect all its child
7049 * modify: must be fully supported.
7053 config_back_initialize( BackendInfo *bi )
7055 ConfigTable *ct = config_back_cf_table;
7059 AttributeDescription *ad = NULL;
7061 static char *controls[] = {
7062 LDAP_CONTROL_MANAGEDSAIT,
7066 /* Make sure we don't exceed the bits reserved for userland */
7067 config_check_userland( CFG_LAST );
7069 bi->bi_controls = controls;
7074 bi->bi_destroy = config_back_destroy;
7076 bi->bi_db_init = config_back_db_init;
7077 bi->bi_db_config = 0;
7078 bi->bi_db_open = config_back_db_open;
7079 bi->bi_db_close = config_back_db_close;
7080 bi->bi_db_destroy = config_back_db_destroy;
7082 bi->bi_op_bind = config_back_bind;
7083 bi->bi_op_unbind = 0;
7084 bi->bi_op_search = config_back_search;
7085 bi->bi_op_compare = 0;
7086 bi->bi_op_modify = config_back_modify;
7087 bi->bi_op_modrdn = config_back_modrdn;
7088 bi->bi_op_add = config_back_add;
7089 bi->bi_op_delete = config_back_delete;
7090 bi->bi_op_abandon = 0;
7092 bi->bi_extended = 0;
7094 bi->bi_chk_referrals = 0;
7096 bi->bi_access_allowed = slap_access_allowed;
7098 bi->bi_connection_init = 0;
7099 bi->bi_connection_destroy = 0;
7101 bi->bi_entry_release_rw = config_entry_release;
7102 bi->bi_entry_get_rw = config_back_entry_get;
7104 bi->bi_tool_entry_open = config_tool_entry_open;
7105 bi->bi_tool_entry_close = config_tool_entry_close;
7106 bi->bi_tool_entry_first = config_tool_entry_first;
7107 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7108 bi->bi_tool_entry_next = config_tool_entry_next;
7109 bi->bi_tool_entry_get = config_tool_entry_get;
7110 bi->bi_tool_entry_put = config_tool_entry_put;
7113 argv[ 0 ] = "slapd";
7119 for (i=0; OidMacros[i].name; i++ ) {
7120 argv[1] = OidMacros[i].name;
7121 argv[2] = OidMacros[i].oid;
7122 parse_oidm( &ca, 0, NULL );
7125 bi->bi_cf_ocs = cf_ocs;
7127 i = config_register_schema( ct, cf_ocs );
7130 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7133 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7134 * basically, we don't care if it fails */
7135 i = slap_str2ad( "olcRootPW", &ad, &text );
7137 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7138 "warning, unable to get \"olcRootPW\" "
7139 "attribute description: %d: %s\n",
7142 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7143 ad->ad_type->sat_oid );
7146 /* set up the notable AttributeDescriptions */
7148 for (;ct->name;ct++) {
7149 if (strcmp(ct->name, ads[i].name)) continue;
7150 *ads[i].desc = ct->ad;
7152 if (!ads[i].name) break;