1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2011 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
88 static struct berval cfdir;
91 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
92 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
94 static ConfigFile *cfn;
96 static Avlnode *CfOcTree;
98 /* System schema state */
99 extern AttributeType *at_sys_tail; /* at.c */
100 extern ObjectClass *oc_sys_tail; /* oc.c */
101 extern OidMacro *om_sys_tail; /* oidm.c */
102 extern Syntax *syn_sys_tail; /* syntax.c */
103 static AttributeType *cf_at_tail;
104 static ObjectClass *cf_oc_tail;
105 static OidMacro *cf_om_tail;
106 static Syntax *cf_syn_tail;
108 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
109 SlapReply *rs, int *renumber, Operation *op );
111 static int config_check_schema( Operation *op, CfBackInfo *cfb );
113 static ConfigDriver config_fname;
114 static ConfigDriver config_cfdir;
115 static ConfigDriver config_generic;
116 static ConfigDriver config_search_base;
117 static ConfigDriver config_passwd_hash;
118 static ConfigDriver config_schema_dn;
119 static ConfigDriver config_sizelimit;
120 static ConfigDriver config_timelimit;
121 static ConfigDriver config_overlay;
122 static ConfigDriver config_subordinate;
123 static ConfigDriver config_suffix;
124 #ifdef LDAP_TCP_BUFFER
125 static ConfigDriver config_tcp_buffer;
126 #endif /* LDAP_TCP_BUFFER */
127 static ConfigDriver config_rootdn;
128 static ConfigDriver config_rootpw;
129 static ConfigDriver config_restrict;
130 static ConfigDriver config_allows;
131 static ConfigDriver config_disallows;
132 static ConfigDriver config_requires;
133 static ConfigDriver config_security;
134 static ConfigDriver config_referral;
135 static ConfigDriver config_loglevel;
136 static ConfigDriver config_updatedn;
137 static ConfigDriver config_updateref;
138 static ConfigDriver config_include;
139 static ConfigDriver config_obsolete;
141 static ConfigDriver config_tls_option;
142 static ConfigDriver config_tls_config;
144 extern ConfigDriver syncrepl_config;
152 CFG_TLS_PROTOCOL_MIN,
203 static OidRec OidMacros[] = {
204 /* OpenLDAProot:1.12.2 */
205 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
206 { "OLcfgAt", "OLcfg:3" },
207 { "OLcfgGlAt", "OLcfgAt:0" },
208 { "OLcfgBkAt", "OLcfgAt:1" },
209 { "OLcfgDbAt", "OLcfgAt:2" },
210 { "OLcfgOvAt", "OLcfgAt:3" },
211 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
212 { "OLcfgOc", "OLcfg:4" },
213 { "OLcfgGlOc", "OLcfgOc:0" },
214 { "OLcfgBkOc", "OLcfgOc:1" },
215 { "OLcfgDbOc", "OLcfgOc:2" },
216 { "OLcfgOvOc", "OLcfgOc:3" },
217 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
219 /* Syntaxes. We should just start using the standard names and
220 * document that they are predefined and available for users
221 * to reference in their own schema. Defining schema without
222 * OID macros is for masochists...
224 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
225 { "OMsBoolean", "OMsyn:7" },
226 { "OMsDN", "OMsyn:12" },
227 { "OMsDirectoryString", "OMsyn:15" },
228 { "OMsIA5String", "OMsyn:26" },
229 { "OMsInteger", "OMsyn:27" },
230 { "OMsOID", "OMsyn:38" },
231 { "OMsOctetString", "OMsyn:40" },
236 * Backend/Database registry
238 * OLcfg{Bk|Db}{Oc|At}:0 -> common
239 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
240 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
241 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
242 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
243 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
244 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
245 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
246 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
252 * OLcfgOv{Oc|At}:1 -> syncprov
253 * OLcfgOv{Oc|At}:2 -> pcache
254 * OLcfgOv{Oc|At}:3 -> chain
255 * OLcfgOv{Oc|At}:4 -> accesslog
256 * OLcfgOv{Oc|At}:5 -> valsort
257 * OLcfgOv{Oc|At}:7 -> distproc
258 * OLcfgOv{Oc|At}:8 -> dynlist
259 * OLcfgOv{Oc|At}:9 -> dds
260 * OLcfgOv{Oc|At}:10 -> unique
261 * OLcfgOv{Oc|At}:11 -> refint
262 * OLcfgOv{Oc|At}:12 -> ppolicy
263 * OLcfgOv{Oc|At}:13 -> constraint
264 * OLcfgOv{Oc|At}:14 -> translucent
265 * OLcfgOv{Oc|At}:15 -> auditlog
266 * OLcfgOv{Oc|At}:16 -> rwm
267 * OLcfgOv{Oc|At}:17 -> dyngroup
268 * OLcfgOv{Oc|At}:18 -> memberof
269 * OLcfgOv{Oc|At}:19 -> collect
270 * OLcfgOv{Oc|At}:20 -> retcode
271 * OLcfgOv{Oc|At}:21 -> sssvlv
274 /* alphabetical ordering */
276 static ConfigTable config_back_cf_table[] = {
277 /* This attr is read-only */
278 { "", "", 0, 0, 0, ARG_MAGIC,
279 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
280 "DESC 'File for slapd configuration directives' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
283 { "", "", 0, 0, 0, ARG_MAGIC,
284 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
285 "DESC 'Directory for slapd configuration backend' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
288 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
289 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
290 "DESC 'Access Control List' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
293 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
294 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
295 "DESC 'Check ACLs against content of Add ops' "
296 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
297 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
298 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
299 "DESC 'Allowed set of deprecated features' "
300 "EQUALITY caseIgnoreMatch "
301 "SYNTAX OMsDirectoryString )", NULL, NULL },
302 { "argsfile", "file", 2, 2, 0, ARG_STRING,
303 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
304 "DESC 'File for slapd command line options' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
307 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
308 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
309 "EQUALITY caseIgnoreMatch "
310 "SYNTAX OMsDirectoryString )", NULL, NULL },
311 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
312 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
313 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
314 "DESC 'OpenLDAP attributeTypes' "
315 "EQUALITY caseIgnoreMatch "
316 "SUBSTR caseIgnoreSubstringsMatch "
317 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
319 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
320 #ifdef SLAP_AUTH_REWRITE
321 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
325 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
326 "EQUALITY caseIgnoreMatch "
327 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
328 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
329 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
330 "EQUALITY caseIgnoreMatch "
331 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
332 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
333 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
334 "EQUALITY caseIgnoreMatch "
335 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
336 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
337 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
338 "DESC 'A type of backend' "
339 "EQUALITY caseIgnoreMatch "
340 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
342 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
343 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
344 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
345 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
346 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
347 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
348 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
349 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
350 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
351 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
352 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
353 "DESC 'The backend type for a database instance' "
354 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
355 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
356 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
357 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
358 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
359 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
360 "EQUALITY caseIgnoreMatch "
361 "SYNTAX OMsDirectoryString )", NULL, NULL },
362 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
363 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
364 "DESC 'OpenLDAP DIT content rules' "
365 "EQUALITY caseIgnoreMatch "
366 "SUBSTR caseIgnoreSubstringsMatch "
367 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
369 { "gentlehup", "on|off", 2, 2, 0,
371 ARG_ON_OFF, &global_gentlehup,
375 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
376 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
377 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
378 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
379 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
380 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
381 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
382 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
383 { "include", "file", 2, 2, 0, ARG_MAGIC,
384 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
385 "SUP labeledURI )", NULL, NULL },
386 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
387 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
388 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
389 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
390 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
391 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
392 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
393 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
394 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
395 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
396 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
397 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
398 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
399 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
402 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
403 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
404 { "ldapsyntax", "syntax", 2, 0, 0,
405 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
406 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
407 "DESC 'OpenLDAP ldapSyntax' "
408 "EQUALITY caseIgnoreMatch "
409 "SUBSTR caseIgnoreSubstringsMatch "
410 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
412 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
413 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
414 "EQUALITY caseIgnoreMatch "
415 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
416 { "listener-threads", "count", 2, 0, 0,
420 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
422 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
423 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
424 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
425 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
426 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
427 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
428 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
429 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
430 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
431 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
432 "EQUALITY caseIgnoreMatch "
433 "SYNTAX OMsDirectoryString )", NULL, NULL },
434 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
435 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
436 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
437 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
438 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
439 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
440 { "moduleload", "file", 2, 0, 0,
442 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
446 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
447 "EQUALITY caseIgnoreMatch "
448 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
449 { "modulepath", "path", 2, 2, 0,
451 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
455 "( OLcfgGlAt:31 NAME 'olcModulePath' "
456 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
457 { "monitoring", "TRUE|FALSE", 2, 2, 0,
458 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
459 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
460 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
461 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
462 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
463 "DESC 'OpenLDAP object classes' "
464 "EQUALITY caseIgnoreMatch "
465 "SUBSTR caseIgnoreSubstringsMatch "
466 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
468 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
469 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
470 "EQUALITY caseIgnoreMatch "
471 "SUBSTR caseIgnoreSubstringsMatch "
472 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
473 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
474 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
475 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
476 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
477 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
478 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
479 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
480 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
481 "EQUALITY caseIgnoreMatch "
482 "SYNTAX OMsDirectoryString )", NULL, NULL },
483 { "pidfile", "file", 2, 2, 0, ARG_STRING,
484 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
485 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
486 { "plugin", NULL, 0, 0, 0,
488 ARG_MAGIC|CFG_PLUGIN, &config_generic,
492 "( OLcfgGlAt:38 NAME 'olcPlugin' "
493 "EQUALITY caseIgnoreMatch "
494 "SYNTAX OMsDirectoryString )", NULL, NULL },
495 { "pluginlog", "filename", 2, 2, 0,
497 ARG_STRING, &slapi_log_file,
501 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
502 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
503 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
504 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
505 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
506 { "referral", "url", 2, 2, 0, ARG_MAGIC,
507 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
508 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
509 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
510 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
511 "EQUALITY caseIgnoreMatch "
512 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
513 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
514 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
515 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
516 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
517 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
518 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
519 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
520 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
521 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
522 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
523 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
526 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
527 "EQUALITY caseIgnoreMatch "
528 "SYNTAX OMsDirectoryString )", NULL, NULL },
529 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
530 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
531 "EQUALITY caseIgnoreMatch "
532 "SYNTAX OMsDirectoryString )", NULL, NULL },
533 { "reverse-lookup", "on|off", 2, 2, 0,
534 #ifdef SLAPD_RLOOKUPS
535 ARG_ON_OFF, &use_reverse_lookup,
539 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
540 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
541 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
542 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
543 "EQUALITY distinguishedNameMatch "
544 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
545 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
546 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
547 "EQUALITY caseIgnoreMatch "
548 "SYNTAX OMsDirectoryString )", NULL, NULL },
549 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
550 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
551 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
552 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
553 &config_generic, NULL, NULL, NULL },
554 { "sasl-auxprops", NULL, 2, 0, 0,
555 #ifdef HAVE_CYRUS_SASL
556 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
560 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
561 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
562 { "sasl-host", "host", 2, 2, 0,
563 #ifdef HAVE_CYRUS_SASL
564 ARG_STRING|ARG_UNIQUE, &sasl_host,
568 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
569 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
570 { "sasl-realm", "realm", 2, 2, 0,
571 #ifdef HAVE_CYRUS_SASL
572 ARG_STRING|ARG_UNIQUE, &global_realm,
576 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
577 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
578 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
579 &config_generic, NULL, NULL, NULL },
580 { "sasl-secprops", "properties", 2, 2, 0,
581 #ifdef HAVE_CYRUS_SASL
582 ARG_MAGIC|CFG_SASLSECP, &config_generic,
586 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
587 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
588 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
589 &config_generic, NULL, NULL, NULL },
590 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
591 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
592 "EQUALITY distinguishedNameMatch "
593 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
594 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
595 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
596 "EQUALITY caseIgnoreMatch "
597 "SYNTAX OMsDirectoryString )", NULL, NULL },
598 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
599 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
600 "EQUALITY caseIgnoreMatch "
601 "SYNTAX OMsDirectoryString )", NULL, NULL },
602 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
603 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
604 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
605 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
606 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
607 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
608 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
609 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
610 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
611 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
612 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
613 "DESC 'Attributes whose values will always be sorted' "
614 "EQUALITY caseIgnoreMatch "
615 "SYNTAX OMsDirectoryString )", NULL, NULL },
616 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
617 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
618 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
619 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
620 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
621 "EQUALITY distinguishedNameMatch "
622 "SYNTAX OMsDN )", NULL, NULL },
623 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
624 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
625 "DESC 'Store sync context in a subentry' "
626 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
627 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
628 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
629 "EQUALITY caseIgnoreMatch "
630 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
631 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
632 #ifndef LDAP_TCP_BUFFER
634 #else /* LDAP_TCP_BUFFER */
635 ARG_MAGIC, &config_tcp_buffer,
636 #endif /* LDAP_TCP_BUFFER */
637 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
638 "DESC 'Custom TCP buffer size' "
639 "SYNTAX OMsDirectoryString )", NULL, NULL },
640 { "threads", "count", 2, 2, 0,
644 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
646 "( OLcfgGlAt:66 NAME 'olcThreads' "
647 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
648 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
649 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
650 "SYNTAX OMsDirectoryString )", NULL, NULL },
651 { "TLSCACertificateFile", NULL, 0, 0, 0,
653 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
657 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
658 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
659 { "TLSCACertificatePath", NULL, 0, 0, 0,
661 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
665 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
666 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
667 { "TLSCertificateFile", NULL, 0, 0, 0,
669 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
673 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
674 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
675 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
677 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
681 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
682 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
683 { "TLSCipherSuite", NULL, 0, 0, 0,
685 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
689 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
690 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
691 { "TLSCRLCheck", NULL, 0, 0, 0,
692 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
693 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
697 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
698 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
699 { "TLSCRLFile", NULL, 0, 0, 0,
700 #if defined(HAVE_GNUTLS)
701 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
705 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
706 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
707 { "TLSRandFile", NULL, 0, 0, 0,
709 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
713 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
714 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
715 { "TLSVerifyClient", NULL, 0, 0, 0,
717 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
721 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
722 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
723 { "TLSDHParamFile", NULL, 0, 0, 0,
725 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
729 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
730 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
731 { "TLSProtocolMin", NULL, 0, 0, 0,
733 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
737 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
738 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
739 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
740 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
741 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
742 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
743 NULL, NULL, NULL, NULL },
744 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
745 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
746 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
747 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
748 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
749 "EQUALITY caseIgnoreMatch "
750 "SUP labeledURI )", NULL, NULL },
751 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
752 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
753 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
754 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
755 NULL, NULL, NULL, NULL }
758 /* Need to no-op this keyword for dynamic config */
759 ConfigTable olcDatabaseDummy[] = {
760 { "", "", 0, 0, 0, ARG_IGNORED,
761 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
762 "DESC 'The backend type for a database instance' "
763 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
764 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
767 /* Routines to check if a child can be added to this type */
768 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
769 cfAddBackend, cfAddModule, cfAddOverlay;
771 /* NOTE: be careful when defining array members
772 * that can be conditionally compiled */
773 #define CFOC_GLOBAL cf_ocs[1]
774 #define CFOC_SCHEMA cf_ocs[2]
775 #define CFOC_BACKEND cf_ocs[3]
776 #define CFOC_DATABASE cf_ocs[4]
777 #define CFOC_OVERLAY cf_ocs[5]
778 #define CFOC_INCLUDE cf_ocs[6]
779 #define CFOC_FRONTEND cf_ocs[7]
781 #define CFOC_MODULE cf_ocs[8]
782 #endif /* SLAPD_MODULES */
784 static ConfigOCs cf_ocs[] = {
787 "DESC 'OpenLDAP configuration object' "
788 "ABSTRACT SUP top )", Cft_Abstract, NULL },
791 "DESC 'OpenLDAP Global configuration options' "
792 "SUP olcConfig STRUCTURAL "
793 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
794 "olcAttributeOptions $ olcAuthIDRewrite $ "
795 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
796 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
797 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
798 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
799 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
800 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
801 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
802 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
803 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
805 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
806 "olcSecurity $ olcServerID $ olcSizeLimit $ "
807 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
809 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
810 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
811 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
812 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
813 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
814 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
815 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
817 "NAME 'olcSchemaConfig' "
818 "DESC 'OpenLDAP schema object' "
819 "SUP olcConfig STRUCTURAL "
820 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
821 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
822 Cft_Schema, NULL, cfAddSchema },
824 "NAME 'olcBackendConfig' "
825 "DESC 'OpenLDAP Backend-specific options' "
826 "SUP olcConfig STRUCTURAL "
827 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
829 "NAME 'olcDatabaseConfig' "
830 "DESC 'OpenLDAP Database-specific options' "
831 "SUP olcConfig STRUCTURAL "
833 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
834 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
835 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
836 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
837 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
838 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
839 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
841 Cft_Database, NULL, cfAddDatabase },
843 "NAME 'olcOverlayConfig' "
844 "DESC 'OpenLDAP Overlay-specific options' "
845 "SUP olcConfig STRUCTURAL "
846 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
848 "NAME 'olcIncludeFile' "
849 "DESC 'OpenLDAP configuration include file' "
850 "SUP olcConfig STRUCTURAL "
852 "MAY ( cn $ olcRootDSE ) )",
853 /* Used to be Cft_Include, that def has been removed */
854 Cft_Abstract, NULL, cfAddInclude },
855 /* This should be STRUCTURAL like all the other database classes, but
856 * that would mean inheriting all of the olcDatabaseConfig attributes,
857 * which causes them to be merged twice in config_build_entry.
860 "NAME 'olcFrontendConfig' "
861 "DESC 'OpenLDAP frontend configuration' "
863 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
864 Cft_Database, NULL, NULL },
867 "NAME 'olcModuleList' "
868 "DESC 'OpenLDAP dynamic module info' "
869 "SUP olcConfig STRUCTURAL "
870 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
871 Cft_Module, NULL, cfAddModule },
876 typedef struct ServerID {
877 struct ServerID *si_next;
878 struct berval si_url;
882 static ServerID *sid_list;
884 typedef struct voidList {
885 struct voidList *vl_next;
889 typedef struct ADlist {
890 struct ADlist *al_next;
891 AttributeDescription *al_desc;
894 static ADlist *sortVals;
897 config_generic(ConfigArgs *c) {
900 if ( c->op == SLAP_CONFIG_EMIT ) {
904 c->value_int = ldap_pvt_thread_get_concurrency();
907 c->value_int = connection_pool_max;
910 c->value_int = slap_tool_thread_max;
913 c->value_uint = slapd_daemon_threads;
917 c->value_string = ch_strdup( passwd_salt );
922 if ( c->be->be_limits ) {
926 for ( i=0; c->be->be_limits[i]; i++ ) {
927 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
928 if ( bv.bv_len >= sizeof( buf ) ) {
929 ber_bvarray_free_x( c->rvalue_vals, NULL );
930 c->rvalue_vals = NULL;
934 bv.bv_val = buf + bv.bv_len;
935 limits_unparse( c->be->be_limits[i], &bv,
936 sizeof( buf ) - ( bv.bv_val - buf ) );
937 bv.bv_len += bv.bv_val - buf;
939 value_add_one( &c->rvalue_vals, &bv );
942 if ( !c->rvalue_vals ) rc = 1;
945 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
948 c->value_string = ch_strdup( slap_sasl_getpolicy());
951 slap_sasl_regexp_unparse( &c->rvalue_vals );
952 if ( !c->rvalue_vals ) rc = 1;
954 #ifdef HAVE_CYRUS_SASL
956 struct berval bv = BER_BVNULL;
957 slap_sasl_secprops_unparse( &bv );
958 if ( !BER_BVISNULL( &bv )) {
959 ber_bvarray_add( &c->rvalue_vals, &bv );
967 c->value_int = c->be->be_max_deref_depth;
970 if ( SLAP_DBHIDDEN( c->be )) {
977 ConfigFile *cf = c->ca_private;
979 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
980 else if ( cf->c_om_head )
981 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
983 if ( !c->rvalue_vals )
988 ad_unparse_options( &c->rvalue_vals );
991 ConfigFile *cf = c->ca_private;
993 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
994 else if ( cf->c_oc_head )
995 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
997 if ( !c->rvalue_vals )
1002 ConfigFile *cf = c->ca_private;
1004 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1005 else if ( cf->c_at_head )
1006 at_unparse( &c->rvalue_vals, cf->c_at_head,
1008 if ( !c->rvalue_vals )
1013 ConfigFile *cf = c->ca_private;
1015 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1016 else if ( cf->c_syn_head )
1017 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1018 cf->c_syn_tail, 0 );
1019 if ( !c->rvalue_vals )
1024 ConfigFile *cf = c->ca_private;
1026 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1027 else if ( cf->c_cr_head )
1028 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1030 if ( !c->rvalue_vals )
1037 char *src, *dst, ibuf[11];
1038 struct berval bv, abv;
1039 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1040 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1041 if ( abv.bv_len >= sizeof( ibuf ) ) {
1042 ber_bvarray_free_x( c->rvalue_vals, NULL );
1043 c->rvalue_vals = NULL;
1047 acl_unparse( a, &bv );
1048 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1049 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1050 /* Turn TAB / EOL into plain space */
1051 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1052 if (isspace((unsigned char)*src)) *dst++ = ' ';
1056 if (dst[-1] == ' ') {
1060 abv.bv_len = dst - abv.bv_val;
1061 ber_bvarray_add( &c->rvalue_vals, &abv );
1067 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1070 ConfigFile *cf = c->ca_private;
1071 if ( cf->c_dseFiles ) {
1072 value_add( &c->rvalue_vals, cf->c_dseFiles );
1083 for ( si = sid_list; si; si=si->si_next ) {
1084 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1085 if ( !BER_BVISEMPTY( &si->si_url )) {
1086 bv.bv_len = si->si_url.bv_len + 6;
1087 bv.bv_val = ch_malloc( bv.bv_len );
1088 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1089 si->si_url.bv_val );
1090 ber_bvarray_add( &c->rvalue_vals, &bv );
1094 bv.bv_len = sprintf( buf, "%d", si->si_num );
1095 value_add_one( &c->rvalue_vals, &bv );
1104 c->value_string = ch_strdup( logfileName );
1109 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1111 case CFG_SYNC_SUBENTRY:
1112 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1114 case CFG_MIRRORMODE:
1115 if ( SLAP_SHADOW(c->be))
1116 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1120 case CFG_MONITORING:
1121 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1123 case CFG_SSTR_IF_MAX:
1124 c->value_uint = index_substr_if_maxlen;
1126 case CFG_SSTR_IF_MIN:
1127 c->value_uint = index_substr_if_minlen;
1130 c->value_int = index_intlen;
1132 case CFG_SORTVALS: {
1135 for ( sv = sortVals; sv; sv = sv->al_next ) {
1136 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1140 #ifdef SLAPD_MODULES
1142 ModPaths *mp = c->ca_private;
1145 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1148 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1149 SLAP_X_ORDERED_FMT "%s", i,
1150 mp->mp_loads[i].bv_val );
1151 if ( bv.bv_len >= sizeof( c->log ) ) {
1152 ber_bvarray_free_x( c->rvalue_vals, NULL );
1153 c->rvalue_vals = NULL;
1156 value_add_one( &c->rvalue_vals, &bv );
1160 rc = c->rvalue_vals ? 0 : 1;
1164 ModPaths *mp = c->ca_private;
1165 if ( !BER_BVISNULL( &mp->mp_path ))
1166 value_add_one( &c->rvalue_vals, &mp->mp_path );
1168 rc = c->rvalue_vals ? 0 : 1;
1174 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1175 if ( !c->rvalue_vals ) rc = 1;
1178 #ifdef SLAP_AUTH_REWRITE
1180 if ( authz_rewrites ) {
1181 struct berval bv, idx;
1186 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1187 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1188 if ( idx.bv_len >= sizeof( ibuf ) ) {
1189 ber_bvarray_free_x( c->rvalue_vals, NULL );
1190 c->rvalue_vals = NULL;
1193 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1194 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1195 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1196 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1197 authz_rewrites[i].bv_val,
1198 authz_rewrites[i].bv_len + 1 );
1199 ber_bvarray_add( &c->rvalue_vals, &bv );
1202 if ( !c->rvalue_vals ) rc = 1;
1209 } else if ( c->op == LDAP_MOD_DELETE ) {
1212 /* single-valued attrs, no-ops */
1221 case CFG_MIRRORMODE:
1222 case CFG_MONITORING:
1224 case CFG_SSTR_IF_MAX:
1225 case CFG_SSTR_IF_MIN:
1227 case CFG_SYNC_SUBENTRY:
1230 /* no-ops, requires slapd restart */
1235 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1239 ch_free( passwd_salt );
1244 ch_free( logfileName );
1252 case CFG_SERVERID: {
1253 ServerID *si, **sip;
1255 for ( i=0, si = sid_list, sip = &sid_list;
1256 si; si = *sip, i++ ) {
1257 if ( c->valx == -1 || i == c->valx ) {
1269 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1273 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1274 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1275 SLAP_INDEX_INTLEN_DEFAULT );
1279 if ( c->valx < 0 ) {
1280 acl_destroy( c->be->be_acl );
1281 c->be->be_acl = NULL;
1284 AccessControl **prev, *a;
1286 for (i=0, prev = &c->be->be_acl; i < c->valx;
1289 prev = &a->acl_next;
1292 *prev = a->acl_next;
1299 /* Can be NULL when undoing a failed add */
1300 if ( c->ca_entry ) {
1301 ce = c->ca_entry->e_private;
1302 /* can't modify the hardcoded schema */
1303 if ( ce->ce_parent->ce_type == Cft_Global )
1307 cfn = c->ca_private;
1308 if ( c->valx < 0 ) {
1311 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1313 if ( oc == cfn->c_oc_tail )
1316 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1318 ObjectClass *oc, *prev = NULL;
1320 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1325 if ( cfn->c_oc_tail == oc ) {
1326 cfn->c_oc_tail = prev;
1328 if ( cfn->c_oc_head == oc ) {
1330 cfn->c_oc_head = oc;
1337 /* Can be NULL when undoing a failed add */
1338 if ( c->ca_entry ) {
1339 ce = c->ca_entry->e_private;
1340 /* can't modify the hardcoded schema */
1341 if ( ce->ce_parent->ce_type == Cft_Global )
1345 cfn = c->ca_private;
1346 if ( c->valx < 0 ) {
1349 for( at = cfn->c_at_head; at; at_next( &at )) {
1351 if ( at == cfn->c_at_tail )
1354 cfn->c_at_head = cfn->c_at_tail = NULL;
1356 AttributeType *at, *prev = NULL;
1358 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1363 if ( cfn->c_at_tail == at ) {
1364 cfn->c_at_tail = prev;
1366 if ( cfn->c_at_head == at ) {
1368 cfn->c_at_head = at;
1375 /* Can be NULL when undoing a failed add */
1376 if ( c->ca_entry ) {
1377 ce = c->ca_entry->e_private;
1378 /* can't modify the hardcoded schema */
1379 if ( ce->ce_parent->ce_type == Cft_Global )
1383 cfn = c->ca_private;
1384 if ( c->valx < 0 ) {
1387 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1389 if ( syn == cfn->c_syn_tail )
1392 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1394 Syntax *syn, *prev = NULL;
1396 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1401 if ( cfn->c_syn_tail == syn ) {
1402 cfn->c_syn_tail = prev;
1404 if ( cfn->c_syn_head == syn ) {
1406 cfn->c_syn_head = syn;
1411 if ( c->valx < 0 ) {
1413 for ( sv = sortVals; sv; sv = sortVals ) {
1414 sortVals = sv->al_next;
1415 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1422 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1423 prev = &sv->al_next;
1426 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1427 *prev = sv->al_next;
1433 /* FIXME: there is no limits_free function */
1434 if ( c->valx < 0 ) {
1435 limits_destroy( c->be->be_limits );
1436 c->be->be_limits = NULL;
1441 if ( c->be->be_limits ) {
1442 for ( num = 0; c->be->be_limits[ num ]; num++ )
1446 if ( c->valx >= num ) {
1451 limits_destroy( c->be->be_limits );
1452 c->be->be_limits = NULL;
1455 limits_free_one( c->be->be_limits[ c->valx ] );
1457 for ( cnt = c->valx; cnt < num; cnt++ ) {
1458 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1465 /* FIXME: there is no ad_option_free function */
1467 /* FIXME: there is no way to remove attributes added by
1481 if(!(c->bi = backend_info(c->argv[1]))) {
1482 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1483 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1484 c->log, c->cr_msg, c->argv[1] );
1491 /* NOTE: config is always the first backend!
1493 if ( !strcasecmp( c->argv[1], "config" )) {
1494 c->be = LDAP_STAILQ_FIRST(&backendDB);
1495 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1498 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1500 if ( c->cr_msg[0] == 0 )
1501 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1502 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1509 ldap_pvt_thread_set_concurrency(c->value_int);
1513 if ( c->value_int < 2 ) {
1514 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1515 "threads=%d smaller than minimum value 2",
1517 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1518 c->log, c->cr_msg, 0 );
1521 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1522 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1523 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1524 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1525 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1526 c->log, c->cr_msg, 0 );
1528 if ( slapMode & SLAP_SERVER_MODE )
1529 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1530 connection_pool_max = c->value_int; /* save for reference */
1534 if ( slapMode & SLAP_TOOL_MODE )
1535 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1536 slap_tool_thread_max = c->value_int; /* save for reference */
1541 /* use a power of two */
1542 while (c->value_uint > 1) {
1543 c->value_uint >>= 1;
1547 slapd_daemon_mask = mask;
1548 slapd_daemon_threads = mask+1;
1553 if ( passwd_salt ) ch_free( passwd_salt );
1554 passwd_salt = c->value_string;
1555 lutil_salt_format(passwd_salt);
1559 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1565 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1567 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1571 ch_free(c->value_string);
1572 if (slap_sasl_setpolicy( c->argv[1] )) {
1573 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1574 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1575 c->log, c->cr_msg, c->argv[1] );
1581 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1585 #ifdef HAVE_CYRUS_SASL
1588 char *txt = slap_sasl_secprops( c->argv[1] );
1590 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1592 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1600 c->be->be_max_deref_depth = c->value_int;
1606 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1607 cfn = c->ca_private;
1608 if(parse_oidm(c, 1, &om))
1610 if (!cfn->c_om_head) cfn->c_om_head = om;
1611 cfn->c_om_tail = om;
1616 ObjectClass *oc, *prev;
1618 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1619 cfn = c->ca_private;
1620 if ( c->valx < 0 ) {
1621 prev = cfn->c_oc_tail;
1624 /* If adding anything after the first, prev is easy */
1627 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1632 /* If adding the first, and head exists, find its prev */
1633 if (cfn->c_oc_head) {
1634 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1639 /* else prev is NULL, append to end of global list */
1641 if(parse_oc(c, &oc, prev)) return(1);
1642 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1643 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1648 AttributeType *at, *prev;
1650 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1651 cfn = c->ca_private;
1652 if ( c->valx < 0 ) {
1653 prev = cfn->c_at_tail;
1656 /* If adding anything after the first, prev is easy */
1659 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1664 /* If adding the first, and head exists, find its prev */
1665 if (cfn->c_at_head) {
1666 for ( at_start( &at ); at != cfn->c_at_head; ) {
1671 /* else prev is NULL, append to end of global list */
1673 if(parse_at(c, &at, prev)) return(1);
1674 if (!cfn->c_at_head) cfn->c_at_head = at;
1675 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1682 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1683 cfn = c->ca_private;
1684 if ( c->valx < 0 ) {
1685 prev = cfn->c_syn_tail;
1688 /* If adding anything after the first, prev is easy */
1691 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1696 /* If adding the first, and head exists, find its prev */
1697 if (cfn->c_syn_head) {
1698 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1703 /* else prev is NULL, append to end of global list */
1705 if ( parse_syn( c, &syn, prev ) ) return(1);
1706 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1707 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1714 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1715 cfn = c->ca_private;
1716 if(parse_cr(c, &cr)) return(1);
1717 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1718 cfn->c_cr_tail = cr;
1723 ad_define_option(NULL, NULL, 0);
1724 for(i = 1; i < c->argc; i++)
1725 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1730 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1731 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1732 else if ( c->value_int > 255 )
1734 index_intlen = c->value_int;
1735 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1739 case CFG_SORTVALS: {
1740 ADlist *svnew = NULL, *svtail, *sv;
1742 for ( i = 1; i < c->argc; i++ ) {
1743 AttributeDescription *ad = NULL;
1747 rc = slap_str2ad( c->argv[i], &ad, &text );
1749 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1752 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1753 c->log, c->cr_msg, c->argv[i] );
1754 for ( sv = svnew; sv; sv = svnew ) {
1755 svnew = sv->al_next;
1760 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1761 ad->ad_type->sat_single_value ) {
1762 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1764 goto sortval_reject;
1766 sv = ch_malloc( sizeof( ADlist ));
1771 svtail->al_next = sv;
1776 for ( sv = svnew; sv; sv = sv->al_next )
1777 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1778 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1780 sv->al_next = svnew;
1787 /* Don't append to the global ACL if we're on a specific DB */
1789 if ( c->valx == -1 ) {
1792 for ( a=c->be->be_acl; a; a = a->acl_next )
1795 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1802 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1804 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1808 if(root_dse_read_file(c->argv[1])) {
1809 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1810 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1811 c->log, c->cr_msg, c->argv[1] );
1816 ber_str2bv( c->argv[1], 0, 1, &bv );
1817 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1818 cfn = c->ca_private;
1819 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1825 ServerID *si, **sip;
1828 if (( lutil_atoi( &num, c->argv[1] ) &&
1829 lutil_atoix( &num, c->argv[1], 16 )) ||
1830 num < 0 || num > SLAP_SYNC_SID_MAX )
1832 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1833 "<%s> illegal server ID", c->argv[0] );
1834 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1835 c->log, c->cr_msg, c->argv[1] );
1838 /* only one value allowed if no URL is given */
1839 if ( c->argc > 2 ) {
1842 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1843 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1844 "<%s> only one server ID allowed now", c->argv[0] );
1845 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1846 c->log, c->cr_msg, c->argv[1] );
1850 if ( ldap_url_parse( c->argv[2], &lud )) {
1851 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1852 "<%s> invalid URL", c->argv[0] );
1853 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1854 c->log, c->cr_msg, c->argv[2] );
1857 len = strlen( c->argv[2] );
1858 si = ch_malloc( sizeof(ServerID) + len + 1 );
1859 si->si_url.bv_val = (char *)(si+1);
1860 si->si_url.bv_len = len;
1861 strcpy( si->si_url.bv_val, c->argv[2] );
1864 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1865 "<%s> unqualified server ID not allowed now", c->argv[0] );
1866 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1867 c->log, c->cr_msg, c->argv[1] );
1870 si = ch_malloc( sizeof(ServerID) );
1871 BER_BVZERO( &si->si_url );
1872 slap_serverID = num;
1873 Debug( LDAP_DEBUG_CONFIG,
1875 c->log, slap_serverID, 0 );
1879 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1882 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1883 Listener *l = config_check_my_url( c->argv[2], lud );
1885 slap_serverID = si->si_num;
1886 Debug( LDAP_DEBUG_CONFIG,
1887 "%s: SID=0x%03x (listener=%s)\n",
1888 c->log, slap_serverID,
1893 ldap_free_urldesc( lud );
1897 if ( logfileName ) ch_free( logfileName );
1898 logfileName = c->value_string;
1899 logfile = fopen(logfileName, "w");
1900 if(logfile) lutil_debug_file(logfile);
1904 if(SLAP_NOLASTMODCMD(c->be)) {
1905 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1906 c->argv[0], c->be->bd_info->bi_type );
1907 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1908 c->log, c->cr_msg, 0 );
1912 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1914 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1917 case CFG_MIRRORMODE:
1918 if(c->value_int && !SLAP_SHADOW(c->be)) {
1919 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1921 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1922 c->log, c->cr_msg, 0 );
1926 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1928 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1931 case CFG_MONITORING:
1933 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1935 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1940 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1942 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1945 case CFG_SYNC_SUBENTRY:
1947 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1949 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1952 case CFG_SSTR_IF_MAX:
1953 if (c->value_uint < index_substr_if_minlen) {
1954 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1955 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1956 c->log, c->cr_msg, c->value_int );
1959 index_substr_if_maxlen = c->value_uint;
1962 case CFG_SSTR_IF_MIN:
1963 if (c->value_uint > index_substr_if_maxlen) {
1964 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1965 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1966 c->log, c->cr_msg, c->value_int );
1969 index_substr_if_minlen = c->value_uint;
1972 #ifdef SLAPD_MODULES
1974 /* If we're just adding a module on an existing modpath,
1975 * make sure we've selected the current path.
1977 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1978 modcur = c->ca_private;
1979 /* This should never fail */
1980 if ( module_path( modcur->mp_path.bv_val )) {
1981 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1983 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1984 c->log, c->cr_msg, modcur->mp_path.bv_val );
1988 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1990 /* Record this load on the current path */
1994 if ( c->op == SLAP_CONFIG_ADD ) {
1995 ptr = c->line + STRLENOF("moduleload");
1996 while (!isspace((unsigned char) *ptr)) ptr++;
1997 while (isspace((unsigned char) *ptr)) ptr++;
2001 ber_str2bv(ptr, 0, 1, &bv);
2002 ber_bvarray_add( &modcur->mp_loads, &bv );
2004 /* Check for any new hardcoded schema */
2005 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2006 config_check_schema( NULL, &cfBackInfo );
2011 if(module_path(c->argv[1])) return(1);
2012 /* Record which path was used with each module */
2016 if (!modpaths.mp_loads) {
2019 mp = ch_malloc( sizeof( ModPaths ));
2020 modlast->mp_next = mp;
2022 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2024 mp->mp_loads = NULL;
2035 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2037 slapi_plugins_used++;
2041 #ifdef SLAP_AUTH_REWRITE
2047 if ( c->op == LDAP_MOD_ADD ) {
2051 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2055 if ( c->argc > 1 ) {
2058 /* quote all args but the first */
2059 line = ldap_charray2str( c->argv, "\" \"" );
2060 ber_str2bv( line, 0, 0, &bv );
2061 s = ber_bvchr( &bv, '"' );
2062 assert( s != NULL );
2063 /* move the trailing quote of argv[0] to the end */
2064 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2065 bv.bv_val[ bv.bv_len - 1 ] = '"';
2068 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2071 ber_bvarray_add( &authz_rewrites, &bv );
2073 if ( c->op == LDAP_MOD_ADD ) {
2083 Debug( LDAP_DEBUG_ANY,
2084 "%s: unknown CFG_TYPE %d.\n",
2085 c->log, c->type, 0 );
2094 config_fname(ConfigArgs *c) {
2095 if(c->op == SLAP_CONFIG_EMIT) {
2096 if (c->ca_private) {
2097 ConfigFile *cf = c->ca_private;
2098 value_add_one( &c->rvalue_vals, &cf->c_file );
2107 config_cfdir(ConfigArgs *c) {
2108 if(c->op == SLAP_CONFIG_EMIT) {
2109 if ( !BER_BVISEMPTY( &cfdir )) {
2110 value_add_one( &c->rvalue_vals, &cfdir );
2119 config_search_base(ConfigArgs *c) {
2120 if(c->op == SLAP_CONFIG_EMIT) {
2122 if (!BER_BVISEMPTY(&default_search_base)) {
2123 value_add_one(&c->rvalue_vals, &default_search_base);
2124 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2128 } else if( c->op == LDAP_MOD_DELETE ) {
2129 ch_free( default_search_base.bv_val );
2130 ch_free( default_search_nbase.bv_val );
2131 BER_BVZERO( &default_search_base );
2132 BER_BVZERO( &default_search_nbase );
2136 if(c->bi || c->be != frontendDB) {
2137 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2138 "prior to any backend or database definition\n",
2143 if(default_search_nbase.bv_len) {
2144 free(default_search_base.bv_val);
2145 free(default_search_nbase.bv_val);
2148 default_search_base = c->value_dn;
2149 default_search_nbase = c->value_ndn;
2153 /* For RE23 compatibility we allow this in the global entry
2154 * but we now defer it to the frontend entry to allow modules
2155 * to load new hash types.
2158 config_passwd_hash(ConfigArgs *c) {
2160 if (c->op == SLAP_CONFIG_EMIT) {
2162 /* Don't generate it in the global entry */
2163 if ( c->table == Cft_Global )
2165 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2166 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2167 value_add_one(&c->rvalue_vals, &bv);
2170 } else if ( c->op == LDAP_MOD_DELETE ) {
2171 /* Deleting from global is a no-op, only the frontendDB entry matters */
2172 if ( c->table == Cft_Global )
2174 if ( c->valx < 0 ) {
2175 ldap_charray_free( default_passwd_hash );
2176 default_passwd_hash = NULL;
2179 ch_free( default_passwd_hash[i] );
2180 for (; default_passwd_hash[i]; i++ )
2181 default_passwd_hash[i] = default_passwd_hash[i+1];
2185 for(i = 1; i < c->argc; i++) {
2186 if(!lutil_passwd_scheme(c->argv[i])) {
2187 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2188 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2189 c->log, c->cr_msg, c->argv[i]);
2191 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2194 if(!default_passwd_hash) {
2195 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2196 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2197 c->log, c->cr_msg, 0 );
2204 config_schema_dn(ConfigArgs *c) {
2205 if ( c->op == SLAP_CONFIG_EMIT ) {
2207 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2208 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2209 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2213 } else if ( c->op == LDAP_MOD_DELETE ) {
2214 ch_free( c->be->be_schemadn.bv_val );
2215 ch_free( c->be->be_schemandn.bv_val );
2216 BER_BVZERO( &c->be->be_schemadn );
2217 BER_BVZERO( &c->be->be_schemandn );
2220 ch_free( c->be->be_schemadn.bv_val );
2221 ch_free( c->be->be_schemandn.bv_val );
2222 c->be->be_schemadn = c->value_dn;
2223 c->be->be_schemandn = c->value_ndn;
2228 config_sizelimit(ConfigArgs *c) {
2230 struct slap_limits_set *lim = &c->be->be_def_limit;
2231 if (c->op == SLAP_CONFIG_EMIT) {
2236 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2237 if ( !BER_BVISEMPTY( &bv ))
2238 value_add_one( &c->rvalue_vals, &bv );
2242 } else if ( c->op == LDAP_MOD_DELETE ) {
2243 /* Reset to defaults or values from frontend */
2244 if ( c->be == frontendDB ) {
2245 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2246 lim->lms_s_hard = 0;
2247 lim->lms_s_unchecked = -1;
2249 lim->lms_s_pr_hide = 0;
2250 lim->lms_s_pr_total = 0;
2252 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2253 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2254 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2255 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2256 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2257 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2261 for(i = 1; i < c->argc; i++) {
2262 if(!strncasecmp(c->argv[i], "size", 4)) {
2263 rc = limits_parse_one(c->argv[i], lim);
2265 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2266 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2267 c->log, c->cr_msg, c->argv[i]);
2271 if(!strcasecmp(c->argv[i], "unlimited")) {
2272 lim->lms_s_soft = -1;
2274 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2275 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2276 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2277 c->log, c->cr_msg, c->argv[i]);
2281 lim->lms_s_hard = 0;
2286 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2287 /* This is a modification to the global limits apply it to
2288 * the other databases as needed */
2289 AttributeDescription *ad=NULL;
2290 const char *text = NULL;
2291 CfEntryInfo *ce = c->ca_entry->e_private;
2293 slap_str2ad(c->argv[0], &ad, &text);
2294 /* if we got here... */
2295 assert( ad != NULL );
2297 if ( ce->ce_type == Cft_Global ){
2300 for (; ce; ce=ce->ce_sibs) {
2301 Entry *dbe = ce->ce_entry;
2302 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2303 && (!attr_find(dbe->e_attrs, ad)) ) {
2304 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2305 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2306 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2307 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2308 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2309 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2317 config_timelimit(ConfigArgs *c) {
2319 struct slap_limits_set *lim = &c->be->be_def_limit;
2320 if (c->op == SLAP_CONFIG_EMIT) {
2325 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2326 if ( !BER_BVISEMPTY( &bv ))
2327 value_add_one( &c->rvalue_vals, &bv );
2331 } else if ( c->op == LDAP_MOD_DELETE ) {
2332 /* Reset to defaults or values from frontend */
2333 if ( c->be == frontendDB ) {
2334 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2335 lim->lms_t_hard = 0;
2337 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2338 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2342 for(i = 1; i < c->argc; i++) {
2343 if(!strncasecmp(c->argv[i], "time", 4)) {
2344 rc = limits_parse_one(c->argv[i], lim);
2346 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2347 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2348 c->log, c->cr_msg, c->argv[i]);
2352 if(!strcasecmp(c->argv[i], "unlimited")) {
2353 lim->lms_t_soft = -1;
2355 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2356 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2357 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2358 c->log, c->cr_msg, c->argv[i]);
2362 lim->lms_t_hard = 0;
2367 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2368 /* This is a modification to the global limits apply it to
2369 * the other databases as needed */
2370 AttributeDescription *ad=NULL;
2371 const char *text = NULL;
2372 CfEntryInfo *ce = c->ca_entry->e_private;
2374 slap_str2ad(c->argv[0], &ad, &text);
2375 /* if we got here... */
2376 assert( ad != NULL );
2378 if ( ce->ce_type == Cft_Global ){
2381 for (; ce; ce=ce->ce_sibs) {
2382 Entry *dbe = ce->ce_entry;
2383 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2384 && (!attr_find(dbe->e_attrs, ad)) ) {
2385 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2386 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2394 config_overlay(ConfigArgs *c) {
2395 if (c->op == SLAP_CONFIG_EMIT) {
2397 } else if ( c->op == LDAP_MOD_DELETE ) {
2400 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2401 c->valx, &c->bi, &c->reply)) {
2403 Debug( LDAP_DEBUG_ANY,
2404 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2405 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2407 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2414 config_subordinate(ConfigArgs *c)
2420 case SLAP_CONFIG_EMIT:
2421 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2424 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2425 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2428 value_add_one( &c->rvalue_vals, &bv );
2432 case LDAP_MOD_DELETE:
2433 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2434 glue_sub_del( c->be );
2436 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2441 case SLAP_CONFIG_ADD:
2442 if ( c->be->be_nsuffix == NULL ) {
2444 snprintf( c->cr_msg, sizeof( c->cr_msg),
2445 "subordinate configuration needs a suffix" );
2446 Debug( LDAP_DEBUG_ANY,
2448 c->log, c->cr_msg, 0 );
2453 if ( c->argc == 2 ) {
2454 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2457 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2459 snprintf( c->cr_msg, sizeof( c->cr_msg),
2460 "subordinate must be \"TRUE\" or \"advertise\"" );
2461 Debug( LDAP_DEBUG_ANY,
2462 "%s: suffix \"%s\": %s.\n",
2463 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2469 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2477 * [listener=<listener>] [{read|write}=]<size>
2480 #ifdef LDAP_TCP_BUFFER
2481 static BerVarray tcp_buffer;
2484 #define SLAP_TCP_RMEM (0x1U)
2485 #define SLAP_TCP_WMEM (0x2U)
2488 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2489 int *size, int *rw, Listener **l )
2491 int i, rc = LDAP_SUCCESS;
2492 LDAPURLDesc *lud = NULL;
2495 if ( val != NULL && argv == NULL ) {
2496 char *s = val->bv_val;
2498 argv = ldap_str2charray( s, " \t" );
2499 if ( argv == NULL ) {
2505 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2508 char *url = argv[ i ] + STRLENOF( "listener=" );
2510 if ( ldap_url_parse( url, &lud ) ) {
2511 rc = LDAP_INVALID_SYNTAX;
2515 *l = config_check_my_url( url, lud );
2517 rc = LDAP_NO_SUCH_ATTRIBUTE;
2525 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2526 *rw |= SLAP_TCP_RMEM;
2527 ptr += STRLENOF( "read=" );
2529 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2530 *rw |= SLAP_TCP_WMEM;
2531 ptr += STRLENOF( "write=" );
2534 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2537 /* accept any base */
2538 if ( lutil_atoix( size, ptr, 0 ) ) {
2539 rc = LDAP_INVALID_SYNTAX;
2544 if ( val != NULL && argv != NULL ) {
2545 ldap_charray_free( argv );
2548 if ( lud != NULL ) {
2549 ldap_free_urldesc( lud );
2556 tcp_buffer_delete_one( struct berval *val )
2559 int size = -1, rw = 0;
2562 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2569 Listener **ll = slapd_get_listeners();
2571 for ( i = 0; ll[ i ] != NULL; i++ ) {
2572 if ( ll[ i ] == l ) break;
2575 if ( ll[ i ] == NULL ) {
2576 return LDAP_NO_SUCH_ATTRIBUTE;
2579 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2580 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2582 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2583 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2584 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2588 /* NOTE: this affects listeners without a specific setting,
2589 * does not reset all listeners. If a listener without
2590 * specific settings was assigned a buffer because of
2591 * a global setting, it will not be reset. In any case,
2592 * buffer changes will only take place at restart. */
2593 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2594 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2601 tcp_buffer_delete( BerVarray vals )
2605 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2606 tcp_buffer_delete_one( &vals[ i ] );
2613 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2615 char buf[sizeof("2147483648")], *ptr;
2617 /* unparse for later use */
2618 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2620 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2623 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2624 if ( rw & SLAP_TCP_RMEM ) {
2625 val->bv_len += STRLENOF( "read=" );
2626 } else if ( rw & SLAP_TCP_WMEM ) {
2627 val->bv_len += STRLENOF( "write=" );
2631 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2636 ptr = lutil_strcopy( ptr, "listener=" );
2637 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2641 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2642 if ( rw & SLAP_TCP_RMEM ) {
2643 ptr = lutil_strcopy( ptr, "read=" );
2644 } else if ( rw & SLAP_TCP_WMEM ) {
2645 ptr = lutil_strcopy( ptr, "write=" );
2649 ptr = lutil_strcopy( ptr, buf );
2652 assert( val->bv_val + val->bv_len == ptr );
2654 return LDAP_SUCCESS;
2658 tcp_buffer_add_one( int argc, char **argv )
2661 int size = -1, rw = 0;
2667 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2672 /* unparse for later use */
2673 rc = tcp_buffer_unparse( size, rw, l, &val );
2674 if ( rc != LDAP_SUCCESS ) {
2678 /* use parsed values */
2681 Listener **ll = slapd_get_listeners();
2683 for ( i = 0; ll[ i ] != NULL; i++ ) {
2684 if ( ll[ i ] == l ) break;
2687 if ( ll[ i ] == NULL ) {
2688 return LDAP_NO_SUCH_ATTRIBUTE;
2691 /* buffer only applies to TCP listeners;
2692 * we do not do any check here, and delegate them
2693 * to setsockopt(2) */
2694 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2695 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2697 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2698 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2699 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2703 /* NOTE: this affects listeners without a specific setting,
2704 * does not set all listeners */
2705 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2706 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2709 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2711 tcp_buffer[ tcp_buffer_num ] = val;
2714 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2720 config_tcp_buffer( ConfigArgs *c )
2722 if ( c->op == SLAP_CONFIG_EMIT ) {
2723 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2726 value_add( &c->rvalue_vals, tcp_buffer );
2727 value_add( &c->rvalue_nvals, tcp_buffer );
2729 } else if ( c->op == LDAP_MOD_DELETE ) {
2731 tcp_buffer_delete( tcp_buffer );
2732 ber_bvarray_free( tcp_buffer );
2738 int size = -1, rw = 0;
2741 struct berval val = BER_BVNULL;
2745 if ( tcp_buffer_num == 0 ) {
2750 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2755 /* unparse for later use */
2756 rc = tcp_buffer_unparse( size, rw, l, &val );
2757 if ( rc != LDAP_SUCCESS ) {
2761 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2762 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2767 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2773 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2774 ber_memfree( tcp_buffer[ i ].bv_val );
2775 for ( ; i < tcp_buffer_num; i++ ) {
2776 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2781 if ( !BER_BVISNULL( &val ) ) {
2782 SLAP_FREE( val.bv_val );
2790 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2792 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2793 "<%s> unable to add value #%d",
2794 c->argv[0], tcp_buffer_num );
2795 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2796 c->log, c->cr_msg, 0 );
2803 #endif /* LDAP_TCP_BUFFER */
2806 config_suffix(ConfigArgs *c)
2809 struct berval pdn, ndn;
2810 char *notallowed = NULL;
2812 if ( c->be == frontendDB ) {
2813 notallowed = "frontend";
2815 } else if ( SLAP_MONITOR(c->be) ) {
2816 notallowed = "monitor";
2818 } else if ( SLAP_CONFIG(c->be) ) {
2819 notallowed = "config";
2822 if ( notallowed != NULL ) {
2823 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2827 case LDAP_MOD_DELETE:
2828 case LDAP_MOD_REPLACE:
2829 case LDAP_MOD_INCREMENT:
2830 case SLAP_CONFIG_ADD:
2831 if ( !BER_BVISNULL( &c->value_dn ) ) {
2832 snprintf( buf, sizeof( buf ), "<%s> ",
2833 c->value_dn.bv_val );
2836 Debug(LDAP_DEBUG_ANY,
2837 "%s: suffix %snot allowed in %s database.\n",
2838 c->log, buf, notallowed );
2841 case SLAP_CONFIG_EMIT:
2842 /* don't complain when emitting... */
2846 /* FIXME: don't know what values may be valid;
2847 * please remove assertion, or add legal values
2848 * to either block */
2856 if (c->op == SLAP_CONFIG_EMIT) {
2857 if ( c->be->be_suffix == NULL
2858 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2862 value_add( &c->rvalue_vals, c->be->be_suffix );
2863 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2866 } else if ( c->op == LDAP_MOD_DELETE ) {
2867 if ( c->valx < 0 ) {
2868 ber_bvarray_free( c->be->be_suffix );
2869 ber_bvarray_free( c->be->be_nsuffix );
2870 c->be->be_suffix = NULL;
2871 c->be->be_nsuffix = NULL;
2874 ch_free( c->be->be_suffix[i].bv_val );
2875 ch_free( c->be->be_nsuffix[i].bv_val );
2877 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2878 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2880 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2885 #ifdef SLAPD_MONITOR_DN
2886 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2887 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2889 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2890 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2895 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2896 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2897 c->argv[0], c->be->bd_info->bi_type );
2898 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2899 c->log, c->cr_msg, 0);
2906 if (SLAP_DBHIDDEN( c->be ))
2909 tbe = select_backend(&ndn, 0);
2911 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2917 BackendDB *b2 = tbe;
2919 /* Does tbe precede be? */
2920 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2923 char *type = tbe->bd_info->bi_type;
2925 if ( overlay_is_over( tbe ) ) {
2926 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2927 type = oi->oi_orig->bi_type;
2930 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2931 "already served by a preceding %s database",
2932 c->argv[0], pdn.bv_val, type );
2933 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2934 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2940 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2941 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2942 "base provided \"%s\" (assuming okay)\n",
2943 c->log, default_search_base.bv_val, 0);
2945 ber_bvarray_add(&c->be->be_suffix, &pdn);
2946 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2951 config_rootdn(ConfigArgs *c) {
2952 if (c->op == SLAP_CONFIG_EMIT) {
2953 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2954 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2955 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2960 } else if ( c->op == LDAP_MOD_DELETE ) {
2961 ch_free( c->be->be_rootdn.bv_val );
2962 ch_free( c->be->be_rootndn.bv_val );
2963 BER_BVZERO( &c->be->be_rootdn );
2964 BER_BVZERO( &c->be->be_rootndn );
2967 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2968 ch_free( c->be->be_rootdn.bv_val );
2969 ch_free( c->be->be_rootndn.bv_val );
2971 c->be->be_rootdn = c->value_dn;
2972 c->be->be_rootndn = c->value_ndn;
2977 config_rootpw(ConfigArgs *c) {
2980 if (c->op == SLAP_CONFIG_EMIT) {
2981 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2982 /* don't copy, because "rootpw" is marked
2984 c->value_bv = c->be->be_rootpw;
2988 } else if ( c->op == LDAP_MOD_DELETE ) {
2989 ch_free( c->be->be_rootpw.bv_val );
2990 BER_BVZERO( &c->be->be_rootpw );
2994 tbe = select_backend(&c->be->be_rootndn, 0);
2996 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2998 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2999 c->log, c->cr_msg, 0);
3002 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3003 ch_free( c->be->be_rootpw.bv_val );
3004 c->be->be_rootpw = c->value_bv;
3009 config_restrict(ConfigArgs *c) {
3010 slap_mask_t restrictops = 0;
3012 slap_verbmasks restrictable_ops[] = {
3013 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3014 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3015 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3016 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3017 { BER_BVC("modrdn"), 0 },
3018 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3019 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3020 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3021 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3022 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3023 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3024 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3025 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3026 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3027 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3028 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3032 if (c->op == SLAP_CONFIG_EMIT) {
3033 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3035 } else if ( c->op == LDAP_MOD_DELETE ) {
3037 c->be->be_restrictops = 0;
3039 restrictops = verb_to_mask( c->line, restrictable_ops );
3040 c->be->be_restrictops ^= restrictops;
3044 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3046 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3047 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3048 c->log, c->cr_msg, c->argv[i]);
3051 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3052 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3053 c->be->be_restrictops |= restrictops;
3058 config_allows(ConfigArgs *c) {
3059 slap_mask_t allows = 0;
3061 slap_verbmasks allowable_ops[] = {
3062 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3063 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3064 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3065 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3066 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3069 if (c->op == SLAP_CONFIG_EMIT) {
3070 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3071 } else if ( c->op == LDAP_MOD_DELETE ) {
3075 allows = verb_to_mask( c->line, allowable_ops );
3076 global_allows ^= allows;
3080 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3082 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3083 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3084 c->log, c->cr_msg, c->argv[i]);
3087 global_allows |= allows;
3092 config_disallows(ConfigArgs *c) {
3093 slap_mask_t disallows = 0;
3095 slap_verbmasks disallowable_ops[] = {
3096 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3097 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3098 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3099 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3100 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3101 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3104 if (c->op == SLAP_CONFIG_EMIT) {
3105 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3106 } else if ( c->op == LDAP_MOD_DELETE ) {
3108 global_disallows = 0;
3110 disallows = verb_to_mask( c->line, disallowable_ops );
3111 global_disallows ^= disallows;
3115 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3117 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3118 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3119 c->log, c->cr_msg, c->argv[i]);
3122 global_disallows |= disallows;
3127 config_requires(ConfigArgs *c) {
3128 slap_mask_t requires = frontendDB->be_requires;
3129 int i, argc = c->argc;
3130 char **argv = c->argv;
3132 slap_verbmasks requires_ops[] = {
3133 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3134 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3135 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3136 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3137 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3140 if (c->op == SLAP_CONFIG_EMIT) {
3141 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3142 } else if ( c->op == LDAP_MOD_DELETE ) {
3144 c->be->be_requires = 0;
3146 requires = verb_to_mask( c->line, requires_ops );
3147 c->be->be_requires ^= requires;
3151 /* "none" can only be first, to wipe out default/global values */
3152 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3157 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3159 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3160 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3161 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3162 c->log, c->cr_msg, 0);
3164 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3165 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3166 c->log, c->cr_msg, c->argv[i]);
3170 c->be->be_requires = requires;
3174 static slap_verbmasks *loglevel_ops;
3177 loglevel_init( void )
3179 slap_verbmasks lo[] = {
3180 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3181 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3182 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3183 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3184 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3185 { BER_BVC("BER"), LDAP_DEBUG_BER },
3186 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3187 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3188 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3189 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3190 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3191 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3192 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3193 #if 0 /* no longer used (nor supported) */
3194 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3195 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3197 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3198 { BER_BVC("None"), LDAP_DEBUG_NONE },
3202 return slap_verbmasks_init( &loglevel_ops, lo );
3206 loglevel_destroy( void )
3208 if ( loglevel_ops ) {
3209 (void)slap_verbmasks_destroy( loglevel_ops );
3211 loglevel_ops = NULL;
3214 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3217 slap_loglevel_register( slap_mask_t m, struct berval *s )
3221 if ( loglevel_ops == NULL ) {
3225 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3228 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3236 slap_loglevel_get( struct berval *s, int *l )
3241 if ( loglevel_ops == NULL ) {
3245 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3246 m |= loglevel_ops[ i ].mask;
3249 for ( i = 1; m & i; i <<= 1 )
3256 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3259 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3270 str2loglevel( const char *s, int *l )
3274 if ( loglevel_ops == NULL ) {
3278 i = verb_to_mask( s, loglevel_ops );
3280 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3284 *l = loglevel_ops[ i ].mask;
3290 loglevel2str( int l )
3292 struct berval bv = BER_BVNULL;
3294 loglevel2bv( l, &bv );
3300 loglevel2bv( int l, struct berval *bv )
3302 if ( loglevel_ops == NULL ) {
3308 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3312 loglevel2bvarray( int l, BerVarray *bva )
3314 if ( loglevel_ops == NULL ) {
3318 return mask_to_verbs( loglevel_ops, l, bva );
3322 loglevel_print( FILE *out )
3326 if ( loglevel_ops == NULL ) {
3330 fprintf( out, "Installed log subsystems:\n\n" );
3331 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3332 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3334 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3335 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3336 loglevel_ops[ i ].word.bv_val, mask, mask );
3339 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3340 "by specific code\n\n" );
3345 static int config_syslog;
3348 config_loglevel(ConfigArgs *c) {
3351 if ( loglevel_ops == NULL ) {
3355 if (c->op == SLAP_CONFIG_EMIT) {
3356 /* Get default or commandline slapd setting */
3357 if ( ldap_syslog && !config_syslog )
3358 config_syslog = ldap_syslog;
3359 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3361 } else if ( c->op == LDAP_MOD_DELETE ) {
3365 int level = verb_to_mask( c->line, loglevel_ops );
3366 config_syslog ^= level;
3368 if ( slapMode & SLAP_SERVER_MODE ) {
3369 ldap_syslog = config_syslog;
3374 for( i=1; i < c->argc; i++ ) {
3377 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3378 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3379 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3380 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3381 c->log, c->cr_msg, c->argv[i]);
3385 if ( str2loglevel( c->argv[i], &level ) ) {
3386 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3387 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3388 c->log, c->cr_msg, c->argv[i]);
3392 /* Explicitly setting a zero clears all the levels */
3394 config_syslog |= level;
3398 if ( slapMode & SLAP_SERVER_MODE ) {
3399 ldap_syslog = config_syslog;
3405 config_referral(ConfigArgs *c) {
3407 if (c->op == SLAP_CONFIG_EMIT) {
3408 if ( default_referral ) {
3409 value_add( &c->rvalue_vals, default_referral );
3414 } else if ( c->op == LDAP_MOD_DELETE ) {
3415 if ( c->valx < 0 ) {
3416 ber_bvarray_free( default_referral );
3417 default_referral = NULL;
3420 ch_free( default_referral[i].bv_val );
3421 for (; default_referral[i].bv_val; i++ )
3422 default_referral[i] = default_referral[i+1];
3426 if(validate_global_referral(c->argv[1])) {
3427 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3428 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3429 c->log, c->cr_msg, c->argv[1]);
3433 ber_str2bv(c->argv[1], 0, 0, &val);
3434 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3442 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3443 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3444 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3445 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3446 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3447 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3448 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3449 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3450 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3455 config_security(ConfigArgs *c) {
3456 slap_ssf_set_t *set = &c->be->be_ssf_set;
3459 if (c->op == SLAP_CONFIG_EMIT) {
3465 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3466 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3469 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3470 if ( bv.bv_len >= sizeof( numbuf ) ) {
3471 ber_bvarray_free_x( c->rvalue_vals, NULL );
3472 c->rvalue_vals = NULL;
3476 bv.bv_len += sec_keys[i].key.bv_len;
3477 bv.bv_val = ch_malloc( bv.bv_len + 1);
3478 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3479 strcpy( next, numbuf );
3480 ber_bvarray_add( &c->rvalue_vals, &bv );
3485 for(i = 1; i < c->argc; i++) {
3486 slap_ssf_t *tgt = NULL;
3488 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3489 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3490 sec_keys[j].key.bv_len)) {
3491 src = c->argv[i] + sec_keys[j].key.bv_len;
3492 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3497 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3498 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3499 c->log, c->cr_msg, c->argv[i]);
3503 if ( lutil_atou( tgt, src ) != 0 ) {
3504 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3505 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3506 c->log, c->cr_msg, c->argv[i]);
3514 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3518 for (; !BER_BVISNULL( &an->an_name ); an++) {
3519 /* if buflen == 0, assume the buffer size has been
3520 * already checked otherwise */
3521 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3522 if ( comma ) *ptr++ = ',';
3523 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3530 config_updatedn(ConfigArgs *c) {
3531 if (c->op == SLAP_CONFIG_EMIT) {
3532 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3533 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3534 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3538 } else if ( c->op == LDAP_MOD_DELETE ) {
3539 ch_free( c->be->be_update_ndn.bv_val );
3540 BER_BVZERO( &c->be->be_update_ndn );
3541 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3544 if(SLAP_SHADOW(c->be)) {
3545 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3546 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3547 c->log, c->cr_msg, 0);
3551 ber_memfree_x( c->value_dn.bv_val, NULL );
3552 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3553 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3555 c->be->be_update_ndn = c->value_ndn;
3556 BER_BVZERO( &c->value_dn );
3557 BER_BVZERO( &c->value_ndn );
3559 return config_slurp_shadow( c );
3563 config_shadow( ConfigArgs *c, slap_mask_t flag )
3565 char *notallowed = NULL;
3567 if ( c->be == frontendDB ) {
3568 notallowed = "frontend";
3570 } else if ( SLAP_MONITOR(c->be) ) {
3571 notallowed = "monitor";
3574 if ( notallowed != NULL ) {
3575 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3579 if ( SLAP_SHADOW(c->be) ) {
3580 /* if already shadow, only check consistency */
3581 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3582 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3588 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3595 config_updateref(ConfigArgs *c) {
3597 if (c->op == SLAP_CONFIG_EMIT) {
3598 if ( c->be->be_update_refs ) {
3599 value_add( &c->rvalue_vals, c->be->be_update_refs );
3604 } else if ( c->op == LDAP_MOD_DELETE ) {
3605 if ( c->valx < 0 ) {
3606 ber_bvarray_free( c->be->be_update_refs );
3607 c->be->be_update_refs = NULL;
3610 ch_free( c->be->be_update_refs[i].bv_val );
3611 for (; c->be->be_update_refs[i].bv_val; i++)
3612 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3616 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3617 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3619 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3620 c->log, c->cr_msg, 0);
3624 if(validate_global_referral(c->argv[1])) {
3625 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3626 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3627 c->log, c->cr_msg, c->argv[1]);
3630 ber_str2bv(c->argv[1], 0, 0, &val);
3631 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3636 config_obsolete(ConfigArgs *c) {
3637 if (c->op == SLAP_CONFIG_EMIT)
3640 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3642 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3647 config_include(ConfigArgs *c) {
3648 int savelineno = c->lineno;
3651 ConfigFile *cfsave = cfn;
3652 ConfigFile *cf2 = NULL;
3654 /* Leftover from RE23. No dynamic config for include files */
3655 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3658 cf = ch_calloc( 1, sizeof(ConfigFile));
3659 if ( cfn->c_kids ) {
3660 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3666 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3667 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3668 c->lineno = savelineno - 1;
3671 if ( cf2 ) cf2->c_sibs = NULL;
3672 else cfn->c_kids = NULL;
3673 ch_free( cf->c_file.bv_val );
3683 config_tls_cleanup(ConfigArgs *c) {
3686 if ( slap_tls_ld ) {
3689 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3691 /* Force new ctx to be created */
3692 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3694 /* The ctx's refcount is bumped up here */
3695 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3696 /* This is a no-op if it's already loaded */
3697 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3704 config_tls_option(ConfigArgs *c) {
3706 LDAP *ld = slap_tls_ld;
3708 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3709 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3710 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3711 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3712 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3713 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3714 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3716 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3718 default: Debug(LDAP_DEBUG_ANY, "%s: "
3719 "unknown tls_option <0x%x>\n",
3720 c->log, c->type, 0);
3723 if (c->op == SLAP_CONFIG_EMIT) {
3724 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3725 } else if ( c->op == LDAP_MOD_DELETE ) {
3726 c->cleanup = config_tls_cleanup;
3727 return ldap_pvt_tls_set_option( ld, flag, NULL );
3729 ch_free(c->value_string);
3730 c->cleanup = config_tls_cleanup;
3731 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3734 /* FIXME: this ought to be provided by libldap */
3736 config_tls_config(ConfigArgs *c) {
3739 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3740 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3741 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3743 Debug(LDAP_DEBUG_ANY, "%s: "
3744 "unknown tls_option <0x%x>\n",
3745 c->log, c->type, 0);
3748 if (c->op == SLAP_CONFIG_EMIT) {
3749 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3750 } else if ( c->op == LDAP_MOD_DELETE ) {
3752 c->cleanup = config_tls_cleanup;
3753 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3755 ch_free( c->value_string );
3756 c->cleanup = config_tls_cleanup;
3757 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3758 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3759 Debug(LDAP_DEBUG_ANY, "%s: "
3760 "unable to parse %s \"%s\"\n",
3761 c->log, c->argv[0], c->argv[1] );
3764 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3766 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3771 static CfEntryInfo *
3772 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3782 if ( dn_match( &root->ce_entry->e_nname, dn ))
3785 c = dn->bv_val+dn->bv_len;
3786 for (;*c != ',';c--);
3790 for (--c;c>dn->bv_val && *c != ',';c--);
3794 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3796 root = root->ce_kids;
3798 for (;root;root=root->ce_sibs) {
3799 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3800 if ( cdn.bv_val == dn->bv_val ) {
3810 typedef struct setup_cookie {
3820 config_ldif_resp( Operation *op, SlapReply *rs )
3822 if ( rs->sr_type == REP_SEARCH ) {
3823 setup_cookie *sc = op->o_callback->sc_private;
3826 sc->cfb->cb_got_ldif = 1;
3827 /* Does the frontend exist? */
3828 if ( !sc->got_frontend ) {
3829 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3830 "olcDatabase", STRLENOF( "olcDatabase" )))
3832 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3833 STRLENOF( "olcDatabase" ), "={-1}frontend",
3834 STRLENOF( "={-1}frontend" )))
3838 sc->ca->be = frontendDB;
3839 sc->ca->bi = frontendDB->bd_info;
3840 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3841 rdn.bv_val = sc->ca->log;
3842 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3843 "%s=" SLAP_X_ORDERED_FMT "%s",
3844 cfAd_database->ad_cname.bv_val, -1,
3845 sc->ca->bi->bi_type);
3847 sc->frontend = config_build_entry( op, rs,
3848 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3849 sc->ca->be->be_cf_ocs );
3859 dnParent( &rs->sr_entry->e_nname, &pdn );
3861 /* Does the configDB exist? */
3862 if ( sc->got_frontend && !sc->got_config &&
3863 !strncmp( rs->sr_entry->e_nname.bv_val,
3864 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3865 dn_match( &config_rdn, &pdn ) )
3867 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3868 STRLENOF( "olcDatabase" ), "={0}config",
3869 STRLENOF( "={0}config" )))
3873 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3874 sc->ca->bi = sc->ca->be->bd_info;
3875 rdn.bv_val = sc->ca->log;
3876 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3877 "%s=" SLAP_X_ORDERED_FMT "%s",
3878 cfAd_database->ad_cname.bv_val, 0,
3879 sc->ca->bi->bi_type);
3881 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3882 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3889 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3890 if ( rs->sr_err != LDAP_SUCCESS ) {
3891 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3892 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3898 /* Configure and read the underlying back-ldif store */
3900 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3901 CfBackInfo *cfb = be->be_private;
3907 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3908 Connection conn = {0};
3909 OperationBuffer opbuf;
3911 SlapReply rs = {REP_RESULT};
3912 Filter filter = { LDAP_FILTER_PRESENT };
3913 struct berval filterstr = BER_BVC("(objectclass=*)");
3916 /* Is the config directory available? */
3917 if ( stat( dir, &st ) < 0 ) {
3918 /* No, so don't bother using the backing store.
3919 * All changes will be in-memory only.
3924 cfb->cb_db.bd_info = backend_info( "ldif" );
3925 if ( !cfb->cb_db.bd_info )
3926 return 0; /* FIXME: eventually this will be a fatal error */
3928 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3931 cfb->cb_db.be_suffix = be->be_suffix;
3932 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3934 /* The suffix is always "cn=config". The underlying DB's rootdn
3935 * is always the same as the suffix.
3937 cfb->cb_db.be_rootdn = be->be_suffix[0];
3938 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3940 ber_str2bv( dir, 0, 1, &cfdir );
3945 argv[0] = "directory";
3946 argv[1] = (char *)dir;
3951 c.table = Cft_Database;
3953 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3957 if ( config_add_vals( ct, &c ))
3960 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3964 void *thrctx = ldap_pvt_thread_pool_context();
3967 connection_fake_init( &conn, &opbuf, thrctx );
3970 filter.f_desc = slap_schema.si_ad_objectClass;
3972 op->o_tag = LDAP_REQ_SEARCH;
3974 op->ors_filter = &filter;
3975 op->ors_filterstr = filterstr;
3976 op->ors_scope = LDAP_SCOPE_SUBTREE;
3978 op->o_dn = c.be->be_rootdn;
3979 op->o_ndn = c.be->be_rootndn;
3981 op->o_req_dn = be->be_suffix[0];
3982 op->o_req_ndn = be->be_nsuffix[0];
3984 op->ors_tlimit = SLAP_NO_LIMIT;
3985 op->ors_slimit = SLAP_NO_LIMIT;
3987 op->ors_attrs = slap_anlist_all_attributes;
3988 op->ors_attrsonly = 0;
3990 op->o_callback = &cb;
3993 cb.sc_private = ≻
3994 sc.got_frontend = 0;
3999 op->o_bd = &cfb->cb_db;
4001 /* Allow unknown attrs in DNs */
4002 prev_DN_strict = slap_DN_strict;
4005 rc = op->o_bd->be_search( op, &rs );
4007 /* Restore normal DN validation */
4008 slap_DN_strict = prev_DN_strict;
4010 op->o_tag = LDAP_REQ_ADD;
4011 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4012 rs_reinit( &rs, REP_RESULT );
4013 op->ora_e = sc.frontend;
4014 rc = op->o_bd->be_add( op, &rs );
4016 if ( rc == LDAP_SUCCESS && sc.config ) {
4017 rs_reinit( &rs, REP_RESULT );
4018 op->ora_e = sc.config;
4019 rc = op->o_bd->be_add( op, &rs );
4021 ldap_pvt_thread_pool_context_reset( thrctx );
4024 /* ITS#4194 - only use if it's present, or we're converting. */
4025 if ( !readit || rc == LDAP_SUCCESS )
4026 cfb->cb_use_ldif = 1;
4032 CfOc_cmp( const void *c1, const void *c2 ) {
4033 const ConfigOCs *co1 = c1;
4034 const ConfigOCs *co2 = c2;
4036 return ber_bvcmp( co1->co_name, co2->co_name );
4040 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4043 i = init_config_attrs( ct );
4046 /* set up the objectclasses */
4047 i = init_config_ocs( ocs );
4050 for (i=0; ocs[i].co_def; i++) {
4051 if ( ocs[i].co_oc ) {
4052 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4053 if ( !ocs[i].co_table )
4054 ocs[i].co_table = ct;
4055 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4062 read_config(const char *fname, const char *dir) {
4065 const char *cfdir, *cfname;
4068 /* Setup the config backend */
4069 be = backend_db_init( "config", NULL, 0, NULL );
4073 cfb = be->be_private;
4074 be->be_dfltaccess = ACL_NONE;
4076 /* If no .conf, or a dir was specified, setup the dir */
4077 if ( !fname || dir ) {
4079 /* If explicitly given, check for existence */
4082 if ( stat( dir, &st ) < 0 ) {
4083 Debug( LDAP_DEBUG_ANY,
4084 "invalid config directory %s, error %d\n",
4090 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4092 /* if fname is defaulted, try reading .d */
4093 rc = config_setup_ldif( be, cfdir, !fname );
4096 /* It may be OK if the base object doesn't exist yet. */
4097 if ( rc != LDAP_NO_SUCH_OBJECT )
4099 /* ITS#4194: But if dir was specified and no fname,
4100 * then we were supposed to read the dir. Unless we're
4101 * trying to slapadd the dir...
4103 if ( dir && !fname ) {
4104 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4106 /* Assume it's slapadd with a config dir, let it continue */
4108 cfb->cb_got_ldif = 1;
4109 cfb->cb_use_ldif = 1;
4114 /* If we read the config from back-ldif, nothing to do here */
4115 if ( cfb->cb_got_ldif ) {
4124 cfname = SLAPD_DEFAULT_CONFIGFILE;
4126 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4129 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4132 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4133 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4134 &frontendDB->be_schemadn );
4135 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4136 if ( rc != LDAP_SUCCESS ) {
4137 Debug(LDAP_DEBUG_ANY, "read_config: "
4138 "unable to normalize default schema DN \"%s\"\n",
4139 frontendDB->be_schemadn.bv_val, 0, 0 );
4140 /* must not happen */
4148 config_back_bind( Operation *op, SlapReply *rs )
4150 if ( be_isroot_pw( op ) ) {
4151 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4152 /* frontend sends result */
4153 return LDAP_SUCCESS;
4156 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4157 send_ldap_result( op, rs );
4163 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4167 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4169 rs->sr_attrs = op->ors_attrs;
4170 rs->sr_entry = ce->ce_entry;
4172 rc = send_search_entry( op, rs );
4173 if ( rc != LDAP_SUCCESS ) {
4177 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4178 if ( ce->ce_kids ) {
4179 rc = config_send( op, rs, ce->ce_kids, 1 );
4180 if ( rc ) return rc;
4183 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4184 rc = config_send( op, rs, ce, 0 );
4192 static ConfigTable *
4193 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4198 for (j=0; j<nocs; j++) {
4199 for (i=0; colst[j]->co_table[i].name; i++)
4200 if ( colst[j]->co_table[i].ad == ad ) {
4201 ca->table = colst[j]->co_type;
4202 return &colst[j]->co_table[i];
4208 /* Sort the attributes of the entry according to the order defined
4209 * in the objectclass, with required attributes occurring before
4210 * allowed attributes. For any attributes with sequencing dependencies
4211 * (e.g., rootDN must be defined after suffix) the objectclass must
4212 * list the attributes in the desired sequence.
4215 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4217 Attribute *a, *head = NULL, *tail = NULL, **prev;
4220 for (i=0; i<nocs; i++) {
4221 if ( colst[i]->co_oc->soc_required ) {
4222 AttributeType **at = colst[i]->co_oc->soc_required;
4223 for (j=0; at[j]; j++) {
4224 for (a=e->e_attrs, prev=&e->e_attrs; a;
4225 prev = &(*prev)->a_next, a=a->a_next) {
4226 if ( a->a_desc == at[j]->sat_ad ) {
4240 if ( colst[i]->co_oc->soc_allowed ) {
4241 AttributeType **at = colst[i]->co_oc->soc_allowed;
4242 for (j=0; at[j]; j++) {
4243 for (a=e->e_attrs, prev=&e->e_attrs; a;
4244 prev = &(*prev)->a_next, a=a->a_next) {
4245 if ( a->a_desc == at[j]->sat_ad ) {
4261 tail->a_next = e->e_attrs;
4267 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4269 Attribute *a = NULL;
4270 AttributeDescription *ad;
4280 Modifications *ml = ptr;
4282 vals = ml->sml_values;
4285 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4286 rc = ordered_value_sort( a, 1 );
4288 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4289 ad->ad_cname.bv_val );
4293 for ( i=0; vals[i].bv_val; i++ ) {
4294 ca->line = vals[i].bv_val;
4295 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4296 ca->line[0] == '{' ) {
4297 char *idx = strchr( ca->line, '}' );
4298 if ( idx ) ca->line = idx+1;
4300 rc = config_parse_vals( ct, ca, i );
4309 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4312 struct berval rtype, rval;
4314 AttributeDescription *ad = NULL;
4316 dnRdn( &e->e_name, rdn );
4317 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4318 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4319 rtype.bv_val = rdn->bv_val;
4320 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4323 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4324 a = attr_find( e->e_attrs, ad );
4325 if (!a ) return LDAP_NAMING_VIOLATION;
4332 config_rename_kids( CfEntryInfo *ce )
4335 struct berval rdn, nrdn;
4337 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4338 struct berval newdn, newndn;
4339 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4340 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4341 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4342 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4343 free( ce2->ce_entry->e_name.bv_val );
4344 free( ce2->ce_entry->e_nname.bv_val );
4345 ce2->ce_entry->e_name = newdn;
4346 ce2->ce_entry->e_nname = newndn;
4347 config_rename_kids( ce2 );
4352 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4353 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4354 struct berval *nnewrdn, int use_ldif )
4358 struct berval odn, ondn;
4362 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4363 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4366 free( a->a_vals[0].bv_val );
4367 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4368 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4369 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4370 strcpy( a->a_vals[0].bv_val, ptr1 );
4372 if ( a->a_nvals != a->a_vals ) {
4373 free( a->a_nvals[0].bv_val );
4374 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4375 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4376 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4377 strcpy( a->a_nvals[0].bv_val, ptr1 );
4380 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4381 BackendDB *be = op->o_bd;
4382 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4383 struct berval dn, ndn, xdn, xndn;
4385 op->o_bd = &cfb->cb_db;
4387 /* Save current rootdn; use the underlying DB's rootdn */
4391 xndn = op->o_req_ndn;
4392 op->o_dn = op->o_bd->be_rootdn;
4393 op->o_ndn = op->o_bd->be_rootndn;
4395 op->o_req_ndn = ondn;
4397 scp = op->o_callback;
4398 op->o_callback = ≻
4399 op->orr_newrdn = *newrdn;
4400 op->orr_nnewrdn = *nnewrdn;
4401 op->orr_newSup = NULL;
4402 op->orr_nnewSup = NULL;
4403 op->orr_deleteoldrdn = 1;
4404 op->orr_modlist = NULL;
4405 slap_modrdn2mods( op, rs );
4406 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4407 rc = op->o_bd->be_modrdn( op, rs );
4408 slap_mods_free( op->orr_modlist, 1 );
4411 op->o_callback = scp;
4415 op->o_req_ndn = xndn;
4418 free( ondn.bv_val );
4420 config_rename_kids( e->e_private );
4425 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4426 Entry *e, int idx, int tailindex, int use_ldif )
4428 struct berval ival, newrdn, nnewrdn;
4431 char ibuf[32], *ptr1, *ptr2 = NULL;
4434 rc = config_rename_attr( rs, e, &rdn, &a );
4435 if ( rc ) return rc;
4438 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4439 if ( ival.bv_len >= sizeof( ibuf ) ) {
4440 return LDAP_NAMING_VIOLATION;
4443 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4444 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4447 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4448 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4451 ptr2 = ber_bvchr( &rdn, '}' );
4455 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4457 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4458 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4459 a->a_desc->ad_cname.bv_len );
4461 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4462 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4466 /* Do the equivalent of ModRDN */
4467 /* Replace DN / NDN */
4468 newrdn.bv_len = ptr1 - newrdn.bv_val;
4469 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4470 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4472 free( nnewrdn.bv_val );
4473 free( newrdn.bv_val );
4478 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4479 SlapReply *rs, int *renum, int *ibase )
4482 int index = -1, gotindex = 0, nsibs, rc = 0;
4483 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4484 char *ptr1, *ptr2 = NULL;
4487 if ( renum ) *renum = 0;
4489 /* These entries don't get indexed/renumbered */
4490 if ( ce_type == Cft_Global ) return 0;
4491 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4493 if ( ce_type == Cft_Module )
4496 /* See if the rdn has an index already */
4497 dnRdn( &e->e_name, &rdn );
4498 if ( ce_type == Cft_Database ) {
4499 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4500 "frontend", STRLENOF("frontend") ))
4502 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4503 "config", STRLENOF("config") ))
4506 ptr1 = ber_bvchr( &e->e_name, '{' );
4507 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4509 ptr2 = strchr( ptr1, '}' );
4510 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4511 return LDAP_NAMING_VIOLATION;
4512 if ( ptr2-ptr1 == 1)
4513 return LDAP_NAMING_VIOLATION;
4515 index = strtol( ptr1 + 1, &next, 10 );
4516 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4517 return LDAP_NAMING_VIOLATION;
4520 /* Special case, we allow -1 for the frontendDB */
4521 if ( index != -1 || !isfrontend )
4522 return LDAP_NAMING_VIOLATION;
4524 if ( isconfig && index != 0 ){
4525 return LDAP_NAMING_VIOLATION;
4529 /* count related kids */
4530 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4531 if ( ce->ce_type == ce_type ) nsibs++;
4534 /* account for -1 frontend */
4535 if ( ce_type == Cft_Database )
4538 if ( index != nsibs ) {
4540 if ( index < nsibs ) {
4541 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4542 /* Siblings need to be renumbered */
4543 if ( index != -1 || !isfrontend )
4547 /* config DB is always "0" */
4548 if ( isconfig && index == -1 ) {
4551 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4555 /* just make index = nsibs */
4557 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4560 if ( ibase ) *ibase = index;
4561 if ( renum ) *renum = renumber;
4566 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4571 co.co_name = &oc->soc_cname;
4572 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4576 /* check for duplicates */
4577 for ( i = 0; i < *nocs; i++ ) {
4578 if ( *copp && (*copp)[i] == cop ) {
4584 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4585 if ( tmp == NULL ) {
4589 (*copp)[*nocs] = cop;
4594 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4595 if ( count_oc( *sups, copp, nocs ) ) {
4604 count_ocs( Attribute *oc_at, int *nocs )
4607 ConfigOCs **colst = NULL;
4611 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4615 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4617 assert( oc != NULL );
4618 if ( count_oc( oc, &colst, nocs ) ) {
4628 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4630 /* Leftover from RE23. Never parse this entry */
4631 return LDAP_COMPARE_TRUE;
4635 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4639 /* This entry is hardcoded, don't re-parse it */
4640 if ( p->ce_type == Cft_Global ) {
4641 cfn = p->ce_private;
4642 ca->ca_private = cfn;
4643 return LDAP_COMPARE_TRUE;
4645 if ( p->ce_type != Cft_Schema )
4646 return LDAP_CONSTRAINT_VIOLATION;
4648 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4649 ca->ca_private = cfn;
4650 cfo = p->ce_private;
4651 cfn->c_sibs = cfo->c_kids;
4653 return LDAP_SUCCESS;
4657 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4659 if ( p->ce_type != Cft_Global ) {
4660 return LDAP_CONSTRAINT_VIOLATION;
4662 /* config must be {0}, nothing else allowed */
4663 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4664 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4665 return LDAP_CONSTRAINT_VIOLATION;
4667 ca->be = frontendDB; /* just to get past check_vals */
4668 return LDAP_SUCCESS;
4672 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4674 if ( p->ce_type != Cft_Global ) {
4675 return LDAP_CONSTRAINT_VIOLATION;
4677 return LDAP_SUCCESS;
4681 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4683 if ( p->ce_type != Cft_Global ) {
4684 return LDAP_CONSTRAINT_VIOLATION;
4686 return LDAP_SUCCESS;
4690 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4692 if ( p->ce_type != Cft_Database ) {
4693 return LDAP_CONSTRAINT_VIOLATION;
4696 return LDAP_SUCCESS;
4700 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4705 AttributeDescription *ad;
4711 if ( cfn->c_cr_head ) {
4712 struct berval bv = BER_BVC("olcDitContentRules");
4714 slap_bv2ad( &bv, &ad, &text );
4715 ct = config_find_table( colst, nocs, ad, ca );
4716 config_del_vals( ct, ca );
4718 if ( cfn->c_oc_head ) {
4719 struct berval bv = BER_BVC("olcObjectClasses");
4721 slap_bv2ad( &bv, &ad, &text );
4722 ct = config_find_table( colst, nocs, ad, ca );
4723 config_del_vals( ct, ca );
4725 if ( cfn->c_at_head ) {
4726 struct berval bv = BER_BVC("olcAttributeTypes");
4728 slap_bv2ad( &bv, &ad, &text );
4729 ct = config_find_table( colst, nocs, ad, ca );
4730 config_del_vals( ct, ca );
4732 if ( cfn->c_syn_head ) {
4733 struct berval bv = BER_BVC("olcLdapSyntaxes");
4735 slap_bv2ad( &bv, &ad, &text );
4736 ct = config_find_table( colst, nocs, ad, ca );
4737 config_del_vals( ct, ca );
4739 if ( cfn->c_om_head ) {
4740 struct berval bv = BER_BVC("olcObjectIdentifier");
4742 slap_bv2ad( &bv, &ad, &text );
4743 ct = config_find_table( colst, nocs, ad, ca );
4744 config_del_vals( ct, ca );
4746 cfo = p->ce_private;
4747 cfo->c_kids = cfn->c_sibs;
4752 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4754 int rc = LDAP_CONSTRAINT_VIOLATION;
4757 if ( (*cop)->co_ldadd ) {
4758 rc = (*cop)->co_ldadd( last, e, ca );
4759 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4764 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4765 ConfigOCs co = { 0 };
4767 co.co_name = &(*ocp)->soc_cname;
4768 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4769 if ( *cop == NULL ) {
4773 rc = config_add_oc( cop, last, e, ca );
4774 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4782 /* Parse an LDAP entry into config directives */
4784 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4785 int *renum, Operation *op )
4787 CfEntryInfo *ce, *last = NULL;
4788 ConfigOCs co, *coptr, **colst;
4789 Attribute *a, *oc_at, *soc_at;
4790 int i, ibase = -1, nocs, rc = 0;
4793 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4795 memset( ca, 0, sizeof(ConfigArgs));
4797 /* Make sure parent exists and entry does not. But allow
4798 * Databases and Overlays to be inserted. Don't do any
4799 * auto-renumbering if manageDSAit control is present.
4801 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4803 if ( ( op && op->o_managedsait ) ||
4804 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4805 ce->ce_type != Cft_Module ) )
4807 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4808 "DN=\"%s\" already exists\n",
4809 log_prefix, e->e_name.bv_val, 0 );
4810 /* global schema ignores all writes */
4811 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4812 return LDAP_COMPARE_TRUE;
4813 return LDAP_ALREADY_EXISTS;
4817 dnParent( &e->e_nname, &pdn );
4819 /* If last is NULL, the new entry is the root/suffix entry,
4820 * otherwise last should be the parent.
4822 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4824 rs->sr_matched = last->ce_entry->e_name.bv_val;
4826 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4827 "DN=\"%s\" not child of DN=\"%s\"\n",
4828 log_prefix, e->e_name.bv_val,
4829 last->ce_entry->e_name.bv_val );
4830 return LDAP_NO_SUCH_OBJECT;
4834 /* No parent, must be root. This will never happen... */
4835 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4836 return LDAP_NO_SUCH_OBJECT;
4839 if ( last && !access_allowed( op, last->ce_entry,
4840 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4842 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4843 "DN=\"%s\" no write access to \"children\" of parent\n",
4844 log_prefix, e->e_name.bv_val, 0 );
4845 return LDAP_INSUFFICIENT_ACCESS;
4849 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4851 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4852 "DN=\"%s\" no objectClass\n",
4853 log_prefix, e->e_name.bv_val, 0 );
4854 return LDAP_OBJECT_CLASS_VIOLATION;
4857 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4859 ObjectClass *soc = NULL;
4860 char textbuf[ SLAP_TEXT_BUFLEN ];
4861 const char *text = textbuf;
4863 /* FIXME: check result */
4864 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4865 &text, textbuf, sizeof(textbuf), NULL );
4866 if ( rc != LDAP_SUCCESS ) {
4867 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4868 "DN=\"%s\" no structural objectClass (%s)\n",
4869 log_prefix, e->e_name.bv_val, text );
4872 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4873 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4874 if ( soc_at == NULL ) {
4875 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4876 "DN=\"%s\" no structural objectClass; "
4877 "unable to merge computed class %s\n",
4878 log_prefix, e->e_name.bv_val,
4879 soc->soc_cname.bv_val );
4880 return LDAP_OBJECT_CLASS_VIOLATION;
4883 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4884 "DN=\"%s\" no structural objectClass; "
4885 "computed objectClass %s merged\n",
4886 log_prefix, e->e_name.bv_val,
4887 soc->soc_cname.bv_val );
4890 /* Fake the coordinates based on whether we're part of an
4891 * LDAP Add or if reading the config dir
4894 ca->fname = "slapd";
4897 ca->fname = cfdir.bv_val;
4902 co.co_name = &soc_at->a_nvals[0];
4903 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4904 if ( coptr == NULL ) {
4905 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4906 "DN=\"%s\" no structural objectClass in configuration table\n",
4907 log_prefix, e->e_name.bv_val, 0 );
4908 return LDAP_OBJECT_CLASS_VIOLATION;
4911 /* Only the root can be Cft_Global, everything else must
4912 * have a parent. Only limited nesting arrangements are allowed.
4914 rc = LDAP_CONSTRAINT_VIOLATION;
4915 if ( coptr->co_type == Cft_Global && !last ) {
4916 cfn = cfb->cb_config;
4917 ca->ca_private = cfn;
4918 ca->be = frontendDB; /* just to get past check_vals */
4922 colst = count_ocs( oc_at, &nocs );
4924 /* Check whether the Add is allowed by its parent, and do
4925 * any necessary arg setup
4928 rc = config_add_oc( &coptr, last, e, ca );
4929 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4930 for ( i = 0; i<nocs; i++ ) {
4931 /* Already checked these */
4932 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4934 if ( colst[i]->co_ldadd &&
4935 ( rc = colst[i]->co_ldadd( last, e, ca ))
4936 != LDAP_CONSTRAINT_VIOLATION ) {
4942 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4943 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4944 "DN=\"%s\" no structural objectClass add function\n",
4945 log_prefix, e->e_name.bv_val, 0 );
4946 return LDAP_OBJECT_CLASS_VIOLATION;
4950 /* Add the entry but don't parse it, we already have its contents */
4951 if ( rc == LDAP_COMPARE_TRUE ) {
4956 if ( rc != LDAP_SUCCESS )
4959 /* Parse all the values and check for simple syntax errors before
4960 * performing any set actions.
4962 * If doing an LDAPadd, check for indexed names and any necessary
4963 * renaming/renumbering. Entries that don't need indexed names are
4964 * ignored. Entries that need an indexed name and arrive without one
4965 * are assigned to the end. Entries that arrive with an index may
4966 * cause the following entries to be renumbered/bumped down.
4968 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4969 * don't allow Adding an entry with an index that's already in use.
4970 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4972 * These entries can have auto-assigned indexes (appended to the end)
4973 * but only the other types support auto-renumbering of siblings.
4976 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4981 if ( renum && *renum && coptr->co_type != Cft_Database &&
4982 coptr->co_type != Cft_Overlay )
4984 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4985 "operation requires sibling renumbering" );
4986 rc = LDAP_UNWILLING_TO_PERFORM;
4991 init_config_argv( ca );
4993 /* Make sure we process attrs in the required order */
4994 sort_attrs( e, colst, nocs );
4996 for ( a = e->e_attrs; a; a = a->a_next ) {
4997 if ( a == oc_at ) continue;
4998 ct = config_find_table( colst, nocs, a->a_desc, ca );
4999 if ( !ct ) continue; /* user data? */
5000 rc = check_vals( ct, ca, a, 1 );
5001 if ( rc ) goto done_noop;
5004 /* Basic syntax checks are OK. Do the actual settings. */
5005 for ( a=e->e_attrs; a; a=a->a_next ) {
5006 if ( a == oc_at ) continue;
5007 ct = config_find_table( colst, nocs, a->a_desc, ca );
5008 if ( !ct ) continue; /* user data? */
5009 for (i=0; a->a_vals[i].bv_val; i++) {
5012 ca->line = a->a_vals[i].bv_val;
5013 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5014 ptr = strchr( ca->line, '}' );
5016 iptr = strchr( ca->line, '{' );
5020 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5022 ca->valx = strtol( iptr+1, NULL, 0 );
5027 rc = config_parse_add( ct, ca, i );
5035 /* Newly added databases and overlays need to be started up */
5036 if ( CONFIG_ONLINE_ADD( ca )) {
5037 if ( coptr->co_type == Cft_Database ) {
5038 rc = backend_startup_one( ca->be, &ca->reply );
5040 } else if ( coptr->co_type == Cft_Overlay ) {
5041 if ( ca->bi->bi_db_open ) {
5042 BackendInfo *bi_orig = ca->be->bd_info;
5043 ca->be->bd_info = ca->bi;
5044 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5045 ca->be->bd_info = bi_orig;
5047 } else if ( ca->cleanup ) {
5048 rc = ca->cleanup( ca );
5051 if (ca->cr_msg[0] == '\0')
5052 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5054 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5055 ca->log, ca->cr_msg, ca->argv[1] );
5062 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5063 ce->ce_parent = last;
5064 ce->ce_entry = entry_dup( e );
5065 ce->ce_entry->e_private = ce;
5066 ce->ce_type = coptr->co_type;
5069 ce->ce_private = ca->ca_private;
5070 ca->ca_entry = ce->ce_entry;
5073 } else if ( last->ce_kids ) {
5074 CfEntryInfo *c2, **cprev;
5076 /* Advance to first of this type */
5077 cprev = &last->ce_kids;
5078 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5079 cprev = &c2->ce_sibs;
5082 /* Account for the (-1) frontendDB entry */
5083 if ( ce->ce_type == Cft_Database ) {
5084 if ( ca->be == frontendDB )
5086 else if ( ibase != -1 )
5091 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5092 cprev = &c2->ce_sibs;
5098 for ( i=0; i<ibase; i++ ) {
5100 cprev = &c2->ce_sibs;
5103 ce->ce_sibs = *cprev;
5111 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5112 if ( ca->be != frontendDB )
5113 backend_destroy_one( ca->be, 1 );
5114 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5115 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5116 } else if ( coptr->co_type == Cft_Schema ) {
5117 schema_destroy_one( ca, colst, nocs, last );
5122 ch_free( ca->argv );
5123 if ( colst ) ch_free( colst );
5127 #define BIGTMP 10000
5129 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5130 int base, int rebase, int max, int use_ldif )
5132 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5133 ConfigType etype = ce->ce_type;
5134 int count = 0, rc = 0;
5136 /* Reverse ce list */
5137 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5138 if (ce2->ce_type != etype) {
5143 ce2->ce_sibs = cetmp;
5146 if ( max && count >= max ) {
5152 /* Move original to a temp name until increments are done */
5154 ce->ce_entry->e_private = NULL;
5155 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5156 base+BIGTMP, 0, use_ldif );
5157 ce->ce_entry->e_private = ce;
5159 /* start incrementing */
5160 for (ce2=cetmp; ce2; ce2=ce3) {
5162 ce2->ce_sibs = cerem;
5165 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5166 count+base, 0, use_ldif );
5170 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5171 base, 0, use_ldif );
5176 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5177 CfEntryInfo *ce2, int old, int use_ldif )
5181 /* Renumber original to a temp value */
5182 ce->ce_entry->e_private = NULL;
5183 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5184 old+BIGTMP, 0, use_ldif );
5185 ce->ce_entry->e_private = ce;
5187 /* start decrementing */
5188 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5189 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5190 count+old, 0, use_ldif );
5193 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5194 count+old, 0, use_ldif );
5197 /* Parse an LDAP entry into config directives, then store in underlying
5201 config_back_add( Operation *op, SlapReply *rs )
5207 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5208 NULL, ACL_WADD, NULL )) {
5209 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5214 * Check for attribute ACL
5216 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5217 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5218 rs->sr_text = "no write access to attribute";
5222 cfb = (CfBackInfo *)op->o_bd->be_private;
5224 /* add opattrs for syncprov */
5226 char textbuf[SLAP_TEXT_BUFLEN];
5227 size_t textlen = sizeof textbuf;
5228 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5229 &rs->sr_text, textbuf, sizeof( textbuf ) );
5230 if ( rs->sr_err != LDAP_SUCCESS )
5232 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5233 if ( rs->sr_err != LDAP_SUCCESS ) {
5234 Debug( LDAP_DEBUG_TRACE,
5235 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5236 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5241 if ( op->o_abandon ) {
5242 rs->sr_err = SLAPD_ABANDON;
5245 ldap_pvt_thread_pool_pause( &connection_pool );
5248 * 1) check for existence of entry
5249 * 2) check for sibling renumbering
5250 * 3) perform internal add
5251 * 4) perform any necessary renumbering
5252 * 5) store entry in underlying database
5254 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5255 if ( rs->sr_err != LDAP_SUCCESS ) {
5256 rs->sr_text = ca.cr_msg;
5261 CfEntryInfo *ce = ca.ca_entry->e_private;
5262 req_add_s addr = op->oq_add;
5263 op->o_tag = LDAP_REQ_MODRDN;
5264 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5265 op->o_tag = LDAP_REQ_ADD;
5267 if ( rs->sr_err != LDAP_SUCCESS ) {
5272 if ( cfb->cb_use_ldif ) {
5273 BackendDB *be = op->o_bd;
5274 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5275 struct berval dn, ndn;
5277 op->o_bd = &cfb->cb_db;
5279 /* Save current rootdn; use the underlying DB's rootdn */
5282 op->o_dn = op->o_bd->be_rootdn;
5283 op->o_ndn = op->o_bd->be_rootndn;
5285 scp = op->o_callback;
5286 op->o_callback = ≻
5287 op->o_bd->be_add( op, rs );
5289 op->o_callback = scp;
5295 ldap_pvt_thread_pool_resume( &connection_pool );
5298 { int repl = op->o_dont_replicate;
5299 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5300 rs->sr_text = NULL; /* Set after config_add_internal */
5301 rs->sr_err = LDAP_SUCCESS;
5302 op->o_dont_replicate = 1;
5304 send_ldap_result( op, rs );
5305 op->o_dont_replicate = repl;
5307 slap_graduate_commit_csn( op );
5311 typedef struct delrec {
5312 struct delrec *next;
5318 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5324 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5325 ca->line[0] == '{' )
5327 char *ptr = strchr( ca->line + 1, '}' );
5331 ca->valx = strtol( ca->line + 1, &next, 0 );
5332 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5338 rc = config_parse_add( ct, ca, i );
5346 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5349 int rc = LDAP_UNWILLING_TO_PERFORM;
5351 Entry *e = ce->ce_entry;
5352 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5357 delrec *dels = NULL, *deltail = NULL;
5359 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5360 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5362 colst = count_ocs( oc_at, &nocs );
5364 /* make sure add/del flags are clear; should always be true */
5365 for ( s = save_attrs; s; s = s->a_next ) {
5366 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5369 e->e_attrs = attrs_dup( e->e_attrs );
5371 init_config_argv( ca );
5374 ca->ca_private = ce->ce_private;
5376 ca->fname = "slapd";
5378 strcpy( ca->log, "back-config" );
5380 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5381 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5382 switch (ml->sml_op) {
5383 case LDAP_MOD_DELETE:
5384 case LDAP_MOD_REPLACE: {
5385 BerVarray vals = NULL, nvals = NULL;
5387 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5389 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5390 ml->sml_desc->ad_cname.bv_val );
5393 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5394 vals = ml->sml_values;
5395 nvals = ml->sml_nvalues;
5396 ml->sml_values = NULL;
5397 ml->sml_nvalues = NULL;
5399 /* If we're deleting by values, remember the indexes of the
5400 * values we deleted.
5402 if ( ct && ml->sml_values ) {
5404 i = ml->sml_numvals;
5405 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5416 rc = modify_delete_vindex(e, &ml->sml_mod,
5417 get_permissiveModify(op),
5418 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5419 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5420 ml->sml_values = vals;
5421 ml->sml_nvalues = nvals;
5426 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5429 case SLAP_MOD_SOFTADD: {
5430 int mop = ml->sml_op;
5432 ml->sml_op = LDAP_MOD_ADD;
5434 if ( ct->arg_type & ARG_NO_INSERT ) {
5435 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5437 navals = a->a_numvals;
5440 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5441 if ( ml->sml_values[i].bv_val[0] == '{' &&
5444 char *next, *val = ml->sml_values[i].bv_val + 1;
5447 j = strtol( val, &next, 0 );
5448 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5450 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5451 ml->sml_desc->ad_cname.bv_val );
5455 rc = check_vals( ct, ca, ml, 0 );
5456 if ( rc ) goto out_noop;
5459 rc = modify_add_values(e, &ml->sml_mod,
5460 get_permissiveModify(op),
5461 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5463 /* If value already exists, show success here
5464 * and ignore this operation down below.
5466 if ( mop == SLAP_MOD_SOFTADD ) {
5467 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5477 case LDAP_MOD_INCREMENT: /* FIXME */
5482 if(rc != LDAP_SUCCESS) break;
5485 if ( rc == LDAP_SUCCESS) {
5486 /* check that the entry still obeys the schema */
5487 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5488 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5490 if ( rc ) goto out_noop;
5492 /* Basic syntax checks are OK. Do the actual settings. */
5493 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5494 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5495 if ( !ct ) continue;
5497 s = attr_find( save_attrs, ml->sml_desc );
5498 a = attr_find( e->e_attrs, ml->sml_desc );
5500 switch (ml->sml_op) {
5501 case LDAP_MOD_DELETE:
5502 case LDAP_MOD_REPLACE: {
5503 BerVarray vals = NULL, nvals = NULL;
5506 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5507 vals = ml->sml_values;
5508 nvals = ml->sml_nvalues;
5509 ml->sml_values = NULL;
5510 ml->sml_nvalues = NULL;
5513 if ( ml->sml_values )
5516 /* If we didn't delete the whole attribute */
5517 if ( ml->sml_values && a ) {
5518 struct berval *mvals;
5521 if ( ml->sml_nvalues )
5522 mvals = ml->sml_nvalues;
5524 mvals = ml->sml_values;
5526 /* use the indexes we saved up above */
5527 for (i=0; i < d->nidx; i++) {
5528 struct berval bv = *mvals++;
5529 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5530 bv.bv_val[0] == '{' ) {
5531 ptr = strchr( bv.bv_val, '}' ) + 1;
5532 bv.bv_len -= ptr - bv.bv_val;
5535 ca->line = bv.bv_val;
5536 ca->valx = d->idx[i];
5537 config_parse_vals(ct, ca, d->idx[i] );
5538 rc = config_del_vals( ct, ca );
5539 if ( rc != LDAP_SUCCESS ) break;
5541 s->a_flags |= SLAP_ATTR_IXDEL;
5542 for (j=i+1; j < d->nidx; j++)
5543 if ( d->idx[j] >d->idx[i] )
5550 rc = config_del_vals( ct, ca );
5551 if ( rc ) rc = LDAP_OTHER;
5553 s->a_flags |= SLAP_ATTR_IXDEL;
5555 if ( ml->sml_values ) {
5560 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5561 ml->sml_values = vals;
5562 ml->sml_nvalues = nvals;
5564 if ( !vals || rc != LDAP_SUCCESS )
5567 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5570 for (i=0; ml->sml_values[i].bv_val; i++) {
5571 ca->line = ml->sml_values[i].bv_val;
5573 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5576 a->a_flags |= SLAP_ATTR_IXADD;
5583 /* Undo for a failed operation */
5584 if ( rc != LDAP_SUCCESS ) {
5585 ConfigReply msg = ca->reply;
5586 for ( s = save_attrs; s; s = s->a_next ) {
5587 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5588 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5589 ct = config_find_table( colst, nocs, s->a_desc, ca );
5590 a = attr_find( e->e_attrs, s->a_desc );
5592 /* clear the flag so the add check below will skip it */
5593 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5597 config_del_vals( ct, ca );
5599 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5600 ca->line = s->a_vals[i].bv_val;
5602 config_modify_add( ct, ca, s->a_desc, i );
5606 for ( a = e->e_attrs; a; a = a->a_next ) {
5607 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5608 ct = config_find_table( colst, nocs, a->a_desc, ca );
5612 config_del_vals( ct, ca );
5613 s = attr_find( save_attrs, a->a_desc );
5615 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5616 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5617 ca->line = s->a_vals[i].bv_val;
5619 config_modify_add( ct, ca, s->a_desc, i );
5630 if ( rc == LDAP_SUCCESS ) {
5631 attrs_free( save_attrs );
5634 attrs_free( e->e_attrs );
5635 e->e_attrs = save_attrs;
5637 ch_free( ca->argv );
5638 if ( colst ) ch_free( colst );
5640 deltail = dels->next;
5649 config_back_modify( Operation *op, SlapReply *rs )
5652 CfEntryInfo *ce, *last;
5654 ConfigArgs ca = {0};
5657 AttributeDescription *rad = NULL;
5660 cfb = (CfBackInfo *)op->o_bd->be_private;
5662 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5665 rs->sr_matched = last->ce_entry->e_name.bv_val;
5666 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5670 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5671 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5675 /* Get type of RDN */
5676 rdn = ce->ce_entry->e_nname;
5677 ptr = strchr( rdn.bv_val, '=' );
5678 rdn.bv_len = ptr - rdn.bv_val;
5679 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5680 if ( rs->sr_err != LDAP_SUCCESS ) {
5684 /* Some basic validation... */
5685 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5686 /* Don't allow Modify of RDN; must use ModRdn for that. */
5687 if ( ml->sml_desc == rad ) {
5688 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5689 rs->sr_text = "Use modrdn to change the entry name";
5692 /* Internal update of contextCSN? */
5693 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5699 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5702 if ( op->o_abandon ) {
5703 rs->sr_err = SLAPD_ABANDON;
5706 ldap_pvt_thread_pool_pause( &connection_pool );
5710 * 1) perform the Modify on the cached Entry.
5711 * 2) verify that the Entry still satisfies the schema.
5712 * 3) perform the individual config operations.
5713 * 4) store Modified entry in underlying LDIF backend.
5715 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5717 rs->sr_text = ca.cr_msg;
5718 } else if ( cfb->cb_use_ldif ) {
5719 BackendDB *be = op->o_bd;
5720 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5721 struct berval dn, ndn;
5723 op->o_bd = &cfb->cb_db;
5727 op->o_dn = op->o_bd->be_rootdn;
5728 op->o_ndn = op->o_bd->be_rootndn;
5730 scp = op->o_callback;
5731 op->o_callback = ≻
5732 op->o_bd->be_modify( op, rs );
5734 op->o_callback = scp;
5740 ldap_pvt_thread_pool_resume( &connection_pool );
5742 send_ldap_result( op, rs );
5743 slap_graduate_commit_csn( op );
5748 config_back_modrdn( Operation *op, SlapReply *rs )
5751 CfEntryInfo *ce, *last;
5755 cfb = (CfBackInfo *)op->o_bd->be_private;
5757 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5760 rs->sr_matched = last->ce_entry->e_name.bv_val;
5761 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5764 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5765 NULL, ACL_WRITE, NULL )) {
5766 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5770 if ( ce->ce_parent )
5771 parent = ce->ce_parent->ce_entry;
5773 parent = (Entry *)&slap_entry_root;
5774 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5775 NULL, ACL_WRITE, NULL )) {
5776 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5781 /* We don't allow moving objects to new parents.
5782 * Generally we only allow reordering a set of ordered entries.
5784 if ( op->orr_newSup ) {
5785 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5789 /* If newRDN == oldRDN, quietly succeed */
5790 dnRdn( &op->o_req_ndn, &rdn );
5791 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5792 rs->sr_err = LDAP_SUCCESS;
5796 /* Current behavior, subject to change as needed:
5798 * For backends and overlays, we only allow renumbering.
5799 * For schema, we allow renaming with the same number.
5800 * Otherwise, the op is not allowed.
5803 if ( ce->ce_type == Cft_Schema ) {
5807 /* Can't alter the main cn=schema entry */
5808 if ( ce->ce_parent->ce_type == Cft_Global ) {
5809 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5810 rs->sr_text = "renaming not allowed for this entry";
5814 /* We could support this later if desired */
5815 ptr1 = ber_bvchr( &rdn, '}' );
5816 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5817 len = ptr1 - rdn.bv_val;
5818 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5819 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5820 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5821 rs->sr_text = "schema reordering not supported";
5824 } else if ( ce->ce_type == Cft_Database ||
5825 ce->ce_type == Cft_Overlay ) {
5826 char *ptr1, *ptr2, *iptr1, *iptr2;
5829 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5830 if ( *iptr2 != '{' ) {
5831 rs->sr_err = LDAP_NAMING_VIOLATION;
5832 rs->sr_text = "new ordering index is required";
5836 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5837 ptr1 = ber_bvchr( &rdn, '}' );
5838 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5840 rs->sr_err = LDAP_NAMING_VIOLATION;
5841 rs->sr_text = "new ordering index is required";
5845 len1 = ptr1 - rdn.bv_val;
5846 len2 = ptr2 - op->orr_newrdn.bv_val;
5848 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5849 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5850 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5851 rs->sr_text = "changing database/overlay type not allowed";
5854 ixold = strtol( iptr1, NULL, 0 );
5855 ixnew = strtol( iptr2, &ptr1, 0 );
5856 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5857 rs->sr_err = LDAP_NAMING_VIOLATION;
5860 /* config DB is always 0, cannot be changed */
5861 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5862 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5866 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5867 rs->sr_text = "renaming not supported for this entry";
5871 if ( op->o_abandon ) {
5872 rs->sr_err = SLAPD_ABANDON;
5875 ldap_pvt_thread_pool_pause( &connection_pool );
5877 if ( ce->ce_type == Cft_Schema ) {
5878 req_modrdn_s modr = op->oq_modrdn;
5881 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5882 if ( rs->sr_err == LDAP_SUCCESS ) {
5883 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5884 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5887 op->oq_modrdn = modr;
5889 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5890 req_modrdn_s modr = op->oq_modrdn;
5893 /* Advance to first of this type */
5894 cprev = &ce->ce_parent->ce_kids;
5895 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5896 cprev = &ce2->ce_sibs;
5899 /* Skip the -1 entry */
5900 if ( ce->ce_type == Cft_Database ) {
5901 cprev = &ce2->ce_sibs;
5907 /* Remove from old slot */
5908 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5909 cprev = &ce2->ce_sibs;
5910 *cprev = ce->ce_sibs;
5911 ceold = ce->ce_sibs;
5913 /* Insert into new slot */
5915 for ( i=0; i<ixnew; i++ ) {
5919 cprev = &ce2->ce_sibs;
5921 ce->ce_sibs = *cprev;
5926 /* NOTE: These should be encoded in the OC tables, not inline here */
5927 if ( ce->ce_type == Cft_Database )
5928 backend_db_move( ce->ce_be, ixnew );
5929 else if ( ce->ce_type == Cft_Overlay )
5930 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5932 if ( ixold < ixnew ) {
5933 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5936 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5937 ixold - ixnew, cfb->cb_use_ldif );
5939 op->oq_modrdn = modr;
5942 ldap_pvt_thread_pool_resume( &connection_pool );
5944 send_ldap_result( op, rs );
5949 config_back_delete( Operation *op, SlapReply *rs )
5951 #ifdef SLAP_CONFIG_DELETE
5953 CfEntryInfo *ce, *last, *ce2;
5955 cfb = (CfBackInfo *)op->o_bd->be_private;
5957 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5960 rs->sr_matched = last->ce_entry->e_name.bv_val;
5961 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5962 } else if ( ce->ce_kids ) {
5963 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5964 } else if ( op->o_abandon ) {
5965 rs->sr_err = SLAPD_ABANDON;
5966 } else if ( ce->ce_type == Cft_Overlay ){
5970 ldap_pvt_thread_pool_pause( &connection_pool );
5972 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5974 /* remove CfEntryInfo from the siblings list */
5975 if ( ce->ce_parent->ce_kids == ce ) {
5976 ce->ce_parent->ce_kids = ce->ce_sibs;
5978 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5979 if ( ce2->ce_sibs == ce ) {
5980 ce2->ce_sibs = ce->ce_sibs;
5986 /* remove from underlying database */
5987 if ( cfb->cb_use_ldif ) {
5988 BackendDB *be = op->o_bd;
5989 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5990 struct berval dn, ndn, req_dn, req_ndn;
5992 op->o_bd = &cfb->cb_db;
5996 req_dn = op->o_req_dn;
5997 req_ndn = op->o_req_ndn;
5999 op->o_dn = op->o_bd->be_rootdn;
6000 op->o_ndn = op->o_bd->be_rootndn;
6001 op->o_req_dn = ce->ce_entry->e_name;
6002 op->o_req_ndn = ce->ce_entry->e_nname;
6004 scp = op->o_callback;
6005 op->o_callback = ≻
6006 op->o_bd->be_delete( op, rs );
6008 op->o_callback = scp;
6011 op->o_req_dn = req_dn;
6012 op->o_req_ndn = req_ndn;
6015 /* renumber siblings */
6016 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6017 ixold = strtol( iptr, NULL, 0 );
6018 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6019 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6020 count+ixold, 0, cfb->cb_use_ldif );
6024 ce->ce_entry->e_private=NULL;
6025 entry_free(ce->ce_entry);
6027 ldap_pvt_thread_pool_resume( &connection_pool );
6029 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6032 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6033 #endif /* SLAP_CONFIG_DELETE */
6034 send_ldap_result( op, rs );
6039 config_back_search( Operation *op, SlapReply *rs )
6042 CfEntryInfo *ce, *last;
6045 cfb = (CfBackInfo *)op->o_bd->be_private;
6047 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6050 rs->sr_matched = last->ce_entry->e_name.bv_val;
6051 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6054 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6055 ACL_SEARCH, NULL, &mask ))
6057 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6058 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6060 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6064 switch ( op->ors_scope ) {
6065 case LDAP_SCOPE_BASE:
6066 case LDAP_SCOPE_SUBTREE:
6067 rs->sr_err = config_send( op, rs, ce, 0 );
6070 case LDAP_SCOPE_ONELEVEL:
6071 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6072 rs->sr_err = config_send( op, rs, ce, 1 );
6081 send_ldap_result( op, rs );
6085 /* no-op, we never free entries */
6086 int config_entry_release(
6091 if ( !e->e_private ) {
6094 return LDAP_SUCCESS;
6097 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6099 int config_back_entry_get(
6103 AttributeDescription *at,
6108 CfEntryInfo *ce, *last;
6109 int rc = LDAP_NO_SUCH_OBJECT;
6111 cfb = (CfBackInfo *)op->o_bd->be_private;
6113 ce = config_find_base( cfb->cb_root, ndn, &last );
6115 *ent = ce->ce_entry;
6118 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6119 rc = LDAP_NO_SUCH_ATTRIBUTE;
6129 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6130 ConfigTable *ct, ConfigArgs *c )
6134 for (; at && *at; at++) {
6135 /* Skip the naming attr */
6136 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6138 for (i=0;ct[i].name;i++) {
6139 if (ct[i].ad == (*at)->sat_ad) {
6140 rc = config_get_vals(&ct[i], c);
6141 /* NOTE: tolerate that config_get_vals()
6142 * returns success with no values */
6143 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6144 if ( c->rvalue_nvals )
6145 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6148 slap_syntax_validate_func *validate =
6149 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6152 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6153 rc = ordered_value_validate( ct[i].ad,
6154 &c->rvalue_vals[j], LDAP_MOD_ADD );
6156 Debug( LDAP_DEBUG_ANY,
6157 "config_build_attrs: error %d on %s value #%d\n",
6158 rc, ct[i].ad->ad_cname.bv_val, j );
6164 rc = attr_merge_normalize(e, ct[i].ad,
6165 c->rvalue_vals, NULL);
6167 ber_bvarray_free( c->rvalue_nvals );
6168 ber_bvarray_free( c->rvalue_vals );
6170 Debug( LDAP_DEBUG_ANY,
6171 "config_build_attrs: error %d on %s\n",
6172 rc, ct[i].ad->ad_cname.bv_val, 0 );
6183 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6186 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6187 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6189 Entry *e = entry_alloc();
6190 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6192 struct berval ad_name;
6193 AttributeDescription *ad = NULL;
6196 const char *text = "";
6200 CfEntryInfo *ceprev = NULL;
6202 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6205 ce->ce_type = main->co_type;
6206 ce->ce_parent = parent;
6208 pdn = parent->ce_entry->e_nname;
6209 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6210 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6211 ceprev->ce_type <= ce->ce_type;
6212 ceprev = ceprev->ce_sibs );
6217 ce->ce_private = c->ca_private;
6221 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6222 ber_dupbv( &e->e_nname, &e->e_name );
6224 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6225 main->co_name, NULL );
6227 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6228 extra->co_name, NULL );
6229 ptr = strchr(rdn->bv_val, '=');
6230 ad_name.bv_val = rdn->bv_val;
6231 ad_name.bv_len = ptr - rdn->bv_val;
6232 rc = slap_bv2ad( &ad_name, &ad, &text );
6237 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6238 attr_merge_normalize_one(e, ad, &val, NULL );
6241 c->table = main->co_type;
6242 if ( oc->soc_required ) {
6243 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6244 if ( rc ) goto fail;
6247 if ( oc->soc_allowed ) {
6248 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6249 if ( rc ) goto fail;
6254 c->table = extra->co_type;
6255 if ( oc->soc_required ) {
6256 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6257 if ( rc ) goto fail;
6260 if ( oc->soc_allowed ) {
6261 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6262 if ( rc ) goto fail;
6266 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6267 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6268 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6269 if ( rc != LDAP_SUCCESS ) {
6271 Debug( LDAP_DEBUG_ANY,
6272 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6273 rdn->bv_val, text, 0);
6276 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6279 op->ora_modlist = NULL;
6280 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6281 if ( !op->o_noop ) {
6282 SlapReply rs2 = {REP_RESULT};
6283 op->o_bd->be_add( op, &rs2 );
6284 rs->sr_err = rs2.sr_err;
6285 rs_assert_done( &rs2 );
6286 if ( ( rs2.sr_err != LDAP_SUCCESS )
6287 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6293 ce->ce_sibs = ceprev->ce_sibs;
6294 ceprev->ce_sibs = ce;
6295 } else if ( parent ) {
6296 ce->ce_sibs = parent->ce_kids;
6297 parent->ce_kids = ce;
6304 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6305 Operation *op, SlapReply *rs )
6308 ConfigFile *cf = c->ca_private;
6310 struct berval bv, rdn;
6312 for (; cf; cf=cf->c_sibs, c->depth++) {
6313 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6314 !cf->c_om_head && !cf->c_syn_head ) continue;
6315 c->value_dn.bv_val = c->log;
6316 LUTIL_SLASHPATH( cf->c_file.bv_val );
6317 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6322 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6324 ptr = strchr( bv.bv_val, '.' );
6326 bv.bv_len = ptr - bv.bv_val;
6327 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6328 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6329 /* FIXME: how can indicate error? */
6332 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6334 c->value_dn.bv_len += bv.bv_len;
6335 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6339 e = config_build_entry( op, rs, ceparent, c, &rdn,
6340 &CFOC_SCHEMA, NULL );
6343 } else if ( e && cf->c_kids ) {
6344 c->ca_private = cf->c_kids;
6345 config_build_schema_inc( c, e->e_private, op, rs );
6351 #ifdef SLAPD_MODULES
6354 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6355 Operation *op, SlapReply *rs )
6360 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6361 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6363 c->value_dn.bv_val = c->log;
6364 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6365 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6366 /* FIXME: how can indicate error? */
6370 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6379 config_check_schema(Operation *op, CfBackInfo *cfb)
6381 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6383 CfEntryInfo *ce, *last;
6386 /* If there's no root entry, we must be in the midst of converting */
6387 if ( !cfb->cb_root )
6390 /* Make sure the main schema entry exists */
6391 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6398 /* Make sure it's up to date */
6399 if ( cf_om_tail != om_sys_tail ) {
6400 a = attr_find( e->e_attrs, cfAd_om );
6402 if ( a->a_nvals != a->a_vals )
6403 ber_bvarray_free( a->a_nvals );
6404 ber_bvarray_free( a->a_vals );
6409 oidm_unparse( &bv, NULL, NULL, 1 );
6410 attr_merge_normalize( e, cfAd_om, bv, NULL );
6411 ber_bvarray_free( bv );
6412 cf_om_tail = om_sys_tail;
6414 if ( cf_at_tail != at_sys_tail ) {
6415 a = attr_find( e->e_attrs, cfAd_attr );
6417 if ( a->a_nvals != a->a_vals )
6418 ber_bvarray_free( a->a_nvals );
6419 ber_bvarray_free( a->a_vals );
6424 at_unparse( &bv, NULL, NULL, 1 );
6425 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6426 ber_bvarray_free( bv );
6427 cf_at_tail = at_sys_tail;
6429 if ( cf_oc_tail != oc_sys_tail ) {
6430 a = attr_find( e->e_attrs, cfAd_oc );
6432 if ( a->a_nvals != a->a_vals )
6433 ber_bvarray_free( a->a_nvals );
6434 ber_bvarray_free( a->a_vals );
6439 oc_unparse( &bv, NULL, NULL, 1 );
6440 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6441 ber_bvarray_free( bv );
6442 cf_oc_tail = oc_sys_tail;
6444 if ( cf_syn_tail != syn_sys_tail ) {
6445 a = attr_find( e->e_attrs, cfAd_syntax );
6447 if ( a->a_nvals != a->a_vals )
6448 ber_bvarray_free( a->a_nvals );
6449 ber_bvarray_free( a->a_vals );
6454 syn_unparse( &bv, NULL, NULL, 1 );
6455 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6456 ber_bvarray_free( bv );
6457 cf_syn_tail = syn_sys_tail;
6460 SlapReply rs = {REP_RESULT};
6461 c.ca_private = NULL;
6462 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6463 &CFOC_SCHEMA, NULL );
6468 ce->ce_private = cfb->cb_config;
6469 cf_at_tail = at_sys_tail;
6470 cf_oc_tail = oc_sys_tail;
6471 cf_om_tail = om_sys_tail;
6472 cf_syn_tail = syn_sys_tail;
6477 static const char *defacl[] = {
6478 NULL, "to", "*", "by", "*", "none", NULL
6482 config_back_db_open( BackendDB *be, ConfigReply *cr )
6484 CfBackInfo *cfb = be->be_private;
6487 CfEntryInfo *ce, *ceparent;
6491 Connection conn = {0};
6492 OperationBuffer opbuf;
6494 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6495 SlapReply rs = {REP_RESULT};
6496 void *thrctx = NULL;
6498 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6500 /* If we have no explicitly configured ACLs, don't just use
6501 * the global ACLs. Explicitly deny access to everything.
6503 if ( !be->bd_self->be_acl ) {
6504 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6507 thrctx = ldap_pvt_thread_pool_context();
6508 connection_fake_init( &conn, &opbuf, thrctx );
6511 op->o_tag = LDAP_REQ_ADD;
6512 op->o_callback = &cb;
6513 op->o_bd = &cfb->cb_db;
6514 op->o_dn = op->o_bd->be_rootdn;
6515 op->o_ndn = op->o_bd->be_rootndn;
6517 if ( !cfb->cb_use_ldif ) {
6521 /* If we read the config from back-ldif, do some quick sanity checks */
6522 if ( cfb->cb_got_ldif ) {
6523 return config_check_schema( op, cfb );
6526 /* create root of tree */
6528 c.ca_private = cfb->cb_config;
6530 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6540 #ifdef SLAPD_MODULES
6541 /* Create Module nodes... */
6542 if ( modpaths.mp_loads ) {
6543 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6549 /* Create schema nodes... cn=schema will contain the hardcoded core
6550 * schema, read-only. Child objects will contain runtime loaded schema
6554 c.ca_private = NULL;
6555 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6560 ce->ce_private = cfb->cb_config;
6561 cf_at_tail = at_sys_tail;
6562 cf_oc_tail = oc_sys_tail;
6563 cf_om_tail = om_sys_tail;
6564 cf_syn_tail = syn_sys_tail;
6566 /* Create schema nodes for included schema... */
6567 if ( cfb->cb_config->c_kids ) {
6570 c.ca_private = cfb->cb_config->c_kids;
6571 rc = config_build_schema_inc( &c, ce, op, &rs );
6577 /* Create backend nodes. Skip if they don't provide a cf_table.
6578 * There usually aren't any of these.
6582 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6583 if (!bi->bi_cf_ocs) {
6584 /* If it only supports the old config mech, complain. */
6585 if ( bi->bi_config ) {
6586 Debug( LDAP_DEBUG_ANY,
6587 "WARNING: No dynamic config support for backend %s.\n",
6588 bi->bi_type, 0, 0 );
6593 if (!bi->bi_private) continue;
6596 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6597 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6598 if ( rdn.bv_len >= sizeof( c.log ) ) {
6599 /* FIXME: holler ... */ ;
6602 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6609 /* Create database nodes... */
6610 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6611 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6612 for ( i = -1, be = frontendDB ; be;
6613 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6614 slap_overinfo *oi = NULL;
6616 if ( overlay_is_over( be )) {
6617 oi = be->bd_info->bi_private;
6623 /* If this backend supports the old config mechanism, but not
6624 * the new mech, complain.
6626 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6627 Debug( LDAP_DEBUG_ANY,
6628 "WARNING: No dynamic config support for database %s.\n",
6629 bi->bi_type, 0, 0 );
6633 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6634 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6636 if ( rdn.bv_len >= sizeof( c.log ) ) {
6637 /* FIXME: holler ... */ ;
6641 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6647 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6648 rs_reinit( &rs, REP_RESULT );
6649 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6651 /* Iterate through overlays */
6656 voidList *vl, *v0 = NULL;
6658 /* overlays are in LIFO order, must reverse stack */
6659 for (on=oi->oi_list; on; on=on->on_next) {
6660 vl = ch_malloc( sizeof( voidList ));
6665 for (j=0; vl; j++,vl=v0) {
6669 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6670 Debug( LDAP_DEBUG_ANY,
6671 "WARNING: No dynamic config support for overlay %s.\n",
6672 on->on_bi.bi_type, 0, 0 );
6676 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6677 "%s=" SLAP_X_ORDERED_FMT "%s",
6678 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6679 if ( rdn.bv_len >= sizeof( c.log ) ) {
6680 /* FIXME: holler ... */ ;
6684 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6685 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6689 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6690 rs_reinit( &rs, REP_RESULT );
6691 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6697 ldap_pvt_thread_pool_context_reset( thrctx );
6699 if ( unsupp && cfb->cb_use_ldif ) {
6700 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6701 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6708 cfb_free_cffile( ConfigFile *cf )
6712 for (; cf; cf=next) {
6715 cfb_free_cffile( cf->c_kids );
6716 ch_free( cf->c_file.bv_val );
6717 ber_bvarray_free( cf->c_dseFiles );
6723 cfb_free_entries( CfEntryInfo *ce )
6727 for (; ce; ce=next) {
6730 cfb_free_entries( ce->ce_kids );
6731 ce->ce_entry->e_private = NULL;
6732 entry_free( ce->ce_entry );
6738 config_back_db_close( BackendDB *be, ConfigReply *cr )
6740 CfBackInfo *cfb = be->be_private;
6742 cfb_free_entries( cfb->cb_root );
6743 cfb->cb_root = NULL;
6745 if ( cfb->cb_db.bd_info ) {
6746 backend_shutdown( &cfb->cb_db );
6753 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6755 CfBackInfo *cfb = be->be_private;
6757 cfb_free_cffile( cfb->cb_config );
6759 ch_free( cfdir.bv_val );
6761 avl_free( CfOcTree, NULL );
6763 if ( cfb->cb_db.bd_info ) {
6764 cfb->cb_db.be_suffix = NULL;
6765 cfb->cb_db.be_nsuffix = NULL;
6766 BER_BVZERO( &cfb->cb_db.be_rootdn );
6767 BER_BVZERO( &cfb->cb_db.be_rootndn );
6769 backend_destroy_one( &cfb->cb_db, 0 );
6778 config_back_db_init( BackendDB *be, ConfigReply* cr )
6784 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6785 cfn = cfb->cb_config;
6786 be->be_private = cfb;
6788 ber_dupbv( &be->be_rootdn, &config_rdn );
6789 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6790 ber_dupbv( &dn, &be->be_rootdn );
6791 ber_bvarray_add( &be->be_suffix, &dn );
6792 ber_dupbv( &dn, &be->be_rootdn );
6793 ber_bvarray_add( &be->be_nsuffix, &dn );
6795 /* Hide from namingContexts */
6796 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6798 /* Check ACLs on content of Adds by default */
6799 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6805 config_back_destroy( BackendInfo *bi )
6807 ldif_must_b64_encode_release();
6812 config_tool_entry_open( BackendDB *be, int mode )
6814 CfBackInfo *cfb = be->be_private;
6815 BackendInfo *bi = cfb->cb_db.bd_info;
6817 if ( bi && bi->bi_tool_entry_open )
6818 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6825 config_tool_entry_close( BackendDB *be )
6827 CfBackInfo *cfb = be->be_private;
6828 BackendInfo *bi = cfb->cb_db.bd_info;
6830 if ( bi && bi->bi_tool_entry_close )
6831 return bi->bi_tool_entry_close( &cfb->cb_db );
6837 config_tool_entry_first( BackendDB *be )
6839 CfBackInfo *cfb = be->be_private;
6840 BackendInfo *bi = cfb->cb_db.bd_info;
6842 if ( bi && bi->bi_tool_entry_first ) {
6843 return bi->bi_tool_entry_first( &cfb->cb_db );
6845 if ( bi && bi->bi_tool_entry_first_x ) {
6846 return bi->bi_tool_entry_first_x( &cfb->cb_db,
6847 NULL, LDAP_SCOPE_DEFAULT, NULL );
6853 config_tool_entry_first_x(
6855 struct berval *base,
6859 CfBackInfo *cfb = be->be_private;
6860 BackendInfo *bi = cfb->cb_db.bd_info;
6862 if ( bi && bi->bi_tool_entry_first_x ) {
6863 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
6869 config_tool_entry_next( BackendDB *be )
6871 CfBackInfo *cfb = be->be_private;
6872 BackendInfo *bi = cfb->cb_db.bd_info;
6874 if ( bi && bi->bi_tool_entry_next )
6875 return bi->bi_tool_entry_next( &cfb->cb_db );
6881 config_tool_entry_get( BackendDB *be, ID id )
6883 CfBackInfo *cfb = be->be_private;
6884 BackendInfo *bi = cfb->cb_db.bd_info;
6886 if ( bi && bi->bi_tool_entry_get )
6887 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6892 static int entry_put_got_frontend=0;
6893 static int entry_put_got_config=0;
6895 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6897 CfBackInfo *cfb = be->be_private;
6898 BackendInfo *bi = cfb->cb_db.bd_info;
6900 struct berval rdn, vals[ 2 ];
6902 OperationBuffer opbuf;
6904 Connection conn = {0};
6905 Operation *op = NULL;
6909 /* Create entry for frontend database if it does not exist already */
6910 if ( !entry_put_got_frontend ) {
6911 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6912 STRLENOF( "olcDatabase" ))) {
6913 if ( strncmp( e->e_nname.bv_val +
6914 STRLENOF( "olcDatabase" ), "={-1}frontend",
6915 STRLENOF( "={-1}frontend" )) &&
6916 strncmp( e->e_nname.bv_val +
6917 STRLENOF( "olcDatabase" ), "=frontend",
6918 STRLENOF( "=frontend" ))) {
6920 vals[1].bv_val = NULL;
6921 memset( &ca, 0, sizeof(ConfigArgs));
6923 ca.bi = frontendDB->bd_info;
6924 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6925 rdn.bv_val = ca.log;
6926 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6927 "%s=" SLAP_X_ORDERED_FMT "%s",
6928 cfAd_database->ad_cname.bv_val, -1,
6930 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6931 &CFOC_DATABASE, ca.be->be_cf_ocs );
6932 thrctx = ldap_pvt_thread_pool_context();
6933 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6935 op->o_bd = &cfb->cb_db;
6936 op->o_tag = LDAP_REQ_ADD;
6938 op->o_dn = be->be_rootdn;
6939 op->o_ndn = be->be_rootndn;
6940 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6941 if ( rc != LDAP_SUCCESS ) {
6942 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6943 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6947 if ( ce && bi && bi->bi_tool_entry_put &&
6948 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6949 entry_put_got_frontend++;
6951 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6952 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6956 entry_put_got_frontend++;
6961 /* Create entry for config database if it does not exist already */
6962 if ( !entry_put_got_config && !isFrontend ) {
6963 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6964 STRLENOF( "olcDatabase" ))) {
6965 if ( strncmp( e->e_nname.bv_val +
6966 STRLENOF( "olcDatabase" ), "={0}config",
6967 STRLENOF( "={0}config" )) &&
6968 strncmp( e->e_nname.bv_val +
6969 STRLENOF( "olcDatabase" ), "=config",
6970 STRLENOF( "=config" )) ) {
6972 vals[1].bv_val = NULL;
6973 memset( &ca, 0, sizeof(ConfigArgs));
6974 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6975 ca.bi = ca.be->bd_info;
6976 rdn.bv_val = ca.log;
6977 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6978 "%s=" SLAP_X_ORDERED_FMT "%s",
6979 cfAd_database->ad_cname.bv_val, 0,
6981 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6984 thrctx = ldap_pvt_thread_pool_context();
6985 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6987 op->o_bd = &cfb->cb_db;
6988 op->o_tag = LDAP_REQ_ADD;
6989 op->o_dn = be->be_rootdn;
6990 op->o_ndn = be->be_rootndn;
6993 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6994 if ( rc != LDAP_SUCCESS ) {
6995 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6996 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6999 if (ce && bi && bi->bi_tool_entry_put &&
7000 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7001 entry_put_got_config++;
7003 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7004 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7008 entry_put_got_config++;
7012 if ( bi && bi->bi_tool_entry_put &&
7013 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7014 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7021 AttributeDescription **desc;
7023 { "attribute", &cfAd_attr },
7024 { "backend", &cfAd_backend },
7025 { "database", &cfAd_database },
7026 { "include", &cfAd_include },
7027 { "ldapsyntax", &cfAd_syntax },
7028 { "objectclass", &cfAd_oc },
7029 { "objectidentifier", &cfAd_om },
7030 { "overlay", &cfAd_overlay },
7035 * add / delete: all types that may be added or deleted must use an
7036 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7037 * should automatically renumber the index of any siblings as needed,
7038 * so that no gaps in the numbering sequence exist after the add/delete
7040 * What can be added:
7042 * backend objects for backend-specific config directives
7046 * delete: probably no support this time around.
7048 * modrdn: generally not done. Will be invoked automatically by add/
7049 * delete to update numbering sequence. Perform as an explicit operation
7050 * so that the renumbering effect may be replicated. Subtree rename must
7051 * be supported, since renumbering a database will affect all its child
7054 * modify: must be fully supported.
7058 config_back_initialize( BackendInfo *bi )
7060 ConfigTable *ct = config_back_cf_table;
7064 AttributeDescription *ad = NULL;
7066 static char *controls[] = {
7067 LDAP_CONTROL_MANAGEDSAIT,
7071 /* Make sure we don't exceed the bits reserved for userland */
7072 config_check_userland( CFG_LAST );
7074 bi->bi_controls = controls;
7079 bi->bi_destroy = config_back_destroy;
7081 bi->bi_db_init = config_back_db_init;
7082 bi->bi_db_config = 0;
7083 bi->bi_db_open = config_back_db_open;
7084 bi->bi_db_close = config_back_db_close;
7085 bi->bi_db_destroy = config_back_db_destroy;
7087 bi->bi_op_bind = config_back_bind;
7088 bi->bi_op_unbind = 0;
7089 bi->bi_op_search = config_back_search;
7090 bi->bi_op_compare = 0;
7091 bi->bi_op_modify = config_back_modify;
7092 bi->bi_op_modrdn = config_back_modrdn;
7093 bi->bi_op_add = config_back_add;
7094 bi->bi_op_delete = config_back_delete;
7095 bi->bi_op_abandon = 0;
7097 bi->bi_extended = 0;
7099 bi->bi_chk_referrals = 0;
7101 bi->bi_access_allowed = slap_access_allowed;
7103 bi->bi_connection_init = 0;
7104 bi->bi_connection_destroy = 0;
7106 bi->bi_entry_release_rw = config_entry_release;
7107 bi->bi_entry_get_rw = config_back_entry_get;
7109 bi->bi_tool_entry_open = config_tool_entry_open;
7110 bi->bi_tool_entry_close = config_tool_entry_close;
7111 bi->bi_tool_entry_first = config_tool_entry_first;
7112 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7113 bi->bi_tool_entry_next = config_tool_entry_next;
7114 bi->bi_tool_entry_get = config_tool_entry_get;
7115 bi->bi_tool_entry_put = config_tool_entry_put;
7118 argv[ 0 ] = "slapd";
7124 for (i=0; OidMacros[i].name; i++ ) {
7125 argv[1] = OidMacros[i].name;
7126 argv[2] = OidMacros[i].oid;
7127 parse_oidm( &ca, 0, NULL );
7130 bi->bi_cf_ocs = cf_ocs;
7132 i = config_register_schema( ct, cf_ocs );
7135 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7138 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7139 * basically, we don't care if it fails */
7140 i = slap_str2ad( "olcRootPW", &ad, &text );
7142 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7143 "warning, unable to get \"olcRootPW\" "
7144 "attribute description: %d: %s\n",
7147 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7148 ad->ad_type->sat_oid );
7151 /* set up the notable AttributeDescriptions */
7153 for (;ct->name;ct++) {
7154 if (strcmp(ct->name, ads[i].name)) continue;
7155 *ads[i].desc = ct->ad;
7157 if (!ads[i].name) break;