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_extra_attrs;
139 static ConfigDriver config_include;
140 static ConfigDriver config_obsolete;
142 static ConfigDriver config_tls_option;
143 static ConfigDriver config_tls_config;
145 extern ConfigDriver syncrepl_config;
153 CFG_TLS_PROTOCOL_MIN,
204 static OidRec OidMacros[] = {
205 /* OpenLDAProot:1.12.2 */
206 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
207 { "OLcfgAt", "OLcfg:3" },
208 { "OLcfgGlAt", "OLcfgAt:0" },
209 { "OLcfgBkAt", "OLcfgAt:1" },
210 { "OLcfgDbAt", "OLcfgAt:2" },
211 { "OLcfgOvAt", "OLcfgAt:3" },
212 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
213 { "OLcfgOc", "OLcfg:4" },
214 { "OLcfgGlOc", "OLcfgOc:0" },
215 { "OLcfgBkOc", "OLcfgOc:1" },
216 { "OLcfgDbOc", "OLcfgOc:2" },
217 { "OLcfgOvOc", "OLcfgOc:3" },
218 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
220 /* Syntaxes. We should just start using the standard names and
221 * document that they are predefined and available for users
222 * to reference in their own schema. Defining schema without
223 * OID macros is for masochists...
225 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
226 { "OMsBoolean", "OMsyn:7" },
227 { "OMsDN", "OMsyn:12" },
228 { "OMsDirectoryString", "OMsyn:15" },
229 { "OMsIA5String", "OMsyn:26" },
230 { "OMsInteger", "OMsyn:27" },
231 { "OMsOID", "OMsyn:38" },
232 { "OMsOctetString", "OMsyn:40" },
237 * Backend/Database registry
239 * OLcfg{Bk|Db}{Oc|At}:0 -> common
240 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
241 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
242 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
243 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
244 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
245 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
246 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
247 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
253 * OLcfgOv{Oc|At}:1 -> syncprov
254 * OLcfgOv{Oc|At}:2 -> pcache
255 * OLcfgOv{Oc|At}:3 -> chain
256 * OLcfgOv{Oc|At}:4 -> accesslog
257 * OLcfgOv{Oc|At}:5 -> valsort
258 * OLcfgOv{Oc|At}:7 -> distproc
259 * OLcfgOv{Oc|At}:8 -> dynlist
260 * OLcfgOv{Oc|At}:9 -> dds
261 * OLcfgOv{Oc|At}:10 -> unique
262 * OLcfgOv{Oc|At}:11 -> refint
263 * OLcfgOv{Oc|At}:12 -> ppolicy
264 * OLcfgOv{Oc|At}:13 -> constraint
265 * OLcfgOv{Oc|At}:14 -> translucent
266 * OLcfgOv{Oc|At}:15 -> auditlog
267 * OLcfgOv{Oc|At}:16 -> rwm
268 * OLcfgOv{Oc|At}:17 -> dyngroup
269 * OLcfgOv{Oc|At}:18 -> memberof
270 * OLcfgOv{Oc|At}:19 -> collect
271 * OLcfgOv{Oc|At}:20 -> retcode
272 * OLcfgOv{Oc|At}:21 -> sssvlv
275 /* alphabetical ordering */
277 static ConfigTable config_back_cf_table[] = {
278 /* This attr is read-only */
279 { "", "", 0, 0, 0, ARG_MAGIC,
280 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
281 "DESC 'File for slapd configuration directives' "
282 "EQUALITY caseIgnoreMatch "
283 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
284 { "", "", 0, 0, 0, ARG_MAGIC,
285 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
286 "DESC 'Directory for slapd configuration backend' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
289 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
290 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
291 "DESC 'Access Control List' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
294 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
295 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
296 "DESC 'Check ACLs against content of Add ops' "
297 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
298 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
299 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
300 "DESC 'Allowed set of deprecated features' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString )", NULL, NULL },
303 { "argsfile", "file", 2, 2, 0, ARG_STRING,
304 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
305 "DESC 'File for slapd command line options' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
308 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
309 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
310 "EQUALITY caseIgnoreMatch "
311 "SYNTAX OMsDirectoryString )", NULL, NULL },
312 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
313 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
314 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
315 "DESC 'OpenLDAP attributeTypes' "
316 "EQUALITY caseIgnoreMatch "
317 "SUBSTR caseIgnoreSubstringsMatch "
318 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
320 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
321 #ifdef SLAP_AUTH_REWRITE
322 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
326 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
327 "EQUALITY caseIgnoreMatch "
328 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
329 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
330 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
331 "EQUALITY caseIgnoreMatch "
332 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
333 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
334 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
335 "EQUALITY caseIgnoreMatch "
336 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
337 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
338 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
339 "DESC 'A type of backend' "
340 "EQUALITY caseIgnoreMatch "
341 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
343 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
344 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
345 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
346 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
347 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
348 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
349 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
350 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
351 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
352 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
353 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
354 "DESC 'The backend type for a database instance' "
355 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
356 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
357 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
358 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
359 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
360 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
361 "EQUALITY caseIgnoreMatch "
362 "SYNTAX OMsDirectoryString )", NULL, NULL },
363 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
364 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
365 "DESC 'OpenLDAP DIT content rules' "
366 "EQUALITY caseIgnoreMatch "
367 "SUBSTR caseIgnoreSubstringsMatch "
368 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
370 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
371 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
372 "EQUALITY caseIgnoreMatch "
373 "SYNTAX OMsDirectoryString )", NULL, NULL },
374 { "gentlehup", "on|off", 2, 2, 0,
376 ARG_ON_OFF, &global_gentlehup,
380 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
381 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
382 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
383 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
384 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
385 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
386 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
387 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
388 { "include", "file", 2, 2, 0, ARG_MAGIC,
389 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
390 "SUP labeledURI )", NULL, NULL },
391 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
392 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
393 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
394 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
395 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
396 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
397 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
398 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
399 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
400 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
401 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
402 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
403 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
404 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
405 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
406 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
407 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
408 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
409 { "ldapsyntax", "syntax", 2, 0, 0,
410 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
411 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
412 "DESC 'OpenLDAP ldapSyntax' "
413 "EQUALITY caseIgnoreMatch "
414 "SUBSTR caseIgnoreSubstringsMatch "
415 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
417 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
418 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
419 "EQUALITY caseIgnoreMatch "
420 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
421 { "listener-threads", "count", 2, 0, 0,
425 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
427 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
428 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
429 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
430 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
431 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
432 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
433 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
434 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
435 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
436 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
437 "EQUALITY caseIgnoreMatch "
438 "SYNTAX OMsDirectoryString )", NULL, NULL },
439 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
440 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
441 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
442 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
443 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
444 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
445 { "moduleload", "file", 2, 0, 0,
447 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
451 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
452 "EQUALITY caseIgnoreMatch "
453 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
454 { "modulepath", "path", 2, 2, 0,
456 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
460 "( OLcfgGlAt:31 NAME 'olcModulePath' "
461 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
462 { "monitoring", "TRUE|FALSE", 2, 2, 0,
463 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
464 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
465 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
466 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
467 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
468 "DESC 'OpenLDAP object classes' "
469 "EQUALITY caseIgnoreMatch "
470 "SUBSTR caseIgnoreSubstringsMatch "
471 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
473 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
474 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
475 "EQUALITY caseIgnoreMatch "
476 "SUBSTR caseIgnoreSubstringsMatch "
477 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
478 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
479 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
480 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
481 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
482 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
483 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
484 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
485 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
486 "EQUALITY caseIgnoreMatch "
487 "SYNTAX OMsDirectoryString )", NULL, NULL },
488 { "pidfile", "file", 2, 2, 0, ARG_STRING,
489 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
490 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
491 { "plugin", NULL, 0, 0, 0,
493 ARG_MAGIC|CFG_PLUGIN, &config_generic,
497 "( OLcfgGlAt:38 NAME 'olcPlugin' "
498 "EQUALITY caseIgnoreMatch "
499 "SYNTAX OMsDirectoryString )", NULL, NULL },
500 { "pluginlog", "filename", 2, 2, 0,
502 ARG_STRING, &slapi_log_file,
506 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
507 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
508 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
509 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
510 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
511 { "referral", "url", 2, 2, 0, ARG_MAGIC,
512 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
513 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
514 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
515 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
516 "EQUALITY caseIgnoreMatch "
517 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
518 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
519 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
520 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
521 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
522 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
523 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
524 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
525 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
526 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
527 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
528 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
529 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
530 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
531 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
532 "EQUALITY caseIgnoreMatch "
533 "SYNTAX OMsDirectoryString )", NULL, NULL },
534 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
535 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
536 "EQUALITY caseIgnoreMatch "
537 "SYNTAX OMsDirectoryString )", NULL, NULL },
538 { "reverse-lookup", "on|off", 2, 2, 0,
539 #ifdef SLAPD_RLOOKUPS
540 ARG_ON_OFF, &use_reverse_lookup,
544 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
545 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
546 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
547 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
548 "EQUALITY distinguishedNameMatch "
549 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
550 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
551 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
552 "EQUALITY caseIgnoreMatch "
553 "SYNTAX OMsDirectoryString )", NULL, NULL },
554 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
555 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
556 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
557 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
558 &config_generic, NULL, NULL, NULL },
559 { "sasl-auxprops", NULL, 2, 0, 0,
560 #ifdef HAVE_CYRUS_SASL
561 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
565 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
566 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
567 { "sasl-host", "host", 2, 2, 0,
568 #ifdef HAVE_CYRUS_SASL
569 ARG_STRING|ARG_UNIQUE, &sasl_host,
573 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
574 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
575 { "sasl-realm", "realm", 2, 2, 0,
576 #ifdef HAVE_CYRUS_SASL
577 ARG_STRING|ARG_UNIQUE, &global_realm,
581 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
582 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
583 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
584 &config_generic, NULL, NULL, NULL },
585 { "sasl-secprops", "properties", 2, 2, 0,
586 #ifdef HAVE_CYRUS_SASL
587 ARG_MAGIC|CFG_SASLSECP, &config_generic,
591 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
592 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
593 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
594 &config_generic, NULL, NULL, NULL },
595 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
596 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
597 "EQUALITY distinguishedNameMatch "
598 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
599 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
600 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
601 "EQUALITY caseIgnoreMatch "
602 "SYNTAX OMsDirectoryString )", NULL, NULL },
603 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
604 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
605 "EQUALITY caseIgnoreMatch "
606 "SYNTAX OMsDirectoryString )", NULL, NULL },
607 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
608 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
609 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
610 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
611 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
612 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
613 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
614 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
615 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
616 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
617 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
618 "DESC 'Attributes whose values will always be sorted' "
619 "EQUALITY caseIgnoreMatch "
620 "SYNTAX OMsDirectoryString )", NULL, NULL },
621 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
622 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
623 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
624 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
625 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
626 "EQUALITY distinguishedNameMatch "
627 "SYNTAX OMsDN )", NULL, NULL },
628 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
629 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
630 "DESC 'Store sync context in a subentry' "
631 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
632 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
633 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
634 "EQUALITY caseIgnoreMatch "
635 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
636 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
637 #ifndef LDAP_TCP_BUFFER
639 #else /* LDAP_TCP_BUFFER */
640 ARG_MAGIC, &config_tcp_buffer,
641 #endif /* LDAP_TCP_BUFFER */
642 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
643 "DESC 'Custom TCP buffer size' "
644 "SYNTAX OMsDirectoryString )", NULL, NULL },
645 { "threads", "count", 2, 2, 0,
649 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
651 "( OLcfgGlAt:66 NAME 'olcThreads' "
652 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
653 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
654 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
655 "SYNTAX OMsDirectoryString )", NULL, NULL },
656 { "TLSCACertificateFile", NULL, 2, 2, 0,
658 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
662 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
663 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
664 { "TLSCACertificatePath", NULL, 2, 2, 0,
666 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
670 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
671 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
672 { "TLSCertificateFile", NULL, 2, 2, 0,
674 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
678 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
679 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
680 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
682 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
686 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
687 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
688 { "TLSCipherSuite", NULL, 2, 2, 0,
690 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
694 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
695 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
696 { "TLSCRLCheck", NULL, 2, 2, 0,
697 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
698 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
702 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
703 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
704 { "TLSCRLFile", NULL, 2, 2, 0,
705 #if defined(HAVE_GNUTLS)
706 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
710 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
711 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
712 { "TLSRandFile", NULL, 2, 2, 0,
714 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
718 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
719 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
720 { "TLSVerifyClient", NULL, 2, 2, 0,
722 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
726 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
727 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
728 { "TLSDHParamFile", NULL, 2, 2, 0,
730 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
734 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
735 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
736 { "TLSProtocolMin", NULL, 2, 2, 0,
738 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
742 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
743 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
744 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
745 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
746 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
747 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
748 NULL, NULL, NULL, NULL },
749 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
750 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
751 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
752 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
753 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
754 "EQUALITY caseIgnoreMatch "
755 "SUP labeledURI )", NULL, NULL },
756 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
757 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
758 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
759 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
760 NULL, NULL, NULL, NULL }
763 /* Need to no-op this keyword for dynamic config */
764 ConfigTable olcDatabaseDummy[] = {
765 { "", "", 0, 0, 0, ARG_IGNORED,
766 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
767 "DESC 'The backend type for a database instance' "
768 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
769 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
772 /* Routines to check if a child can be added to this type */
773 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
774 cfAddBackend, cfAddModule, cfAddOverlay;
776 /* NOTE: be careful when defining array members
777 * that can be conditionally compiled */
778 #define CFOC_GLOBAL cf_ocs[1]
779 #define CFOC_SCHEMA cf_ocs[2]
780 #define CFOC_BACKEND cf_ocs[3]
781 #define CFOC_DATABASE cf_ocs[4]
782 #define CFOC_OVERLAY cf_ocs[5]
783 #define CFOC_INCLUDE cf_ocs[6]
784 #define CFOC_FRONTEND cf_ocs[7]
786 #define CFOC_MODULE cf_ocs[8]
787 #endif /* SLAPD_MODULES */
789 static ConfigOCs cf_ocs[] = {
792 "DESC 'OpenLDAP configuration object' "
793 "ABSTRACT SUP top )", Cft_Abstract, NULL },
796 "DESC 'OpenLDAP Global configuration options' "
797 "SUP olcConfig STRUCTURAL "
798 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
799 "olcAttributeOptions $ olcAuthIDRewrite $ "
800 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
801 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
802 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
803 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
804 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
805 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
806 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
807 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
808 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
810 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
811 "olcSecurity $ olcServerID $ olcSizeLimit $ "
812 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
814 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
815 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
816 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
817 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
818 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
819 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
820 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
822 "NAME 'olcSchemaConfig' "
823 "DESC 'OpenLDAP schema object' "
824 "SUP olcConfig STRUCTURAL "
825 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
826 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
827 Cft_Schema, NULL, cfAddSchema },
829 "NAME 'olcBackendConfig' "
830 "DESC 'OpenLDAP Backend-specific options' "
831 "SUP olcConfig STRUCTURAL "
832 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
834 "NAME 'olcDatabaseConfig' "
835 "DESC 'OpenLDAP Database-specific options' "
836 "SUP olcConfig STRUCTURAL "
838 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
839 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
840 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
841 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
842 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
843 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
844 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
845 "olcMonitoring $ olcExtraAttrs ) )",
846 Cft_Database, NULL, cfAddDatabase },
848 "NAME 'olcOverlayConfig' "
849 "DESC 'OpenLDAP Overlay-specific options' "
850 "SUP olcConfig STRUCTURAL "
851 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
853 "NAME 'olcIncludeFile' "
854 "DESC 'OpenLDAP configuration include file' "
855 "SUP olcConfig STRUCTURAL "
857 "MAY ( cn $ olcRootDSE ) )",
858 /* Used to be Cft_Include, that def has been removed */
859 Cft_Abstract, NULL, cfAddInclude },
860 /* This should be STRUCTURAL like all the other database classes, but
861 * that would mean inheriting all of the olcDatabaseConfig attributes,
862 * which causes them to be merged twice in config_build_entry.
865 "NAME 'olcFrontendConfig' "
866 "DESC 'OpenLDAP frontend configuration' "
868 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
869 Cft_Database, NULL, NULL },
872 "NAME 'olcModuleList' "
873 "DESC 'OpenLDAP dynamic module info' "
874 "SUP olcConfig STRUCTURAL "
875 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
876 Cft_Module, NULL, cfAddModule },
881 typedef struct ServerID {
882 struct ServerID *si_next;
883 struct berval si_url;
887 static ServerID *sid_list;
889 typedef struct voidList {
890 struct voidList *vl_next;
894 typedef struct ADlist {
895 struct ADlist *al_next;
896 AttributeDescription *al_desc;
899 static ADlist *sortVals;
902 config_generic(ConfigArgs *c) {
905 if ( c->op == SLAP_CONFIG_EMIT ) {
909 c->value_int = ldap_pvt_thread_get_concurrency();
912 c->value_int = connection_pool_max;
915 c->value_int = slap_tool_thread_max;
918 c->value_uint = slapd_daemon_threads;
922 c->value_string = ch_strdup( passwd_salt );
927 if ( c->be->be_limits ) {
931 for ( i=0; c->be->be_limits[i]; i++ ) {
932 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
933 if ( bv.bv_len >= sizeof( buf ) ) {
934 ber_bvarray_free_x( c->rvalue_vals, NULL );
935 c->rvalue_vals = NULL;
939 bv.bv_val = buf + bv.bv_len;
940 limits_unparse( c->be->be_limits[i], &bv,
941 sizeof( buf ) - ( bv.bv_val - buf ) );
942 bv.bv_len += bv.bv_val - buf;
944 value_add_one( &c->rvalue_vals, &bv );
947 if ( !c->rvalue_vals ) rc = 1;
950 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
953 c->value_string = ch_strdup( slap_sasl_getpolicy());
956 slap_sasl_regexp_unparse( &c->rvalue_vals );
957 if ( !c->rvalue_vals ) rc = 1;
959 #ifdef HAVE_CYRUS_SASL
961 struct berval bv = BER_BVNULL;
962 slap_sasl_secprops_unparse( &bv );
963 if ( !BER_BVISNULL( &bv )) {
964 ber_bvarray_add( &c->rvalue_vals, &bv );
972 c->value_int = c->be->be_max_deref_depth;
975 if ( SLAP_DBHIDDEN( c->be )) {
982 ConfigFile *cf = c->ca_private;
984 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
985 else if ( cf->c_om_head )
986 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
988 if ( !c->rvalue_vals )
993 ad_unparse_options( &c->rvalue_vals );
996 ConfigFile *cf = c->ca_private;
998 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
999 else if ( cf->c_oc_head )
1000 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1002 if ( !c->rvalue_vals )
1007 ConfigFile *cf = c->ca_private;
1009 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1010 else if ( cf->c_at_head )
1011 at_unparse( &c->rvalue_vals, cf->c_at_head,
1013 if ( !c->rvalue_vals )
1018 ConfigFile *cf = c->ca_private;
1020 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1021 else if ( cf->c_syn_head )
1022 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1023 cf->c_syn_tail, 0 );
1024 if ( !c->rvalue_vals )
1029 ConfigFile *cf = c->ca_private;
1031 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1032 else if ( cf->c_cr_head )
1033 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1035 if ( !c->rvalue_vals )
1042 char *src, *dst, ibuf[11];
1043 struct berval bv, abv;
1044 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1045 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1046 if ( abv.bv_len >= sizeof( ibuf ) ) {
1047 ber_bvarray_free_x( c->rvalue_vals, NULL );
1048 c->rvalue_vals = NULL;
1052 acl_unparse( a, &bv );
1053 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1054 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1055 /* Turn TAB / EOL into plain space */
1056 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1057 if (isspace((unsigned char)*src)) *dst++ = ' ';
1061 if (dst[-1] == ' ') {
1065 abv.bv_len = dst - abv.bv_val;
1066 ber_bvarray_add( &c->rvalue_vals, &abv );
1072 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1075 ConfigFile *cf = c->ca_private;
1076 if ( cf->c_dseFiles ) {
1077 value_add( &c->rvalue_vals, cf->c_dseFiles );
1088 for ( si = sid_list; si; si=si->si_next ) {
1089 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1090 if ( !BER_BVISEMPTY( &si->si_url )) {
1091 bv.bv_len = si->si_url.bv_len + 6;
1092 bv.bv_val = ch_malloc( bv.bv_len );
1093 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1094 si->si_url.bv_val );
1095 ber_bvarray_add( &c->rvalue_vals, &bv );
1099 bv.bv_len = sprintf( buf, "%d", si->si_num );
1100 value_add_one( &c->rvalue_vals, &bv );
1109 c->value_string = ch_strdup( logfileName );
1114 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1116 case CFG_SYNC_SUBENTRY:
1117 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1119 case CFG_MIRRORMODE:
1120 if ( SLAP_SHADOW(c->be))
1121 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1125 case CFG_MONITORING:
1126 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1128 case CFG_SSTR_IF_MAX:
1129 c->value_uint = index_substr_if_maxlen;
1131 case CFG_SSTR_IF_MIN:
1132 c->value_uint = index_substr_if_minlen;
1135 c->value_int = index_intlen;
1137 case CFG_SORTVALS: {
1140 for ( sv = sortVals; sv; sv = sv->al_next ) {
1141 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1145 #ifdef SLAPD_MODULES
1147 ModPaths *mp = c->ca_private;
1150 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1153 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1154 SLAP_X_ORDERED_FMT "%s", i,
1155 mp->mp_loads[i].bv_val );
1156 if ( bv.bv_len >= sizeof( c->log ) ) {
1157 ber_bvarray_free_x( c->rvalue_vals, NULL );
1158 c->rvalue_vals = NULL;
1161 value_add_one( &c->rvalue_vals, &bv );
1165 rc = c->rvalue_vals ? 0 : 1;
1169 ModPaths *mp = c->ca_private;
1170 if ( !BER_BVISNULL( &mp->mp_path ))
1171 value_add_one( &c->rvalue_vals, &mp->mp_path );
1173 rc = c->rvalue_vals ? 0 : 1;
1179 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1180 if ( !c->rvalue_vals ) rc = 1;
1183 #ifdef SLAP_AUTH_REWRITE
1185 if ( authz_rewrites ) {
1186 struct berval bv, idx;
1191 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1192 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1193 if ( idx.bv_len >= sizeof( ibuf ) ) {
1194 ber_bvarray_free_x( c->rvalue_vals, NULL );
1195 c->rvalue_vals = NULL;
1198 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1199 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1200 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1201 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1202 authz_rewrites[i].bv_val,
1203 authz_rewrites[i].bv_len + 1 );
1204 ber_bvarray_add( &c->rvalue_vals, &bv );
1207 if ( !c->rvalue_vals ) rc = 1;
1214 } else if ( c->op == LDAP_MOD_DELETE ) {
1217 /* single-valued attrs, no-ops */
1226 case CFG_MIRRORMODE:
1227 case CFG_MONITORING:
1229 case CFG_SSTR_IF_MAX:
1230 case CFG_SSTR_IF_MIN:
1232 case CFG_SYNC_SUBENTRY:
1235 /* no-ops, requires slapd restart */
1240 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1244 ch_free( passwd_salt );
1249 ch_free( logfileName );
1257 case CFG_SERVERID: {
1258 ServerID *si, **sip;
1260 for ( i=0, si = sid_list, sip = &sid_list;
1261 si; si = *sip, i++ ) {
1262 if ( c->valx == -1 || i == c->valx ) {
1274 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1278 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1279 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1280 SLAP_INDEX_INTLEN_DEFAULT );
1284 if ( c->valx < 0 ) {
1285 acl_destroy( c->be->be_acl );
1286 c->be->be_acl = NULL;
1289 AccessControl **prev, *a;
1291 for (i=0, prev = &c->be->be_acl; i < c->valx;
1294 prev = &a->acl_next;
1297 *prev = a->acl_next;
1304 /* Can be NULL when undoing a failed add */
1305 if ( c->ca_entry ) {
1306 ce = c->ca_entry->e_private;
1307 /* can't modify the hardcoded schema */
1308 if ( ce->ce_parent->ce_type == Cft_Global )
1312 cfn = c->ca_private;
1313 if ( c->valx < 0 ) {
1316 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1318 if ( oc == cfn->c_oc_tail )
1321 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1323 ObjectClass *oc, *prev = NULL;
1325 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1330 if ( cfn->c_oc_tail == oc ) {
1331 cfn->c_oc_tail = prev;
1333 if ( cfn->c_oc_head == oc ) {
1335 cfn->c_oc_head = oc;
1342 /* Can be NULL when undoing a failed add */
1343 if ( c->ca_entry ) {
1344 ce = c->ca_entry->e_private;
1345 /* can't modify the hardcoded schema */
1346 if ( ce->ce_parent->ce_type == Cft_Global )
1350 cfn = c->ca_private;
1351 if ( c->valx < 0 ) {
1354 for( at = cfn->c_at_head; at; at_next( &at )) {
1356 if ( at == cfn->c_at_tail )
1359 cfn->c_at_head = cfn->c_at_tail = NULL;
1361 AttributeType *at, *prev = NULL;
1363 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1368 if ( cfn->c_at_tail == at ) {
1369 cfn->c_at_tail = prev;
1371 if ( cfn->c_at_head == at ) {
1373 cfn->c_at_head = at;
1380 /* Can be NULL when undoing a failed add */
1381 if ( c->ca_entry ) {
1382 ce = c->ca_entry->e_private;
1383 /* can't modify the hardcoded schema */
1384 if ( ce->ce_parent->ce_type == Cft_Global )
1388 cfn = c->ca_private;
1389 if ( c->valx < 0 ) {
1392 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1394 if ( syn == cfn->c_syn_tail )
1397 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1399 Syntax *syn, *prev = NULL;
1401 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1406 if ( cfn->c_syn_tail == syn ) {
1407 cfn->c_syn_tail = prev;
1409 if ( cfn->c_syn_head == syn ) {
1411 cfn->c_syn_head = syn;
1416 if ( c->valx < 0 ) {
1418 for ( sv = sortVals; sv; sv = sortVals ) {
1419 sortVals = sv->al_next;
1420 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1427 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1428 prev = &sv->al_next;
1431 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1432 *prev = sv->al_next;
1438 /* FIXME: there is no limits_free function */
1439 if ( c->valx < 0 ) {
1440 limits_destroy( c->be->be_limits );
1441 c->be->be_limits = NULL;
1446 if ( c->be->be_limits ) {
1447 for ( num = 0; c->be->be_limits[ num ]; num++ )
1451 if ( c->valx >= num ) {
1456 limits_destroy( c->be->be_limits );
1457 c->be->be_limits = NULL;
1460 limits_free_one( c->be->be_limits[ c->valx ] );
1462 for ( cnt = c->valx; cnt < num; cnt++ ) {
1463 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1470 /* FIXME: there is no ad_option_free function */
1472 /* FIXME: there is no way to remove attributes added by
1486 if(!(c->bi = backend_info(c->argv[1]))) {
1487 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1488 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1489 c->log, c->cr_msg, c->argv[1] );
1496 /* NOTE: config is always the first backend!
1498 if ( !strcasecmp( c->argv[1], "config" )) {
1499 c->be = LDAP_STAILQ_FIRST(&backendDB);
1500 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1503 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1505 if ( c->cr_msg[0] == 0 )
1506 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1507 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1514 ldap_pvt_thread_set_concurrency(c->value_int);
1518 if ( c->value_int < 2 ) {
1519 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1520 "threads=%d smaller than minimum value 2",
1522 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1523 c->log, c->cr_msg, 0 );
1526 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1527 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1528 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1529 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1530 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1531 c->log, c->cr_msg, 0 );
1533 if ( slapMode & SLAP_SERVER_MODE )
1534 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1535 connection_pool_max = c->value_int; /* save for reference */
1539 if ( slapMode & SLAP_TOOL_MODE )
1540 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1541 slap_tool_thread_max = c->value_int; /* save for reference */
1546 /* use a power of two */
1547 while (c->value_uint > 1) {
1548 c->value_uint >>= 1;
1552 slapd_daemon_mask = mask;
1553 slapd_daemon_threads = mask+1;
1558 if ( passwd_salt ) ch_free( passwd_salt );
1559 passwd_salt = c->value_string;
1560 lutil_salt_format(passwd_salt);
1564 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1570 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1572 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1576 ch_free(c->value_string);
1577 if (slap_sasl_setpolicy( c->argv[1] )) {
1578 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1579 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1580 c->log, c->cr_msg, c->argv[1] );
1586 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1590 #ifdef HAVE_CYRUS_SASL
1593 char *txt = slap_sasl_secprops( c->argv[1] );
1595 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1597 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1605 c->be->be_max_deref_depth = c->value_int;
1611 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1612 cfn = c->ca_private;
1613 if(parse_oidm(c, 1, &om))
1615 if (!cfn->c_om_head) cfn->c_om_head = om;
1616 cfn->c_om_tail = om;
1621 ObjectClass *oc, *prev;
1623 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1624 cfn = c->ca_private;
1625 if ( c->valx < 0 ) {
1626 prev = cfn->c_oc_tail;
1629 /* If adding anything after the first, prev is easy */
1632 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1634 if ( !oc_next( &oc ))
1638 /* If adding the first, and head exists, find its prev */
1639 if (cfn->c_oc_head) {
1640 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1645 /* else prev is NULL, append to end of global list */
1647 if(parse_oc(c, &oc, prev)) return(1);
1648 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1649 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1654 AttributeType *at, *prev;
1656 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1657 cfn = c->ca_private;
1658 if ( c->valx < 0 ) {
1659 prev = cfn->c_at_tail;
1662 /* If adding anything after the first, prev is easy */
1665 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1667 if ( !at_next( &at ))
1671 /* If adding the first, and head exists, find its prev */
1672 if (cfn->c_at_head) {
1673 for ( at_start( &at ); at != cfn->c_at_head; ) {
1678 /* else prev is NULL, append to end of global list */
1680 if(parse_at(c, &at, prev)) return(1);
1681 if (!cfn->c_at_head) cfn->c_at_head = at;
1682 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1689 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1690 cfn = c->ca_private;
1691 if ( c->valx < 0 ) {
1692 prev = cfn->c_syn_tail;
1695 /* If adding anything after the first, prev is easy */
1698 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1700 if ( !syn_next( &syn ))
1704 /* If adding the first, and head exists, find its prev */
1705 if (cfn->c_syn_head) {
1706 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1711 /* else prev is NULL, append to end of global list */
1713 if ( parse_syn( c, &syn, prev ) ) return(1);
1714 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1715 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1722 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1723 cfn = c->ca_private;
1724 if(parse_cr(c, &cr)) return(1);
1725 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1726 cfn->c_cr_tail = cr;
1731 ad_define_option(NULL, NULL, 0);
1732 for(i = 1; i < c->argc; i++)
1733 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1738 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1739 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1740 else if ( c->value_int > 255 )
1742 index_intlen = c->value_int;
1743 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1747 case CFG_SORTVALS: {
1748 ADlist *svnew = NULL, *svtail, *sv;
1750 for ( i = 1; i < c->argc; i++ ) {
1751 AttributeDescription *ad = NULL;
1755 rc = slap_str2ad( c->argv[i], &ad, &text );
1757 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1760 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1761 c->log, c->cr_msg, c->argv[i] );
1762 for ( sv = svnew; sv; sv = svnew ) {
1763 svnew = sv->al_next;
1768 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1769 ad->ad_type->sat_single_value ) {
1770 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1772 goto sortval_reject;
1774 sv = ch_malloc( sizeof( ADlist ));
1779 svtail->al_next = sv;
1784 for ( sv = svnew; sv; sv = sv->al_next )
1785 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1786 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1788 sv->al_next = svnew;
1795 /* Don't append to the global ACL if we're on a specific DB */
1797 if ( c->valx == -1 ) {
1800 for ( a=c->be->be_acl; a; a = a->acl_next )
1803 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1810 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1812 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1816 if(root_dse_read_file(c->argv[1])) {
1817 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1818 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1819 c->log, c->cr_msg, c->argv[1] );
1824 ber_str2bv( c->argv[1], 0, 1, &bv );
1825 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1826 cfn = c->ca_private;
1827 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1833 ServerID *si, **sip;
1836 if (( lutil_atoi( &num, c->argv[1] ) &&
1837 lutil_atoix( &num, c->argv[1], 16 )) ||
1838 num < 0 || num > SLAP_SYNC_SID_MAX )
1840 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1841 "<%s> illegal server ID", c->argv[0] );
1842 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1843 c->log, c->cr_msg, c->argv[1] );
1846 /* only one value allowed if no URL is given */
1847 if ( c->argc > 2 ) {
1850 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1851 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1852 "<%s> only one server ID allowed now", c->argv[0] );
1853 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1854 c->log, c->cr_msg, c->argv[1] );
1858 if ( ldap_url_parse( c->argv[2], &lud )) {
1859 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1860 "<%s> invalid URL", c->argv[0] );
1861 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1862 c->log, c->cr_msg, c->argv[2] );
1865 len = strlen( c->argv[2] );
1866 si = ch_malloc( sizeof(ServerID) + len + 1 );
1867 si->si_url.bv_val = (char *)(si+1);
1868 si->si_url.bv_len = len;
1869 strcpy( si->si_url.bv_val, c->argv[2] );
1872 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1873 "<%s> unqualified server ID not allowed now", c->argv[0] );
1874 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1875 c->log, c->cr_msg, c->argv[1] );
1878 si = ch_malloc( sizeof(ServerID) );
1879 BER_BVZERO( &si->si_url );
1880 slap_serverID = num;
1881 Debug( LDAP_DEBUG_CONFIG,
1883 c->log, slap_serverID, 0 );
1887 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1890 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1891 Listener *l = config_check_my_url( c->argv[2], lud );
1893 slap_serverID = si->si_num;
1894 Debug( LDAP_DEBUG_CONFIG,
1895 "%s: SID=0x%03x (listener=%s)\n",
1896 c->log, slap_serverID,
1901 ldap_free_urldesc( lud );
1905 if ( logfileName ) ch_free( logfileName );
1906 logfileName = c->value_string;
1907 logfile = fopen(logfileName, "w");
1908 if(logfile) lutil_debug_file(logfile);
1912 if(SLAP_NOLASTMODCMD(c->be)) {
1913 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1914 c->argv[0], c->be->bd_info->bi_type );
1915 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1916 c->log, c->cr_msg, 0 );
1920 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1922 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1925 case CFG_MIRRORMODE:
1926 if(c->value_int && !SLAP_SHADOW(c->be)) {
1927 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1929 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1930 c->log, c->cr_msg, 0 );
1934 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1936 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1939 case CFG_MONITORING:
1941 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1943 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1948 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1950 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1953 case CFG_SYNC_SUBENTRY:
1955 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1957 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1960 case CFG_SSTR_IF_MAX:
1961 if (c->value_uint < index_substr_if_minlen) {
1962 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1963 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1964 c->log, c->cr_msg, c->value_int );
1967 index_substr_if_maxlen = c->value_uint;
1970 case CFG_SSTR_IF_MIN:
1971 if (c->value_uint > index_substr_if_maxlen) {
1972 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1973 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1974 c->log, c->cr_msg, c->value_int );
1977 index_substr_if_minlen = c->value_uint;
1980 #ifdef SLAPD_MODULES
1982 /* If we're just adding a module on an existing modpath,
1983 * make sure we've selected the current path.
1985 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1986 modcur = c->ca_private;
1987 /* This should never fail */
1988 if ( module_path( modcur->mp_path.bv_val )) {
1989 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1991 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1992 c->log, c->cr_msg, modcur->mp_path.bv_val );
1996 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1998 /* Record this load on the current path */
2002 if ( c->op == SLAP_CONFIG_ADD ) {
2003 ptr = c->line + STRLENOF("moduleload");
2004 while (!isspace((unsigned char) *ptr)) ptr++;
2005 while (isspace((unsigned char) *ptr)) ptr++;
2009 ber_str2bv(ptr, 0, 1, &bv);
2010 ber_bvarray_add( &modcur->mp_loads, &bv );
2012 /* Check for any new hardcoded schema */
2013 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2014 config_check_schema( NULL, &cfBackInfo );
2019 if(module_path(c->argv[1])) return(1);
2020 /* Record which path was used with each module */
2024 if (!modpaths.mp_loads) {
2027 mp = ch_malloc( sizeof( ModPaths ));
2028 modlast->mp_next = mp;
2030 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2032 mp->mp_loads = NULL;
2043 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2045 slapi_plugins_used++;
2049 #ifdef SLAP_AUTH_REWRITE
2055 if ( c->op == LDAP_MOD_ADD ) {
2059 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2063 if ( c->argc > 1 ) {
2066 /* quote all args but the first */
2067 line = ldap_charray2str( c->argv, "\" \"" );
2068 ber_str2bv( line, 0, 0, &bv );
2069 s = ber_bvchr( &bv, '"' );
2070 assert( s != NULL );
2071 /* move the trailing quote of argv[0] to the end */
2072 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2073 bv.bv_val[ bv.bv_len - 1 ] = '"';
2076 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2079 ber_bvarray_add( &authz_rewrites, &bv );
2081 if ( c->op == LDAP_MOD_ADD ) {
2091 Debug( LDAP_DEBUG_ANY,
2092 "%s: unknown CFG_TYPE %d.\n",
2093 c->log, c->type, 0 );
2102 config_fname(ConfigArgs *c) {
2103 if(c->op == SLAP_CONFIG_EMIT) {
2104 if (c->ca_private) {
2105 ConfigFile *cf = c->ca_private;
2106 value_add_one( &c->rvalue_vals, &cf->c_file );
2115 config_cfdir(ConfigArgs *c) {
2116 if(c->op == SLAP_CONFIG_EMIT) {
2117 if ( !BER_BVISEMPTY( &cfdir )) {
2118 value_add_one( &c->rvalue_vals, &cfdir );
2127 config_search_base(ConfigArgs *c) {
2128 if(c->op == SLAP_CONFIG_EMIT) {
2130 if (!BER_BVISEMPTY(&default_search_base)) {
2131 value_add_one(&c->rvalue_vals, &default_search_base);
2132 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2136 } else if( c->op == LDAP_MOD_DELETE ) {
2137 ch_free( default_search_base.bv_val );
2138 ch_free( default_search_nbase.bv_val );
2139 BER_BVZERO( &default_search_base );
2140 BER_BVZERO( &default_search_nbase );
2144 if(c->bi || c->be != frontendDB) {
2145 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2146 "prior to any backend or database definition\n",
2151 if(default_search_nbase.bv_len) {
2152 free(default_search_base.bv_val);
2153 free(default_search_nbase.bv_val);
2156 default_search_base = c->value_dn;
2157 default_search_nbase = c->value_ndn;
2161 /* For RE23 compatibility we allow this in the global entry
2162 * but we now defer it to the frontend entry to allow modules
2163 * to load new hash types.
2166 config_passwd_hash(ConfigArgs *c) {
2168 if (c->op == SLAP_CONFIG_EMIT) {
2170 /* Don't generate it in the global entry */
2171 if ( c->table == Cft_Global )
2173 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2174 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2175 value_add_one(&c->rvalue_vals, &bv);
2178 } else if ( c->op == LDAP_MOD_DELETE ) {
2179 /* Deleting from global is a no-op, only the frontendDB entry matters */
2180 if ( c->table == Cft_Global )
2182 if ( c->valx < 0 ) {
2183 ldap_charray_free( default_passwd_hash );
2184 default_passwd_hash = NULL;
2187 ch_free( default_passwd_hash[i] );
2188 for (; default_passwd_hash[i]; i++ )
2189 default_passwd_hash[i] = default_passwd_hash[i+1];
2193 for(i = 1; i < c->argc; i++) {
2194 if(!lutil_passwd_scheme(c->argv[i])) {
2195 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2196 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2197 c->log, c->cr_msg, c->argv[i]);
2199 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2202 if(!default_passwd_hash) {
2203 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2204 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2205 c->log, c->cr_msg, 0 );
2212 config_schema_dn(ConfigArgs *c) {
2213 if ( c->op == SLAP_CONFIG_EMIT ) {
2215 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2216 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2217 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2221 } else if ( c->op == LDAP_MOD_DELETE ) {
2222 ch_free( c->be->be_schemadn.bv_val );
2223 ch_free( c->be->be_schemandn.bv_val );
2224 BER_BVZERO( &c->be->be_schemadn );
2225 BER_BVZERO( &c->be->be_schemandn );
2228 ch_free( c->be->be_schemadn.bv_val );
2229 ch_free( c->be->be_schemandn.bv_val );
2230 c->be->be_schemadn = c->value_dn;
2231 c->be->be_schemandn = c->value_ndn;
2236 config_sizelimit(ConfigArgs *c) {
2238 struct slap_limits_set *lim = &c->be->be_def_limit;
2239 if (c->op == SLAP_CONFIG_EMIT) {
2244 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2245 if ( !BER_BVISEMPTY( &bv ))
2246 value_add_one( &c->rvalue_vals, &bv );
2250 } else if ( c->op == LDAP_MOD_DELETE ) {
2251 /* Reset to defaults or values from frontend */
2252 if ( c->be == frontendDB ) {
2253 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2254 lim->lms_s_hard = 0;
2255 lim->lms_s_unchecked = -1;
2257 lim->lms_s_pr_hide = 0;
2258 lim->lms_s_pr_total = 0;
2260 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2261 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2262 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2263 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2264 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2265 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2269 for(i = 1; i < c->argc; i++) {
2270 if(!strncasecmp(c->argv[i], "size", 4)) {
2271 rc = limits_parse_one(c->argv[i], lim);
2273 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2274 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2275 c->log, c->cr_msg, c->argv[i]);
2279 if(!strcasecmp(c->argv[i], "unlimited")) {
2280 lim->lms_s_soft = -1;
2282 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2283 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2284 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2285 c->log, c->cr_msg, c->argv[i]);
2289 lim->lms_s_hard = 0;
2294 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2295 /* This is a modification to the global limits apply it to
2296 * the other databases as needed */
2297 AttributeDescription *ad=NULL;
2298 const char *text = NULL;
2299 CfEntryInfo *ce = c->ca_entry->e_private;
2301 slap_str2ad(c->argv[0], &ad, &text);
2302 /* if we got here... */
2303 assert( ad != NULL );
2305 if ( ce->ce_type == Cft_Global ){
2308 for (; ce; ce=ce->ce_sibs) {
2309 Entry *dbe = ce->ce_entry;
2310 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2311 && (!attr_find(dbe->e_attrs, ad)) ) {
2312 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2313 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2314 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2315 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2316 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2317 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2325 config_timelimit(ConfigArgs *c) {
2327 struct slap_limits_set *lim = &c->be->be_def_limit;
2328 if (c->op == SLAP_CONFIG_EMIT) {
2333 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2334 if ( !BER_BVISEMPTY( &bv ))
2335 value_add_one( &c->rvalue_vals, &bv );
2339 } else if ( c->op == LDAP_MOD_DELETE ) {
2340 /* Reset to defaults or values from frontend */
2341 if ( c->be == frontendDB ) {
2342 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2343 lim->lms_t_hard = 0;
2345 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2346 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2350 for(i = 1; i < c->argc; i++) {
2351 if(!strncasecmp(c->argv[i], "time", 4)) {
2352 rc = limits_parse_one(c->argv[i], lim);
2354 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2355 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2356 c->log, c->cr_msg, c->argv[i]);
2360 if(!strcasecmp(c->argv[i], "unlimited")) {
2361 lim->lms_t_soft = -1;
2363 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2364 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2365 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2366 c->log, c->cr_msg, c->argv[i]);
2370 lim->lms_t_hard = 0;
2375 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2376 /* This is a modification to the global limits apply it to
2377 * the other databases as needed */
2378 AttributeDescription *ad=NULL;
2379 const char *text = NULL;
2380 CfEntryInfo *ce = c->ca_entry->e_private;
2382 slap_str2ad(c->argv[0], &ad, &text);
2383 /* if we got here... */
2384 assert( ad != NULL );
2386 if ( ce->ce_type == Cft_Global ){
2389 for (; ce; ce=ce->ce_sibs) {
2390 Entry *dbe = ce->ce_entry;
2391 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2392 && (!attr_find(dbe->e_attrs, ad)) ) {
2393 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2394 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2402 config_overlay(ConfigArgs *c) {
2403 if (c->op == SLAP_CONFIG_EMIT) {
2405 } else if ( c->op == LDAP_MOD_DELETE ) {
2408 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2409 c->valx, &c->bi, &c->reply)) {
2411 Debug( LDAP_DEBUG_ANY,
2412 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2413 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2415 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2422 config_subordinate(ConfigArgs *c)
2428 case SLAP_CONFIG_EMIT:
2429 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2432 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2433 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2436 value_add_one( &c->rvalue_vals, &bv );
2440 case LDAP_MOD_DELETE:
2441 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2442 glue_sub_del( c->be );
2444 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2449 case SLAP_CONFIG_ADD:
2450 if ( c->be->be_nsuffix == NULL ) {
2452 snprintf( c->cr_msg, sizeof( c->cr_msg),
2453 "subordinate configuration needs a suffix" );
2454 Debug( LDAP_DEBUG_ANY,
2456 c->log, c->cr_msg, 0 );
2461 if ( c->argc == 2 ) {
2462 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2465 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2467 snprintf( c->cr_msg, sizeof( c->cr_msg),
2468 "subordinate must be \"TRUE\" or \"advertise\"" );
2469 Debug( LDAP_DEBUG_ANY,
2470 "%s: suffix \"%s\": %s.\n",
2471 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2477 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2485 * [listener=<listener>] [{read|write}=]<size>
2488 #ifdef LDAP_TCP_BUFFER
2489 static BerVarray tcp_buffer;
2492 #define SLAP_TCP_RMEM (0x1U)
2493 #define SLAP_TCP_WMEM (0x2U)
2496 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2497 int *size, int *rw, Listener **l )
2499 int i, rc = LDAP_SUCCESS;
2500 LDAPURLDesc *lud = NULL;
2503 if ( val != NULL && argv == NULL ) {
2504 char *s = val->bv_val;
2506 argv = ldap_str2charray( s, " \t" );
2507 if ( argv == NULL ) {
2513 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2516 char *url = argv[ i ] + STRLENOF( "listener=" );
2518 if ( ldap_url_parse( url, &lud ) ) {
2519 rc = LDAP_INVALID_SYNTAX;
2523 *l = config_check_my_url( url, lud );
2525 rc = LDAP_NO_SUCH_ATTRIBUTE;
2533 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2534 *rw |= SLAP_TCP_RMEM;
2535 ptr += STRLENOF( "read=" );
2537 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2538 *rw |= SLAP_TCP_WMEM;
2539 ptr += STRLENOF( "write=" );
2542 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2545 /* accept any base */
2546 if ( lutil_atoix( size, ptr, 0 ) ) {
2547 rc = LDAP_INVALID_SYNTAX;
2552 if ( val != NULL && argv != NULL ) {
2553 ldap_charray_free( argv );
2556 if ( lud != NULL ) {
2557 ldap_free_urldesc( lud );
2564 tcp_buffer_delete_one( struct berval *val )
2567 int size = -1, rw = 0;
2570 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2577 Listener **ll = slapd_get_listeners();
2579 for ( i = 0; ll[ i ] != NULL; i++ ) {
2580 if ( ll[ i ] == l ) break;
2583 if ( ll[ i ] == NULL ) {
2584 return LDAP_NO_SUCH_ATTRIBUTE;
2587 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2588 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2590 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2591 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2592 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2596 /* NOTE: this affects listeners without a specific setting,
2597 * does not reset all listeners. If a listener without
2598 * specific settings was assigned a buffer because of
2599 * a global setting, it will not be reset. In any case,
2600 * buffer changes will only take place at restart. */
2601 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2602 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2609 tcp_buffer_delete( BerVarray vals )
2613 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2614 tcp_buffer_delete_one( &vals[ i ] );
2621 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2623 char buf[sizeof("2147483648")], *ptr;
2625 /* unparse for later use */
2626 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2628 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2631 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2632 if ( rw & SLAP_TCP_RMEM ) {
2633 val->bv_len += STRLENOF( "read=" );
2634 } else if ( rw & SLAP_TCP_WMEM ) {
2635 val->bv_len += STRLENOF( "write=" );
2639 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2644 ptr = lutil_strcopy( ptr, "listener=" );
2645 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2649 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2650 if ( rw & SLAP_TCP_RMEM ) {
2651 ptr = lutil_strcopy( ptr, "read=" );
2652 } else if ( rw & SLAP_TCP_WMEM ) {
2653 ptr = lutil_strcopy( ptr, "write=" );
2657 ptr = lutil_strcopy( ptr, buf );
2660 assert( val->bv_val + val->bv_len == ptr );
2662 return LDAP_SUCCESS;
2666 tcp_buffer_add_one( int argc, char **argv )
2669 int size = -1, rw = 0;
2675 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2680 /* unparse for later use */
2681 rc = tcp_buffer_unparse( size, rw, l, &val );
2682 if ( rc != LDAP_SUCCESS ) {
2686 /* use parsed values */
2689 Listener **ll = slapd_get_listeners();
2691 for ( i = 0; ll[ i ] != NULL; i++ ) {
2692 if ( ll[ i ] == l ) break;
2695 if ( ll[ i ] == NULL ) {
2696 return LDAP_NO_SUCH_ATTRIBUTE;
2699 /* buffer only applies to TCP listeners;
2700 * we do not do any check here, and delegate them
2701 * to setsockopt(2) */
2702 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2703 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2705 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2706 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2707 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2711 /* NOTE: this affects listeners without a specific setting,
2712 * does not set all listeners */
2713 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2714 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2717 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2719 tcp_buffer[ tcp_buffer_num ] = val;
2722 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2728 config_tcp_buffer( ConfigArgs *c )
2730 if ( c->op == SLAP_CONFIG_EMIT ) {
2731 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2734 value_add( &c->rvalue_vals, tcp_buffer );
2735 value_add( &c->rvalue_nvals, tcp_buffer );
2737 } else if ( c->op == LDAP_MOD_DELETE ) {
2739 tcp_buffer_delete( tcp_buffer );
2740 ber_bvarray_free( tcp_buffer );
2746 int size = -1, rw = 0;
2749 struct berval val = BER_BVNULL;
2753 if ( tcp_buffer_num == 0 ) {
2758 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2763 /* unparse for later use */
2764 rc = tcp_buffer_unparse( size, rw, l, &val );
2765 if ( rc != LDAP_SUCCESS ) {
2769 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2770 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2775 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2781 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2782 ber_memfree( tcp_buffer[ i ].bv_val );
2783 for ( ; i < tcp_buffer_num; i++ ) {
2784 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2789 if ( !BER_BVISNULL( &val ) ) {
2790 SLAP_FREE( val.bv_val );
2798 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2800 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2801 "<%s> unable to add value #%d",
2802 c->argv[0], tcp_buffer_num );
2803 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2804 c->log, c->cr_msg, 0 );
2811 #endif /* LDAP_TCP_BUFFER */
2814 config_suffix(ConfigArgs *c)
2817 struct berval pdn, ndn;
2818 char *notallowed = NULL;
2820 if ( c->be == frontendDB ) {
2821 notallowed = "frontend";
2823 } else if ( SLAP_MONITOR(c->be) ) {
2824 notallowed = "monitor";
2826 } else if ( SLAP_CONFIG(c->be) ) {
2827 notallowed = "config";
2830 if ( notallowed != NULL ) {
2831 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2835 case LDAP_MOD_DELETE:
2836 case LDAP_MOD_REPLACE:
2837 case LDAP_MOD_INCREMENT:
2838 case SLAP_CONFIG_ADD:
2839 if ( !BER_BVISNULL( &c->value_dn ) ) {
2840 snprintf( buf, sizeof( buf ), "<%s> ",
2841 c->value_dn.bv_val );
2844 Debug(LDAP_DEBUG_ANY,
2845 "%s: suffix %snot allowed in %s database.\n",
2846 c->log, buf, notallowed );
2849 case SLAP_CONFIG_EMIT:
2850 /* don't complain when emitting... */
2854 /* FIXME: don't know what values may be valid;
2855 * please remove assertion, or add legal values
2856 * to either block */
2864 if (c->op == SLAP_CONFIG_EMIT) {
2865 if ( c->be->be_suffix == NULL
2866 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2870 value_add( &c->rvalue_vals, c->be->be_suffix );
2871 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2874 } else if ( c->op == LDAP_MOD_DELETE ) {
2875 if ( c->valx < 0 ) {
2876 ber_bvarray_free( c->be->be_suffix );
2877 ber_bvarray_free( c->be->be_nsuffix );
2878 c->be->be_suffix = NULL;
2879 c->be->be_nsuffix = NULL;
2882 ch_free( c->be->be_suffix[i].bv_val );
2883 ch_free( c->be->be_nsuffix[i].bv_val );
2885 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2886 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2888 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2893 #ifdef SLAPD_MONITOR_DN
2894 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2895 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2897 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2898 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2903 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2904 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2905 c->argv[0], c->be->bd_info->bi_type );
2906 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2907 c->log, c->cr_msg, 0);
2914 if (SLAP_DBHIDDEN( c->be ))
2917 tbe = select_backend(&ndn, 0);
2919 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2925 BackendDB *b2 = tbe;
2927 /* Does tbe precede be? */
2928 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2931 char *type = tbe->bd_info->bi_type;
2933 if ( overlay_is_over( tbe ) ) {
2934 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2935 type = oi->oi_orig->bi_type;
2938 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2939 "already served by a preceding %s database",
2940 c->argv[0], pdn.bv_val, type );
2941 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2942 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2948 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2949 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2950 "base provided \"%s\" (assuming okay)\n",
2951 c->log, default_search_base.bv_val, 0);
2953 ber_bvarray_add(&c->be->be_suffix, &pdn);
2954 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2959 config_rootdn(ConfigArgs *c) {
2960 if (c->op == SLAP_CONFIG_EMIT) {
2961 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2962 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2963 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2968 } else if ( c->op == LDAP_MOD_DELETE ) {
2969 ch_free( c->be->be_rootdn.bv_val );
2970 ch_free( c->be->be_rootndn.bv_val );
2971 BER_BVZERO( &c->be->be_rootdn );
2972 BER_BVZERO( &c->be->be_rootndn );
2975 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2976 ch_free( c->be->be_rootdn.bv_val );
2977 ch_free( c->be->be_rootndn.bv_val );
2979 c->be->be_rootdn = c->value_dn;
2980 c->be->be_rootndn = c->value_ndn;
2985 config_rootpw(ConfigArgs *c) {
2988 if (c->op == SLAP_CONFIG_EMIT) {
2989 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2990 /* don't copy, because "rootpw" is marked
2992 c->value_bv = c->be->be_rootpw;
2996 } else if ( c->op == LDAP_MOD_DELETE ) {
2997 ch_free( c->be->be_rootpw.bv_val );
2998 BER_BVZERO( &c->be->be_rootpw );
3002 tbe = select_backend(&c->be->be_rootndn, 0);
3004 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3006 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3007 c->log, c->cr_msg, 0);
3010 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3011 ch_free( c->be->be_rootpw.bv_val );
3012 c->be->be_rootpw = c->value_bv;
3017 config_restrict(ConfigArgs *c) {
3018 slap_mask_t restrictops = 0;
3020 slap_verbmasks restrictable_ops[] = {
3021 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3022 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3023 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3024 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3025 { BER_BVC("modrdn"), 0 },
3026 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3027 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3028 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3029 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3030 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3031 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3032 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3033 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3034 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3035 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3036 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3040 if (c->op == SLAP_CONFIG_EMIT) {
3041 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3043 } else if ( c->op == LDAP_MOD_DELETE ) {
3045 c->be->be_restrictops = 0;
3047 restrictops = verb_to_mask( c->line, restrictable_ops );
3048 c->be->be_restrictops ^= restrictops;
3052 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3054 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3055 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3056 c->log, c->cr_msg, c->argv[i]);
3059 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3060 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3061 c->be->be_restrictops |= restrictops;
3066 config_allows(ConfigArgs *c) {
3067 slap_mask_t allows = 0;
3069 slap_verbmasks allowable_ops[] = {
3070 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3071 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3072 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3073 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3074 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3077 if (c->op == SLAP_CONFIG_EMIT) {
3078 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3079 } else if ( c->op == LDAP_MOD_DELETE ) {
3083 allows = verb_to_mask( c->line, allowable_ops );
3084 global_allows ^= allows;
3088 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3090 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3091 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3092 c->log, c->cr_msg, c->argv[i]);
3095 global_allows |= allows;
3100 config_disallows(ConfigArgs *c) {
3101 slap_mask_t disallows = 0;
3103 slap_verbmasks disallowable_ops[] = {
3104 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3105 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3106 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3107 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3108 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3109 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3112 if (c->op == SLAP_CONFIG_EMIT) {
3113 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3114 } else if ( c->op == LDAP_MOD_DELETE ) {
3116 global_disallows = 0;
3118 disallows = verb_to_mask( c->line, disallowable_ops );
3119 global_disallows ^= disallows;
3123 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3125 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3126 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3127 c->log, c->cr_msg, c->argv[i]);
3130 global_disallows |= disallows;
3135 config_requires(ConfigArgs *c) {
3136 slap_mask_t requires = frontendDB->be_requires;
3137 int i, argc = c->argc;
3138 char **argv = c->argv;
3140 slap_verbmasks requires_ops[] = {
3141 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3142 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3143 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3144 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3145 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3148 if (c->op == SLAP_CONFIG_EMIT) {
3149 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3150 } else if ( c->op == LDAP_MOD_DELETE ) {
3152 c->be->be_requires = 0;
3154 requires = verb_to_mask( c->line, requires_ops );
3155 c->be->be_requires ^= requires;
3159 /* "none" can only be first, to wipe out default/global values */
3160 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3165 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3167 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3168 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3169 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3170 c->log, c->cr_msg, 0);
3172 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3173 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3174 c->log, c->cr_msg, c->argv[i]);
3178 c->be->be_requires = requires;
3183 config_extra_attrs(ConfigArgs *c)
3185 assert( c->be != NULL );
3187 if ( c->op == SLAP_CONFIG_EMIT ) {
3190 if ( c->be->be_extra_anlist == NULL ) {
3194 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3195 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3198 } else if ( c->op == LDAP_MOD_DELETE ) {
3199 if ( c->be->be_extra_anlist == NULL ) {
3203 if ( c->valx < 0 ) {
3204 anlist_free( c->be->be_extra_anlist, 1, NULL );
3205 c->be->be_extra_anlist = NULL;
3210 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3213 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3217 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3219 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3220 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3225 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3226 if ( c->be->be_extra_anlist == NULL ) {
3234 static slap_verbmasks *loglevel_ops;
3237 loglevel_init( void )
3239 slap_verbmasks lo[] = {
3240 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3241 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3242 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3243 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3244 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3245 { BER_BVC("BER"), LDAP_DEBUG_BER },
3246 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3247 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3248 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3249 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3250 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3251 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3252 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3253 #if 0 /* no longer used (nor supported) */
3254 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3255 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3257 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3258 { BER_BVC("None"), LDAP_DEBUG_NONE },
3262 return slap_verbmasks_init( &loglevel_ops, lo );
3266 loglevel_destroy( void )
3268 if ( loglevel_ops ) {
3269 (void)slap_verbmasks_destroy( loglevel_ops );
3271 loglevel_ops = NULL;
3274 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3277 slap_loglevel_register( slap_mask_t m, struct berval *s )
3281 if ( loglevel_ops == NULL ) {
3285 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3288 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3296 slap_loglevel_get( struct berval *s, int *l )
3301 if ( loglevel_ops == NULL ) {
3305 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3306 m |= loglevel_ops[ i ].mask;
3309 for ( i = 1; m & i; i <<= 1 )
3316 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3319 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3330 str2loglevel( const char *s, int *l )
3334 if ( loglevel_ops == NULL ) {
3338 i = verb_to_mask( s, loglevel_ops );
3340 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3344 *l = loglevel_ops[ i ].mask;
3350 loglevel2str( int l )
3352 struct berval bv = BER_BVNULL;
3354 loglevel2bv( l, &bv );
3360 loglevel2bv( int l, struct berval *bv )
3362 if ( loglevel_ops == NULL ) {
3368 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3372 loglevel2bvarray( int l, BerVarray *bva )
3374 if ( loglevel_ops == NULL ) {
3378 return mask_to_verbs( loglevel_ops, l, bva );
3382 loglevel_print( FILE *out )
3386 if ( loglevel_ops == NULL ) {
3390 fprintf( out, "Installed log subsystems:\n\n" );
3391 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3392 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3394 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3395 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3396 loglevel_ops[ i ].word.bv_val, mask, mask );
3399 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3400 "by specific code\n\n" );
3405 static int config_syslog;
3408 config_loglevel(ConfigArgs *c) {
3411 if ( loglevel_ops == NULL ) {
3415 if (c->op == SLAP_CONFIG_EMIT) {
3416 /* Get default or commandline slapd setting */
3417 if ( ldap_syslog && !config_syslog )
3418 config_syslog = ldap_syslog;
3419 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3421 } else if ( c->op == LDAP_MOD_DELETE ) {
3425 int level = verb_to_mask( c->line, loglevel_ops );
3426 config_syslog ^= level;
3428 if ( slapMode & SLAP_SERVER_MODE ) {
3429 ldap_syslog = config_syslog;
3434 for( i=1; i < c->argc; i++ ) {
3437 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3438 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3439 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3440 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3441 c->log, c->cr_msg, c->argv[i]);
3445 if ( str2loglevel( c->argv[i], &level ) ) {
3446 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3447 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3448 c->log, c->cr_msg, c->argv[i]);
3452 /* Explicitly setting a zero clears all the levels */
3454 config_syslog |= level;
3458 if ( slapMode & SLAP_SERVER_MODE ) {
3459 ldap_syslog = config_syslog;
3465 config_referral(ConfigArgs *c) {
3467 if (c->op == SLAP_CONFIG_EMIT) {
3468 if ( default_referral ) {
3469 value_add( &c->rvalue_vals, default_referral );
3474 } else if ( c->op == LDAP_MOD_DELETE ) {
3475 if ( c->valx < 0 ) {
3476 ber_bvarray_free( default_referral );
3477 default_referral = NULL;
3480 ch_free( default_referral[i].bv_val );
3481 for (; default_referral[i].bv_val; i++ )
3482 default_referral[i] = default_referral[i+1];
3486 if(validate_global_referral(c->argv[1])) {
3487 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3488 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3489 c->log, c->cr_msg, c->argv[1]);
3493 ber_str2bv(c->argv[1], 0, 0, &val);
3494 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3502 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3503 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3504 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3505 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3506 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3507 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3508 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3509 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3510 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3515 config_security(ConfigArgs *c) {
3516 slap_ssf_set_t *set = &c->be->be_ssf_set;
3519 if (c->op == SLAP_CONFIG_EMIT) {
3525 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3526 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3529 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3530 if ( bv.bv_len >= sizeof( numbuf ) ) {
3531 ber_bvarray_free_x( c->rvalue_vals, NULL );
3532 c->rvalue_vals = NULL;
3536 bv.bv_len += sec_keys[i].key.bv_len;
3537 bv.bv_val = ch_malloc( bv.bv_len + 1);
3538 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3539 strcpy( next, numbuf );
3540 ber_bvarray_add( &c->rvalue_vals, &bv );
3545 for(i = 1; i < c->argc; i++) {
3546 slap_ssf_t *tgt = NULL;
3548 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3549 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3550 sec_keys[j].key.bv_len)) {
3551 src = c->argv[i] + sec_keys[j].key.bv_len;
3552 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3557 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3558 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3559 c->log, c->cr_msg, c->argv[i]);
3563 if ( lutil_atou( tgt, src ) != 0 ) {
3564 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3565 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3566 c->log, c->cr_msg, c->argv[i]);
3574 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3578 for (; !BER_BVISNULL( &an->an_name ); an++) {
3579 /* if buflen == 0, assume the buffer size has been
3580 * already checked otherwise */
3581 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3582 if ( comma ) *ptr++ = ',';
3583 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3590 config_updatedn(ConfigArgs *c) {
3591 if (c->op == SLAP_CONFIG_EMIT) {
3592 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3593 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3594 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3598 } else if ( c->op == LDAP_MOD_DELETE ) {
3599 ch_free( c->be->be_update_ndn.bv_val );
3600 BER_BVZERO( &c->be->be_update_ndn );
3601 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3604 if(SLAP_SHADOW(c->be)) {
3605 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3606 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3607 c->log, c->cr_msg, 0);
3611 ber_memfree_x( c->value_dn.bv_val, NULL );
3612 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3613 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3615 c->be->be_update_ndn = c->value_ndn;
3616 BER_BVZERO( &c->value_dn );
3617 BER_BVZERO( &c->value_ndn );
3619 return config_slurp_shadow( c );
3623 config_shadow( ConfigArgs *c, slap_mask_t flag )
3625 char *notallowed = NULL;
3627 if ( c->be == frontendDB ) {
3628 notallowed = "frontend";
3630 } else if ( SLAP_MONITOR(c->be) ) {
3631 notallowed = "monitor";
3634 if ( notallowed != NULL ) {
3635 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3639 if ( SLAP_SHADOW(c->be) ) {
3640 /* if already shadow, only check consistency */
3641 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3642 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3648 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3655 config_updateref(ConfigArgs *c) {
3657 if (c->op == SLAP_CONFIG_EMIT) {
3658 if ( c->be->be_update_refs ) {
3659 value_add( &c->rvalue_vals, c->be->be_update_refs );
3664 } else if ( c->op == LDAP_MOD_DELETE ) {
3665 if ( c->valx < 0 ) {
3666 ber_bvarray_free( c->be->be_update_refs );
3667 c->be->be_update_refs = NULL;
3670 ch_free( c->be->be_update_refs[i].bv_val );
3671 for (; c->be->be_update_refs[i].bv_val; i++)
3672 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3676 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3677 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3679 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3680 c->log, c->cr_msg, 0);
3684 if(validate_global_referral(c->argv[1])) {
3685 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3686 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3687 c->log, c->cr_msg, c->argv[1]);
3690 ber_str2bv(c->argv[1], 0, 0, &val);
3691 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3696 config_obsolete(ConfigArgs *c) {
3697 if (c->op == SLAP_CONFIG_EMIT)
3700 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3702 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3707 config_include(ConfigArgs *c) {
3708 int savelineno = c->lineno;
3711 ConfigFile *cfsave = cfn;
3712 ConfigFile *cf2 = NULL;
3714 /* Leftover from RE23. No dynamic config for include files */
3715 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3718 cf = ch_calloc( 1, sizeof(ConfigFile));
3719 if ( cfn->c_kids ) {
3720 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3726 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3727 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3728 c->lineno = savelineno - 1;
3731 if ( cf2 ) cf2->c_sibs = NULL;
3732 else cfn->c_kids = NULL;
3733 ch_free( cf->c_file.bv_val );
3743 config_tls_cleanup(ConfigArgs *c) {
3746 if ( slap_tls_ld ) {
3749 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3751 /* Force new ctx to be created */
3752 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3754 /* The ctx's refcount is bumped up here */
3755 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3756 /* This is a no-op if it's already loaded */
3757 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3764 config_tls_option(ConfigArgs *c) {
3766 LDAP *ld = slap_tls_ld;
3768 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3769 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3770 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3771 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3772 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3773 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3774 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3776 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3778 default: Debug(LDAP_DEBUG_ANY, "%s: "
3779 "unknown tls_option <0x%x>\n",
3780 c->log, c->type, 0);
3783 if (c->op == SLAP_CONFIG_EMIT) {
3784 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3785 } else if ( c->op == LDAP_MOD_DELETE ) {
3786 c->cleanup = config_tls_cleanup;
3787 return ldap_pvt_tls_set_option( ld, flag, NULL );
3789 ch_free(c->value_string);
3790 c->cleanup = config_tls_cleanup;
3791 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3794 /* FIXME: this ought to be provided by libldap */
3796 config_tls_config(ConfigArgs *c) {
3799 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3800 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3801 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3803 Debug(LDAP_DEBUG_ANY, "%s: "
3804 "unknown tls_option <0x%x>\n",
3805 c->log, c->type, 0);
3808 if (c->op == SLAP_CONFIG_EMIT) {
3809 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3810 } else if ( c->op == LDAP_MOD_DELETE ) {
3812 c->cleanup = config_tls_cleanup;
3813 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3815 ch_free( c->value_string );
3816 c->cleanup = config_tls_cleanup;
3817 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3818 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3819 Debug(LDAP_DEBUG_ANY, "%s: "
3820 "unable to parse %s \"%s\"\n",
3821 c->log, c->argv[0], c->argv[1] );
3824 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3826 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3831 static CfEntryInfo *
3832 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3842 if ( dn_match( &root->ce_entry->e_nname, dn ))
3845 c = dn->bv_val+dn->bv_len;
3846 for (;*c != ',';c--);
3850 for (--c;c>dn->bv_val && *c != ',';c--);
3854 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3856 root = root->ce_kids;
3858 for (;root;root=root->ce_sibs) {
3859 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3860 if ( cdn.bv_val == dn->bv_val ) {
3870 typedef struct setup_cookie {
3880 config_ldif_resp( Operation *op, SlapReply *rs )
3882 if ( rs->sr_type == REP_SEARCH ) {
3883 setup_cookie *sc = op->o_callback->sc_private;
3886 sc->cfb->cb_got_ldif = 1;
3887 /* Does the frontend exist? */
3888 if ( !sc->got_frontend ) {
3889 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3890 "olcDatabase", STRLENOF( "olcDatabase" )))
3892 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3893 STRLENOF( "olcDatabase" ), "={-1}frontend",
3894 STRLENOF( "={-1}frontend" )))
3898 sc->ca->be = frontendDB;
3899 sc->ca->bi = frontendDB->bd_info;
3900 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3901 rdn.bv_val = sc->ca->log;
3902 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3903 "%s=" SLAP_X_ORDERED_FMT "%s",
3904 cfAd_database->ad_cname.bv_val, -1,
3905 sc->ca->bi->bi_type);
3907 sc->frontend = config_build_entry( op, rs,
3908 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3909 sc->ca->be->be_cf_ocs );
3919 dnParent( &rs->sr_entry->e_nname, &pdn );
3921 /* Does the configDB exist? */
3922 if ( sc->got_frontend && !sc->got_config &&
3923 !strncmp( rs->sr_entry->e_nname.bv_val,
3924 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3925 dn_match( &config_rdn, &pdn ) )
3927 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3928 STRLENOF( "olcDatabase" ), "={0}config",
3929 STRLENOF( "={0}config" )))
3933 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3934 sc->ca->bi = sc->ca->be->bd_info;
3935 rdn.bv_val = sc->ca->log;
3936 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3937 "%s=" SLAP_X_ORDERED_FMT "%s",
3938 cfAd_database->ad_cname.bv_val, 0,
3939 sc->ca->bi->bi_type);
3941 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3942 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3949 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3950 if ( rs->sr_err != LDAP_SUCCESS ) {
3951 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3952 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3958 /* Configure and read the underlying back-ldif store */
3960 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3961 CfBackInfo *cfb = be->be_private;
3967 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3968 Connection conn = {0};
3969 OperationBuffer opbuf;
3971 SlapReply rs = {REP_RESULT};
3972 Filter filter = { LDAP_FILTER_PRESENT };
3973 struct berval filterstr = BER_BVC("(objectclass=*)");
3976 /* Is the config directory available? */
3977 if ( stat( dir, &st ) < 0 ) {
3978 /* No, so don't bother using the backing store.
3979 * All changes will be in-memory only.
3984 cfb->cb_db.bd_info = backend_info( "ldif" );
3985 if ( !cfb->cb_db.bd_info )
3986 return 0; /* FIXME: eventually this will be a fatal error */
3988 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3991 cfb->cb_db.be_suffix = be->be_suffix;
3992 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3994 /* The suffix is always "cn=config". The underlying DB's rootdn
3995 * is always the same as the suffix.
3997 cfb->cb_db.be_rootdn = be->be_suffix[0];
3998 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4000 ber_str2bv( dir, 0, 1, &cfdir );
4005 argv[0] = "directory";
4006 argv[1] = (char *)dir;
4011 c.table = Cft_Database;
4013 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4017 if ( config_add_vals( ct, &c ))
4020 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4024 void *thrctx = ldap_pvt_thread_pool_context();
4027 connection_fake_init( &conn, &opbuf, thrctx );
4030 filter.f_desc = slap_schema.si_ad_objectClass;
4032 op->o_tag = LDAP_REQ_SEARCH;
4034 op->ors_filter = &filter;
4035 op->ors_filterstr = filterstr;
4036 op->ors_scope = LDAP_SCOPE_SUBTREE;
4038 op->o_dn = c.be->be_rootdn;
4039 op->o_ndn = c.be->be_rootndn;
4041 op->o_req_dn = be->be_suffix[0];
4042 op->o_req_ndn = be->be_nsuffix[0];
4044 op->ors_tlimit = SLAP_NO_LIMIT;
4045 op->ors_slimit = SLAP_NO_LIMIT;
4047 op->ors_attrs = slap_anlist_all_attributes;
4048 op->ors_attrsonly = 0;
4050 op->o_callback = &cb;
4053 cb.sc_private = ≻
4054 sc.got_frontend = 0;
4059 op->o_bd = &cfb->cb_db;
4061 /* Allow unknown attrs in DNs */
4062 prev_DN_strict = slap_DN_strict;
4065 rc = op->o_bd->be_search( op, &rs );
4067 /* Restore normal DN validation */
4068 slap_DN_strict = prev_DN_strict;
4070 op->o_tag = LDAP_REQ_ADD;
4071 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4072 rs_reinit( &rs, REP_RESULT );
4073 op->ora_e = sc.frontend;
4074 rc = op->o_bd->be_add( op, &rs );
4076 if ( rc == LDAP_SUCCESS && sc.config ) {
4077 rs_reinit( &rs, REP_RESULT );
4078 op->ora_e = sc.config;
4079 rc = op->o_bd->be_add( op, &rs );
4081 ldap_pvt_thread_pool_context_reset( thrctx );
4084 /* ITS#4194 - only use if it's present, or we're converting. */
4085 if ( !readit || rc == LDAP_SUCCESS )
4086 cfb->cb_use_ldif = 1;
4092 CfOc_cmp( const void *c1, const void *c2 ) {
4093 const ConfigOCs *co1 = c1;
4094 const ConfigOCs *co2 = c2;
4096 return ber_bvcmp( co1->co_name, co2->co_name );
4100 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4103 i = init_config_attrs( ct );
4106 /* set up the objectclasses */
4107 i = init_config_ocs( ocs );
4110 for (i=0; ocs[i].co_def; i++) {
4111 if ( ocs[i].co_oc ) {
4112 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4113 if ( !ocs[i].co_table )
4114 ocs[i].co_table = ct;
4115 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4122 read_config(const char *fname, const char *dir) {
4125 const char *cfdir, *cfname;
4128 /* Setup the config backend */
4129 be = backend_db_init( "config", NULL, 0, NULL );
4133 cfb = be->be_private;
4134 be->be_dfltaccess = ACL_NONE;
4136 /* If no .conf, or a dir was specified, setup the dir */
4137 if ( !fname || dir ) {
4139 /* If explicitly given, check for existence */
4142 if ( stat( dir, &st ) < 0 ) {
4143 Debug( LDAP_DEBUG_ANY,
4144 "invalid config directory %s, error %d\n",
4150 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4152 /* if fname is defaulted, try reading .d */
4153 rc = config_setup_ldif( be, cfdir, !fname );
4156 /* It may be OK if the base object doesn't exist yet. */
4157 if ( rc != LDAP_NO_SUCH_OBJECT )
4159 /* ITS#4194: But if dir was specified and no fname,
4160 * then we were supposed to read the dir. Unless we're
4161 * trying to slapadd the dir...
4163 if ( dir && !fname ) {
4164 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4166 /* Assume it's slapadd with a config dir, let it continue */
4168 cfb->cb_got_ldif = 1;
4169 cfb->cb_use_ldif = 1;
4174 /* If we read the config from back-ldif, nothing to do here */
4175 if ( cfb->cb_got_ldif ) {
4184 cfname = SLAPD_DEFAULT_CONFIGFILE;
4186 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4189 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4192 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4193 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4194 &frontendDB->be_schemadn );
4195 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4196 if ( rc != LDAP_SUCCESS ) {
4197 Debug(LDAP_DEBUG_ANY, "read_config: "
4198 "unable to normalize default schema DN \"%s\"\n",
4199 frontendDB->be_schemadn.bv_val, 0, 0 );
4200 /* must not happen */
4208 config_back_bind( Operation *op, SlapReply *rs )
4210 if ( be_isroot_pw( op ) ) {
4211 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4212 /* frontend sends result */
4213 return LDAP_SUCCESS;
4216 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4217 send_ldap_result( op, rs );
4223 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4227 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4229 rs->sr_attrs = op->ors_attrs;
4230 rs->sr_entry = ce->ce_entry;
4232 rc = send_search_entry( op, rs );
4233 if ( rc != LDAP_SUCCESS ) {
4237 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4238 if ( ce->ce_kids ) {
4239 rc = config_send( op, rs, ce->ce_kids, 1 );
4240 if ( rc ) return rc;
4243 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4244 rc = config_send( op, rs, ce, 0 );
4252 static ConfigTable *
4253 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4258 for (j=0; j<nocs; j++) {
4259 for (i=0; colst[j]->co_table[i].name; i++)
4260 if ( colst[j]->co_table[i].ad == ad ) {
4261 ca->table = colst[j]->co_type;
4262 return &colst[j]->co_table[i];
4268 /* Sort the attributes of the entry according to the order defined
4269 * in the objectclass, with required attributes occurring before
4270 * allowed attributes. For any attributes with sequencing dependencies
4271 * (e.g., rootDN must be defined after suffix) the objectclass must
4272 * list the attributes in the desired sequence.
4275 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4277 Attribute *a, *head = NULL, *tail = NULL, **prev;
4280 for (i=0; i<nocs; i++) {
4281 if ( colst[i]->co_oc->soc_required ) {
4282 AttributeType **at = colst[i]->co_oc->soc_required;
4283 for (j=0; at[j]; j++) {
4284 for (a=e->e_attrs, prev=&e->e_attrs; a;
4285 prev = &(*prev)->a_next, a=a->a_next) {
4286 if ( a->a_desc == at[j]->sat_ad ) {
4300 if ( colst[i]->co_oc->soc_allowed ) {
4301 AttributeType **at = colst[i]->co_oc->soc_allowed;
4302 for (j=0; at[j]; j++) {
4303 for (a=e->e_attrs, prev=&e->e_attrs; a;
4304 prev = &(*prev)->a_next, a=a->a_next) {
4305 if ( a->a_desc == at[j]->sat_ad ) {
4321 tail->a_next = e->e_attrs;
4327 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4329 Attribute *a = NULL;
4330 AttributeDescription *ad;
4340 Modifications *ml = ptr;
4342 vals = ml->sml_values;
4345 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4346 rc = ordered_value_sort( a, 1 );
4348 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4349 ad->ad_cname.bv_val );
4353 for ( i=0; vals[i].bv_val; i++ ) {
4354 ca->line = vals[i].bv_val;
4355 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4356 ca->line[0] == '{' ) {
4357 char *idx = strchr( ca->line, '}' );
4358 if ( idx ) ca->line = idx+1;
4360 rc = config_parse_vals( ct, ca, i );
4369 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4372 struct berval rtype, rval;
4374 AttributeDescription *ad = NULL;
4376 dnRdn( &e->e_name, rdn );
4377 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4378 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4379 rtype.bv_val = rdn->bv_val;
4380 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4383 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4384 a = attr_find( e->e_attrs, ad );
4385 if (!a ) return LDAP_NAMING_VIOLATION;
4392 config_rename_kids( CfEntryInfo *ce )
4395 struct berval rdn, nrdn;
4397 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4398 struct berval newdn, newndn;
4399 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4400 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4401 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4402 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4403 free( ce2->ce_entry->e_name.bv_val );
4404 free( ce2->ce_entry->e_nname.bv_val );
4405 ce2->ce_entry->e_name = newdn;
4406 ce2->ce_entry->e_nname = newndn;
4407 config_rename_kids( ce2 );
4412 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4413 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4414 struct berval *nnewrdn, int use_ldif )
4418 struct berval odn, ondn;
4422 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4423 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4426 free( a->a_vals[0].bv_val );
4427 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4428 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4429 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4430 strcpy( a->a_vals[0].bv_val, ptr1 );
4432 if ( a->a_nvals != a->a_vals ) {
4433 free( a->a_nvals[0].bv_val );
4434 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4435 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4436 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4437 strcpy( a->a_nvals[0].bv_val, ptr1 );
4440 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4441 BackendDB *be = op->o_bd;
4442 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4443 struct berval dn, ndn, xdn, xndn;
4445 op->o_bd = &cfb->cb_db;
4447 /* Save current rootdn; use the underlying DB's rootdn */
4451 xndn = op->o_req_ndn;
4452 op->o_dn = op->o_bd->be_rootdn;
4453 op->o_ndn = op->o_bd->be_rootndn;
4455 op->o_req_ndn = ondn;
4457 scp = op->o_callback;
4458 op->o_callback = ≻
4459 op->orr_newrdn = *newrdn;
4460 op->orr_nnewrdn = *nnewrdn;
4461 op->orr_newSup = NULL;
4462 op->orr_nnewSup = NULL;
4463 op->orr_deleteoldrdn = 1;
4464 op->orr_modlist = NULL;
4465 slap_modrdn2mods( op, rs );
4466 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4467 rc = op->o_bd->be_modrdn( op, rs );
4468 slap_mods_free( op->orr_modlist, 1 );
4471 op->o_callback = scp;
4475 op->o_req_ndn = xndn;
4478 free( ondn.bv_val );
4480 config_rename_kids( e->e_private );
4485 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4486 Entry *e, int idx, int tailindex, int use_ldif )
4488 struct berval ival, newrdn, nnewrdn;
4491 char ibuf[32], *ptr1, *ptr2 = NULL;
4494 rc = config_rename_attr( rs, e, &rdn, &a );
4495 if ( rc ) return rc;
4498 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4499 if ( ival.bv_len >= sizeof( ibuf ) ) {
4500 return LDAP_NAMING_VIOLATION;
4503 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4504 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4507 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4508 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4511 ptr2 = ber_bvchr( &rdn, '}' );
4515 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4517 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4518 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4519 a->a_desc->ad_cname.bv_len );
4521 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4522 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4526 /* Do the equivalent of ModRDN */
4527 /* Replace DN / NDN */
4528 newrdn.bv_len = ptr1 - newrdn.bv_val;
4529 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4530 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4532 free( nnewrdn.bv_val );
4533 free( newrdn.bv_val );
4538 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4539 SlapReply *rs, int *renum, int *ibase )
4542 int index = -1, gotindex = 0, nsibs, rc = 0;
4543 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4544 char *ptr1, *ptr2 = NULL;
4547 if ( renum ) *renum = 0;
4549 /* These entries don't get indexed/renumbered */
4550 if ( ce_type == Cft_Global ) return 0;
4551 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4553 if ( ce_type == Cft_Module )
4556 /* See if the rdn has an index already */
4557 dnRdn( &e->e_name, &rdn );
4558 if ( ce_type == Cft_Database ) {
4559 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4560 "frontend", STRLENOF("frontend") ))
4562 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4563 "config", STRLENOF("config") ))
4566 ptr1 = ber_bvchr( &e->e_name, '{' );
4567 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4569 ptr2 = strchr( ptr1, '}' );
4570 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4571 return LDAP_NAMING_VIOLATION;
4572 if ( ptr2-ptr1 == 1)
4573 return LDAP_NAMING_VIOLATION;
4575 index = strtol( ptr1 + 1, &next, 10 );
4576 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4577 return LDAP_NAMING_VIOLATION;
4580 /* Special case, we allow -1 for the frontendDB */
4581 if ( index != -1 || !isfrontend )
4582 return LDAP_NAMING_VIOLATION;
4584 if ( isconfig && index != 0 ){
4585 return LDAP_NAMING_VIOLATION;
4589 /* count related kids */
4590 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4591 if ( ce->ce_type == ce_type ) nsibs++;
4594 /* account for -1 frontend */
4595 if ( ce_type == Cft_Database )
4598 if ( index != nsibs ) {
4600 if ( index < nsibs ) {
4601 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4602 /* Siblings need to be renumbered */
4603 if ( index != -1 || !isfrontend )
4607 /* config DB is always "0" */
4608 if ( isconfig && index == -1 ) {
4611 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4615 /* just make index = nsibs */
4617 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4620 if ( ibase ) *ibase = index;
4621 if ( renum ) *renum = renumber;
4625 /* Insert all superior classes of the given class */
4627 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4632 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4633 if ( count_oc( *sups, copp, nocs ) ) {
4638 co.co_name = &oc->soc_cname;
4639 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4643 /* check for duplicates */
4644 for ( i = 0; i < *nocs; i++ ) {
4645 if ( *copp && (*copp)[i] == cop ) {
4651 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4652 if ( tmp == NULL ) {
4656 (*copp)[*nocs] = cop;
4664 /* Find all superior classes of the given objectclasses,
4665 * return list in order of most-subordinate first.
4667 * Special / auxiliary / Cft_Misc classes always take precedence.
4670 count_ocs( Attribute *oc_at, int *nocs )
4672 int i, j, misc = -1;
4673 ConfigOCs **colst = NULL;
4677 for ( i = oc_at->a_numvals; i--; ) {
4678 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4680 assert( oc != NULL );
4681 if ( count_oc( oc, &colst, nocs ) ) {
4691 ConfigOCs *tmp = colst[i];
4692 colst[i] = colst[j];
4694 if (tmp->co_type == Cft_Misc)
4698 /* Move misc class to front of list */
4700 ConfigOCs *tmp = colst[misc];
4701 for (i=misc; i>0; i--)
4702 colst[i] = colst[i-1];
4710 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4712 /* Leftover from RE23. Never parse this entry */
4713 return LDAP_COMPARE_TRUE;
4717 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4721 /* This entry is hardcoded, don't re-parse it */
4722 if ( p->ce_type == Cft_Global ) {
4723 cfn = p->ce_private;
4724 ca->ca_private = cfn;
4725 return LDAP_COMPARE_TRUE;
4727 if ( p->ce_type != Cft_Schema )
4728 return LDAP_CONSTRAINT_VIOLATION;
4730 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4731 ca->ca_private = cfn;
4732 cfo = p->ce_private;
4733 cfn->c_sibs = cfo->c_kids;
4735 return LDAP_SUCCESS;
4739 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4741 if ( p->ce_type != Cft_Global ) {
4742 return LDAP_CONSTRAINT_VIOLATION;
4744 /* config must be {0}, nothing else allowed */
4745 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4746 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4747 return LDAP_CONSTRAINT_VIOLATION;
4749 ca->be = frontendDB; /* just to get past check_vals */
4750 return LDAP_SUCCESS;
4754 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4756 if ( p->ce_type != Cft_Global ) {
4757 return LDAP_CONSTRAINT_VIOLATION;
4759 return LDAP_SUCCESS;
4763 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4765 if ( p->ce_type != Cft_Global ) {
4766 return LDAP_CONSTRAINT_VIOLATION;
4768 return LDAP_SUCCESS;
4772 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4774 if ( p->ce_type != Cft_Database ) {
4775 return LDAP_CONSTRAINT_VIOLATION;
4778 return LDAP_SUCCESS;
4782 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4787 AttributeDescription *ad;
4793 if ( cfn->c_cr_head ) {
4794 struct berval bv = BER_BVC("olcDitContentRules");
4796 slap_bv2ad( &bv, &ad, &text );
4797 ct = config_find_table( colst, nocs, ad, ca );
4798 config_del_vals( ct, ca );
4800 if ( cfn->c_oc_head ) {
4801 struct berval bv = BER_BVC("olcObjectClasses");
4803 slap_bv2ad( &bv, &ad, &text );
4804 ct = config_find_table( colst, nocs, ad, ca );
4805 config_del_vals( ct, ca );
4807 if ( cfn->c_at_head ) {
4808 struct berval bv = BER_BVC("olcAttributeTypes");
4810 slap_bv2ad( &bv, &ad, &text );
4811 ct = config_find_table( colst, nocs, ad, ca );
4812 config_del_vals( ct, ca );
4814 if ( cfn->c_syn_head ) {
4815 struct berval bv = BER_BVC("olcLdapSyntaxes");
4817 slap_bv2ad( &bv, &ad, &text );
4818 ct = config_find_table( colst, nocs, ad, ca );
4819 config_del_vals( ct, ca );
4821 if ( cfn->c_om_head ) {
4822 struct berval bv = BER_BVC("olcObjectIdentifier");
4824 slap_bv2ad( &bv, &ad, &text );
4825 ct = config_find_table( colst, nocs, ad, ca );
4826 config_del_vals( ct, ca );
4828 cfo = p->ce_private;
4829 cfo->c_kids = cfn->c_sibs;
4834 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4836 int rc = LDAP_CONSTRAINT_VIOLATION;
4839 if ( (*cop)->co_ldadd ) {
4840 rc = (*cop)->co_ldadd( last, e, ca );
4841 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4846 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4847 ConfigOCs co = { 0 };
4849 co.co_name = &(*ocp)->soc_cname;
4850 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4851 if ( *cop == NULL ) {
4855 rc = config_add_oc( cop, last, e, ca );
4856 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4864 /* Parse an LDAP entry into config directives */
4866 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4867 int *renum, Operation *op )
4869 CfEntryInfo *ce, *last = NULL;
4870 ConfigOCs co, *coptr, **colst;
4871 Attribute *a, *oc_at, *soc_at;
4872 int i, ibase = -1, nocs, rc = 0;
4875 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4877 memset( ca, 0, sizeof(ConfigArgs));
4879 /* Make sure parent exists and entry does not. But allow
4880 * Databases and Overlays to be inserted. Don't do any
4881 * auto-renumbering if manageDSAit control is present.
4883 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4885 if ( ( op && op->o_managedsait ) ||
4886 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4887 ce->ce_type != Cft_Module ) )
4889 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4890 "DN=\"%s\" already exists\n",
4891 log_prefix, e->e_name.bv_val, 0 );
4892 /* global schema ignores all writes */
4893 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4894 return LDAP_COMPARE_TRUE;
4895 return LDAP_ALREADY_EXISTS;
4899 dnParent( &e->e_nname, &pdn );
4901 /* If last is NULL, the new entry is the root/suffix entry,
4902 * otherwise last should be the parent.
4904 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4906 rs->sr_matched = last->ce_entry->e_name.bv_val;
4908 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4909 "DN=\"%s\" not child of DN=\"%s\"\n",
4910 log_prefix, e->e_name.bv_val,
4911 last->ce_entry->e_name.bv_val );
4912 return LDAP_NO_SUCH_OBJECT;
4916 /* No parent, must be root. This will never happen... */
4917 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4918 return LDAP_NO_SUCH_OBJECT;
4921 if ( last && !access_allowed( op, last->ce_entry,
4922 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4924 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4925 "DN=\"%s\" no write access to \"children\" of parent\n",
4926 log_prefix, e->e_name.bv_val, 0 );
4927 return LDAP_INSUFFICIENT_ACCESS;
4931 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4933 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4934 "DN=\"%s\" no objectClass\n",
4935 log_prefix, e->e_name.bv_val, 0 );
4936 return LDAP_OBJECT_CLASS_VIOLATION;
4939 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4941 ObjectClass *soc = NULL;
4942 char textbuf[ SLAP_TEXT_BUFLEN ];
4943 const char *text = textbuf;
4945 /* FIXME: check result */
4946 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4947 &text, textbuf, sizeof(textbuf), NULL );
4948 if ( rc != LDAP_SUCCESS ) {
4949 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4950 "DN=\"%s\" no structural objectClass (%s)\n",
4951 log_prefix, e->e_name.bv_val, text );
4954 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4955 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4956 if ( soc_at == NULL ) {
4957 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4958 "DN=\"%s\" no structural objectClass; "
4959 "unable to merge computed class %s\n",
4960 log_prefix, e->e_name.bv_val,
4961 soc->soc_cname.bv_val );
4962 return LDAP_OBJECT_CLASS_VIOLATION;
4965 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4966 "DN=\"%s\" no structural objectClass; "
4967 "computed objectClass %s merged\n",
4968 log_prefix, e->e_name.bv_val,
4969 soc->soc_cname.bv_val );
4972 /* Fake the coordinates based on whether we're part of an
4973 * LDAP Add or if reading the config dir
4976 ca->fname = "slapd";
4979 ca->fname = cfdir.bv_val;
4984 co.co_name = &soc_at->a_nvals[0];
4985 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4986 if ( coptr == NULL ) {
4987 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4988 "DN=\"%s\" no structural objectClass in configuration table\n",
4989 log_prefix, e->e_name.bv_val, 0 );
4990 return LDAP_OBJECT_CLASS_VIOLATION;
4993 /* Only the root can be Cft_Global, everything else must
4994 * have a parent. Only limited nesting arrangements are allowed.
4996 rc = LDAP_CONSTRAINT_VIOLATION;
4997 if ( coptr->co_type == Cft_Global && !last ) {
4998 cfn = cfb->cb_config;
4999 ca->ca_private = cfn;
5000 ca->be = frontendDB; /* just to get past check_vals */
5004 colst = count_ocs( oc_at, &nocs );
5006 /* Check whether the Add is allowed by its parent, and do
5007 * any necessary arg setup
5010 rc = config_add_oc( &coptr, last, e, ca );
5011 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5012 for ( i = 0; i<nocs; i++ ) {
5013 /* Already checked these */
5014 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5016 if ( colst[i]->co_ldadd &&
5017 ( rc = colst[i]->co_ldadd( last, e, ca ))
5018 != LDAP_CONSTRAINT_VIOLATION ) {
5024 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5025 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5026 "DN=\"%s\" no structural objectClass add function\n",
5027 log_prefix, e->e_name.bv_val, 0 );
5028 return LDAP_OBJECT_CLASS_VIOLATION;
5032 /* Add the entry but don't parse it, we already have its contents */
5033 if ( rc == LDAP_COMPARE_TRUE ) {
5038 if ( rc != LDAP_SUCCESS )
5041 /* Parse all the values and check for simple syntax errors before
5042 * performing any set actions.
5044 * If doing an LDAPadd, check for indexed names and any necessary
5045 * renaming/renumbering. Entries that don't need indexed names are
5046 * ignored. Entries that need an indexed name and arrive without one
5047 * are assigned to the end. Entries that arrive with an index may
5048 * cause the following entries to be renumbered/bumped down.
5050 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5051 * don't allow Adding an entry with an index that's already in use.
5052 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5054 * These entries can have auto-assigned indexes (appended to the end)
5055 * but only the other types support auto-renumbering of siblings.
5058 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5063 if ( renum && *renum && coptr->co_type != Cft_Database &&
5064 coptr->co_type != Cft_Overlay )
5066 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5067 "operation requires sibling renumbering" );
5068 rc = LDAP_UNWILLING_TO_PERFORM;
5073 init_config_argv( ca );
5075 /* Make sure we process attrs in the required order */
5076 sort_attrs( e, colst, nocs );
5078 for ( a = e->e_attrs; a; a = a->a_next ) {
5079 if ( a == oc_at ) continue;
5080 ct = config_find_table( colst, nocs, a->a_desc, ca );
5081 if ( !ct ) continue; /* user data? */
5082 rc = check_vals( ct, ca, a, 1 );
5083 if ( rc ) goto done_noop;
5086 /* Basic syntax checks are OK. Do the actual settings. */
5087 for ( a=e->e_attrs; a; a=a->a_next ) {
5088 if ( a == oc_at ) continue;
5089 ct = config_find_table( colst, nocs, a->a_desc, ca );
5090 if ( !ct ) continue; /* user data? */
5091 for (i=0; a->a_vals[i].bv_val; i++) {
5094 ca->line = a->a_vals[i].bv_val;
5095 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5096 ptr = strchr( ca->line, '}' );
5098 iptr = strchr( ca->line, '{' );
5102 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5104 ca->valx = strtol( iptr+1, NULL, 0 );
5109 rc = config_parse_add( ct, ca, i );
5117 /* Newly added databases and overlays need to be started up */
5118 if ( CONFIG_ONLINE_ADD( ca )) {
5119 if ( coptr->co_type == Cft_Database ) {
5120 rc = backend_startup_one( ca->be, &ca->reply );
5122 } else if ( coptr->co_type == Cft_Overlay ) {
5123 if ( ca->bi->bi_db_open ) {
5124 BackendInfo *bi_orig = ca->be->bd_info;
5125 ca->be->bd_info = ca->bi;
5126 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5127 ca->be->bd_info = bi_orig;
5129 } else if ( ca->cleanup ) {
5130 rc = ca->cleanup( ca );
5133 if (ca->cr_msg[0] == '\0')
5134 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5136 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5137 ca->log, ca->cr_msg, ca->argv[1] );
5144 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5145 ce->ce_parent = last;
5146 ce->ce_entry = entry_dup( e );
5147 ce->ce_entry->e_private = ce;
5148 ce->ce_type = coptr->co_type;
5151 ce->ce_private = ca->ca_private;
5152 ca->ca_entry = ce->ce_entry;
5155 } else if ( last->ce_kids ) {
5156 CfEntryInfo *c2, **cprev;
5158 /* Advance to first of this type */
5159 cprev = &last->ce_kids;
5160 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5161 cprev = &c2->ce_sibs;
5164 /* Account for the (-1) frontendDB entry */
5165 if ( ce->ce_type == Cft_Database ) {
5166 if ( ca->be == frontendDB )
5168 else if ( ibase != -1 )
5173 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5174 cprev = &c2->ce_sibs;
5180 for ( i=0; i<ibase; i++ ) {
5182 cprev = &c2->ce_sibs;
5185 ce->ce_sibs = *cprev;
5193 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5194 if ( ca->be != frontendDB )
5195 backend_destroy_one( ca->be, 1 );
5196 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5197 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5198 } else if ( coptr->co_type == Cft_Schema ) {
5199 schema_destroy_one( ca, colst, nocs, last );
5204 ch_free( ca->argv );
5205 if ( colst ) ch_free( colst );
5209 #define BIGTMP 10000
5211 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5212 int base, int rebase, int max, int use_ldif )
5214 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5215 ConfigType etype = ce->ce_type;
5216 int count = 0, rc = 0;
5218 /* Reverse ce list */
5219 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5220 if (ce2->ce_type != etype) {
5225 ce2->ce_sibs = cetmp;
5228 if ( max && count >= max ) {
5234 /* Move original to a temp name until increments are done */
5236 ce->ce_entry->e_private = NULL;
5237 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5238 base+BIGTMP, 0, use_ldif );
5239 ce->ce_entry->e_private = ce;
5241 /* start incrementing */
5242 for (ce2=cetmp; ce2; ce2=ce3) {
5244 ce2->ce_sibs = cerem;
5247 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5248 count+base, 0, use_ldif );
5252 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5253 base, 0, use_ldif );
5258 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5259 CfEntryInfo *ce2, int old, int use_ldif )
5263 /* Renumber original to a temp value */
5264 ce->ce_entry->e_private = NULL;
5265 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5266 old+BIGTMP, 0, use_ldif );
5267 ce->ce_entry->e_private = ce;
5269 /* start decrementing */
5270 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5271 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5272 count+old, 0, use_ldif );
5275 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5276 count+old, 0, use_ldif );
5279 /* Parse an LDAP entry into config directives, then store in underlying
5283 config_back_add( Operation *op, SlapReply *rs )
5289 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5290 NULL, ACL_WADD, NULL )) {
5291 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5296 * Check for attribute ACL
5298 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5299 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5300 rs->sr_text = "no write access to attribute";
5304 cfb = (CfBackInfo *)op->o_bd->be_private;
5306 /* add opattrs for syncprov */
5308 char textbuf[SLAP_TEXT_BUFLEN];
5309 size_t textlen = sizeof textbuf;
5310 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5311 &rs->sr_text, textbuf, sizeof( textbuf ) );
5312 if ( rs->sr_err != LDAP_SUCCESS )
5314 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5315 if ( rs->sr_err != LDAP_SUCCESS ) {
5316 Debug( LDAP_DEBUG_TRACE,
5317 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5318 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5323 if ( op->o_abandon ) {
5324 rs->sr_err = SLAPD_ABANDON;
5327 ldap_pvt_thread_pool_pause( &connection_pool );
5330 * 1) check for existence of entry
5331 * 2) check for sibling renumbering
5332 * 3) perform internal add
5333 * 4) perform any necessary renumbering
5334 * 5) store entry in underlying database
5336 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5337 if ( rs->sr_err != LDAP_SUCCESS ) {
5338 rs->sr_text = ca.cr_msg;
5343 CfEntryInfo *ce = ca.ca_entry->e_private;
5344 req_add_s addr = op->oq_add;
5345 op->o_tag = LDAP_REQ_MODRDN;
5346 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5347 op->o_tag = LDAP_REQ_ADD;
5349 if ( rs->sr_err != LDAP_SUCCESS ) {
5354 if ( cfb->cb_use_ldif ) {
5355 BackendDB *be = op->o_bd;
5356 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5357 struct berval dn, ndn;
5359 op->o_bd = &cfb->cb_db;
5361 /* Save current rootdn; use the underlying DB's rootdn */
5364 op->o_dn = op->o_bd->be_rootdn;
5365 op->o_ndn = op->o_bd->be_rootndn;
5367 scp = op->o_callback;
5368 op->o_callback = ≻
5369 op->o_bd->be_add( op, rs );
5371 op->o_callback = scp;
5377 ldap_pvt_thread_pool_resume( &connection_pool );
5380 { int repl = op->o_dont_replicate;
5381 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5382 rs->sr_text = NULL; /* Set after config_add_internal */
5383 rs->sr_err = LDAP_SUCCESS;
5384 op->o_dont_replicate = 1;
5386 send_ldap_result( op, rs );
5387 op->o_dont_replicate = repl;
5389 slap_graduate_commit_csn( op );
5393 typedef struct delrec {
5394 struct delrec *next;
5400 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5406 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5407 ca->line[0] == '{' )
5409 char *ptr = strchr( ca->line + 1, '}' );
5413 ca->valx = strtol( ca->line + 1, &next, 0 );
5414 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5420 rc = config_parse_add( ct, ca, i );
5428 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5431 int rc = LDAP_UNWILLING_TO_PERFORM;
5433 Entry *e = ce->ce_entry;
5434 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5439 delrec *dels = NULL, *deltail = NULL;
5441 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5442 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5444 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5445 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5449 colst = count_ocs( oc_at, &nocs );
5451 /* make sure add/del flags are clear; should always be true */
5452 for ( s = save_attrs; s; s = s->a_next ) {
5453 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5456 e->e_attrs = attrs_dup( e->e_attrs );
5458 init_config_argv( ca );
5461 ca->ca_private = ce->ce_private;
5463 ca->fname = "slapd";
5465 strcpy( ca->log, "back-config" );
5467 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5468 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5469 switch (ml->sml_op) {
5470 case LDAP_MOD_DELETE:
5471 case LDAP_MOD_REPLACE:
5472 case SLAP_MOD_SOFTDEL:
5474 BerVarray vals = NULL, nvals = NULL;
5476 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5478 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5479 ml->sml_desc->ad_cname.bv_val );
5482 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5483 vals = ml->sml_values;
5484 nvals = ml->sml_nvalues;
5485 ml->sml_values = NULL;
5486 ml->sml_nvalues = NULL;
5488 /* If we're deleting by values, remember the indexes of the
5489 * values we deleted.
5491 if ( ct && ml->sml_values ) {
5493 i = ml->sml_numvals;
5494 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5505 rc = modify_delete_vindex(e, &ml->sml_mod,
5506 get_permissiveModify(op),
5507 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5508 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5509 ml->sml_values = vals;
5510 ml->sml_nvalues = nvals;
5512 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5516 /* FIXME: check rc before fallthru? */
5520 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5522 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5523 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5524 && attr_find( e->e_attrs, ml->sml_desc ) )
5531 case SLAP_MOD_SOFTADD: {
5532 int mop = ml->sml_op;
5534 ml->sml_op = LDAP_MOD_ADD;
5536 if ( ct->arg_type & ARG_NO_INSERT ) {
5537 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5539 navals = a->a_numvals;
5542 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5543 if ( ml->sml_values[i].bv_val[0] == '{' &&
5546 char *next, *val = ml->sml_values[i].bv_val + 1;
5549 j = strtol( val, &next, 0 );
5550 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5552 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5553 ml->sml_desc->ad_cname.bv_val );
5557 rc = check_vals( ct, ca, ml, 0 );
5558 if ( rc ) goto out_noop;
5561 rc = modify_add_values(e, &ml->sml_mod,
5562 get_permissiveModify(op),
5563 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5565 /* If value already exists, show success here
5566 * and ignore this operation down below.
5568 if ( mop == SLAP_MOD_SOFTADD ) {
5569 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5579 case LDAP_MOD_INCREMENT: /* FIXME */
5584 if(rc != LDAP_SUCCESS) break;
5587 if ( rc == LDAP_SUCCESS) {
5588 /* check that the entry still obeys the schema */
5589 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5590 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5592 if ( rc ) goto out_noop;
5594 /* Basic syntax checks are OK. Do the actual settings. */
5595 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5596 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5597 if ( !ct ) continue;
5599 s = attr_find( save_attrs, ml->sml_desc );
5600 a = attr_find( e->e_attrs, ml->sml_desc );
5602 switch (ml->sml_op) {
5603 case LDAP_MOD_DELETE:
5604 case LDAP_MOD_REPLACE: {
5605 BerVarray vals = NULL, nvals = NULL;
5608 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5609 vals = ml->sml_values;
5610 nvals = ml->sml_nvalues;
5611 ml->sml_values = NULL;
5612 ml->sml_nvalues = NULL;
5615 if ( ml->sml_values )
5618 /* If we didn't delete the whole attribute */
5619 if ( ml->sml_values && a ) {
5620 struct berval *mvals;
5623 if ( ml->sml_nvalues )
5624 mvals = ml->sml_nvalues;
5626 mvals = ml->sml_values;
5628 /* use the indexes we saved up above */
5629 for (i=0; i < d->nidx; i++) {
5630 struct berval bv = *mvals++;
5631 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5632 bv.bv_val[0] == '{' ) {
5633 ptr = strchr( bv.bv_val, '}' ) + 1;
5634 bv.bv_len -= ptr - bv.bv_val;
5637 ca->line = bv.bv_val;
5638 ca->valx = d->idx[i];
5639 config_parse_vals(ct, ca, d->idx[i] );
5640 rc = config_del_vals( ct, ca );
5641 if ( rc != LDAP_SUCCESS ) break;
5643 s->a_flags |= SLAP_ATTR_IXDEL;
5644 for (j=i+1; j < d->nidx; j++)
5645 if ( d->idx[j] >d->idx[i] )
5652 rc = config_del_vals( ct, ca );
5653 if ( rc ) rc = LDAP_OTHER;
5655 s->a_flags |= SLAP_ATTR_IXDEL;
5657 if ( ml->sml_values ) {
5662 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5663 ml->sml_values = vals;
5664 ml->sml_nvalues = nvals;
5666 if ( !vals || rc != LDAP_SUCCESS )
5669 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5672 for (i=0; ml->sml_values[i].bv_val; i++) {
5673 ca->line = ml->sml_values[i].bv_val;
5675 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5678 a->a_flags |= SLAP_ATTR_IXADD;
5685 /* Undo for a failed operation */
5686 if ( rc != LDAP_SUCCESS ) {
5687 ConfigReply msg = ca->reply;
5688 for ( s = save_attrs; s; s = s->a_next ) {
5689 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5690 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5691 ct = config_find_table( colst, nocs, s->a_desc, ca );
5692 a = attr_find( e->e_attrs, s->a_desc );
5694 /* clear the flag so the add check below will skip it */
5695 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5699 config_del_vals( ct, ca );
5701 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5702 ca->line = s->a_vals[i].bv_val;
5704 config_modify_add( ct, ca, s->a_desc, i );
5708 for ( a = e->e_attrs; a; a = a->a_next ) {
5709 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5710 ct = config_find_table( colst, nocs, a->a_desc, ca );
5714 config_del_vals( ct, ca );
5715 s = attr_find( save_attrs, a->a_desc );
5717 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5718 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5719 ca->line = s->a_vals[i].bv_val;
5721 config_modify_add( ct, ca, s->a_desc, i );
5732 if ( rc == LDAP_SUCCESS ) {
5733 attrs_free( save_attrs );
5736 attrs_free( e->e_attrs );
5737 e->e_attrs = save_attrs;
5739 ch_free( ca->argv );
5740 if ( colst ) ch_free( colst );
5742 deltail = dels->next;
5751 config_back_modify( Operation *op, SlapReply *rs )
5754 CfEntryInfo *ce, *last;
5756 ConfigArgs ca = {0};
5759 AttributeDescription *rad = NULL;
5762 cfb = (CfBackInfo *)op->o_bd->be_private;
5764 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5767 rs->sr_matched = last->ce_entry->e_name.bv_val;
5768 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5772 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5773 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5777 /* Get type of RDN */
5778 rdn = ce->ce_entry->e_nname;
5779 ptr = strchr( rdn.bv_val, '=' );
5780 rdn.bv_len = ptr - rdn.bv_val;
5781 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5782 if ( rs->sr_err != LDAP_SUCCESS ) {
5786 /* Some basic validation... */
5787 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5788 /* Don't allow Modify of RDN; must use ModRdn for that. */
5789 if ( ml->sml_desc == rad ) {
5790 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5791 rs->sr_text = "Use modrdn to change the entry name";
5794 /* Internal update of contextCSN? */
5795 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5801 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5804 if ( op->o_abandon ) {
5805 rs->sr_err = SLAPD_ABANDON;
5808 ldap_pvt_thread_pool_pause( &connection_pool );
5812 * 1) perform the Modify on the cached Entry.
5813 * 2) verify that the Entry still satisfies the schema.
5814 * 3) perform the individual config operations.
5815 * 4) store Modified entry in underlying LDIF backend.
5817 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5819 rs->sr_text = ca.cr_msg;
5820 } else if ( cfb->cb_use_ldif ) {
5821 BackendDB *be = op->o_bd;
5822 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5823 struct berval dn, ndn;
5825 op->o_bd = &cfb->cb_db;
5829 op->o_dn = op->o_bd->be_rootdn;
5830 op->o_ndn = op->o_bd->be_rootndn;
5832 scp = op->o_callback;
5833 op->o_callback = ≻
5834 op->o_bd->be_modify( op, rs );
5836 op->o_callback = scp;
5842 ldap_pvt_thread_pool_resume( &connection_pool );
5844 send_ldap_result( op, rs );
5845 slap_graduate_commit_csn( op );
5850 config_back_modrdn( Operation *op, SlapReply *rs )
5853 CfEntryInfo *ce, *last;
5857 cfb = (CfBackInfo *)op->o_bd->be_private;
5859 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5862 rs->sr_matched = last->ce_entry->e_name.bv_val;
5863 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5866 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5867 NULL, ACL_WRITE, NULL )) {
5868 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5872 if ( ce->ce_parent )
5873 parent = ce->ce_parent->ce_entry;
5875 parent = (Entry *)&slap_entry_root;
5876 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5877 NULL, ACL_WRITE, NULL )) {
5878 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5883 /* We don't allow moving objects to new parents.
5884 * Generally we only allow reordering a set of ordered entries.
5886 if ( op->orr_newSup ) {
5887 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5891 /* If newRDN == oldRDN, quietly succeed */
5892 dnRdn( &op->o_req_ndn, &rdn );
5893 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5894 rs->sr_err = LDAP_SUCCESS;
5898 /* Current behavior, subject to change as needed:
5900 * For backends and overlays, we only allow renumbering.
5901 * For schema, we allow renaming with the same number.
5902 * Otherwise, the op is not allowed.
5905 if ( ce->ce_type == Cft_Schema ) {
5909 /* Can't alter the main cn=schema entry */
5910 if ( ce->ce_parent->ce_type == Cft_Global ) {
5911 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5912 rs->sr_text = "renaming not allowed for this entry";
5916 /* We could support this later if desired */
5917 ptr1 = ber_bvchr( &rdn, '}' );
5918 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5919 len = ptr1 - rdn.bv_val;
5920 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5921 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5922 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5923 rs->sr_text = "schema reordering not supported";
5926 } else if ( ce->ce_type == Cft_Database ||
5927 ce->ce_type == Cft_Overlay ) {
5928 char *ptr1, *ptr2, *iptr1, *iptr2;
5931 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5932 if ( *iptr2 != '{' ) {
5933 rs->sr_err = LDAP_NAMING_VIOLATION;
5934 rs->sr_text = "new ordering index is required";
5938 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5939 ptr1 = ber_bvchr( &rdn, '}' );
5940 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5942 rs->sr_err = LDAP_NAMING_VIOLATION;
5943 rs->sr_text = "new ordering index is required";
5947 len1 = ptr1 - rdn.bv_val;
5948 len2 = ptr2 - op->orr_newrdn.bv_val;
5950 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5951 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5952 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5953 rs->sr_text = "changing database/overlay type not allowed";
5956 ixold = strtol( iptr1, NULL, 0 );
5957 ixnew = strtol( iptr2, &ptr1, 0 );
5958 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5959 rs->sr_err = LDAP_NAMING_VIOLATION;
5962 /* config DB is always 0, cannot be changed */
5963 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5964 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5968 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5969 rs->sr_text = "renaming not supported for this entry";
5973 if ( op->o_abandon ) {
5974 rs->sr_err = SLAPD_ABANDON;
5977 ldap_pvt_thread_pool_pause( &connection_pool );
5979 if ( ce->ce_type == Cft_Schema ) {
5980 req_modrdn_s modr = op->oq_modrdn;
5983 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5984 if ( rs->sr_err == LDAP_SUCCESS ) {
5985 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5986 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5989 op->oq_modrdn = modr;
5991 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5992 req_modrdn_s modr = op->oq_modrdn;
5995 /* Advance to first of this type */
5996 cprev = &ce->ce_parent->ce_kids;
5997 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5998 cprev = &ce2->ce_sibs;
6001 /* Skip the -1 entry */
6002 if ( ce->ce_type == Cft_Database ) {
6003 cprev = &ce2->ce_sibs;
6009 /* Remove from old slot */
6010 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6011 cprev = &ce2->ce_sibs;
6012 *cprev = ce->ce_sibs;
6013 ceold = ce->ce_sibs;
6015 /* Insert into new slot */
6017 for ( i=0; i<ixnew; i++ ) {
6021 cprev = &ce2->ce_sibs;
6023 ce->ce_sibs = *cprev;
6028 /* NOTE: These should be encoded in the OC tables, not inline here */
6029 if ( ce->ce_type == Cft_Database )
6030 backend_db_move( ce->ce_be, ixnew );
6031 else if ( ce->ce_type == Cft_Overlay )
6032 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6034 if ( ixold < ixnew ) {
6035 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6038 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6039 ixold - ixnew, cfb->cb_use_ldif );
6041 op->oq_modrdn = modr;
6044 ldap_pvt_thread_pool_resume( &connection_pool );
6046 send_ldap_result( op, rs );
6051 config_back_delete( Operation *op, SlapReply *rs )
6053 #ifdef SLAP_CONFIG_DELETE
6055 CfEntryInfo *ce, *last, *ce2;
6057 cfb = (CfBackInfo *)op->o_bd->be_private;
6059 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6062 rs->sr_matched = last->ce_entry->e_name.bv_val;
6063 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6064 } else if ( ce->ce_kids ) {
6065 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6066 } else if ( op->o_abandon ) {
6067 rs->sr_err = SLAPD_ABANDON;
6068 } else if ( ce->ce_type == Cft_Overlay ){
6072 ldap_pvt_thread_pool_pause( &connection_pool );
6074 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
6076 /* remove CfEntryInfo from the siblings list */
6077 if ( ce->ce_parent->ce_kids == ce ) {
6078 ce->ce_parent->ce_kids = ce->ce_sibs;
6080 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6081 if ( ce2->ce_sibs == ce ) {
6082 ce2->ce_sibs = ce->ce_sibs;
6088 /* remove from underlying database */
6089 if ( cfb->cb_use_ldif ) {
6090 BackendDB *be = op->o_bd;
6091 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6092 struct berval dn, ndn, req_dn, req_ndn;
6094 op->o_bd = &cfb->cb_db;
6098 req_dn = op->o_req_dn;
6099 req_ndn = op->o_req_ndn;
6101 op->o_dn = op->o_bd->be_rootdn;
6102 op->o_ndn = op->o_bd->be_rootndn;
6103 op->o_req_dn = ce->ce_entry->e_name;
6104 op->o_req_ndn = ce->ce_entry->e_nname;
6106 scp = op->o_callback;
6107 op->o_callback = ≻
6108 op->o_bd->be_delete( op, rs );
6110 op->o_callback = scp;
6113 op->o_req_dn = req_dn;
6114 op->o_req_ndn = req_ndn;
6117 /* renumber siblings */
6118 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6119 ixold = strtol( iptr, NULL, 0 );
6120 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6121 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6122 count+ixold, 0, cfb->cb_use_ldif );
6126 ce->ce_entry->e_private=NULL;
6127 entry_free(ce->ce_entry);
6129 ldap_pvt_thread_pool_resume( &connection_pool );
6131 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6134 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6135 #endif /* SLAP_CONFIG_DELETE */
6136 send_ldap_result( op, rs );
6141 config_back_search( Operation *op, SlapReply *rs )
6144 CfEntryInfo *ce, *last;
6147 cfb = (CfBackInfo *)op->o_bd->be_private;
6149 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6152 rs->sr_matched = last->ce_entry->e_name.bv_val;
6153 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6156 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6157 ACL_SEARCH, NULL, &mask ))
6159 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6160 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6162 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6166 switch ( op->ors_scope ) {
6167 case LDAP_SCOPE_BASE:
6168 case LDAP_SCOPE_SUBTREE:
6169 rs->sr_err = config_send( op, rs, ce, 0 );
6172 case LDAP_SCOPE_ONELEVEL:
6173 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6174 rs->sr_err = config_send( op, rs, ce, 1 );
6183 send_ldap_result( op, rs );
6187 /* no-op, we never free entries */
6188 int config_entry_release(
6193 if ( !e->e_private ) {
6196 return LDAP_SUCCESS;
6199 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6201 int config_back_entry_get(
6205 AttributeDescription *at,
6210 CfEntryInfo *ce, *last;
6211 int rc = LDAP_NO_SUCH_OBJECT;
6213 cfb = (CfBackInfo *)op->o_bd->be_private;
6215 ce = config_find_base( cfb->cb_root, ndn, &last );
6217 *ent = ce->ce_entry;
6220 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6221 rc = LDAP_NO_SUCH_ATTRIBUTE;
6230 static AccessControl *defacl_parsed = NULL;
6232 int config_back_access_allowed(
6235 AttributeDescription *desc,
6237 slap_access_t access,
6238 AccessControlState *state,
6239 slap_mask_t *maskp )
6242 BackendDB *be_orig = op->o_bd, db = *op->o_bd;
6244 /* If we have no explicitly configured ACLs, don't just use
6245 * the global ACLs. Explicitly deny access to everything.
6247 if ( ! db.be_acl ) {
6248 Debug( LDAP_DEBUG_ACL, "=> config_back_access_allowed: "
6249 "No explicit ACL for back-config configured, "
6250 "using hardcoded default\n", 0, 0, 0 );
6251 db.be_acl = defacl_parsed;
6254 result = slap_access_allowed( op, e , desc, val, access, state, maskp );
6260 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6261 ConfigTable *ct, ConfigArgs *c )
6265 for (; at && *at; at++) {
6266 /* Skip the naming attr */
6267 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6269 for (i=0;ct[i].name;i++) {
6270 if (ct[i].ad == (*at)->sat_ad) {
6271 rc = config_get_vals(&ct[i], c);
6272 /* NOTE: tolerate that config_get_vals()
6273 * returns success with no values */
6274 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6275 if ( c->rvalue_nvals )
6276 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6279 slap_syntax_validate_func *validate =
6280 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6283 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6284 rc = ordered_value_validate( ct[i].ad,
6285 &c->rvalue_vals[j], LDAP_MOD_ADD );
6287 Debug( LDAP_DEBUG_ANY,
6288 "config_build_attrs: error %d on %s value #%d\n",
6289 rc, ct[i].ad->ad_cname.bv_val, j );
6295 rc = attr_merge_normalize(e, ct[i].ad,
6296 c->rvalue_vals, NULL);
6298 ber_bvarray_free( c->rvalue_nvals );
6299 ber_bvarray_free( c->rvalue_vals );
6301 Debug( LDAP_DEBUG_ANY,
6302 "config_build_attrs: error %d on %s\n",
6303 rc, ct[i].ad->ad_cname.bv_val, 0 );
6314 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6317 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6318 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6320 Entry *e = entry_alloc();
6321 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6323 struct berval ad_name;
6324 AttributeDescription *ad = NULL;
6327 const char *text = "";
6331 CfEntryInfo *ceprev = NULL;
6333 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6336 ce->ce_type = main->co_type;
6337 ce->ce_parent = parent;
6339 pdn = parent->ce_entry->e_nname;
6340 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6341 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6342 ceprev->ce_type <= ce->ce_type;
6343 ceprev = ceprev->ce_sibs );
6348 ce->ce_private = c->ca_private;
6352 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6353 ber_dupbv( &e->e_nname, &e->e_name );
6355 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6356 main->co_name, NULL );
6358 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6359 extra->co_name, NULL );
6360 ptr = strchr(rdn->bv_val, '=');
6361 ad_name.bv_val = rdn->bv_val;
6362 ad_name.bv_len = ptr - rdn->bv_val;
6363 rc = slap_bv2ad( &ad_name, &ad, &text );
6368 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6369 attr_merge_normalize_one(e, ad, &val, NULL );
6372 c->table = main->co_type;
6373 if ( oc->soc_required ) {
6374 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6375 if ( rc ) goto fail;
6378 if ( oc->soc_allowed ) {
6379 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6380 if ( rc ) goto fail;
6385 c->table = extra->co_type;
6386 if ( oc->soc_required ) {
6387 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6388 if ( rc ) goto fail;
6391 if ( oc->soc_allowed ) {
6392 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6393 if ( rc ) goto fail;
6397 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6398 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6399 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6400 if ( rc != LDAP_SUCCESS ) {
6402 Debug( LDAP_DEBUG_ANY,
6403 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6404 rdn->bv_val, text, 0);
6407 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6410 op->ora_modlist = NULL;
6411 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6412 if ( !op->o_noop ) {
6413 SlapReply rs2 = {REP_RESULT};
6414 op->o_bd->be_add( op, &rs2 );
6415 rs->sr_err = rs2.sr_err;
6416 rs_assert_done( &rs2 );
6417 if ( ( rs2.sr_err != LDAP_SUCCESS )
6418 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6424 ce->ce_sibs = ceprev->ce_sibs;
6425 ceprev->ce_sibs = ce;
6426 } else if ( parent ) {
6427 ce->ce_sibs = parent->ce_kids;
6428 parent->ce_kids = ce;
6435 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6436 Operation *op, SlapReply *rs )
6439 ConfigFile *cf = c->ca_private;
6441 struct berval bv, rdn;
6443 for (; cf; cf=cf->c_sibs, c->depth++) {
6444 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6445 !cf->c_om_head && !cf->c_syn_head ) continue;
6446 c->value_dn.bv_val = c->log;
6447 LUTIL_SLASHPATH( cf->c_file.bv_val );
6448 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6453 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6455 ptr = strchr( bv.bv_val, '.' );
6457 bv.bv_len = ptr - bv.bv_val;
6458 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6459 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6460 /* FIXME: how can indicate error? */
6463 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6465 c->value_dn.bv_len += bv.bv_len;
6466 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6467 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6470 e = config_build_entry( op, rs, ceparent, c, &rdn,
6471 &CFOC_SCHEMA, NULL );
6472 ch_free( rdn.bv_val );
6475 } else if ( e && cf->c_kids ) {
6476 c->ca_private = cf->c_kids;
6477 config_build_schema_inc( c, e->e_private, op, rs );
6483 #ifdef SLAPD_MODULES
6486 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6487 Operation *op, SlapReply *rs )
6492 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6493 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6495 c->value_dn.bv_val = c->log;
6496 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6497 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6498 /* FIXME: how can indicate error? */
6502 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6511 config_check_schema(Operation *op, CfBackInfo *cfb)
6513 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6515 CfEntryInfo *ce, *last;
6518 /* If there's no root entry, we must be in the midst of converting */
6519 if ( !cfb->cb_root )
6522 /* Make sure the main schema entry exists */
6523 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6530 /* Make sure it's up to date */
6531 if ( cf_om_tail != om_sys_tail ) {
6532 a = attr_find( e->e_attrs, cfAd_om );
6534 if ( a->a_nvals != a->a_vals )
6535 ber_bvarray_free( a->a_nvals );
6536 ber_bvarray_free( a->a_vals );
6541 oidm_unparse( &bv, NULL, NULL, 1 );
6542 attr_merge_normalize( e, cfAd_om, bv, NULL );
6543 ber_bvarray_free( bv );
6544 cf_om_tail = om_sys_tail;
6546 if ( cf_at_tail != at_sys_tail ) {
6547 a = attr_find( e->e_attrs, cfAd_attr );
6549 if ( a->a_nvals != a->a_vals )
6550 ber_bvarray_free( a->a_nvals );
6551 ber_bvarray_free( a->a_vals );
6556 at_unparse( &bv, NULL, NULL, 1 );
6557 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6558 ber_bvarray_free( bv );
6559 cf_at_tail = at_sys_tail;
6561 if ( cf_oc_tail != oc_sys_tail ) {
6562 a = attr_find( e->e_attrs, cfAd_oc );
6564 if ( a->a_nvals != a->a_vals )
6565 ber_bvarray_free( a->a_nvals );
6566 ber_bvarray_free( a->a_vals );
6571 oc_unparse( &bv, NULL, NULL, 1 );
6572 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6573 ber_bvarray_free( bv );
6574 cf_oc_tail = oc_sys_tail;
6576 if ( cf_syn_tail != syn_sys_tail ) {
6577 a = attr_find( e->e_attrs, cfAd_syntax );
6579 if ( a->a_nvals != a->a_vals )
6580 ber_bvarray_free( a->a_nvals );
6581 ber_bvarray_free( a->a_vals );
6586 syn_unparse( &bv, NULL, NULL, 1 );
6587 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6588 ber_bvarray_free( bv );
6589 cf_syn_tail = syn_sys_tail;
6592 SlapReply rs = {REP_RESULT};
6593 c.ca_private = NULL;
6594 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6595 &CFOC_SCHEMA, NULL );
6600 ce->ce_private = cfb->cb_config;
6601 cf_at_tail = at_sys_tail;
6602 cf_oc_tail = oc_sys_tail;
6603 cf_om_tail = om_sys_tail;
6604 cf_syn_tail = syn_sys_tail;
6609 static const char *defacl[] = {
6610 NULL, "to", "*", "by", "*", "none", NULL
6614 config_back_db_open( BackendDB *be, ConfigReply *cr )
6616 CfBackInfo *cfb = be->be_private;
6619 CfEntryInfo *ce, *ceparent;
6623 Connection conn = {0};
6624 OperationBuffer opbuf;
6626 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6627 SlapReply rs = {REP_RESULT};
6628 void *thrctx = NULL;
6629 AccessControl *save_access;
6631 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6633 /* prepare a hardcoded default ACL which is used when no
6634 * explicit ACL is defined for this database. See also:
6635 * config_back_access_allowed() */
6636 save_access = be->bd_self->be_acl;
6637 be->bd_self->be_acl = NULL;
6638 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6639 defacl_parsed = be->bd_self->be_acl;
6640 be->bd_self->be_acl = save_access;
6642 thrctx = ldap_pvt_thread_pool_context();
6643 connection_fake_init( &conn, &opbuf, thrctx );
6646 op->o_tag = LDAP_REQ_ADD;
6647 op->o_callback = &cb;
6648 op->o_bd = &cfb->cb_db;
6649 op->o_dn = op->o_bd->be_rootdn;
6650 op->o_ndn = op->o_bd->be_rootndn;
6652 if ( !cfb->cb_use_ldif ) {
6656 /* If we read the config from back-ldif, do some quick sanity checks */
6657 if ( cfb->cb_got_ldif ) {
6658 return config_check_schema( op, cfb );
6661 /* create root of tree */
6663 c.ca_private = cfb->cb_config;
6665 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6675 #ifdef SLAPD_MODULES
6676 /* Create Module nodes... */
6677 if ( modpaths.mp_loads ) {
6678 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6684 /* Create schema nodes... cn=schema will contain the hardcoded core
6685 * schema, read-only. Child objects will contain runtime loaded schema
6689 c.ca_private = NULL;
6690 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6695 ce->ce_private = cfb->cb_config;
6696 cf_at_tail = at_sys_tail;
6697 cf_oc_tail = oc_sys_tail;
6698 cf_om_tail = om_sys_tail;
6699 cf_syn_tail = syn_sys_tail;
6701 /* Create schema nodes for included schema... */
6702 if ( cfb->cb_config->c_kids ) {
6705 c.ca_private = cfb->cb_config->c_kids;
6706 rc = config_build_schema_inc( &c, ce, op, &rs );
6712 /* Create backend nodes. Skip if they don't provide a cf_table.
6713 * There usually aren't any of these.
6717 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6718 if (!bi->bi_cf_ocs) {
6719 /* If it only supports the old config mech, complain. */
6720 if ( bi->bi_config ) {
6721 Debug( LDAP_DEBUG_ANY,
6722 "WARNING: No dynamic config support for backend %s.\n",
6723 bi->bi_type, 0, 0 );
6728 if (!bi->bi_private) continue;
6731 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6732 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6733 if ( rdn.bv_len >= sizeof( c.log ) ) {
6734 /* FIXME: holler ... */ ;
6737 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6744 /* Create database nodes... */
6745 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6746 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6747 for ( i = -1, be = frontendDB ; be;
6748 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6749 slap_overinfo *oi = NULL;
6751 if ( overlay_is_over( be )) {
6752 oi = be->bd_info->bi_private;
6758 /* If this backend supports the old config mechanism, but not
6759 * the new mech, complain.
6761 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6762 Debug( LDAP_DEBUG_ANY,
6763 "WARNING: No dynamic config support for database %s.\n",
6764 bi->bi_type, 0, 0 );
6768 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6769 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6771 if ( rdn.bv_len >= sizeof( c.log ) ) {
6772 /* FIXME: holler ... */ ;
6776 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6782 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6783 rs_reinit( &rs, REP_RESULT );
6784 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6786 /* Iterate through overlays */
6791 voidList *vl, *v0 = NULL;
6793 /* overlays are in LIFO order, must reverse stack */
6794 for (on=oi->oi_list; on; on=on->on_next) {
6795 vl = ch_malloc( sizeof( voidList ));
6800 for (j=0; vl; j++,vl=v0) {
6804 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6805 Debug( LDAP_DEBUG_ANY,
6806 "WARNING: No dynamic config support for overlay %s.\n",
6807 on->on_bi.bi_type, 0, 0 );
6811 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6812 "%s=" SLAP_X_ORDERED_FMT "%s",
6813 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6814 if ( rdn.bv_len >= sizeof( c.log ) ) {
6815 /* FIXME: holler ... */ ;
6819 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6820 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6824 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6825 rs_reinit( &rs, REP_RESULT );
6826 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6832 ldap_pvt_thread_pool_context_reset( thrctx );
6834 if ( unsupp && cfb->cb_use_ldif ) {
6835 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6836 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6843 cfb_free_cffile( ConfigFile *cf )
6847 for (; cf; cf=next) {
6850 cfb_free_cffile( cf->c_kids );
6851 ch_free( cf->c_file.bv_val );
6852 ber_bvarray_free( cf->c_dseFiles );
6858 cfb_free_entries( CfEntryInfo *ce )
6862 for (; ce; ce=next) {
6865 cfb_free_entries( ce->ce_kids );
6866 ce->ce_entry->e_private = NULL;
6867 entry_free( ce->ce_entry );
6873 config_back_db_close( BackendDB *be, ConfigReply *cr )
6875 CfBackInfo *cfb = be->be_private;
6877 cfb_free_entries( cfb->cb_root );
6878 cfb->cb_root = NULL;
6880 if ( cfb->cb_db.bd_info ) {
6881 backend_shutdown( &cfb->cb_db );
6884 if ( defacl_parsed ) {
6885 acl_free( defacl_parsed );
6886 defacl_parsed = NULL;
6893 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6895 CfBackInfo *cfb = be->be_private;
6897 cfb_free_cffile( cfb->cb_config );
6899 ch_free( cfdir.bv_val );
6901 avl_free( CfOcTree, NULL );
6903 if ( cfb->cb_db.bd_info ) {
6904 cfb->cb_db.be_suffix = NULL;
6905 cfb->cb_db.be_nsuffix = NULL;
6906 BER_BVZERO( &cfb->cb_db.be_rootdn );
6907 BER_BVZERO( &cfb->cb_db.be_rootndn );
6909 backend_destroy_one( &cfb->cb_db, 0 );
6918 config_back_db_init( BackendDB *be, ConfigReply* cr )
6924 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6925 cfn = cfb->cb_config;
6926 be->be_private = cfb;
6928 ber_dupbv( &be->be_rootdn, &config_rdn );
6929 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6930 ber_dupbv( &dn, &be->be_rootdn );
6931 ber_bvarray_add( &be->be_suffix, &dn );
6932 ber_dupbv( &dn, &be->be_rootdn );
6933 ber_bvarray_add( &be->be_nsuffix, &dn );
6935 /* Hide from namingContexts */
6936 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6938 /* Check ACLs on content of Adds by default */
6939 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6945 config_back_destroy( BackendInfo *bi )
6947 ldif_must_b64_encode_release();
6952 config_tool_entry_open( BackendDB *be, int mode )
6954 CfBackInfo *cfb = be->be_private;
6955 BackendInfo *bi = cfb->cb_db.bd_info;
6957 if ( bi && bi->bi_tool_entry_open )
6958 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6965 config_tool_entry_close( BackendDB *be )
6967 CfBackInfo *cfb = be->be_private;
6968 BackendInfo *bi = cfb->cb_db.bd_info;
6970 if ( bi && bi->bi_tool_entry_close )
6971 return bi->bi_tool_entry_close( &cfb->cb_db );
6977 config_tool_entry_first( BackendDB *be )
6979 CfBackInfo *cfb = be->be_private;
6980 BackendInfo *bi = cfb->cb_db.bd_info;
6982 if ( bi && bi->bi_tool_entry_first ) {
6983 return bi->bi_tool_entry_first( &cfb->cb_db );
6985 if ( bi && bi->bi_tool_entry_first_x ) {
6986 return bi->bi_tool_entry_first_x( &cfb->cb_db,
6987 NULL, LDAP_SCOPE_DEFAULT, NULL );
6993 config_tool_entry_first_x(
6995 struct berval *base,
6999 CfBackInfo *cfb = be->be_private;
7000 BackendInfo *bi = cfb->cb_db.bd_info;
7002 if ( bi && bi->bi_tool_entry_first_x ) {
7003 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7009 config_tool_entry_next( BackendDB *be )
7011 CfBackInfo *cfb = be->be_private;
7012 BackendInfo *bi = cfb->cb_db.bd_info;
7014 if ( bi && bi->bi_tool_entry_next )
7015 return bi->bi_tool_entry_next( &cfb->cb_db );
7021 config_tool_entry_get( BackendDB *be, ID id )
7023 CfBackInfo *cfb = be->be_private;
7024 BackendInfo *bi = cfb->cb_db.bd_info;
7026 if ( bi && bi->bi_tool_entry_get )
7027 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7032 static int entry_put_got_frontend=0;
7033 static int entry_put_got_config=0;
7035 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7037 CfBackInfo *cfb = be->be_private;
7038 BackendInfo *bi = cfb->cb_db.bd_info;
7040 struct berval rdn, vals[ 2 ];
7042 OperationBuffer opbuf;
7044 Connection conn = {0};
7045 Operation *op = NULL;
7048 int isFrontendChild = 0;
7050 /* Create entry for frontend database if it does not exist already */
7051 if ( !entry_put_got_frontend ) {
7052 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7053 STRLENOF( "olcDatabase" ))) {
7054 if ( strncmp( e->e_nname.bv_val +
7055 STRLENOF( "olcDatabase" ), "={-1}frontend",
7056 STRLENOF( "={-1}frontend" )) &&
7057 strncmp( e->e_nname.bv_val +
7058 STRLENOF( "olcDatabase" ), "=frontend",
7059 STRLENOF( "=frontend" ))) {
7061 vals[1].bv_val = NULL;
7062 memset( &ca, 0, sizeof(ConfigArgs));
7064 ca.bi = frontendDB->bd_info;
7065 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7066 rdn.bv_val = ca.log;
7067 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7068 "%s=" SLAP_X_ORDERED_FMT "%s",
7069 cfAd_database->ad_cname.bv_val, -1,
7071 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7072 &CFOC_DATABASE, ca.be->be_cf_ocs );
7073 thrctx = ldap_pvt_thread_pool_context();
7074 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7076 op->o_bd = &cfb->cb_db;
7077 op->o_tag = LDAP_REQ_ADD;
7079 op->o_dn = be->be_rootdn;
7080 op->o_ndn = be->be_rootndn;
7081 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7082 if ( rc != LDAP_SUCCESS ) {
7083 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7084 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7088 if ( ce && bi && bi->bi_tool_entry_put &&
7089 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7090 entry_put_got_frontend++;
7092 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7093 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7097 if ( !strncmp( e->e_nname.bv_val +
7098 STRLENOF( "olcDatabase" ), "=frontend",
7099 STRLENOF( "=frontend" ) ) )
7101 struct berval rdn, pdn, ndn;
7102 dnParent( &e->e_nname, &pdn );
7103 rdn.bv_val = ca.log;
7104 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7105 "%s=" SLAP_X_ORDERED_FMT "%s",
7106 cfAd_database->ad_cname.bv_val, -1,
7107 frontendDB->bd_info->bi_type );
7108 build_new_dn( &ndn, &pdn, &rdn, NULL );
7109 ber_memfree( e->e_name.bv_val );
7111 ber_bvreplace( &e->e_nname, &e->e_name );
7113 entry_put_got_frontend++;
7119 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7120 * instances, may appear before the config database entry in the ldif, skip
7121 * auto-creation of olcDatabase={0}config in such a case */
7122 if ( !entry_put_got_config &&
7123 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7125 dnParent( &e->e_nname, &pdn );
7126 while ( pdn.bv_len ) {
7127 if ( !strncmp( pdn.bv_val, "olcDatabase",
7128 STRLENOF( "olcDatabase" ))) {
7129 if ( !strncmp( pdn.bv_val +
7130 STRLENOF( "olcDatabase" ), "={-1}frontend",
7131 STRLENOF( "={-1}frontend" )) ||
7132 !strncmp( pdn.bv_val +
7133 STRLENOF( "olcDatabase" ), "=frontend",
7134 STRLENOF( "=frontend" ))) {
7136 isFrontendChild = 1;
7140 dnParent( &pdn, &pdn );
7144 /* Create entry for config database if it does not exist already */
7145 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7146 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7147 STRLENOF( "olcDatabase" ))) {
7148 if ( strncmp( e->e_nname.bv_val +
7149 STRLENOF( "olcDatabase" ), "={0}config",
7150 STRLENOF( "={0}config" )) &&
7151 strncmp( e->e_nname.bv_val +
7152 STRLENOF( "olcDatabase" ), "=config",
7153 STRLENOF( "=config" )) ) {
7155 vals[1].bv_val = NULL;
7156 memset( &ca, 0, sizeof(ConfigArgs));
7157 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7158 ca.bi = ca.be->bd_info;
7159 rdn.bv_val = ca.log;
7160 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7161 "%s=" SLAP_X_ORDERED_FMT "%s",
7162 cfAd_database->ad_cname.bv_val, 0,
7164 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7167 thrctx = ldap_pvt_thread_pool_context();
7168 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7170 op->o_bd = &cfb->cb_db;
7171 op->o_tag = LDAP_REQ_ADD;
7172 op->o_dn = be->be_rootdn;
7173 op->o_ndn = be->be_rootndn;
7176 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7177 if ( rc != LDAP_SUCCESS ) {
7178 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7179 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7182 if (ce && bi && bi->bi_tool_entry_put &&
7183 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7184 entry_put_got_config++;
7186 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7187 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7191 entry_put_got_config++;
7195 if ( bi && bi->bi_tool_entry_put &&
7196 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7197 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7204 AttributeDescription **desc;
7206 { "attribute", &cfAd_attr },
7207 { "backend", &cfAd_backend },
7208 { "database", &cfAd_database },
7209 { "include", &cfAd_include },
7210 { "ldapsyntax", &cfAd_syntax },
7211 { "objectclass", &cfAd_oc },
7212 { "objectidentifier", &cfAd_om },
7213 { "overlay", &cfAd_overlay },
7218 * add / delete: all types that may be added or deleted must use an
7219 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7220 * should automatically renumber the index of any siblings as needed,
7221 * so that no gaps in the numbering sequence exist after the add/delete
7223 * What can be added:
7225 * backend objects for backend-specific config directives
7229 * delete: probably no support this time around.
7231 * modrdn: generally not done. Will be invoked automatically by add/
7232 * delete to update numbering sequence. Perform as an explicit operation
7233 * so that the renumbering effect may be replicated. Subtree rename must
7234 * be supported, since renumbering a database will affect all its child
7237 * modify: must be fully supported.
7241 config_back_initialize( BackendInfo *bi )
7243 ConfigTable *ct = config_back_cf_table;
7247 AttributeDescription *ad = NULL;
7249 static char *controls[] = {
7250 LDAP_CONTROL_MANAGEDSAIT,
7254 /* Make sure we don't exceed the bits reserved for userland */
7255 config_check_userland( CFG_LAST );
7257 bi->bi_controls = controls;
7262 bi->bi_destroy = config_back_destroy;
7264 bi->bi_db_init = config_back_db_init;
7265 bi->bi_db_config = 0;
7266 bi->bi_db_open = config_back_db_open;
7267 bi->bi_db_close = config_back_db_close;
7268 bi->bi_db_destroy = config_back_db_destroy;
7270 bi->bi_op_bind = config_back_bind;
7271 bi->bi_op_unbind = 0;
7272 bi->bi_op_search = config_back_search;
7273 bi->bi_op_compare = 0;
7274 bi->bi_op_modify = config_back_modify;
7275 bi->bi_op_modrdn = config_back_modrdn;
7276 bi->bi_op_add = config_back_add;
7277 bi->bi_op_delete = config_back_delete;
7278 bi->bi_op_abandon = 0;
7280 bi->bi_extended = 0;
7282 bi->bi_chk_referrals = 0;
7284 bi->bi_access_allowed = config_back_access_allowed;
7286 bi->bi_connection_init = 0;
7287 bi->bi_connection_destroy = 0;
7289 bi->bi_entry_release_rw = config_entry_release;
7290 bi->bi_entry_get_rw = config_back_entry_get;
7292 bi->bi_tool_entry_open = config_tool_entry_open;
7293 bi->bi_tool_entry_close = config_tool_entry_close;
7294 bi->bi_tool_entry_first = config_tool_entry_first;
7295 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7296 bi->bi_tool_entry_next = config_tool_entry_next;
7297 bi->bi_tool_entry_get = config_tool_entry_get;
7298 bi->bi_tool_entry_put = config_tool_entry_put;
7301 argv[ 0 ] = "slapd";
7307 for (i=0; OidMacros[i].name; i++ ) {
7308 argv[1] = OidMacros[i].name;
7309 argv[2] = OidMacros[i].oid;
7310 parse_oidm( &ca, 0, NULL );
7313 bi->bi_cf_ocs = cf_ocs;
7315 i = config_register_schema( ct, cf_ocs );
7318 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7321 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7322 * basically, we don't care if it fails */
7323 i = slap_str2ad( "olcRootPW", &ad, &text );
7325 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7326 "warning, unable to get \"olcRootPW\" "
7327 "attribute description: %d: %s\n",
7330 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7331 ad->ad_type->sat_oid );
7334 /* set up the notable AttributeDescriptions */
7336 for (;ct->name;ct++) {
7337 if (strcmp(ct->name, ads[i].name)) continue;
7338 *ads[i].desc = ct->ad;
7340 if (!ads[i].name) break;