1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2009 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
88 static struct berval cfdir;
91 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
92 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
94 static ConfigFile *cfn;
96 static Avlnode *CfOcTree;
98 /* System schema state */
99 extern AttributeType *at_sys_tail; /* at.c */
100 extern ObjectClass *oc_sys_tail; /* oc.c */
101 extern OidMacro *om_sys_tail; /* oidm.c */
102 extern Syntax *syn_sys_tail; /* syntax.c */
103 static AttributeType *cf_at_tail;
104 static ObjectClass *cf_oc_tail;
105 static OidMacro *cf_om_tail;
106 static Syntax *cf_syn_tail;
108 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
109 SlapReply *rs, int *renumber, Operation *op );
111 static int config_check_schema( Operation *op, CfBackInfo *cfb );
113 static ConfigDriver config_fname;
114 static ConfigDriver config_cfdir;
115 static ConfigDriver config_generic;
116 static ConfigDriver config_search_base;
117 static ConfigDriver config_passwd_hash;
118 static ConfigDriver config_schema_dn;
119 static ConfigDriver config_sizelimit;
120 static ConfigDriver config_timelimit;
121 static ConfigDriver config_overlay;
122 static ConfigDriver config_subordinate;
123 static ConfigDriver config_suffix;
124 #ifdef LDAP_TCP_BUFFER
125 static ConfigDriver config_tcp_buffer;
126 #endif /* LDAP_TCP_BUFFER */
127 static ConfigDriver config_rootdn;
128 static ConfigDriver config_rootpw;
129 static ConfigDriver config_restrict;
130 static ConfigDriver config_allows;
131 static ConfigDriver config_disallows;
132 static ConfigDriver config_requires;
133 static ConfigDriver config_security;
134 static ConfigDriver config_referral;
135 static ConfigDriver config_loglevel;
136 static ConfigDriver config_updatedn;
137 static ConfigDriver config_updateref;
138 static ConfigDriver config_include;
139 static ConfigDriver config_obsolete;
141 static ConfigDriver config_tls_option;
142 static ConfigDriver config_tls_config;
144 extern ConfigDriver syncrepl_config;
152 CFG_TLS_PROTOCOL_MIN,
202 static OidRec OidMacros[] = {
203 /* OpenLDAProot:1.12.2 */
204 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
205 { "OLcfgAt", "OLcfg:3" },
206 { "OLcfgGlAt", "OLcfgAt:0" },
207 { "OLcfgBkAt", "OLcfgAt:1" },
208 { "OLcfgDbAt", "OLcfgAt:2" },
209 { "OLcfgOvAt", "OLcfgAt:3" },
210 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
211 { "OLcfgOc", "OLcfg:4" },
212 { "OLcfgGlOc", "OLcfgOc:0" },
213 { "OLcfgBkOc", "OLcfgOc:1" },
214 { "OLcfgDbOc", "OLcfgOc:2" },
215 { "OLcfgOvOc", "OLcfgOc:3" },
216 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
218 /* Syntaxes. We should just start using the standard names and
219 * document that they are predefined and available for users
220 * to reference in their own schema. Defining schema without
221 * OID macros is for masochists...
223 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
224 { "OMsBoolean", "OMsyn:7" },
225 { "OMsDN", "OMsyn:12" },
226 { "OMsDirectoryString", "OMsyn:15" },
227 { "OMsIA5String", "OMsyn:26" },
228 { "OMsInteger", "OMsyn:27" },
229 { "OMsOID", "OMsyn:38" },
230 { "OMsOctetString", "OMsyn:40" },
235 * Backend/Database registry
237 * OLcfg{Bk|Db}{Oc|At}:0 -> common
238 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
239 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
240 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
241 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
242 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
243 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
244 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
250 * OLcfgOv{Oc|At}:1 -> syncprov
251 * OLcfgOv{Oc|At}:2 -> pcache
252 * OLcfgOv{Oc|At}:3 -> chain
253 * OLcfgOv{Oc|At}:4 -> accesslog
254 * OLcfgOv{Oc|At}:5 -> valsort
255 * OLcfgOv{Oc|At}:7 -> distproc
256 * OLcfgOv{Oc|At}:8 -> dynlist
257 * OLcfgOv{Oc|At}:9 -> dds
258 * OLcfgOv{Oc|At}:10 -> unique
259 * OLcfgOv{Oc|At}:11 -> refint
260 * OLcfgOv{Oc|At}:12 -> ppolicy
261 * OLcfgOv{Oc|At}:13 -> constraint
262 * OLcfgOv{Oc|At}:14 -> translucent
263 * OLcfgOv{Oc|At}:15 -> auditlog
264 * OLcfgOv{Oc|At}:16 -> rwm
265 * OLcfgOv{Oc|At}:17 -> dyngroup
266 * OLcfgOv{Oc|At}:18 -> memberof
267 * OLcfgOv{Oc|At}:19 -> collect
268 * OLcfgOv{Oc|At}:20 -> retcode
269 * OLcfgOv{Oc|At}:21 -> sssvlv
272 /* alphabetical ordering */
274 static ConfigTable config_back_cf_table[] = {
275 /* This attr is read-only */
276 { "", "", 0, 0, 0, ARG_MAGIC,
277 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
278 "DESC 'File for slapd configuration directives' "
279 "EQUALITY caseIgnoreMatch "
280 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
281 { "", "", 0, 0, 0, ARG_MAGIC,
282 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
283 "DESC 'Directory for slapd configuration backend' "
284 "EQUALITY caseIgnoreMatch "
285 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
286 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
287 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
288 "DESC 'Access Control List' "
289 "EQUALITY caseIgnoreMatch "
290 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
291 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
292 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
293 "DESC 'Check ACLs against content of Add ops' "
294 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
295 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
296 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
297 "DESC 'Allowed set of deprecated features' "
298 "EQUALITY caseIgnoreMatch "
299 "SYNTAX OMsDirectoryString )", NULL, NULL },
300 { "argsfile", "file", 2, 2, 0, ARG_STRING,
301 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
302 "DESC 'File for slapd command line options' "
303 "EQUALITY caseIgnoreMatch "
304 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
305 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
306 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString )", NULL, NULL },
309 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
310 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
311 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
312 "DESC 'OpenLDAP attributeTypes' "
313 "EQUALITY caseIgnoreMatch "
314 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
316 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
317 #ifdef SLAP_AUTH_REWRITE
318 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
322 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
323 "EQUALITY caseIgnoreMatch "
324 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
325 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
326 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
327 "EQUALITY caseIgnoreMatch "
328 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
329 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
330 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
331 "EQUALITY caseIgnoreMatch "
332 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
333 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
334 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
335 "DESC 'A type of backend' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
339 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
340 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
341 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
342 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
343 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
344 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
345 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
346 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
347 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
348 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
349 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
350 "DESC 'The backend type for a database instance' "
351 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
352 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
353 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
354 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
355 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
356 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
357 "EQUALITY caseIgnoreMatch "
358 "SYNTAX OMsDirectoryString )", NULL, NULL },
359 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
360 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
361 "DESC 'OpenLDAP DIT content rules' "
362 "EQUALITY caseIgnoreMatch "
363 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
365 { "gentlehup", "on|off", 2, 2, 0,
367 ARG_ON_OFF, &global_gentlehup,
371 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
372 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
373 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
374 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
375 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
376 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
377 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
378 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
379 { "include", "file", 2, 2, 0, ARG_MAGIC,
380 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
381 "SUP labeledURI )", NULL, NULL },
382 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
383 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
384 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
385 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
386 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
387 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
388 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
389 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
390 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
391 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
392 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
393 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
394 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
395 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
396 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
397 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
398 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
399 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
400 { "ldapsyntax", "syntax", 2, 0, 0,
401 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
402 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
403 "DESC 'OpenLDAP ldapSyntax' "
404 "EQUALITY caseIgnoreMatch "
405 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
407 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
408 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
409 "EQUALITY caseIgnoreMatch "
410 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
411 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
412 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
413 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
414 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
415 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
416 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
417 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
418 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
419 "EQUALITY caseIgnoreMatch "
420 "SYNTAX OMsDirectoryString )", NULL, NULL },
421 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
422 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
423 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
424 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
425 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
426 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
427 { "moduleload", "file", 2, 0, 0,
429 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
433 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
434 "EQUALITY caseIgnoreMatch "
435 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
436 { "modulepath", "path", 2, 2, 0,
438 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
442 "( OLcfgGlAt:31 NAME 'olcModulePath' "
443 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
444 { "monitoring", "TRUE|FALSE", 2, 2, 0,
445 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
446 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
447 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
448 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
449 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
450 "DESC 'OpenLDAP object classes' "
451 "EQUALITY caseIgnoreMatch "
452 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
454 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
455 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
456 "EQUALITY caseIgnoreMatch "
457 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
458 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
459 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
460 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
461 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
462 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
463 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
464 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
465 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
466 "EQUALITY caseIgnoreMatch "
467 "SYNTAX OMsDirectoryString )", NULL, NULL },
468 { "pidfile", "file", 2, 2, 0, ARG_STRING,
469 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
470 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
471 { "plugin", NULL, 0, 0, 0,
473 ARG_MAGIC|CFG_PLUGIN, &config_generic,
477 "( OLcfgGlAt:38 NAME 'olcPlugin' "
478 "EQUALITY caseIgnoreMatch "
479 "SYNTAX OMsDirectoryString )", NULL, NULL },
480 { "pluginlog", "filename", 2, 2, 0,
482 ARG_STRING, &slapi_log_file,
486 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
487 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
488 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
489 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
490 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
491 { "referral", "url", 2, 2, 0, ARG_MAGIC,
492 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
493 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
494 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
495 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
496 "EQUALITY caseIgnoreMatch "
497 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
498 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
499 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
500 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
501 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
502 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
503 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
504 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
505 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
506 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
507 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
508 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
509 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
510 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
511 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
512 "EQUALITY caseIgnoreMatch "
513 "SYNTAX OMsDirectoryString )", NULL, NULL },
514 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
515 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
516 "EQUALITY caseIgnoreMatch "
517 "SYNTAX OMsDirectoryString )", NULL, NULL },
518 { "reverse-lookup", "on|off", 2, 2, 0,
519 #ifdef SLAPD_RLOOKUPS
520 ARG_ON_OFF, &use_reverse_lookup,
524 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
525 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
526 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
527 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
528 "EQUALITY distinguishedNameMatch "
529 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
530 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
531 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
532 "EQUALITY caseIgnoreMatch "
533 "SYNTAX OMsDirectoryString )", NULL, NULL },
534 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
535 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
536 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
537 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
538 &config_generic, NULL, NULL, NULL },
539 { "sasl-auxprops", NULL, 2, 0, 0,
540 #ifdef HAVE_CYRUS_SASL
541 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
545 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
546 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
547 { "sasl-host", "host", 2, 2, 0,
548 #ifdef HAVE_CYRUS_SASL
549 ARG_STRING|ARG_UNIQUE, &sasl_host,
553 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
554 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
555 { "sasl-realm", "realm", 2, 2, 0,
556 #ifdef HAVE_CYRUS_SASL
557 ARG_STRING|ARG_UNIQUE, &global_realm,
561 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
562 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
563 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
564 &config_generic, NULL, NULL, NULL },
565 { "sasl-secprops", "properties", 2, 2, 0,
566 #ifdef HAVE_CYRUS_SASL
567 ARG_MAGIC|CFG_SASLSECP, &config_generic,
571 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
574 &config_generic, NULL, NULL, NULL },
575 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
576 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
577 "EQUALITY distinguishedNameMatch "
578 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
579 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
580 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
581 "EQUALITY caseIgnoreMatch "
582 "SYNTAX OMsDirectoryString )", NULL, NULL },
583 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
584 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
585 "EQUALITY caseIgnoreMatch "
586 "SYNTAX OMsDirectoryString )", NULL, NULL },
587 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
588 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
589 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
590 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
591 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
592 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
593 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
594 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
595 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
596 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
597 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
598 "DESC 'Attributes whose values will always be sorted' "
599 "EQUALITY caseIgnoreMatch "
600 "SYNTAX OMsDirectoryString )", NULL, NULL },
601 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
602 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
603 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
604 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
605 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
606 "EQUALITY distinguishedNameMatch "
607 "SYNTAX OMsDN )", NULL, NULL },
608 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
609 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
610 "DESC 'Store sync context in a subentry' "
611 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
612 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
613 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
614 "EQUALITY caseIgnoreMatch "
615 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
616 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
617 #ifndef LDAP_TCP_BUFFER
619 #else /* LDAP_TCP_BUFFER */
620 ARG_MAGIC, &config_tcp_buffer,
621 #endif /* LDAP_TCP_BUFFER */
622 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
623 "DESC 'Custom TCP buffer size' "
624 "SYNTAX OMsDirectoryString )", NULL, NULL },
625 { "threads", "count", 2, 2, 0,
629 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
631 "( OLcfgGlAt:66 NAME 'olcThreads' "
632 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
633 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
634 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
635 "SYNTAX OMsDirectoryString )", NULL, NULL },
636 { "TLSCACertificateFile", NULL, 0, 0, 0,
638 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
642 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
643 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
644 { "TLSCACertificatePath", NULL, 0, 0, 0,
646 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
650 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
651 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
652 { "TLSCertificateFile", NULL, 0, 0, 0,
654 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
658 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
659 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
660 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
662 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
666 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
667 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
668 { "TLSCipherSuite", NULL, 0, 0, 0,
670 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
674 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
675 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
676 { "TLSCRLCheck", NULL, 0, 0, 0,
677 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
678 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
682 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
683 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
684 { "TLSCRLFile", NULL, 0, 0, 0,
685 #if defined(HAVE_GNUTLS)
686 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
690 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
691 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
692 { "TLSRandFile", NULL, 0, 0, 0,
694 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
698 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
699 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
700 { "TLSVerifyClient", NULL, 0, 0, 0,
702 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
706 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
707 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
708 { "TLSDHParamFile", NULL, 0, 0, 0,
710 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
714 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
715 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
716 { "TLSProtocolMin", NULL, 0, 0, 0,
718 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
722 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
723 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
724 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
725 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
726 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
727 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
728 NULL, NULL, NULL, NULL },
729 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
730 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
731 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
732 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
733 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
734 "EQUALITY caseIgnoreMatch "
735 "SUP labeledURI )", NULL, NULL },
736 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
737 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
738 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
739 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
740 NULL, NULL, NULL, NULL }
743 /* Need to no-op this keyword for dynamic config */
744 ConfigTable olcDatabaseDummy[] = {
745 { "", "", 0, 0, 0, ARG_IGNORED,
746 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
747 "DESC 'The backend type for a database instance' "
748 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
749 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
752 /* Routines to check if a child can be added to this type */
753 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
754 cfAddBackend, cfAddModule, cfAddOverlay;
756 /* NOTE: be careful when defining array members
757 * that can be conditionally compiled */
758 #define CFOC_GLOBAL cf_ocs[1]
759 #define CFOC_SCHEMA cf_ocs[2]
760 #define CFOC_BACKEND cf_ocs[3]
761 #define CFOC_DATABASE cf_ocs[4]
762 #define CFOC_OVERLAY cf_ocs[5]
763 #define CFOC_INCLUDE cf_ocs[6]
764 #define CFOC_FRONTEND cf_ocs[7]
766 #define CFOC_MODULE cf_ocs[8]
767 #endif /* SLAPD_MODULES */
769 static ConfigOCs cf_ocs[] = {
772 "DESC 'OpenLDAP configuration object' "
773 "ABSTRACT SUP top )", Cft_Abstract, NULL },
776 "DESC 'OpenLDAP Global configuration options' "
777 "SUP olcConfig STRUCTURAL "
778 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
779 "olcAttributeOptions $ olcAuthIDRewrite $ "
780 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
781 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
782 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
783 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
784 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
785 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
786 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
787 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
788 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
790 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
791 "olcSecurity $ olcServerID $ olcSizeLimit $ "
792 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
794 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
795 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
796 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
797 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
798 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
799 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
800 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
802 "NAME 'olcSchemaConfig' "
803 "DESC 'OpenLDAP schema object' "
804 "SUP olcConfig STRUCTURAL "
805 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
806 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
807 Cft_Schema, NULL, cfAddSchema },
809 "NAME 'olcBackendConfig' "
810 "DESC 'OpenLDAP Backend-specific options' "
811 "SUP olcConfig STRUCTURAL "
812 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
814 "NAME 'olcDatabaseConfig' "
815 "DESC 'OpenLDAP Database-specific options' "
816 "SUP olcConfig STRUCTURAL "
818 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
819 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
820 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
821 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
822 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
823 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
824 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
826 Cft_Database, NULL, cfAddDatabase },
828 "NAME 'olcOverlayConfig' "
829 "DESC 'OpenLDAP Overlay-specific options' "
830 "SUP olcConfig STRUCTURAL "
831 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
833 "NAME 'olcIncludeFile' "
834 "DESC 'OpenLDAP configuration include file' "
835 "SUP olcConfig STRUCTURAL "
837 "MAY ( cn $ olcRootDSE ) )",
838 /* Used to be Cft_Include, that def has been removed */
839 Cft_Abstract, NULL, cfAddInclude },
840 /* This should be STRUCTURAL like all the other database classes, but
841 * that would mean inheriting all of the olcDatabaseConfig attributes,
842 * which causes them to be merged twice in config_build_entry.
845 "NAME 'olcFrontendConfig' "
846 "DESC 'OpenLDAP frontend configuration' "
848 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
849 Cft_Database, NULL, NULL },
852 "NAME 'olcModuleList' "
853 "DESC 'OpenLDAP dynamic module info' "
854 "SUP olcConfig STRUCTURAL "
855 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
856 Cft_Module, NULL, cfAddModule },
861 typedef struct ServerID {
862 struct ServerID *si_next;
863 struct berval si_url;
867 static ServerID *sid_list;
869 typedef struct voidList {
870 struct voidList *vl_next;
874 typedef struct ADlist {
875 struct ADlist *al_next;
876 AttributeDescription *al_desc;
879 static ADlist *sortVals;
882 config_generic(ConfigArgs *c) {
885 if ( c->op == SLAP_CONFIG_EMIT ) {
889 c->value_int = ldap_pvt_thread_get_concurrency();
892 c->value_int = connection_pool_max;
895 c->value_int = slap_tool_thread_max;
899 c->value_string = ch_strdup( passwd_salt );
904 if ( c->be->be_limits ) {
908 for ( i=0; c->be->be_limits[i]; i++ ) {
909 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
910 if ( bv.bv_len >= sizeof( buf ) ) {
911 ber_bvarray_free_x( c->rvalue_vals, NULL );
912 c->rvalue_vals = NULL;
916 bv.bv_val = buf + bv.bv_len;
917 limits_unparse( c->be->be_limits[i], &bv,
918 sizeof( buf ) - ( bv.bv_val - buf ) );
919 bv.bv_len += bv.bv_val - buf;
921 value_add_one( &c->rvalue_vals, &bv );
924 if ( !c->rvalue_vals ) rc = 1;
927 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
930 c->value_string = ch_strdup( slap_sasl_getpolicy());
933 slap_sasl_regexp_unparse( &c->rvalue_vals );
934 if ( !c->rvalue_vals ) rc = 1;
936 #ifdef HAVE_CYRUS_SASL
938 struct berval bv = BER_BVNULL;
939 slap_sasl_secprops_unparse( &bv );
940 if ( !BER_BVISNULL( &bv )) {
941 ber_bvarray_add( &c->rvalue_vals, &bv );
949 c->value_int = c->be->be_max_deref_depth;
952 if ( SLAP_DBHIDDEN( c->be )) {
959 ConfigFile *cf = c->ca_private;
961 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
962 else if ( cf->c_om_head )
963 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
965 if ( !c->rvalue_vals )
970 ad_unparse_options( &c->rvalue_vals );
973 ConfigFile *cf = c->ca_private;
975 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
976 else if ( cf->c_oc_head )
977 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
979 if ( !c->rvalue_vals )
984 ConfigFile *cf = c->ca_private;
986 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
987 else if ( cf->c_at_head )
988 at_unparse( &c->rvalue_vals, cf->c_at_head,
990 if ( !c->rvalue_vals )
995 ConfigFile *cf = c->ca_private;
997 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
998 else if ( cf->c_syn_head )
999 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1000 cf->c_syn_tail, 0 );
1001 if ( !c->rvalue_vals )
1006 ConfigFile *cf = c->ca_private;
1008 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1009 else if ( cf->c_cr_head )
1010 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1012 if ( !c->rvalue_vals )
1019 char *src, *dst, ibuf[11];
1020 struct berval bv, abv;
1021 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1022 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1023 if ( abv.bv_len >= sizeof( ibuf ) ) {
1024 ber_bvarray_free_x( c->rvalue_vals, NULL );
1025 c->rvalue_vals = NULL;
1029 acl_unparse( a, &bv );
1030 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1031 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1032 /* Turn TAB / EOL into plain space */
1033 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1034 if (isspace((unsigned char)*src)) *dst++ = ' ';
1038 if (dst[-1] == ' ') {
1042 abv.bv_len = dst - abv.bv_val;
1043 ber_bvarray_add( &c->rvalue_vals, &abv );
1049 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1052 ConfigFile *cf = c->ca_private;
1053 if ( cf->c_dseFiles ) {
1054 value_add( &c->rvalue_vals, cf->c_dseFiles );
1065 for ( si = sid_list; si; si=si->si_next ) {
1066 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1067 if ( !BER_BVISEMPTY( &si->si_url )) {
1068 bv.bv_len = si->si_url.bv_len + 6;
1069 bv.bv_val = ch_malloc( bv.bv_len );
1070 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1071 si->si_url.bv_val );
1072 ber_bvarray_add( &c->rvalue_vals, &bv );
1076 bv.bv_len = sprintf( buf, "%d", si->si_num );
1077 value_add_one( &c->rvalue_vals, &bv );
1086 c->value_string = ch_strdup( logfileName );
1091 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1093 case CFG_SYNC_SUBENTRY:
1094 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1096 case CFG_MIRRORMODE:
1097 if ( SLAP_SHADOW(c->be))
1098 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1102 case CFG_MONITORING:
1103 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1105 case CFG_SSTR_IF_MAX:
1106 c->value_uint = index_substr_if_maxlen;
1108 case CFG_SSTR_IF_MIN:
1109 c->value_uint = index_substr_if_minlen;
1112 c->value_int = index_intlen;
1114 case CFG_SORTVALS: {
1117 for ( sv = sortVals; sv; sv = sv->al_next ) {
1118 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1122 #ifdef SLAPD_MODULES
1124 ModPaths *mp = c->ca_private;
1127 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1130 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1131 SLAP_X_ORDERED_FMT "%s", i,
1132 mp->mp_loads[i].bv_val );
1133 if ( bv.bv_len >= sizeof( c->log ) ) {
1134 ber_bvarray_free_x( c->rvalue_vals, NULL );
1135 c->rvalue_vals = NULL;
1138 value_add_one( &c->rvalue_vals, &bv );
1142 rc = c->rvalue_vals ? 0 : 1;
1146 ModPaths *mp = c->ca_private;
1147 if ( !BER_BVISNULL( &mp->mp_path ))
1148 value_add_one( &c->rvalue_vals, &mp->mp_path );
1150 rc = c->rvalue_vals ? 0 : 1;
1156 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1157 if ( !c->rvalue_vals ) rc = 1;
1160 #ifdef SLAP_AUTH_REWRITE
1162 if ( authz_rewrites ) {
1163 struct berval bv, idx;
1168 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1169 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1170 if ( idx.bv_len >= sizeof( ibuf ) ) {
1171 ber_bvarray_free_x( c->rvalue_vals, NULL );
1172 c->rvalue_vals = NULL;
1175 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1176 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1177 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1178 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1179 authz_rewrites[i].bv_val,
1180 authz_rewrites[i].bv_len + 1 );
1181 ber_bvarray_add( &c->rvalue_vals, &bv );
1184 if ( !c->rvalue_vals ) rc = 1;
1191 } else if ( c->op == LDAP_MOD_DELETE ) {
1194 /* single-valued attrs, no-ops */
1202 case CFG_MIRRORMODE:
1203 case CFG_MONITORING:
1205 case CFG_SSTR_IF_MAX:
1206 case CFG_SSTR_IF_MIN:
1208 case CFG_SYNC_SUBENTRY:
1211 /* no-ops, requires slapd restart */
1216 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1220 ch_free( passwd_salt );
1225 ch_free( logfileName );
1233 case CFG_SERVERID: {
1234 ServerID *si, **sip;
1236 for ( i=0, si = sid_list, sip = &sid_list;
1237 si; si = *sip, i++ ) {
1238 if ( c->valx == -1 || i == c->valx ) {
1250 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1254 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1255 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1256 SLAP_INDEX_INTLEN_DEFAULT );
1260 if ( c->valx < 0 ) {
1261 acl_destroy( c->be->be_acl );
1262 c->be->be_acl = NULL;
1265 AccessControl **prev, *a;
1267 for (i=0, prev = &c->be->be_acl; i < c->valx;
1270 prev = &a->acl_next;
1273 *prev = a->acl_next;
1280 /* Can be NULL when undoing a failed add */
1281 if ( c->ca_entry ) {
1282 ce = c->ca_entry->e_private;
1283 /* can't modify the hardcoded schema */
1284 if ( ce->ce_parent->ce_type == Cft_Global )
1288 cfn = c->ca_private;
1289 if ( c->valx < 0 ) {
1292 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1294 if ( oc == cfn->c_oc_tail )
1297 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1299 ObjectClass *oc, *prev = NULL;
1301 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1306 if ( cfn->c_oc_tail == oc ) {
1307 cfn->c_oc_tail = prev;
1309 if ( cfn->c_oc_head == oc ) {
1311 cfn->c_oc_head = oc;
1318 /* Can be NULL when undoing a failed add */
1319 if ( c->ca_entry ) {
1320 ce = c->ca_entry->e_private;
1321 /* can't modify the hardcoded schema */
1322 if ( ce->ce_parent->ce_type == Cft_Global )
1326 cfn = c->ca_private;
1327 if ( c->valx < 0 ) {
1330 for( at = cfn->c_at_head; at; at_next( &at )) {
1332 if ( at == cfn->c_at_tail )
1335 cfn->c_at_head = cfn->c_at_tail = NULL;
1337 AttributeType *at, *prev = NULL;
1339 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1344 if ( cfn->c_at_tail == at ) {
1345 cfn->c_at_tail = prev;
1347 if ( cfn->c_at_head == at ) {
1349 cfn->c_at_head = at;
1356 /* Can be NULL when undoing a failed add */
1357 if ( c->ca_entry ) {
1358 ce = c->ca_entry->e_private;
1359 /* can't modify the hardcoded schema */
1360 if ( ce->ce_parent->ce_type == Cft_Global )
1364 cfn = c->ca_private;
1365 if ( c->valx < 0 ) {
1368 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1370 if ( syn == cfn->c_syn_tail )
1373 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1375 Syntax *syn, *prev = NULL;
1377 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1382 if ( cfn->c_syn_tail == syn ) {
1383 cfn->c_syn_tail = prev;
1385 if ( cfn->c_syn_head == syn ) {
1387 cfn->c_syn_head = syn;
1392 if ( c->valx < 0 ) {
1394 for ( sv = sortVals; sv; sv = sortVals ) {
1395 sortVals = sv->al_next;
1396 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1403 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1404 prev = &sv->al_next;
1407 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1408 *prev = sv->al_next;
1414 /* FIXME: there is no limits_free function */
1415 if ( c->valx < 0 ) {
1416 limits_destroy( c->be->be_limits );
1417 c->be->be_limits = NULL;
1422 if ( c->be->be_limits ) {
1423 for ( num = 0; c->be->be_limits[ num ]; num++ )
1427 if ( c->valx >= num ) {
1432 limits_destroy( c->be->be_limits );
1433 c->be->be_limits = NULL;
1436 limits_free_one( c->be->be_limits[ c->valx ] );
1438 for ( cnt = c->valx; cnt < num; cnt++ ) {
1439 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1446 /* FIXME: there is no ad_option_free function */
1448 /* FIXME: there is no way to remove attributes added by
1462 if(!(c->bi = backend_info(c->argv[1]))) {
1463 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1464 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1465 c->log, c->cr_msg, c->argv[1] );
1472 /* NOTE: config is always the first backend!
1474 if ( !strcasecmp( c->argv[1], "config" )) {
1475 c->be = LDAP_STAILQ_FIRST(&backendDB);
1476 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1479 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1481 if ( c->cr_msg[0] == 0 )
1482 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1483 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1490 ldap_pvt_thread_set_concurrency(c->value_int);
1494 if ( c->value_int < 2 ) {
1495 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1496 "threads=%d smaller than minimum value 2",
1498 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1499 c->log, c->cr_msg, 0 );
1502 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1503 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1504 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1505 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1506 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1507 c->log, c->cr_msg, 0 );
1509 if ( slapMode & SLAP_SERVER_MODE )
1510 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1511 connection_pool_max = c->value_int; /* save for reference */
1515 if ( slapMode & SLAP_TOOL_MODE )
1516 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1517 slap_tool_thread_max = c->value_int; /* save for reference */
1521 if ( passwd_salt ) ch_free( passwd_salt );
1522 passwd_salt = c->value_string;
1523 lutil_salt_format(passwd_salt);
1527 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1533 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1535 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1539 ch_free(c->value_string);
1540 if (slap_sasl_setpolicy( c->argv[1] )) {
1541 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1542 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1543 c->log, c->cr_msg, c->argv[1] );
1549 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1553 #ifdef HAVE_CYRUS_SASL
1556 char *txt = slap_sasl_secprops( c->argv[1] );
1558 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1560 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1568 c->be->be_max_deref_depth = c->value_int;
1574 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1575 cfn = c->ca_private;
1576 if(parse_oidm(c, 1, &om))
1578 if (!cfn->c_om_head) cfn->c_om_head = om;
1579 cfn->c_om_tail = om;
1584 ObjectClass *oc, *prev;
1586 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1587 cfn = c->ca_private;
1588 if ( c->valx < 0 ) {
1589 prev = cfn->c_oc_tail;
1592 /* If adding anything after the first, prev is easy */
1595 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1600 /* If adding the first, and head exists, find its prev */
1601 if (cfn->c_oc_head) {
1602 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1607 /* else prev is NULL, append to end of global list */
1609 if(parse_oc(c, &oc, prev)) return(1);
1610 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1611 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1616 AttributeType *at, *prev;
1618 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1619 cfn = c->ca_private;
1620 if ( c->valx < 0 ) {
1621 prev = cfn->c_at_tail;
1624 /* If adding anything after the first, prev is easy */
1627 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1632 /* If adding the first, and head exists, find its prev */
1633 if (cfn->c_at_head) {
1634 for ( at_start( &at ); at != cfn->c_at_head; ) {
1639 /* else prev is NULL, append to end of global list */
1641 if(parse_at(c, &at, prev)) return(1);
1642 if (!cfn->c_at_head) cfn->c_at_head = at;
1643 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1650 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1651 cfn = c->ca_private;
1652 if ( c->valx < 0 ) {
1653 prev = cfn->c_syn_tail;
1656 /* If adding anything after the first, prev is easy */
1659 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1664 /* If adding the first, and head exists, find its prev */
1665 if (cfn->c_syn_head) {
1666 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1671 /* else prev is NULL, append to end of global list */
1673 if ( parse_syn( c, &syn, prev ) ) return(1);
1674 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1675 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1682 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1683 cfn = c->ca_private;
1684 if(parse_cr(c, &cr)) return(1);
1685 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1686 cfn->c_cr_tail = cr;
1691 ad_define_option(NULL, NULL, 0);
1692 for(i = 1; i < c->argc; i++)
1693 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1698 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1699 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1700 else if ( c->value_int > 255 )
1702 index_intlen = c->value_int;
1703 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1707 case CFG_SORTVALS: {
1708 ADlist *svnew = NULL, *svtail, *sv;
1710 for ( i = 1; i < c->argc; i++ ) {
1711 AttributeDescription *ad = NULL;
1715 rc = slap_str2ad( c->argv[i], &ad, &text );
1717 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1720 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1721 c->log, c->cr_msg, c->argv[i] );
1722 for ( sv = svnew; sv; sv = svnew ) {
1723 svnew = sv->al_next;
1728 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1729 ad->ad_type->sat_single_value ) {
1730 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1732 goto sortval_reject;
1734 sv = ch_malloc( sizeof( ADlist ));
1739 svtail->al_next = sv;
1744 for ( sv = svnew; sv; sv = sv->al_next )
1745 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1746 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1748 sv->al_next = svnew;
1755 /* Don't append to the global ACL if we're on a specific DB */
1757 if ( c->valx == -1 ) {
1760 for ( a=c->be->be_acl; a; a = a->acl_next )
1763 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1770 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1772 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1776 if(root_dse_read_file(c->argv[1])) {
1777 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1778 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1779 c->log, c->cr_msg, c->argv[1] );
1784 ber_str2bv( c->argv[1], 0, 1, &bv );
1785 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1786 cfn = c->ca_private;
1787 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1793 ServerID *si, **sip;
1796 if (( lutil_atoi( &num, c->argv[1] ) &&
1797 lutil_atoix( &num, c->argv[1], 16 )) ||
1798 num < 0 || num > SLAP_SYNC_SID_MAX )
1800 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1801 "<%s> illegal server ID", c->argv[0] );
1802 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1803 c->log, c->cr_msg, c->argv[1] );
1806 /* only one value allowed if no URL is given */
1807 if ( c->argc > 2 ) {
1810 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1811 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1812 "<%s> only one server ID allowed now", c->argv[0] );
1813 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1814 c->log, c->cr_msg, c->argv[1] );
1818 if ( ldap_url_parse( c->argv[2], &lud )) {
1819 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1820 "<%s> invalid URL", c->argv[0] );
1821 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1822 c->log, c->cr_msg, c->argv[2] );
1825 len = strlen( c->argv[2] );
1826 si = ch_malloc( sizeof(ServerID) + len + 1 );
1827 si->si_url.bv_val = (char *)(si+1);
1828 si->si_url.bv_len = len;
1829 strcpy( si->si_url.bv_val, c->argv[2] );
1832 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1833 "<%s> unqualified server ID not allowed now", c->argv[0] );
1834 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1835 c->log, c->cr_msg, c->argv[1] );
1838 si = ch_malloc( sizeof(ServerID) );
1839 BER_BVZERO( &si->si_url );
1840 slap_serverID = num;
1841 Debug( LDAP_DEBUG_CONFIG,
1843 c->log, slap_serverID, 0 );
1847 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1850 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1851 Listener *l = config_check_my_url( c->argv[2], lud );
1853 slap_serverID = si->si_num;
1854 Debug( LDAP_DEBUG_CONFIG,
1855 "%s: SID=0x%03x (listener=%s)\n",
1856 c->log, slap_serverID,
1861 ldap_free_urldesc( lud );
1865 if ( logfileName ) ch_free( logfileName );
1866 logfileName = c->value_string;
1867 logfile = fopen(logfileName, "w");
1868 if(logfile) lutil_debug_file(logfile);
1872 if(SLAP_NOLASTMODCMD(c->be)) {
1873 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1874 c->argv[0], c->be->bd_info->bi_type );
1875 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1876 c->log, c->cr_msg, 0 );
1880 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1882 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1885 case CFG_MIRRORMODE:
1886 if(c->value_int && !SLAP_SHADOW(c->be)) {
1887 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1889 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1890 c->log, c->cr_msg, 0 );
1894 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1896 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1899 case CFG_MONITORING:
1901 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1903 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1908 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1910 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1913 case CFG_SYNC_SUBENTRY:
1915 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1917 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1920 case CFG_SSTR_IF_MAX:
1921 if (c->value_uint < index_substr_if_minlen) {
1922 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1923 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1924 c->log, c->cr_msg, c->value_int );
1927 index_substr_if_maxlen = c->value_uint;
1930 case CFG_SSTR_IF_MIN:
1931 if (c->value_uint > index_substr_if_maxlen) {
1932 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1933 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1934 c->log, c->cr_msg, c->value_int );
1937 index_substr_if_minlen = c->value_uint;
1940 #ifdef SLAPD_MODULES
1942 /* If we're just adding a module on an existing modpath,
1943 * make sure we've selected the current path.
1945 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1946 modcur = c->ca_private;
1947 /* This should never fail */
1948 if ( module_path( modcur->mp_path.bv_val )) {
1949 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1951 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1952 c->log, c->cr_msg, modcur->mp_path.bv_val );
1956 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1958 /* Record this load on the current path */
1962 if ( c->op == SLAP_CONFIG_ADD ) {
1963 ptr = c->line + STRLENOF("moduleload");
1964 while (!isspace((unsigned char) *ptr)) ptr++;
1965 while (isspace((unsigned char) *ptr)) ptr++;
1969 ber_str2bv(ptr, 0, 1, &bv);
1970 ber_bvarray_add( &modcur->mp_loads, &bv );
1972 /* Check for any new hardcoded schema */
1973 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1974 config_check_schema( NULL, &cfBackInfo );
1979 if(module_path(c->argv[1])) return(1);
1980 /* Record which path was used with each module */
1984 if (!modpaths.mp_loads) {
1987 mp = ch_malloc( sizeof( ModPaths ));
1988 modlast->mp_next = mp;
1990 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1992 mp->mp_loads = NULL;
2003 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2005 slapi_plugins_used++;
2009 #ifdef SLAP_AUTH_REWRITE
2015 if ( c->op == LDAP_MOD_ADD ) {
2019 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2023 if ( c->argc > 1 ) {
2026 /* quote all args but the first */
2027 line = ldap_charray2str( c->argv, "\" \"" );
2028 ber_str2bv( line, 0, 0, &bv );
2029 s = ber_bvchr( &bv, '"' );
2030 assert( s != NULL );
2031 /* move the trailing quote of argv[0] to the end */
2032 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2033 bv.bv_val[ bv.bv_len - 1 ] = '"';
2036 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2039 ber_bvarray_add( &authz_rewrites, &bv );
2041 if ( c->op == LDAP_MOD_ADD ) {
2051 Debug( LDAP_DEBUG_ANY,
2052 "%s: unknown CFG_TYPE %d.\n",
2053 c->log, c->type, 0 );
2062 config_fname(ConfigArgs *c) {
2063 if(c->op == SLAP_CONFIG_EMIT) {
2064 if (c->ca_private) {
2065 ConfigFile *cf = c->ca_private;
2066 value_add_one( &c->rvalue_vals, &cf->c_file );
2075 config_cfdir(ConfigArgs *c) {
2076 if(c->op == SLAP_CONFIG_EMIT) {
2077 if ( !BER_BVISEMPTY( &cfdir )) {
2078 value_add_one( &c->rvalue_vals, &cfdir );
2087 config_search_base(ConfigArgs *c) {
2088 if(c->op == SLAP_CONFIG_EMIT) {
2090 if (!BER_BVISEMPTY(&default_search_base)) {
2091 value_add_one(&c->rvalue_vals, &default_search_base);
2092 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2096 } else if( c->op == LDAP_MOD_DELETE ) {
2097 ch_free( default_search_base.bv_val );
2098 ch_free( default_search_nbase.bv_val );
2099 BER_BVZERO( &default_search_base );
2100 BER_BVZERO( &default_search_nbase );
2104 if(c->bi || c->be != frontendDB) {
2105 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2106 "prior to any backend or database definition\n",
2111 if(default_search_nbase.bv_len) {
2112 free(default_search_base.bv_val);
2113 free(default_search_nbase.bv_val);
2116 default_search_base = c->value_dn;
2117 default_search_nbase = c->value_ndn;
2121 /* For RE23 compatibility we allow this in the global entry
2122 * but we now defer it to the frontend entry to allow modules
2123 * to load new hash types.
2126 config_passwd_hash(ConfigArgs *c) {
2128 if (c->op == SLAP_CONFIG_EMIT) {
2130 /* Don't generate it in the global entry */
2131 if ( c->table == Cft_Global )
2133 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2134 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2135 value_add_one(&c->rvalue_vals, &bv);
2138 } else if ( c->op == LDAP_MOD_DELETE ) {
2139 /* Deleting from global is a no-op, only the frontendDB entry matters */
2140 if ( c->table == Cft_Global )
2142 if ( c->valx < 0 ) {
2143 ldap_charray_free( default_passwd_hash );
2144 default_passwd_hash = NULL;
2147 ch_free( default_passwd_hash[i] );
2148 for (; default_passwd_hash[i]; i++ )
2149 default_passwd_hash[i] = default_passwd_hash[i+1];
2153 for(i = 1; i < c->argc; i++) {
2154 if(!lutil_passwd_scheme(c->argv[i])) {
2155 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2156 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2157 c->log, c->cr_msg, c->argv[i]);
2159 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2162 if(!default_passwd_hash) {
2163 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2164 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2165 c->log, c->cr_msg, 0 );
2172 config_schema_dn(ConfigArgs *c) {
2173 if ( c->op == SLAP_CONFIG_EMIT ) {
2175 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2176 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2177 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2181 } else if ( c->op == LDAP_MOD_DELETE ) {
2182 ch_free( c->be->be_schemadn.bv_val );
2183 ch_free( c->be->be_schemandn.bv_val );
2184 BER_BVZERO( &c->be->be_schemadn );
2185 BER_BVZERO( &c->be->be_schemandn );
2188 ch_free( c->be->be_schemadn.bv_val );
2189 ch_free( c->be->be_schemandn.bv_val );
2190 c->be->be_schemadn = c->value_dn;
2191 c->be->be_schemandn = c->value_ndn;
2196 config_sizelimit(ConfigArgs *c) {
2198 struct slap_limits_set *lim = &c->be->be_def_limit;
2199 if (c->op == SLAP_CONFIG_EMIT) {
2204 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2205 if ( !BER_BVISEMPTY( &bv ))
2206 value_add_one( &c->rvalue_vals, &bv );
2210 } else if ( c->op == LDAP_MOD_DELETE ) {
2211 /* Reset to defaults or values from frontend */
2212 if ( c->be == frontendDB ) {
2213 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2214 lim->lms_s_hard = 0;
2215 lim->lms_s_unchecked = -1;
2217 lim->lms_s_pr_hide = 0;
2218 lim->lms_s_pr_total = 0;
2220 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2221 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2222 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2223 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2224 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2225 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2229 for(i = 1; i < c->argc; i++) {
2230 if(!strncasecmp(c->argv[i], "size", 4)) {
2231 rc = limits_parse_one(c->argv[i], lim);
2233 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2234 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2235 c->log, c->cr_msg, c->argv[i]);
2239 if(!strcasecmp(c->argv[i], "unlimited")) {
2240 lim->lms_s_soft = -1;
2242 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2243 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2244 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2245 c->log, c->cr_msg, c->argv[i]);
2249 lim->lms_s_hard = 0;
2254 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2255 /* This is a modification to the global limits apply it to
2256 * the other databases as needed */
2257 AttributeDescription *ad=NULL;
2258 const char *text = NULL;
2259 slap_str2ad(c->argv[0], &ad, &text);
2260 /* if we got here... */
2261 assert( ad != NULL );
2263 CfEntryInfo *ce = c->ca_entry->e_private;
2264 if ( ce->ce_type == Cft_Global ){
2267 for (; ce; ce=ce->ce_sibs) {
2268 Entry *dbe = ce->ce_entry;
2269 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2270 && (!attr_find(dbe->e_attrs, ad)) ) {
2271 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2272 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2273 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2274 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2275 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2276 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2284 config_timelimit(ConfigArgs *c) {
2286 struct slap_limits_set *lim = &c->be->be_def_limit;
2287 if (c->op == SLAP_CONFIG_EMIT) {
2292 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2293 if ( !BER_BVISEMPTY( &bv ))
2294 value_add_one( &c->rvalue_vals, &bv );
2298 } else if ( c->op == LDAP_MOD_DELETE ) {
2299 /* Reset to defaults */
2300 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2301 lim->lms_t_hard = 0;
2304 for(i = 1; i < c->argc; i++) {
2305 if(!strncasecmp(c->argv[i], "time", 4)) {
2306 rc = limits_parse_one(c->argv[i], lim);
2308 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2309 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2310 c->log, c->cr_msg, c->argv[i]);
2314 if(!strcasecmp(c->argv[i], "unlimited")) {
2315 lim->lms_t_soft = -1;
2317 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2318 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2319 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2320 c->log, c->cr_msg, c->argv[i]);
2324 lim->lms_t_hard = 0;
2331 config_overlay(ConfigArgs *c) {
2332 if (c->op == SLAP_CONFIG_EMIT) {
2334 } else if ( c->op == LDAP_MOD_DELETE ) {
2337 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2338 c->valx, &c->bi, &c->reply)) {
2340 Debug( LDAP_DEBUG_ANY,
2341 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2342 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2344 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2351 config_subordinate(ConfigArgs *c)
2357 case SLAP_CONFIG_EMIT:
2358 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2361 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2362 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2365 value_add_one( &c->rvalue_vals, &bv );
2369 case LDAP_MOD_DELETE:
2370 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2371 glue_sub_del( c->be );
2373 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2378 case SLAP_CONFIG_ADD:
2379 if ( c->be->be_nsuffix == NULL ) {
2381 snprintf( c->cr_msg, sizeof( c->cr_msg),
2382 "subordinate configuration needs a suffix" );
2383 Debug( LDAP_DEBUG_ANY,
2385 c->log, c->cr_msg, 0 );
2390 if ( c->argc == 2 ) {
2391 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2394 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2396 snprintf( c->cr_msg, sizeof( c->cr_msg),
2397 "subordinate must be \"TRUE\" or \"advertise\"" );
2398 Debug( LDAP_DEBUG_ANY,
2399 "%s: suffix \"%s\": %s.\n",
2400 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2406 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2414 * [listener=<listener>] [{read|write}=]<size>
2417 #ifdef LDAP_TCP_BUFFER
2418 static BerVarray tcp_buffer;
2421 #define SLAP_TCP_RMEM (0x1U)
2422 #define SLAP_TCP_WMEM (0x2U)
2425 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2426 int *size, int *rw, Listener **l )
2428 int i, rc = LDAP_SUCCESS;
2429 LDAPURLDesc *lud = NULL;
2432 if ( val != NULL && argv == NULL ) {
2433 char *s = val->bv_val;
2435 argv = ldap_str2charray( s, " \t" );
2436 if ( argv == NULL ) {
2442 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2445 char *url = argv[ i ] + STRLENOF( "listener=" );
2447 if ( ldap_url_parse( url, &lud ) ) {
2448 rc = LDAP_INVALID_SYNTAX;
2452 *l = config_check_my_url( url, lud );
2454 rc = LDAP_NO_SUCH_ATTRIBUTE;
2462 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2463 *rw |= SLAP_TCP_RMEM;
2464 ptr += STRLENOF( "read=" );
2466 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2467 *rw |= SLAP_TCP_WMEM;
2468 ptr += STRLENOF( "write=" );
2471 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2474 /* accept any base */
2475 if ( lutil_atoix( size, ptr, 0 ) ) {
2476 rc = LDAP_INVALID_SYNTAX;
2481 if ( val != NULL && argv != NULL ) {
2482 ldap_charray_free( argv );
2485 if ( lud != NULL ) {
2486 ldap_free_urldesc( lud );
2493 tcp_buffer_delete_one( struct berval *val )
2496 int size = -1, rw = 0;
2499 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2506 Listener **ll = slapd_get_listeners();
2508 for ( i = 0; ll[ i ] != NULL; i++ ) {
2509 if ( ll[ i ] == l ) break;
2512 if ( ll[ i ] == NULL ) {
2513 return LDAP_NO_SUCH_ATTRIBUTE;
2516 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2517 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2519 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2520 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2521 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2525 /* NOTE: this affects listeners without a specific setting,
2526 * does not reset all listeners. If a listener without
2527 * specific settings was assigned a buffer because of
2528 * a global setting, it will not be reset. In any case,
2529 * buffer changes will only take place at restart. */
2530 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2531 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2538 tcp_buffer_delete( BerVarray vals )
2542 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2543 tcp_buffer_delete_one( &vals[ i ] );
2550 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2552 char buf[sizeof("2147483648")], *ptr;
2554 /* unparse for later use */
2555 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2557 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2560 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2561 if ( rw & SLAP_TCP_RMEM ) {
2562 val->bv_len += STRLENOF( "read=" );
2563 } else if ( rw & SLAP_TCP_WMEM ) {
2564 val->bv_len += STRLENOF( "write=" );
2568 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2573 ptr = lutil_strcopy( ptr, "listener=" );
2574 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2578 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2579 if ( rw & SLAP_TCP_RMEM ) {
2580 ptr = lutil_strcopy( ptr, "read=" );
2581 } else if ( rw & SLAP_TCP_WMEM ) {
2582 ptr = lutil_strcopy( ptr, "write=" );
2586 ptr = lutil_strcopy( ptr, buf );
2589 assert( val->bv_val + val->bv_len == ptr );
2591 return LDAP_SUCCESS;
2595 tcp_buffer_add_one( int argc, char **argv )
2598 int size = -1, rw = 0;
2604 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2609 /* unparse for later use */
2610 rc = tcp_buffer_unparse( size, rw, l, &val );
2611 if ( rc != LDAP_SUCCESS ) {
2615 /* use parsed values */
2618 Listener **ll = slapd_get_listeners();
2620 for ( i = 0; ll[ i ] != NULL; i++ ) {
2621 if ( ll[ i ] == l ) break;
2624 if ( ll[ i ] == NULL ) {
2625 return LDAP_NO_SUCH_ATTRIBUTE;
2628 /* buffer only applies to TCP listeners;
2629 * we do not do any check here, and delegate them
2630 * to setsockopt(2) */
2631 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2632 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2634 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2635 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2636 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2640 /* NOTE: this affects listeners without a specific setting,
2641 * does not set all listeners */
2642 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2643 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2646 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2648 tcp_buffer[ tcp_buffer_num ] = val;
2651 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2657 config_tcp_buffer( ConfigArgs *c )
2659 if ( c->op == SLAP_CONFIG_EMIT ) {
2660 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2663 value_add( &c->rvalue_vals, tcp_buffer );
2664 value_add( &c->rvalue_nvals, tcp_buffer );
2666 } else if ( c->op == LDAP_MOD_DELETE ) {
2668 tcp_buffer_delete( tcp_buffer );
2669 ber_bvarray_free( tcp_buffer );
2675 int size = -1, rw = 0;
2678 struct berval val = BER_BVNULL;
2682 if ( tcp_buffer_num == 0 ) {
2687 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2692 /* unparse for later use */
2693 rc = tcp_buffer_unparse( size, rw, l, &val );
2694 if ( rc != LDAP_SUCCESS ) {
2698 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2699 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2704 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2710 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2711 ber_memfree( tcp_buffer[ i ].bv_val );
2712 for ( ; i < tcp_buffer_num; i++ ) {
2713 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2718 if ( !BER_BVISNULL( &val ) ) {
2719 SLAP_FREE( val.bv_val );
2727 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2729 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2730 "<%s> unable to add value #%d",
2731 c->argv[0], tcp_buffer_num );
2732 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2733 c->log, c->cr_msg, 0 );
2740 #endif /* LDAP_TCP_BUFFER */
2743 config_suffix(ConfigArgs *c)
2746 struct berval pdn, ndn;
2747 char *notallowed = NULL;
2749 if ( c->be == frontendDB ) {
2750 notallowed = "frontend";
2752 } else if ( SLAP_MONITOR(c->be) ) {
2753 notallowed = "monitor";
2755 } else if ( SLAP_CONFIG(c->be) ) {
2756 notallowed = "config";
2759 if ( notallowed != NULL ) {
2760 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2764 case LDAP_MOD_DELETE:
2765 case LDAP_MOD_REPLACE:
2766 case LDAP_MOD_INCREMENT:
2767 case SLAP_CONFIG_ADD:
2768 if ( !BER_BVISNULL( &c->value_dn ) ) {
2769 snprintf( buf, sizeof( buf ), "<%s> ",
2770 c->value_dn.bv_val );
2773 Debug(LDAP_DEBUG_ANY,
2774 "%s: suffix %snot allowed in %s database.\n",
2775 c->log, buf, notallowed );
2778 case SLAP_CONFIG_EMIT:
2779 /* don't complain when emitting... */
2783 /* FIXME: don't know what values may be valid;
2784 * please remove assertion, or add legal values
2785 * to either block */
2793 if (c->op == SLAP_CONFIG_EMIT) {
2794 if ( c->be->be_suffix == NULL
2795 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2799 value_add( &c->rvalue_vals, c->be->be_suffix );
2800 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2803 } else if ( c->op == LDAP_MOD_DELETE ) {
2804 if ( c->valx < 0 ) {
2805 ber_bvarray_free( c->be->be_suffix );
2806 ber_bvarray_free( c->be->be_nsuffix );
2807 c->be->be_suffix = NULL;
2808 c->be->be_nsuffix = NULL;
2811 ch_free( c->be->be_suffix[i].bv_val );
2812 ch_free( c->be->be_nsuffix[i].bv_val );
2814 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2815 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2817 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2822 #ifdef SLAPD_MONITOR_DN
2823 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2824 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2826 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2827 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2832 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2833 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2834 c->argv[0], c->be->bd_info->bi_type );
2835 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2836 c->log, c->cr_msg, 0);
2843 if (SLAP_DBHIDDEN( c->be ))
2846 tbe = select_backend(&ndn, 0);
2848 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2854 BackendDB *b2 = tbe;
2856 /* Does tbe precede be? */
2857 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2860 char *type = tbe->bd_info->bi_type;
2862 if ( overlay_is_over( tbe ) ) {
2863 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2864 type = oi->oi_orig->bi_type;
2867 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2868 "already served by a preceding %s database",
2869 c->argv[0], pdn.bv_val, type );
2870 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2871 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2877 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2878 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2879 "base provided \"%s\" (assuming okay)\n",
2880 c->log, default_search_base.bv_val, 0);
2882 ber_bvarray_add(&c->be->be_suffix, &pdn);
2883 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2888 config_rootdn(ConfigArgs *c) {
2889 if (c->op == SLAP_CONFIG_EMIT) {
2890 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2891 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2892 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2897 } else if ( c->op == LDAP_MOD_DELETE ) {
2898 ch_free( c->be->be_rootdn.bv_val );
2899 ch_free( c->be->be_rootndn.bv_val );
2900 BER_BVZERO( &c->be->be_rootdn );
2901 BER_BVZERO( &c->be->be_rootndn );
2904 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2905 ch_free( c->be->be_rootdn.bv_val );
2906 ch_free( c->be->be_rootndn.bv_val );
2908 c->be->be_rootdn = c->value_dn;
2909 c->be->be_rootndn = c->value_ndn;
2914 config_rootpw(ConfigArgs *c) {
2917 if (c->op == SLAP_CONFIG_EMIT) {
2918 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2919 /* don't copy, because "rootpw" is marked
2921 c->value_bv = c->be->be_rootpw;
2925 } else if ( c->op == LDAP_MOD_DELETE ) {
2926 ch_free( c->be->be_rootpw.bv_val );
2927 BER_BVZERO( &c->be->be_rootpw );
2931 tbe = select_backend(&c->be->be_rootndn, 0);
2933 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2935 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2936 c->log, c->cr_msg, 0);
2939 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2940 ch_free( c->be->be_rootpw.bv_val );
2941 c->be->be_rootpw = c->value_bv;
2946 config_restrict(ConfigArgs *c) {
2947 slap_mask_t restrictops = 0;
2949 slap_verbmasks restrictable_ops[] = {
2950 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2951 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2952 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2953 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2954 { BER_BVC("modrdn"), 0 },
2955 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2956 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2957 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2958 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2959 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2960 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2961 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2962 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2963 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2964 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2965 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2969 if (c->op == SLAP_CONFIG_EMIT) {
2970 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2972 } else if ( c->op == LDAP_MOD_DELETE ) {
2974 c->be->be_restrictops = 0;
2976 restrictops = verb_to_mask( c->line, restrictable_ops );
2977 c->be->be_restrictops ^= restrictops;
2981 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2983 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2984 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2985 c->log, c->cr_msg, c->argv[i]);
2988 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2989 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2990 c->be->be_restrictops |= restrictops;
2995 config_allows(ConfigArgs *c) {
2996 slap_mask_t allows = 0;
2998 slap_verbmasks allowable_ops[] = {
2999 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3000 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3001 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3002 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3003 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3006 if (c->op == SLAP_CONFIG_EMIT) {
3007 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3008 } else if ( c->op == LDAP_MOD_DELETE ) {
3012 allows = verb_to_mask( c->line, allowable_ops );
3013 global_allows ^= allows;
3017 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3019 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3020 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3021 c->log, c->cr_msg, c->argv[i]);
3024 global_allows |= allows;
3029 config_disallows(ConfigArgs *c) {
3030 slap_mask_t disallows = 0;
3032 slap_verbmasks disallowable_ops[] = {
3033 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3034 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3035 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3036 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3037 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3038 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3041 if (c->op == SLAP_CONFIG_EMIT) {
3042 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3043 } else if ( c->op == LDAP_MOD_DELETE ) {
3045 global_disallows = 0;
3047 disallows = verb_to_mask( c->line, disallowable_ops );
3048 global_disallows ^= disallows;
3052 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3054 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3055 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3056 c->log, c->cr_msg, c->argv[i]);
3059 global_disallows |= disallows;
3064 config_requires(ConfigArgs *c) {
3065 slap_mask_t requires = frontendDB->be_requires;
3066 int i, argc = c->argc;
3067 char **argv = c->argv;
3069 slap_verbmasks requires_ops[] = {
3070 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3071 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3072 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3073 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3074 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3077 if (c->op == SLAP_CONFIG_EMIT) {
3078 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3079 } else if ( c->op == LDAP_MOD_DELETE ) {
3081 c->be->be_requires = 0;
3083 requires = verb_to_mask( c->line, requires_ops );
3084 c->be->be_requires ^= requires;
3088 /* "none" can only be first, to wipe out default/global values */
3089 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3094 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3096 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3097 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3098 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3099 c->log, c->cr_msg, 0);
3101 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3102 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3103 c->log, c->cr_msg, c->argv[i]);
3107 c->be->be_requires = requires;
3111 static slap_verbmasks *loglevel_ops;
3114 loglevel_init( void )
3116 slap_verbmasks lo[] = {
3117 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3118 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3119 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3120 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3121 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3122 { BER_BVC("BER"), LDAP_DEBUG_BER },
3123 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3124 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3125 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3126 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3127 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3128 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3129 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3130 #if 0 /* no longer used (nor supported) */
3131 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3132 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3134 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3135 { BER_BVC("None"), LDAP_DEBUG_NONE },
3139 return slap_verbmasks_init( &loglevel_ops, lo );
3143 loglevel_destroy( void )
3145 if ( loglevel_ops ) {
3146 (void)slap_verbmasks_destroy( loglevel_ops );
3148 loglevel_ops = NULL;
3151 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3154 slap_loglevel_register( slap_mask_t m, struct berval *s )
3158 if ( loglevel_ops == NULL ) {
3162 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3165 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3173 slap_loglevel_get( struct berval *s, int *l )
3178 if ( loglevel_ops == NULL ) {
3182 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3183 m |= loglevel_ops[ i ].mask;
3186 for ( i = 1; m & i; i <<= 1 )
3193 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3196 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3207 str2loglevel( const char *s, int *l )
3211 if ( loglevel_ops == NULL ) {
3215 i = verb_to_mask( s, loglevel_ops );
3217 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3221 *l = loglevel_ops[ i ].mask;
3227 loglevel2str( int l )
3229 struct berval bv = BER_BVNULL;
3231 loglevel2bv( l, &bv );
3237 loglevel2bv( int l, struct berval *bv )
3239 if ( loglevel_ops == NULL ) {
3245 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3249 loglevel2bvarray( int l, BerVarray *bva )
3251 if ( loglevel_ops == NULL ) {
3255 return mask_to_verbs( loglevel_ops, l, bva );
3259 loglevel_print( FILE *out )
3263 if ( loglevel_ops == NULL ) {
3267 fprintf( out, "Installed log subsystems:\n\n" );
3268 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3269 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3271 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3272 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3273 loglevel_ops[ i ].word.bv_val, mask, mask );
3276 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3277 "by specific code\n\n" );
3282 static int config_syslog;
3285 config_loglevel(ConfigArgs *c) {
3288 if ( loglevel_ops == NULL ) {
3292 if (c->op == SLAP_CONFIG_EMIT) {
3293 /* Get default or commandline slapd setting */
3294 if ( ldap_syslog && !config_syslog )
3295 config_syslog = ldap_syslog;
3296 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3298 } else if ( c->op == LDAP_MOD_DELETE ) {
3302 int level = verb_to_mask( c->line, loglevel_ops );
3303 config_syslog ^= level;
3305 if ( slapMode & SLAP_SERVER_MODE ) {
3306 ldap_syslog = config_syslog;
3311 for( i=1; i < c->argc; i++ ) {
3314 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3315 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3316 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3317 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3318 c->log, c->cr_msg, c->argv[i]);
3322 if ( str2loglevel( c->argv[i], &level ) ) {
3323 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3324 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3325 c->log, c->cr_msg, c->argv[i]);
3329 /* Explicitly setting a zero clears all the levels */
3331 config_syslog |= level;
3335 if ( slapMode & SLAP_SERVER_MODE ) {
3336 ldap_syslog = config_syslog;
3342 config_referral(ConfigArgs *c) {
3344 if (c->op == SLAP_CONFIG_EMIT) {
3345 if ( default_referral ) {
3346 value_add( &c->rvalue_vals, default_referral );
3351 } else if ( c->op == LDAP_MOD_DELETE ) {
3352 if ( c->valx < 0 ) {
3353 ber_bvarray_free( default_referral );
3354 default_referral = NULL;
3357 ch_free( default_referral[i].bv_val );
3358 for (; default_referral[i].bv_val; i++ )
3359 default_referral[i] = default_referral[i+1];
3363 if(validate_global_referral(c->argv[1])) {
3364 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3365 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3366 c->log, c->cr_msg, c->argv[1]);
3370 ber_str2bv(c->argv[1], 0, 0, &val);
3371 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3379 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3380 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3381 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3382 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3383 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3384 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3385 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3386 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3387 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3392 config_security(ConfigArgs *c) {
3393 slap_ssf_set_t *set = &c->be->be_ssf_set;
3396 if (c->op == SLAP_CONFIG_EMIT) {
3402 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3403 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3406 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3407 if ( bv.bv_len >= sizeof( numbuf ) ) {
3408 ber_bvarray_free_x( c->rvalue_vals, NULL );
3409 c->rvalue_vals = NULL;
3413 bv.bv_len += sec_keys[i].key.bv_len;
3414 bv.bv_val = ch_malloc( bv.bv_len + 1);
3415 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3416 strcpy( next, numbuf );
3417 ber_bvarray_add( &c->rvalue_vals, &bv );
3422 for(i = 1; i < c->argc; i++) {
3423 slap_ssf_t *tgt = NULL;
3425 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3426 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3427 sec_keys[j].key.bv_len)) {
3428 src = c->argv[i] + sec_keys[j].key.bv_len;
3429 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3434 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3435 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3436 c->log, c->cr_msg, c->argv[i]);
3440 if ( lutil_atou( tgt, src ) != 0 ) {
3441 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3442 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3443 c->log, c->cr_msg, c->argv[i]);
3451 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3455 for (; !BER_BVISNULL( &an->an_name ); an++) {
3456 /* if buflen == 0, assume the buffer size has been
3457 * already checked otherwise */
3458 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3459 if ( comma ) *ptr++ = ',';
3460 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3467 config_updatedn(ConfigArgs *c) {
3468 if (c->op == SLAP_CONFIG_EMIT) {
3469 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3470 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3471 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3475 } else if ( c->op == LDAP_MOD_DELETE ) {
3476 ch_free( c->be->be_update_ndn.bv_val );
3477 BER_BVZERO( &c->be->be_update_ndn );
3478 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3481 if(SLAP_SHADOW(c->be)) {
3482 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3483 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3484 c->log, c->cr_msg, 0);
3488 ber_memfree_x( c->value_dn.bv_val, NULL );
3489 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3490 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3492 c->be->be_update_ndn = c->value_ndn;
3493 BER_BVZERO( &c->value_dn );
3494 BER_BVZERO( &c->value_ndn );
3496 return config_slurp_shadow( c );
3500 config_shadow( ConfigArgs *c, slap_mask_t flag )
3502 char *notallowed = NULL;
3504 if ( c->be == frontendDB ) {
3505 notallowed = "frontend";
3507 } else if ( SLAP_MONITOR(c->be) ) {
3508 notallowed = "monitor";
3511 if ( notallowed != NULL ) {
3512 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3516 if ( SLAP_SHADOW(c->be) ) {
3517 /* if already shadow, only check consistency */
3518 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3519 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3525 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3532 config_updateref(ConfigArgs *c) {
3534 if (c->op == SLAP_CONFIG_EMIT) {
3535 if ( c->be->be_update_refs ) {
3536 value_add( &c->rvalue_vals, c->be->be_update_refs );
3541 } else if ( c->op == LDAP_MOD_DELETE ) {
3542 if ( c->valx < 0 ) {
3543 ber_bvarray_free( c->be->be_update_refs );
3544 c->be->be_update_refs = NULL;
3547 ch_free( c->be->be_update_refs[i].bv_val );
3548 for (; c->be->be_update_refs[i].bv_val; i++)
3549 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3553 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3554 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3556 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3557 c->log, c->cr_msg, 0);
3561 if(validate_global_referral(c->argv[1])) {
3562 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3563 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3564 c->log, c->cr_msg, c->argv[1]);
3567 ber_str2bv(c->argv[1], 0, 0, &val);
3568 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3573 config_obsolete(ConfigArgs *c) {
3574 if (c->op == SLAP_CONFIG_EMIT)
3577 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3579 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3584 config_include(ConfigArgs *c) {
3585 int savelineno = c->lineno;
3588 ConfigFile *cfsave = cfn;
3589 ConfigFile *cf2 = NULL;
3591 /* Leftover from RE23. No dynamic config for include files */
3592 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3595 cf = ch_calloc( 1, sizeof(ConfigFile));
3596 if ( cfn->c_kids ) {
3597 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3603 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3604 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3605 c->lineno = savelineno - 1;
3608 if ( cf2 ) cf2->c_sibs = NULL;
3609 else cfn->c_kids = NULL;
3610 ch_free( cf->c_file.bv_val );
3620 config_tls_cleanup(ConfigArgs *c) {
3623 if ( slap_tls_ld ) {
3626 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3628 /* Force new ctx to be created */
3629 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3631 /* The ctx's refcount is bumped up here */
3632 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3633 /* This is a no-op if it's already loaded */
3634 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3641 config_tls_option(ConfigArgs *c) {
3643 LDAP *ld = slap_tls_ld;
3645 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3646 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3647 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3648 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3649 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3650 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3651 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3653 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3655 default: Debug(LDAP_DEBUG_ANY, "%s: "
3656 "unknown tls_option <0x%x>\n",
3657 c->log, c->type, 0);
3660 if (c->op == SLAP_CONFIG_EMIT) {
3661 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3662 } else if ( c->op == LDAP_MOD_DELETE ) {
3663 c->cleanup = config_tls_cleanup;
3664 return ldap_pvt_tls_set_option( ld, flag, NULL );
3666 ch_free(c->value_string);
3667 c->cleanup = config_tls_cleanup;
3668 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3671 /* FIXME: this ought to be provided by libldap */
3673 config_tls_config(ConfigArgs *c) {
3676 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3677 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3678 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3680 Debug(LDAP_DEBUG_ANY, "%s: "
3681 "unknown tls_option <0x%x>\n",
3682 c->log, c->type, 0);
3685 if (c->op == SLAP_CONFIG_EMIT) {
3686 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3687 } else if ( c->op == LDAP_MOD_DELETE ) {
3689 c->cleanup = config_tls_cleanup;
3690 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3692 ch_free( c->value_string );
3693 c->cleanup = config_tls_cleanup;
3694 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3695 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3696 Debug(LDAP_DEBUG_ANY, "%s: "
3697 "unable to parse %s \"%s\"\n",
3698 c->log, c->argv[0], c->argv[1] );
3701 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3703 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
3708 static CfEntryInfo *
3709 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3719 if ( dn_match( &root->ce_entry->e_nname, dn ))
3722 c = dn->bv_val+dn->bv_len;
3723 for (;*c != ',';c--);
3727 for (--c;c>dn->bv_val && *c != ',';c--);
3731 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3733 root = root->ce_kids;
3735 for (;root;root=root->ce_sibs) {
3736 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3737 if ( cdn.bv_val == dn->bv_val ) {
3747 typedef struct setup_cookie {
3757 config_ldif_resp( Operation *op, SlapReply *rs )
3759 if ( rs->sr_type == REP_SEARCH ) {
3760 setup_cookie *sc = op->o_callback->sc_private;
3763 sc->cfb->cb_got_ldif = 1;
3764 /* Does the frontend exist? */
3765 if ( !sc->got_frontend ) {
3766 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3767 "olcDatabase", STRLENOF( "olcDatabase" )))
3769 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3770 STRLENOF( "olcDatabase" ), "={-1}frontend",
3771 STRLENOF( "={-1}frontend" )))
3775 sc->ca->be = frontendDB;
3776 sc->ca->bi = frontendDB->bd_info;
3777 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3778 rdn.bv_val = sc->ca->log;
3779 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3780 "%s=" SLAP_X_ORDERED_FMT "%s",
3781 cfAd_database->ad_cname.bv_val, -1,
3782 sc->ca->bi->bi_type);
3784 sc->frontend = config_build_entry( op, rs,
3785 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3786 sc->ca->be->be_cf_ocs );
3796 dnParent( &rs->sr_entry->e_nname, &pdn );
3798 /* Does the configDB exist? */
3799 if ( sc->got_frontend && !sc->got_config &&
3800 !strncmp( rs->sr_entry->e_nname.bv_val,
3801 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3802 dn_match( &config_rdn, &pdn ) )
3804 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3805 STRLENOF( "olcDatabase" ), "={0}config",
3806 STRLENOF( "={0}config" )))
3810 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3811 sc->ca->bi = sc->ca->be->bd_info;
3812 rdn.bv_val = sc->ca->log;
3813 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3814 "%s=" SLAP_X_ORDERED_FMT "%s",
3815 cfAd_database->ad_cname.bv_val, 0,
3816 sc->ca->bi->bi_type);
3818 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3819 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3826 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3827 if ( rs->sr_err != LDAP_SUCCESS ) {
3828 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3829 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3835 /* Configure and read the underlying back-ldif store */
3837 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3838 CfBackInfo *cfb = be->be_private;
3844 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3845 Connection conn = {0};
3846 OperationBuffer opbuf;
3848 SlapReply rs = {REP_RESULT};
3849 Filter filter = { LDAP_FILTER_PRESENT };
3850 struct berval filterstr = BER_BVC("(objectclass=*)");
3853 /* Is the config directory available? */
3854 if ( stat( dir, &st ) < 0 ) {
3855 /* No, so don't bother using the backing store.
3856 * All changes will be in-memory only.
3861 cfb->cb_db.bd_info = backend_info( "ldif" );
3862 if ( !cfb->cb_db.bd_info )
3863 return 0; /* FIXME: eventually this will be a fatal error */
3865 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3868 cfb->cb_db.be_suffix = be->be_suffix;
3869 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3871 /* The suffix is always "cn=config". The underlying DB's rootdn
3872 * is always the same as the suffix.
3874 cfb->cb_db.be_rootdn = be->be_suffix[0];
3875 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3877 ber_str2bv( dir, 0, 1, &cfdir );
3882 argv[0] = "directory";
3883 argv[1] = (char *)dir;
3888 c.table = Cft_Database;
3890 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3894 if ( config_add_vals( ct, &c ))
3897 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3901 void *thrctx = ldap_pvt_thread_pool_context();
3904 connection_fake_init( &conn, &opbuf, thrctx );
3907 filter.f_desc = slap_schema.si_ad_objectClass;
3909 op->o_tag = LDAP_REQ_SEARCH;
3911 op->ors_filter = &filter;
3912 op->ors_filterstr = filterstr;
3913 op->ors_scope = LDAP_SCOPE_SUBTREE;
3915 op->o_dn = c.be->be_rootdn;
3916 op->o_ndn = c.be->be_rootndn;
3918 op->o_req_dn = be->be_suffix[0];
3919 op->o_req_ndn = be->be_nsuffix[0];
3921 op->ors_tlimit = SLAP_NO_LIMIT;
3922 op->ors_slimit = SLAP_NO_LIMIT;
3924 op->ors_attrs = slap_anlist_all_attributes;
3925 op->ors_attrsonly = 0;
3927 op->o_callback = &cb;
3930 cb.sc_private = ≻
3931 sc.got_frontend = 0;
3936 op->o_bd = &cfb->cb_db;
3938 /* Allow unknown attrs in DNs */
3939 prev_DN_strict = slap_DN_strict;
3942 rc = op->o_bd->be_search( op, &rs );
3944 /* Restore normal DN validation */
3945 slap_DN_strict = prev_DN_strict;
3947 op->o_tag = LDAP_REQ_ADD;
3948 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3949 op->ora_e = sc.frontend;
3950 rc = op->o_bd->be_add( op, &rs );
3952 if ( rc == LDAP_SUCCESS && sc.config ) {
3953 op->ora_e = sc.config;
3954 rc = op->o_bd->be_add( op, &rs );
3956 ldap_pvt_thread_pool_context_reset( thrctx );
3959 /* ITS#4194 - only use if it's present, or we're converting. */
3960 if ( !readit || rc == LDAP_SUCCESS )
3961 cfb->cb_use_ldif = 1;
3967 CfOc_cmp( const void *c1, const void *c2 ) {
3968 const ConfigOCs *co1 = c1;
3969 const ConfigOCs *co2 = c2;
3971 return ber_bvcmp( co1->co_name, co2->co_name );
3975 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3978 i = init_config_attrs( ct );
3981 /* set up the objectclasses */
3982 i = init_config_ocs( ocs );
3985 for (i=0; ocs[i].co_def; i++) {
3986 if ( ocs[i].co_oc ) {
3987 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3988 if ( !ocs[i].co_table )
3989 ocs[i].co_table = ct;
3990 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3997 read_config(const char *fname, const char *dir) {
4000 const char *cfdir, *cfname;
4003 /* Setup the config backend */
4004 be = backend_db_init( "config", NULL, 0, NULL );
4008 cfb = be->be_private;
4009 be->be_dfltaccess = ACL_NONE;
4011 /* If no .conf, or a dir was specified, setup the dir */
4012 if ( !fname || dir ) {
4014 /* If explicitly given, check for existence */
4017 if ( stat( dir, &st ) < 0 ) {
4018 Debug( LDAP_DEBUG_ANY,
4019 "invalid config directory %s, error %d\n",
4025 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4027 /* if fname is defaulted, try reading .d */
4028 rc = config_setup_ldif( be, cfdir, !fname );
4031 /* It may be OK if the base object doesn't exist yet. */
4032 if ( rc != LDAP_NO_SUCH_OBJECT )
4034 /* ITS#4194: But if dir was specified and no fname,
4035 * then we were supposed to read the dir. Unless we're
4036 * trying to slapadd the dir...
4038 if ( dir && !fname ) {
4039 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4041 /* Assume it's slapadd with a config dir, let it continue */
4043 cfb->cb_got_ldif = 1;
4044 cfb->cb_use_ldif = 1;
4049 /* If we read the config from back-ldif, nothing to do here */
4050 if ( cfb->cb_got_ldif ) {
4059 cfname = SLAPD_DEFAULT_CONFIGFILE;
4061 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4064 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4067 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4068 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4069 &frontendDB->be_schemadn );
4070 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4071 if ( rc != LDAP_SUCCESS ) {
4072 Debug(LDAP_DEBUG_ANY, "read_config: "
4073 "unable to normalize default schema DN \"%s\"\n",
4074 frontendDB->be_schemadn.bv_val, 0, 0 );
4075 /* must not happen */
4083 config_back_bind( Operation *op, SlapReply *rs )
4085 if ( be_isroot_pw( op ) ) {
4086 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4087 /* frontend sends result */
4088 return LDAP_SUCCESS;
4091 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4092 send_ldap_result( op, rs );
4098 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4102 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4104 rs->sr_attrs = op->ors_attrs;
4105 rs->sr_entry = ce->ce_entry;
4107 rc = send_search_entry( op, rs );
4108 if ( rc != LDAP_SUCCESS ) {
4112 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4113 if ( ce->ce_kids ) {
4114 rc = config_send( op, rs, ce->ce_kids, 1 );
4115 if ( rc ) return rc;
4118 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4119 rc = config_send( op, rs, ce, 0 );
4127 static ConfigTable *
4128 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4133 for (j=0; j<nocs; j++) {
4134 for (i=0; colst[j]->co_table[i].name; i++)
4135 if ( colst[j]->co_table[i].ad == ad ) {
4136 ca->table = colst[j]->co_type;
4137 return &colst[j]->co_table[i];
4143 /* Sort the attributes of the entry according to the order defined
4144 * in the objectclass, with required attributes occurring before
4145 * allowed attributes. For any attributes with sequencing dependencies
4146 * (e.g., rootDN must be defined after suffix) the objectclass must
4147 * list the attributes in the desired sequence.
4150 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4152 Attribute *a, *head = NULL, *tail = NULL, **prev;
4155 for (i=0; i<nocs; i++) {
4156 if ( colst[i]->co_oc->soc_required ) {
4157 AttributeType **at = colst[i]->co_oc->soc_required;
4158 for (j=0; at[j]; j++) {
4159 for (a=e->e_attrs, prev=&e->e_attrs; a;
4160 prev = &(*prev)->a_next, a=a->a_next) {
4161 if ( a->a_desc == at[j]->sat_ad ) {
4175 if ( colst[i]->co_oc->soc_allowed ) {
4176 AttributeType **at = colst[i]->co_oc->soc_allowed;
4177 for (j=0; at[j]; j++) {
4178 for (a=e->e_attrs, prev=&e->e_attrs; a;
4179 prev = &(*prev)->a_next, a=a->a_next) {
4180 if ( a->a_desc == at[j]->sat_ad ) {
4196 tail->a_next = e->e_attrs;
4202 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4204 Attribute *a = NULL;
4205 AttributeDescription *ad;
4215 Modifications *ml = ptr;
4217 vals = ml->sml_values;
4220 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4221 rc = ordered_value_sort( a, 1 );
4223 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4224 ad->ad_cname.bv_val );
4228 for ( i=0; vals[i].bv_val; i++ ) {
4229 ca->line = vals[i].bv_val;
4230 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4231 ca->line[0] == '{' ) {
4232 char *idx = strchr( ca->line, '}' );
4233 if ( idx ) ca->line = idx+1;
4235 rc = config_parse_vals( ct, ca, i );
4244 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4247 struct berval rtype, rval;
4249 AttributeDescription *ad = NULL;
4251 dnRdn( &e->e_name, rdn );
4252 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4253 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4254 rtype.bv_val = rdn->bv_val;
4255 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4258 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4259 a = attr_find( e->e_attrs, ad );
4260 if (!a ) return LDAP_NAMING_VIOLATION;
4267 config_rename_kids( CfEntryInfo *ce )
4270 struct berval rdn, nrdn;
4272 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4273 struct berval newdn, newndn;
4274 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4275 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4276 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4277 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4278 free( ce2->ce_entry->e_name.bv_val );
4279 free( ce2->ce_entry->e_nname.bv_val );
4280 ce2->ce_entry->e_name = newdn;
4281 ce2->ce_entry->e_nname = newndn;
4282 config_rename_kids( ce2 );
4287 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4288 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4289 struct berval *nnewrdn, int use_ldif )
4293 struct berval odn, ondn;
4297 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4298 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4301 free( a->a_vals[0].bv_val );
4302 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4303 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4304 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4305 strcpy( a->a_vals[0].bv_val, ptr1 );
4307 if ( a->a_nvals != a->a_vals ) {
4308 free( a->a_nvals[0].bv_val );
4309 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4310 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4311 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4312 strcpy( a->a_nvals[0].bv_val, ptr1 );
4315 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4316 BackendDB *be = op->o_bd;
4317 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4318 struct berval dn, ndn, xdn, xndn;
4320 op->o_bd = &cfb->cb_db;
4322 /* Save current rootdn; use the underlying DB's rootdn */
4326 xndn = op->o_req_ndn;
4327 op->o_dn = op->o_bd->be_rootdn;
4328 op->o_ndn = op->o_bd->be_rootndn;
4330 op->o_req_ndn = ondn;
4332 scp = op->o_callback;
4333 op->o_callback = ≻
4334 op->orr_newrdn = *newrdn;
4335 op->orr_nnewrdn = *nnewrdn;
4336 op->orr_newSup = NULL;
4337 op->orr_nnewSup = NULL;
4338 op->orr_deleteoldrdn = 1;
4339 op->orr_modlist = NULL;
4340 slap_modrdn2mods( op, rs );
4341 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4342 rc = op->o_bd->be_modrdn( op, rs );
4343 slap_mods_free( op->orr_modlist, 1 );
4346 op->o_callback = scp;
4350 op->o_req_ndn = xndn;
4353 free( ondn.bv_val );
4355 config_rename_kids( e->e_private );
4360 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4361 Entry *e, int idx, int tailindex, int use_ldif )
4363 struct berval ival, newrdn, nnewrdn;
4366 char ibuf[32], *ptr1, *ptr2 = NULL;
4369 rc = config_rename_attr( rs, e, &rdn, &a );
4370 if ( rc ) return rc;
4373 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4374 if ( ival.bv_len >= sizeof( ibuf ) ) {
4375 return LDAP_NAMING_VIOLATION;
4378 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4379 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4382 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4383 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4386 ptr2 = ber_bvchr( &rdn, '}' );
4390 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4392 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4393 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4394 a->a_desc->ad_cname.bv_len );
4396 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4397 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4401 /* Do the equivalent of ModRDN */
4402 /* Replace DN / NDN */
4403 newrdn.bv_len = ptr1 - newrdn.bv_val;
4404 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4405 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4407 free( nnewrdn.bv_val );
4408 free( newrdn.bv_val );
4413 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4414 SlapReply *rs, int *renum, int *ibase )
4417 int index = -1, gotindex = 0, nsibs, rc = 0;
4418 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4419 char *ptr1, *ptr2 = NULL;
4422 if ( renum ) *renum = 0;
4424 /* These entries don't get indexed/renumbered */
4425 if ( ce_type == Cft_Global ) return 0;
4426 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4428 if ( ce_type == Cft_Module )
4431 /* See if the rdn has an index already */
4432 dnRdn( &e->e_name, &rdn );
4433 if ( ce_type == Cft_Database ) {
4434 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4435 "frontend", STRLENOF("frontend") ))
4437 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4438 "config", STRLENOF("config") ))
4441 ptr1 = ber_bvchr( &e->e_name, '{' );
4442 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4444 ptr2 = strchr( ptr1, '}' );
4445 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4446 return LDAP_NAMING_VIOLATION;
4447 if ( ptr2-ptr1 == 1)
4448 return LDAP_NAMING_VIOLATION;
4450 index = strtol( ptr1 + 1, &next, 10 );
4451 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4452 return LDAP_NAMING_VIOLATION;
4455 /* Special case, we allow -1 for the frontendDB */
4456 if ( index != -1 || !isfrontend )
4457 return LDAP_NAMING_VIOLATION;
4459 if ( isconfig && index != 0 ){
4460 return LDAP_NAMING_VIOLATION;
4464 /* count related kids */
4465 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4466 if ( ce->ce_type == ce_type ) nsibs++;
4469 /* account for -1 frontend */
4470 if ( ce_type == Cft_Database )
4473 if ( index != nsibs ) {
4475 if ( index < nsibs ) {
4476 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4477 /* Siblings need to be renumbered */
4478 if ( index != -1 || !isfrontend )
4482 /* config DB is always "0" */
4483 if ( isconfig && index == -1 ) {
4486 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4490 /* just make index = nsibs */
4492 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4495 if ( ibase ) *ibase = index;
4496 if ( renum ) *renum = renumber;
4501 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4506 co.co_name = &oc->soc_cname;
4507 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4511 /* check for duplicates */
4512 for ( i = 0; i < *nocs; i++ ) {
4513 if ( *copp && (*copp)[i] == cop ) {
4519 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4520 if ( tmp == NULL ) {
4524 (*copp)[*nocs] = cop;
4529 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4530 if ( count_oc( *sups, copp, nocs ) ) {
4539 count_ocs( Attribute *oc_at, int *nocs )
4542 ConfigOCs **colst = NULL;
4546 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4550 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4552 assert( oc != NULL );
4553 if ( count_oc( oc, &colst, nocs ) ) {
4563 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4565 /* Leftover from RE23. Never parse this entry */
4566 return LDAP_COMPARE_TRUE;
4570 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4574 /* This entry is hardcoded, don't re-parse it */
4575 if ( p->ce_type == Cft_Global ) {
4576 cfn = p->ce_private;
4577 ca->ca_private = cfn;
4578 return LDAP_COMPARE_TRUE;
4580 if ( p->ce_type != Cft_Schema )
4581 return LDAP_CONSTRAINT_VIOLATION;
4583 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4584 ca->ca_private = cfn;
4585 cfo = p->ce_private;
4586 cfn->c_sibs = cfo->c_kids;
4588 return LDAP_SUCCESS;
4592 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4594 if ( p->ce_type != Cft_Global ) {
4595 return LDAP_CONSTRAINT_VIOLATION;
4597 /* config must be {0}, nothing else allowed */
4598 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4599 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4600 return LDAP_CONSTRAINT_VIOLATION;
4602 ca->be = frontendDB; /* just to get past check_vals */
4603 return LDAP_SUCCESS;
4607 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4609 if ( p->ce_type != Cft_Global ) {
4610 return LDAP_CONSTRAINT_VIOLATION;
4612 return LDAP_SUCCESS;
4616 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4618 if ( p->ce_type != Cft_Global ) {
4619 return LDAP_CONSTRAINT_VIOLATION;
4621 return LDAP_SUCCESS;
4625 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4627 if ( p->ce_type != Cft_Database ) {
4628 return LDAP_CONSTRAINT_VIOLATION;
4631 return LDAP_SUCCESS;
4635 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4640 AttributeDescription *ad;
4646 if ( cfn->c_cr_head ) {
4647 struct berval bv = BER_BVC("olcDitContentRules");
4649 slap_bv2ad( &bv, &ad, &text );
4650 ct = config_find_table( colst, nocs, ad, ca );
4651 config_del_vals( ct, ca );
4653 if ( cfn->c_oc_head ) {
4654 struct berval bv = BER_BVC("olcObjectClasses");
4656 slap_bv2ad( &bv, &ad, &text );
4657 ct = config_find_table( colst, nocs, ad, ca );
4658 config_del_vals( ct, ca );
4660 if ( cfn->c_at_head ) {
4661 struct berval bv = BER_BVC("olcAttributeTypes");
4663 slap_bv2ad( &bv, &ad, &text );
4664 ct = config_find_table( colst, nocs, ad, ca );
4665 config_del_vals( ct, ca );
4667 if ( cfn->c_syn_head ) {
4668 struct berval bv = BER_BVC("olcLdapSyntaxes");
4670 slap_bv2ad( &bv, &ad, &text );
4671 ct = config_find_table( colst, nocs, ad, ca );
4672 config_del_vals( ct, ca );
4674 if ( cfn->c_om_head ) {
4675 struct berval bv = BER_BVC("olcObjectIdentifier");
4677 slap_bv2ad( &bv, &ad, &text );
4678 ct = config_find_table( colst, nocs, ad, ca );
4679 config_del_vals( ct, ca );
4681 cfo = p->ce_private;
4682 cfo->c_kids = cfn->c_sibs;
4687 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4689 int rc = LDAP_CONSTRAINT_VIOLATION;
4692 if ( (*cop)->co_ldadd ) {
4693 rc = (*cop)->co_ldadd( last, e, ca );
4694 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4699 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4700 ConfigOCs co = { 0 };
4702 co.co_name = &(*ocp)->soc_cname;
4703 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4704 if ( *cop == NULL ) {
4708 rc = config_add_oc( cop, last, e, ca );
4709 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4717 /* Parse an LDAP entry into config directives */
4719 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4720 int *renum, Operation *op )
4722 CfEntryInfo *ce, *last = NULL;
4723 ConfigOCs co, *coptr, **colst;
4724 Attribute *a, *oc_at, *soc_at;
4725 int i, ibase = -1, nocs, rc = 0;
4728 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4730 memset( ca, 0, sizeof(ConfigArgs));
4732 /* Make sure parent exists and entry does not. But allow
4733 * Databases and Overlays to be inserted. Don't do any
4734 * auto-renumbering if manageDSAit control is present.
4736 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4738 if ( ( op && op->o_managedsait ) ||
4739 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4740 ce->ce_type != Cft_Module ) )
4742 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4743 "DN=\"%s\" already exists\n",
4744 log_prefix, e->e_name.bv_val, 0 );
4745 /* global schema ignores all writes */
4746 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4747 return LDAP_COMPARE_TRUE;
4748 return LDAP_ALREADY_EXISTS;
4752 dnParent( &e->e_nname, &pdn );
4754 /* If last is NULL, the new entry is the root/suffix entry,
4755 * otherwise last should be the parent.
4757 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4759 rs->sr_matched = last->ce_entry->e_name.bv_val;
4761 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4762 "DN=\"%s\" not child of DN=\"%s\"\n",
4763 log_prefix, e->e_name.bv_val,
4764 last->ce_entry->e_name.bv_val );
4765 return LDAP_NO_SUCH_OBJECT;
4769 /* No parent, must be root. This will never happen... */
4770 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4771 return LDAP_NO_SUCH_OBJECT;
4774 if ( last && !access_allowed( op, last->ce_entry,
4775 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4777 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4778 "DN=\"%s\" no write access to \"children\" of parent\n",
4779 log_prefix, e->e_name.bv_val, 0 );
4780 return LDAP_INSUFFICIENT_ACCESS;
4784 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4786 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4787 "DN=\"%s\" no objectClass\n",
4788 log_prefix, e->e_name.bv_val, 0 );
4789 return LDAP_OBJECT_CLASS_VIOLATION;
4792 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4794 ObjectClass *soc = NULL;
4795 char textbuf[ SLAP_TEXT_BUFLEN ];
4796 const char *text = textbuf;
4798 /* FIXME: check result */
4799 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4800 &text, textbuf, sizeof(textbuf), NULL );
4801 if ( rc != LDAP_SUCCESS ) {
4802 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4803 "DN=\"%s\" no structural objectClass (%s)\n",
4804 log_prefix, e->e_name.bv_val, text );
4807 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4808 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4809 if ( soc_at == NULL ) {
4810 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4811 "DN=\"%s\" no structural objectClass; "
4812 "unable to merge computed class %s\n",
4813 log_prefix, e->e_name.bv_val,
4814 soc->soc_cname.bv_val );
4815 return LDAP_OBJECT_CLASS_VIOLATION;
4818 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4819 "DN=\"%s\" no structural objectClass; "
4820 "computed objectClass %s merged\n",
4821 log_prefix, e->e_name.bv_val,
4822 soc->soc_cname.bv_val );
4825 /* Fake the coordinates based on whether we're part of an
4826 * LDAP Add or if reading the config dir
4829 ca->fname = "slapd";
4832 ca->fname = cfdir.bv_val;
4837 co.co_name = &soc_at->a_nvals[0];
4838 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4839 if ( coptr == NULL ) {
4840 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4841 "DN=\"%s\" no structural objectClass in configuration table\n",
4842 log_prefix, e->e_name.bv_val, 0 );
4843 return LDAP_OBJECT_CLASS_VIOLATION;
4846 /* Only the root can be Cft_Global, everything else must
4847 * have a parent. Only limited nesting arrangements are allowed.
4849 rc = LDAP_CONSTRAINT_VIOLATION;
4850 if ( coptr->co_type == Cft_Global && !last ) {
4851 cfn = cfb->cb_config;
4852 ca->ca_private = cfn;
4853 ca->be = frontendDB; /* just to get past check_vals */
4857 colst = count_ocs( oc_at, &nocs );
4859 /* Check whether the Add is allowed by its parent, and do
4860 * any necessary arg setup
4863 rc = config_add_oc( &coptr, last, e, ca );
4864 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4865 for ( i = 0; i<nocs; i++ ) {
4866 /* Already checked these */
4867 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4869 if ( colst[i]->co_ldadd &&
4870 ( rc = colst[i]->co_ldadd( last, e, ca ))
4871 != LDAP_CONSTRAINT_VIOLATION ) {
4877 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4878 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4879 "DN=\"%s\" no structural objectClass add function\n",
4880 log_prefix, e->e_name.bv_val, 0 );
4881 return LDAP_OBJECT_CLASS_VIOLATION;
4885 /* Add the entry but don't parse it, we already have its contents */
4886 if ( rc == LDAP_COMPARE_TRUE ) {
4891 if ( rc != LDAP_SUCCESS )
4894 /* Parse all the values and check for simple syntax errors before
4895 * performing any set actions.
4897 * If doing an LDAPadd, check for indexed names and any necessary
4898 * renaming/renumbering. Entries that don't need indexed names are
4899 * ignored. Entries that need an indexed name and arrive without one
4900 * are assigned to the end. Entries that arrive with an index may
4901 * cause the following entries to be renumbered/bumped down.
4903 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4904 * don't allow Adding an entry with an index that's already in use.
4905 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4907 * These entries can have auto-assigned indexes (appended to the end)
4908 * but only the other types support auto-renumbering of siblings.
4911 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4916 if ( renum && *renum && coptr->co_type != Cft_Database &&
4917 coptr->co_type != Cft_Overlay )
4919 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4920 "operation requires sibling renumbering" );
4921 rc = LDAP_UNWILLING_TO_PERFORM;
4926 init_config_argv( ca );
4928 /* Make sure we process attrs in the required order */
4929 sort_attrs( e, colst, nocs );
4931 for ( a = e->e_attrs; a; a = a->a_next ) {
4932 if ( a == oc_at ) continue;
4933 ct = config_find_table( colst, nocs, a->a_desc, ca );
4934 if ( !ct ) continue; /* user data? */
4935 rc = check_vals( ct, ca, a, 1 );
4936 if ( rc ) goto done_noop;
4939 /* Basic syntax checks are OK. Do the actual settings. */
4940 for ( a=e->e_attrs; a; a=a->a_next ) {
4941 if ( a == oc_at ) continue;
4942 ct = config_find_table( colst, nocs, a->a_desc, ca );
4943 if ( !ct ) continue; /* user data? */
4944 for (i=0; a->a_vals[i].bv_val; i++) {
4947 ca->line = a->a_vals[i].bv_val;
4948 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4949 ptr = strchr( ca->line, '}' );
4951 iptr = strchr( ca->line, '{' );
4955 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4957 ca->valx = strtol( iptr+1, NULL, 0 );
4962 rc = config_parse_add( ct, ca, i );
4970 /* Newly added databases and overlays need to be started up */
4971 if ( CONFIG_ONLINE_ADD( ca )) {
4972 if ( coptr->co_type == Cft_Database ) {
4973 rc = backend_startup_one( ca->be, &ca->reply );
4975 } else if ( coptr->co_type == Cft_Overlay ) {
4976 if ( ca->bi->bi_db_open ) {
4977 BackendInfo *bi_orig = ca->be->bd_info;
4978 ca->be->bd_info = ca->bi;
4979 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4980 ca->be->bd_info = bi_orig;
4982 } else if ( ca->cleanup ) {
4983 rc = ca->cleanup( ca );
4986 if (ca->cr_msg[0] == '\0')
4987 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4989 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4990 ca->log, ca->cr_msg, ca->argv[1] );
4997 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4998 ce->ce_parent = last;
4999 ce->ce_entry = entry_dup( e );
5000 ce->ce_entry->e_private = ce;
5001 ce->ce_type = coptr->co_type;
5004 ce->ce_private = ca->ca_private;
5005 ca->ca_entry = ce->ce_entry;
5008 } else if ( last->ce_kids ) {
5009 CfEntryInfo *c2, **cprev;
5011 /* Advance to first of this type */
5012 cprev = &last->ce_kids;
5013 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5014 cprev = &c2->ce_sibs;
5017 /* Account for the (-1) frontendDB entry */
5018 if ( ce->ce_type == Cft_Database ) {
5019 if ( ca->be == frontendDB )
5021 else if ( ibase != -1 )
5026 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5027 cprev = &c2->ce_sibs;
5033 for ( i=0; i<ibase; i++ ) {
5035 cprev = &c2->ce_sibs;
5038 ce->ce_sibs = *cprev;
5046 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5047 if ( ca->be != frontendDB )
5048 backend_destroy_one( ca->be, 1 );
5049 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5050 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5051 } else if ( coptr->co_type == Cft_Schema ) {
5052 schema_destroy_one( ca, colst, nocs, last );
5057 ch_free( ca->argv );
5058 if ( colst ) ch_free( colst );
5062 #define BIGTMP 10000
5064 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5065 int base, int rebase, int max, int use_ldif )
5067 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5068 ConfigType etype = ce->ce_type;
5069 int count = 0, rc = 0;
5071 /* Reverse ce list */
5072 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5073 if (ce2->ce_type != etype) {
5078 ce2->ce_sibs = cetmp;
5081 if ( max && count >= max ) {
5087 /* Move original to a temp name until increments are done */
5089 ce->ce_entry->e_private = NULL;
5090 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5091 base+BIGTMP, 0, use_ldif );
5092 ce->ce_entry->e_private = ce;
5094 /* start incrementing */
5095 for (ce2=cetmp; ce2; ce2=ce3) {
5097 ce2->ce_sibs = cerem;
5100 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5101 count+base, 0, use_ldif );
5105 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5106 base, 0, use_ldif );
5111 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5112 CfEntryInfo *ce2, int old, int use_ldif )
5116 /* Renumber original to a temp value */
5117 ce->ce_entry->e_private = NULL;
5118 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5119 old+BIGTMP, 0, use_ldif );
5120 ce->ce_entry->e_private = ce;
5122 /* start decrementing */
5123 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5124 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5125 count+old, 0, use_ldif );
5128 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5129 count+old, 0, use_ldif );
5132 /* Parse an LDAP entry into config directives, then store in underlying
5136 config_back_add( Operation *op, SlapReply *rs )
5142 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5143 NULL, ACL_WADD, NULL )) {
5144 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5149 * Check for attribute ACL
5151 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5152 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5153 rs->sr_text = "no write access to attribute";
5157 cfb = (CfBackInfo *)op->o_bd->be_private;
5159 /* add opattrs for syncprov */
5161 char textbuf[SLAP_TEXT_BUFLEN];
5162 size_t textlen = sizeof textbuf;
5163 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5164 &rs->sr_text, textbuf, sizeof( textbuf ) );
5165 if ( rs->sr_err != LDAP_SUCCESS )
5167 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5168 if ( rs->sr_err != LDAP_SUCCESS ) {
5169 Debug( LDAP_DEBUG_TRACE,
5170 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5171 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5176 if ( op->o_abandon ) {
5177 rs->sr_err = SLAPD_ABANDON;
5180 ldap_pvt_thread_pool_pause( &connection_pool );
5183 * 1) check for existence of entry
5184 * 2) check for sibling renumbering
5185 * 3) perform internal add
5186 * 4) perform any necessary renumbering
5187 * 5) store entry in underlying database
5189 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5190 if ( rs->sr_err != LDAP_SUCCESS ) {
5191 rs->sr_text = ca.cr_msg;
5196 CfEntryInfo *ce = ca.ca_entry->e_private;
5197 req_add_s addr = op->oq_add;
5198 op->o_tag = LDAP_REQ_MODRDN;
5199 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5200 op->o_tag = LDAP_REQ_ADD;
5202 if ( rs->sr_err != LDAP_SUCCESS ) {
5207 if ( cfb->cb_use_ldif ) {
5208 BackendDB *be = op->o_bd;
5209 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5210 struct berval dn, ndn;
5212 op->o_bd = &cfb->cb_db;
5214 /* Save current rootdn; use the underlying DB's rootdn */
5217 op->o_dn = op->o_bd->be_rootdn;
5218 op->o_ndn = op->o_bd->be_rootndn;
5220 scp = op->o_callback;
5221 op->o_callback = ≻
5222 op->o_bd->be_add( op, rs );
5224 op->o_callback = scp;
5230 ldap_pvt_thread_pool_resume( &connection_pool );
5233 { int repl = op->o_dont_replicate;
5234 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5235 rs->sr_err = LDAP_SUCCESS;
5236 op->o_dont_replicate = 1;
5238 send_ldap_result( op, rs );
5239 op->o_dont_replicate = repl;
5241 slap_graduate_commit_csn( op );
5245 typedef struct delrec {
5246 struct delrec *next;
5252 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5258 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5259 ca->line[0] == '{' )
5261 char *ptr = strchr( ca->line + 1, '}' );
5265 ca->valx = strtol( ca->line + 1, &next, 0 );
5266 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5272 rc = config_parse_add( ct, ca, i );
5280 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5283 int rc = LDAP_UNWILLING_TO_PERFORM;
5285 Entry *e = ce->ce_entry;
5286 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5291 delrec *dels = NULL, *deltail = NULL;
5293 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5294 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5296 colst = count_ocs( oc_at, &nocs );
5298 /* make sure add/del flags are clear; should always be true */
5299 for ( s = save_attrs; s; s = s->a_next ) {
5300 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5303 e->e_attrs = attrs_dup( e->e_attrs );
5305 init_config_argv( ca );
5308 ca->ca_private = ce->ce_private;
5310 ca->fname = "slapd";
5312 strcpy( ca->log, "back-config" );
5314 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5315 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5316 switch (ml->sml_op) {
5317 case LDAP_MOD_DELETE:
5318 case LDAP_MOD_REPLACE: {
5319 BerVarray vals = NULL, nvals = NULL;
5321 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5323 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5324 ml->sml_desc->ad_cname.bv_val );
5327 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5328 vals = ml->sml_values;
5329 nvals = ml->sml_nvalues;
5330 ml->sml_values = NULL;
5331 ml->sml_nvalues = NULL;
5333 /* If we're deleting by values, remember the indexes of the
5334 * values we deleted.
5336 if ( ct && ml->sml_values ) {
5338 i = ml->sml_numvals;
5339 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5350 rc = modify_delete_vindex(e, &ml->sml_mod,
5351 get_permissiveModify(op),
5352 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5353 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5354 ml->sml_values = vals;
5355 ml->sml_nvalues = nvals;
5360 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5363 case SLAP_MOD_SOFTADD: {
5364 int mop = ml->sml_op;
5366 ml->sml_op = LDAP_MOD_ADD;
5368 if ( ct->arg_type & ARG_NO_INSERT ) {
5369 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5371 navals = a->a_numvals;
5374 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5375 if ( ml->sml_values[i].bv_val[0] == '{' &&
5378 char *next, *val = ml->sml_values[i].bv_val + 1;
5381 j = strtol( val, &next, 0 );
5382 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5384 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5385 ml->sml_desc->ad_cname.bv_val );
5389 rc = check_vals( ct, ca, ml, 0 );
5390 if ( rc ) goto out_noop;
5393 rc = modify_add_values(e, &ml->sml_mod,
5394 get_permissiveModify(op),
5395 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5397 /* If value already exists, show success here
5398 * and ignore this operation down below.
5400 if ( mop == SLAP_MOD_SOFTADD ) {
5401 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5411 case LDAP_MOD_INCREMENT: /* FIXME */
5416 if(rc != LDAP_SUCCESS) break;
5419 if ( rc == LDAP_SUCCESS) {
5420 /* check that the entry still obeys the schema */
5421 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5422 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5424 if ( rc ) goto out_noop;
5426 /* Basic syntax checks are OK. Do the actual settings. */
5427 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5428 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5429 if ( !ct ) continue;
5431 s = attr_find( save_attrs, ml->sml_desc );
5432 a = attr_find( e->e_attrs, ml->sml_desc );
5434 switch (ml->sml_op) {
5435 case LDAP_MOD_DELETE:
5436 case LDAP_MOD_REPLACE: {
5437 BerVarray vals = NULL, nvals = NULL;
5440 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5441 vals = ml->sml_values;
5442 nvals = ml->sml_nvalues;
5443 ml->sml_values = NULL;
5444 ml->sml_nvalues = NULL;
5447 if ( ml->sml_values )
5450 /* If we didn't delete the whole attribute */
5451 if ( ml->sml_values && a ) {
5452 struct berval *mvals;
5455 if ( ml->sml_nvalues )
5456 mvals = ml->sml_nvalues;
5458 mvals = ml->sml_values;
5460 /* use the indexes we saved up above */
5461 for (i=0; i < d->nidx; i++) {
5462 struct berval bv = *mvals++;
5463 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5464 bv.bv_val[0] == '{' ) {
5465 ptr = strchr( bv.bv_val, '}' ) + 1;
5466 bv.bv_len -= ptr - bv.bv_val;
5469 ca->line = bv.bv_val;
5470 ca->valx = d->idx[i];
5471 config_parse_vals(ct, ca, d->idx[i] );
5472 rc = config_del_vals( ct, ca );
5473 if ( rc != LDAP_SUCCESS ) break;
5475 s->a_flags |= SLAP_ATTR_IXDEL;
5476 for (j=i+1; j < d->nidx; j++)
5477 if ( d->idx[j] >d->idx[i] )
5484 rc = config_del_vals( ct, ca );
5485 if ( rc ) rc = LDAP_OTHER;
5487 s->a_flags |= SLAP_ATTR_IXDEL;
5489 if ( ml->sml_values ) {
5494 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5495 ml->sml_values = vals;
5496 ml->sml_nvalues = nvals;
5498 if ( !vals || rc != LDAP_SUCCESS )
5501 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5504 for (i=0; ml->sml_values[i].bv_val; i++) {
5505 ca->line = ml->sml_values[i].bv_val;
5507 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5510 a->a_flags |= SLAP_ATTR_IXADD;
5517 /* Undo for a failed operation */
5518 if ( rc != LDAP_SUCCESS ) {
5519 ConfigReply msg = ca->reply;
5520 for ( s = save_attrs; s; s = s->a_next ) {
5521 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5522 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5523 ct = config_find_table( colst, nocs, s->a_desc, ca );
5524 a = attr_find( e->e_attrs, s->a_desc );
5526 /* clear the flag so the add check below will skip it */
5527 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5531 config_del_vals( ct, ca );
5533 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5534 ca->line = s->a_vals[i].bv_val;
5536 config_modify_add( ct, ca, s->a_desc, i );
5540 for ( a = e->e_attrs; a; a = a->a_next ) {
5541 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5542 ct = config_find_table( colst, nocs, a->a_desc, ca );
5546 config_del_vals( ct, ca );
5547 s = attr_find( save_attrs, a->a_desc );
5549 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5550 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5551 ca->line = s->a_vals[i].bv_val;
5553 config_modify_add( ct, ca, s->a_desc, i );
5564 if ( rc == LDAP_SUCCESS ) {
5565 attrs_free( save_attrs );
5567 attrs_free( e->e_attrs );
5568 e->e_attrs = save_attrs;
5570 ch_free( ca->argv );
5571 if ( colst ) ch_free( colst );
5573 deltail = dels->next;
5582 config_back_modify( Operation *op, SlapReply *rs )
5585 CfEntryInfo *ce, *last;
5587 ConfigArgs ca = {0};
5590 AttributeDescription *rad = NULL;
5593 cfb = (CfBackInfo *)op->o_bd->be_private;
5595 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5598 rs->sr_matched = last->ce_entry->e_name.bv_val;
5599 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5603 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5604 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5608 /* Get type of RDN */
5609 rdn = ce->ce_entry->e_nname;
5610 ptr = strchr( rdn.bv_val, '=' );
5611 rdn.bv_len = ptr - rdn.bv_val;
5612 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5614 /* Some basic validation... */
5615 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5616 /* Don't allow Modify of RDN; must use ModRdn for that. */
5617 if ( ml->sml_desc == rad ) {
5618 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5619 rs->sr_text = "Use modrdn to change the entry name";
5622 /* Internal update of contextCSN? */
5623 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5629 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5632 if ( op->o_abandon ) {
5633 rs->sr_err = SLAPD_ABANDON;
5636 ldap_pvt_thread_pool_pause( &connection_pool );
5640 * 1) perform the Modify on the cached Entry.
5641 * 2) verify that the Entry still satisfies the schema.
5642 * 3) perform the individual config operations.
5643 * 4) store Modified entry in underlying LDIF backend.
5645 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5647 rs->sr_text = ca.cr_msg;
5648 } else if ( cfb->cb_use_ldif ) {
5649 BackendDB *be = op->o_bd;
5650 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5651 struct berval dn, ndn;
5653 op->o_bd = &cfb->cb_db;
5657 op->o_dn = op->o_bd->be_rootdn;
5658 op->o_ndn = op->o_bd->be_rootndn;
5660 scp = op->o_callback;
5661 op->o_callback = ≻
5662 op->o_bd->be_modify( op, rs );
5664 op->o_callback = scp;
5670 ldap_pvt_thread_pool_resume( &connection_pool );
5672 send_ldap_result( op, rs );
5673 slap_graduate_commit_csn( op );
5678 config_back_modrdn( Operation *op, SlapReply *rs )
5681 CfEntryInfo *ce, *last;
5685 cfb = (CfBackInfo *)op->o_bd->be_private;
5687 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5690 rs->sr_matched = last->ce_entry->e_name.bv_val;
5691 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5694 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5695 NULL, ACL_WRITE, NULL )) {
5696 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5700 if ( ce->ce_parent )
5701 parent = ce->ce_parent->ce_entry;
5703 parent = (Entry *)&slap_entry_root;
5704 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5705 NULL, ACL_WRITE, NULL )) {
5706 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5711 /* We don't allow moving objects to new parents.
5712 * Generally we only allow reordering a set of ordered entries.
5714 if ( op->orr_newSup ) {
5715 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5719 /* If newRDN == oldRDN, quietly succeed */
5720 dnRdn( &op->o_req_ndn, &rdn );
5721 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5722 rs->sr_err = LDAP_SUCCESS;
5726 /* Current behavior, subject to change as needed:
5728 * For backends and overlays, we only allow renumbering.
5729 * For schema, we allow renaming with the same number.
5730 * Otherwise, the op is not allowed.
5733 if ( ce->ce_type == Cft_Schema ) {
5737 /* Can't alter the main cn=schema entry */
5738 if ( ce->ce_parent->ce_type == Cft_Global ) {
5739 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5740 rs->sr_text = "renaming not allowed for this entry";
5744 /* We could support this later if desired */
5745 ptr1 = ber_bvchr( &rdn, '}' );
5746 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5747 len = ptr1 - rdn.bv_val;
5748 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5749 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5750 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5751 rs->sr_text = "schema reordering not supported";
5754 } else if ( ce->ce_type == Cft_Database ||
5755 ce->ce_type == Cft_Overlay ) {
5756 char *ptr1, *ptr2, *iptr1, *iptr2;
5759 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5760 if ( *iptr2 != '{' ) {
5761 rs->sr_err = LDAP_NAMING_VIOLATION;
5762 rs->sr_text = "new ordering index is required";
5766 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5767 ptr1 = ber_bvchr( &rdn, '}' );
5768 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5770 rs->sr_err = LDAP_NAMING_VIOLATION;
5771 rs->sr_text = "new ordering index is required";
5775 len1 = ptr1 - rdn.bv_val;
5776 len2 = ptr2 - op->orr_newrdn.bv_val;
5778 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5779 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5780 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5781 rs->sr_text = "changing database/overlay type not allowed";
5784 ixold = strtol( iptr1, NULL, 0 );
5785 ixnew = strtol( iptr2, &ptr1, 0 );
5786 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5787 rs->sr_err = LDAP_NAMING_VIOLATION;
5790 /* config DB is always 0, cannot be changed */
5791 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5792 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5796 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5797 rs->sr_text = "renaming not supported for this entry";
5801 if ( op->o_abandon ) {
5802 rs->sr_err = SLAPD_ABANDON;
5805 ldap_pvt_thread_pool_pause( &connection_pool );
5807 if ( ce->ce_type == Cft_Schema ) {
5808 req_modrdn_s modr = op->oq_modrdn;
5811 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5812 if ( rs->sr_err == LDAP_SUCCESS ) {
5813 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5814 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5817 op->oq_modrdn = modr;
5819 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5820 req_modrdn_s modr = op->oq_modrdn;
5823 /* Advance to first of this type */
5824 cprev = &ce->ce_parent->ce_kids;
5825 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5826 cprev = &ce2->ce_sibs;
5829 /* Skip the -1 entry */
5830 if ( ce->ce_type == Cft_Database ) {
5831 cprev = &ce2->ce_sibs;
5837 /* Remove from old slot */
5838 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5839 cprev = &ce2->ce_sibs;
5840 *cprev = ce->ce_sibs;
5841 ceold = ce->ce_sibs;
5843 /* Insert into new slot */
5845 for ( i=0; i<ixnew; i++ ) {
5849 cprev = &ce2->ce_sibs;
5851 ce->ce_sibs = *cprev;
5856 /* NOTE: These should be encoded in the OC tables, not inline here */
5857 if ( ce->ce_type == Cft_Database )
5858 backend_db_move( ce->ce_be, ixnew );
5859 else if ( ce->ce_type == Cft_Overlay )
5860 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5862 if ( ixold < ixnew ) {
5863 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5866 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5867 ixold - ixnew, cfb->cb_use_ldif );
5869 op->oq_modrdn = modr;
5872 ldap_pvt_thread_pool_resume( &connection_pool );
5874 send_ldap_result( op, rs );
5879 config_back_delete( Operation *op, SlapReply *rs )
5881 #ifdef SLAP_CONFIG_DELETE
5883 CfEntryInfo *ce, *last, *ce2;
5885 cfb = (CfBackInfo *)op->o_bd->be_private;
5887 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5890 rs->sr_matched = last->ce_entry->e_name.bv_val;
5891 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5892 } else if ( ce->ce_kids ) {
5893 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5894 } else if ( op->o_abandon ) {
5895 rs->sr_err = SLAPD_ABANDON;
5896 } else if ( ce->ce_type == Cft_Overlay || ce->ce_type == Cft_Database ){
5900 ldap_pvt_thread_pool_pause( &connection_pool );
5902 if ( ce->ce_type == Cft_Overlay ){
5903 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5904 } else { /* Cft_Database*/
5905 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
5906 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5907 rs->sr_text = "Cannot delete config or frontend database";
5908 ldap_pvt_thread_pool_resume( &connection_pool );
5911 if ( ce->ce_be->bd_info->bi_db_close ) {
5912 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
5914 backend_destroy_one( ce->ce_be, 1);
5917 /* remove CfEntryInfo from the siblings list */
5918 if ( ce->ce_parent->ce_kids == ce ) {
5919 ce->ce_parent->ce_kids = ce->ce_sibs;
5921 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5922 if ( ce2->ce_sibs == ce ) {
5923 ce2->ce_sibs = ce->ce_sibs;
5929 /* remove from underlying database */
5930 if ( cfb->cb_use_ldif ) {
5931 BackendDB *be = op->o_bd;
5932 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5933 struct berval dn, ndn, req_dn, req_ndn;
5935 op->o_bd = &cfb->cb_db;
5939 req_dn = op->o_req_dn;
5940 req_ndn = op->o_req_ndn;
5942 op->o_dn = op->o_bd->be_rootdn;
5943 op->o_ndn = op->o_bd->be_rootndn;
5944 op->o_req_dn = ce->ce_entry->e_name;
5945 op->o_req_ndn = ce->ce_entry->e_nname;
5947 scp = op->o_callback;
5948 op->o_callback = ≻
5949 op->o_bd->be_delete( op, rs );
5951 op->o_callback = scp;
5954 op->o_req_dn = req_dn;
5955 op->o_req_ndn = req_ndn;
5958 /* renumber siblings */
5959 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5960 ixold = strtol( iptr, NULL, 0 );
5961 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5962 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5963 count+ixold, 0, cfb->cb_use_ldif );
5967 ce->ce_entry->e_private=NULL;
5968 entry_free(ce->ce_entry);
5970 ldap_pvt_thread_pool_resume( &connection_pool );
5972 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5975 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5976 #endif /* SLAP_CONFIG_DELETE */
5978 send_ldap_result( op, rs );
5983 config_back_search( Operation *op, SlapReply *rs )
5986 CfEntryInfo *ce, *last;
5989 cfb = (CfBackInfo *)op->o_bd->be_private;
5991 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5994 rs->sr_matched = last->ce_entry->e_name.bv_val;
5995 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5998 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5999 ACL_SEARCH, NULL, &mask ))
6001 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6002 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6004 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6008 switch ( op->ors_scope ) {
6009 case LDAP_SCOPE_BASE:
6010 case LDAP_SCOPE_SUBTREE:
6011 rs->sr_err = config_send( op, rs, ce, 0 );
6014 case LDAP_SCOPE_ONELEVEL:
6015 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6016 rs->sr_err = config_send( op, rs, ce, 1 );
6025 send_ldap_result( op, rs );
6029 /* no-op, we never free entries */
6030 int config_entry_release(
6035 if ( !e->e_private ) {
6038 return LDAP_SUCCESS;
6041 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6043 int config_back_entry_get(
6047 AttributeDescription *at,
6052 CfEntryInfo *ce, *last;
6053 int rc = LDAP_NO_SUCH_OBJECT;
6055 cfb = (CfBackInfo *)op->o_bd->be_private;
6057 ce = config_find_base( cfb->cb_root, ndn, &last );
6059 *ent = ce->ce_entry;
6062 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6063 rc = LDAP_NO_SUCH_ATTRIBUTE;
6073 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6074 ConfigTable *ct, ConfigArgs *c )
6078 for (; at && *at; at++) {
6079 /* Skip the naming attr */
6080 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6082 for (i=0;ct[i].name;i++) {
6083 if (ct[i].ad == (*at)->sat_ad) {
6084 rc = config_get_vals(&ct[i], c);
6085 /* NOTE: tolerate that config_get_vals()
6086 * returns success with no values */
6087 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6088 if ( c->rvalue_nvals )
6089 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6092 slap_syntax_validate_func *validate =
6093 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6096 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6097 rc = ordered_value_validate( ct[i].ad,
6098 &c->rvalue_vals[j], LDAP_MOD_ADD );
6100 Debug( LDAP_DEBUG_ANY,
6101 "config_build_attrs: error %d on %s value #%d\n",
6102 rc, ct[i].ad->ad_cname.bv_val, j );
6108 rc = attr_merge_normalize(e, ct[i].ad,
6109 c->rvalue_vals, NULL);
6111 ber_bvarray_free( c->rvalue_nvals );
6112 ber_bvarray_free( c->rvalue_vals );
6114 Debug( LDAP_DEBUG_ANY,
6115 "config_build_attrs: error %d on %s\n",
6116 rc, ct[i].ad->ad_cname.bv_val, 0 );
6128 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6129 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6131 Entry *e = entry_alloc();
6132 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6134 struct berval ad_name;
6135 AttributeDescription *ad = NULL;
6138 const char *text = "";
6142 CfEntryInfo *ceprev = NULL;
6144 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6147 ce->ce_type = main->co_type;
6148 ce->ce_parent = parent;
6150 pdn = parent->ce_entry->e_nname;
6151 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6152 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6153 ceprev->ce_type <= ce->ce_type;
6154 ceprev = ceprev->ce_sibs );
6159 ce->ce_private = c->ca_private;
6163 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6164 ber_dupbv( &e->e_nname, &e->e_name );
6166 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6167 main->co_name, NULL );
6169 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6170 extra->co_name, NULL );
6171 ptr = strchr(rdn->bv_val, '=');
6172 ad_name.bv_val = rdn->bv_val;
6173 ad_name.bv_len = ptr - rdn->bv_val;
6174 rc = slap_bv2ad( &ad_name, &ad, &text );
6179 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6180 attr_merge_normalize_one(e, ad, &val, NULL );
6183 c->table = main->co_type;
6184 if ( oc->soc_required ) {
6185 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6186 if ( rc ) goto fail;
6189 if ( oc->soc_allowed ) {
6190 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6191 if ( rc ) goto fail;
6196 c->table = extra->co_type;
6197 if ( oc->soc_required ) {
6198 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6199 if ( rc ) goto fail;
6202 if ( oc->soc_allowed ) {
6203 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6204 if ( rc ) goto fail;
6208 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6209 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6210 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6211 if ( rc != LDAP_SUCCESS ) {
6213 Debug( LDAP_DEBUG_ANY,
6214 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6215 rdn->bv_val, text, 0);
6218 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6221 op->ora_modlist = NULL;
6222 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6223 if ( !op->o_noop ) {
6224 op->o_bd->be_add( op, rs );
6225 if ( ( rs->sr_err != LDAP_SUCCESS )
6226 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
6232 ce->ce_sibs = ceprev->ce_sibs;
6233 ceprev->ce_sibs = ce;
6234 } else if ( parent ) {
6235 ce->ce_sibs = parent->ce_kids;
6236 parent->ce_kids = ce;
6243 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6244 Operation *op, SlapReply *rs )
6247 ConfigFile *cf = c->ca_private;
6249 struct berval bv, rdn;
6251 for (; cf; cf=cf->c_sibs, c->depth++) {
6252 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6253 !cf->c_om_head && !cf->c_syn_head ) continue;
6254 c->value_dn.bv_val = c->log;
6255 LUTIL_SLASHPATH( cf->c_file.bv_val );
6256 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6261 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6263 ptr = strchr( bv.bv_val, '.' );
6265 bv.bv_len = ptr - bv.bv_val;
6266 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6267 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6268 /* FIXME: how can indicate error? */
6271 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6273 c->value_dn.bv_len += bv.bv_len;
6274 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6278 e = config_build_entry( op, rs, ceparent, c, &rdn,
6279 &CFOC_SCHEMA, NULL );
6282 } else if ( e && cf->c_kids ) {
6283 c->ca_private = cf->c_kids;
6284 config_build_schema_inc( c, e->e_private, op, rs );
6290 #ifdef SLAPD_MODULES
6293 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6294 Operation *op, SlapReply *rs )
6299 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6300 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6302 c->value_dn.bv_val = c->log;
6303 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6304 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6305 /* FIXME: how can indicate error? */
6309 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6318 config_check_schema(Operation *op, CfBackInfo *cfb)
6320 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6322 CfEntryInfo *ce, *last;
6325 /* If there's no root entry, we must be in the midst of converting */
6326 if ( !cfb->cb_root )
6329 /* Make sure the main schema entry exists */
6330 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6337 /* Make sure it's up to date */
6338 if ( cf_om_tail != om_sys_tail ) {
6339 a = attr_find( e->e_attrs, cfAd_om );
6341 if ( a->a_nvals != a->a_vals )
6342 ber_bvarray_free( a->a_nvals );
6343 ber_bvarray_free( a->a_vals );
6348 oidm_unparse( &bv, NULL, NULL, 1 );
6349 attr_merge_normalize( e, cfAd_om, bv, NULL );
6350 ber_bvarray_free( bv );
6351 cf_om_tail = om_sys_tail;
6353 if ( cf_at_tail != at_sys_tail ) {
6354 a = attr_find( e->e_attrs, cfAd_attr );
6356 if ( a->a_nvals != a->a_vals )
6357 ber_bvarray_free( a->a_nvals );
6358 ber_bvarray_free( a->a_vals );
6363 at_unparse( &bv, NULL, NULL, 1 );
6364 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6365 ber_bvarray_free( bv );
6366 cf_at_tail = at_sys_tail;
6368 if ( cf_oc_tail != oc_sys_tail ) {
6369 a = attr_find( e->e_attrs, cfAd_oc );
6371 if ( a->a_nvals != a->a_vals )
6372 ber_bvarray_free( a->a_nvals );
6373 ber_bvarray_free( a->a_vals );
6378 oc_unparse( &bv, NULL, NULL, 1 );
6379 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6380 ber_bvarray_free( bv );
6381 cf_oc_tail = oc_sys_tail;
6383 if ( cf_syn_tail != syn_sys_tail ) {
6384 a = attr_find( e->e_attrs, cfAd_syntax );
6386 if ( a->a_nvals != a->a_vals )
6387 ber_bvarray_free( a->a_nvals );
6388 ber_bvarray_free( a->a_vals );
6393 syn_unparse( &bv, NULL, NULL, 1 );
6394 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6395 ber_bvarray_free( bv );
6396 cf_syn_tail = syn_sys_tail;
6399 SlapReply rs = {REP_RESULT};
6400 c.ca_private = NULL;
6401 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6402 &CFOC_SCHEMA, NULL );
6407 ce->ce_private = cfb->cb_config;
6408 cf_at_tail = at_sys_tail;
6409 cf_oc_tail = oc_sys_tail;
6410 cf_om_tail = om_sys_tail;
6411 cf_syn_tail = syn_sys_tail;
6416 static const char *defacl[] = {
6417 NULL, "to", "*", "by", "*", "none", NULL
6421 config_back_db_open( BackendDB *be, ConfigReply *cr )
6423 CfBackInfo *cfb = be->be_private;
6426 CfEntryInfo *ce, *ceparent;
6430 Connection conn = {0};
6431 OperationBuffer opbuf;
6433 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6434 SlapReply rs = {REP_RESULT};
6435 void *thrctx = NULL;
6437 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6439 /* If we have no explicitly configured ACLs, don't just use
6440 * the global ACLs. Explicitly deny access to everything.
6442 if ( !be->be_acl ) {
6443 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6446 thrctx = ldap_pvt_thread_pool_context();
6447 connection_fake_init( &conn, &opbuf, thrctx );
6450 op->o_tag = LDAP_REQ_ADD;
6451 op->o_callback = &cb;
6452 op->o_bd = &cfb->cb_db;
6453 op->o_dn = op->o_bd->be_rootdn;
6454 op->o_ndn = op->o_bd->be_rootndn;
6456 if ( !cfb->cb_use_ldif ) {
6460 /* If we read the config from back-ldif, do some quick sanity checks */
6461 if ( cfb->cb_got_ldif ) {
6462 return config_check_schema( op, cfb );
6465 /* create root of tree */
6467 c.ca_private = cfb->cb_config;
6469 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6479 #ifdef SLAPD_MODULES
6480 /* Create Module nodes... */
6481 if ( modpaths.mp_loads ) {
6482 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6488 /* Create schema nodes... cn=schema will contain the hardcoded core
6489 * schema, read-only. Child objects will contain runtime loaded schema
6493 c.ca_private = NULL;
6494 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6499 ce->ce_private = cfb->cb_config;
6500 cf_at_tail = at_sys_tail;
6501 cf_oc_tail = oc_sys_tail;
6502 cf_om_tail = om_sys_tail;
6503 cf_syn_tail = syn_sys_tail;
6505 /* Create schema nodes for included schema... */
6506 if ( cfb->cb_config->c_kids ) {
6508 c.ca_private = cfb->cb_config->c_kids;
6509 if (config_build_schema_inc( &c, ce, op, &rs )) {
6514 /* Create backend nodes. Skip if they don't provide a cf_table.
6515 * There usually aren't any of these.
6519 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6520 if (!bi->bi_cf_ocs) {
6521 /* If it only supports the old config mech, complain. */
6522 if ( bi->bi_config ) {
6523 Debug( LDAP_DEBUG_ANY,
6524 "WARNING: No dynamic config support for backend %s.\n",
6525 bi->bi_type, 0, 0 );
6530 if (!bi->bi_private) continue;
6533 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6534 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6535 if ( rdn.bv_len >= sizeof( c.log ) ) {
6536 /* FIXME: holler ... */ ;
6539 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6546 /* Create database nodes... */
6547 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6548 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6549 for ( i = -1, be = frontendDB ; be;
6550 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6551 slap_overinfo *oi = NULL;
6553 if ( overlay_is_over( be )) {
6554 oi = be->bd_info->bi_private;
6560 /* If this backend supports the old config mechanism, but not
6561 * the new mech, complain.
6563 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6564 Debug( LDAP_DEBUG_ANY,
6565 "WARNING: No dynamic config support for database %s.\n",
6566 bi->bi_type, 0, 0 );
6570 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6571 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6573 if ( rdn.bv_len >= sizeof( c.log ) ) {
6574 /* FIXME: holler ... */ ;
6578 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6584 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6585 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6586 /* Iterate through overlays */
6591 voidList *vl, *v0 = NULL;
6593 /* overlays are in LIFO order, must reverse stack */
6594 for (on=oi->oi_list; on; on=on->on_next) {
6595 vl = ch_malloc( sizeof( voidList ));
6600 for (j=0; vl; j++,vl=v0) {
6604 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6605 Debug( LDAP_DEBUG_ANY,
6606 "WARNING: No dynamic config support for overlay %s.\n",
6607 on->on_bi.bi_type, 0, 0 );
6611 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6612 "%s=" SLAP_X_ORDERED_FMT "%s",
6613 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6614 if ( rdn.bv_len >= sizeof( c.log ) ) {
6615 /* FIXME: holler ... */ ;
6619 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6620 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6624 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6625 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6630 ldap_pvt_thread_pool_context_reset( thrctx );
6632 if ( unsupp && cfb->cb_use_ldif ) {
6633 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6634 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6641 cfb_free_cffile( ConfigFile *cf )
6645 for (; cf; cf=next) {
6648 cfb_free_cffile( cf->c_kids );
6649 ch_free( cf->c_file.bv_val );
6650 ber_bvarray_free( cf->c_dseFiles );
6656 cfb_free_entries( CfEntryInfo *ce )
6660 for (; ce; ce=next) {
6663 cfb_free_entries( ce->ce_kids );
6664 ce->ce_entry->e_private = NULL;
6665 entry_free( ce->ce_entry );
6671 config_back_db_close( BackendDB *be, ConfigReply *cr )
6673 CfBackInfo *cfb = be->be_private;
6675 cfb_free_entries( cfb->cb_root );
6676 cfb->cb_root = NULL;
6678 if ( cfb->cb_db.bd_info ) {
6679 backend_shutdown( &cfb->cb_db );
6686 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6688 CfBackInfo *cfb = be->be_private;
6690 cfb_free_cffile( cfb->cb_config );
6692 ch_free( cfdir.bv_val );
6694 avl_free( CfOcTree, NULL );
6696 if ( cfb->cb_db.bd_info ) {
6697 cfb->cb_db.be_suffix = NULL;
6698 cfb->cb_db.be_nsuffix = NULL;
6699 BER_BVZERO( &cfb->cb_db.be_rootdn );
6700 BER_BVZERO( &cfb->cb_db.be_rootndn );
6702 backend_destroy_one( &cfb->cb_db, 0 );
6711 config_back_db_init( BackendDB *be, ConfigReply* cr )
6717 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6718 cfn = cfb->cb_config;
6719 be->be_private = cfb;
6721 ber_dupbv( &be->be_rootdn, &config_rdn );
6722 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6723 ber_dupbv( &dn, &be->be_rootdn );
6724 ber_bvarray_add( &be->be_suffix, &dn );
6725 ber_dupbv( &dn, &be->be_rootdn );
6726 ber_bvarray_add( &be->be_nsuffix, &dn );
6728 /* Hide from namingContexts */
6729 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6731 /* Check ACLs on content of Adds by default */
6732 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6738 config_back_destroy( BackendInfo *bi )
6740 ldif_must_b64_encode_release();
6745 config_tool_entry_open( BackendDB *be, int mode )
6747 CfBackInfo *cfb = be->be_private;
6748 BackendInfo *bi = cfb->cb_db.bd_info;
6750 if ( bi && bi->bi_tool_entry_open )
6751 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6758 config_tool_entry_close( BackendDB *be )
6760 CfBackInfo *cfb = be->be_private;
6761 BackendInfo *bi = cfb->cb_db.bd_info;
6763 if ( bi && bi->bi_tool_entry_close )
6764 return bi->bi_tool_entry_close( &cfb->cb_db );
6770 config_tool_entry_first( BackendDB *be )
6772 CfBackInfo *cfb = be->be_private;
6773 BackendInfo *bi = cfb->cb_db.bd_info;
6775 if ( bi && bi->bi_tool_entry_first )
6776 return bi->bi_tool_entry_first( &cfb->cb_db );
6782 config_tool_entry_next( BackendDB *be )
6784 CfBackInfo *cfb = be->be_private;
6785 BackendInfo *bi = cfb->cb_db.bd_info;
6787 if ( bi && bi->bi_tool_entry_next )
6788 return bi->bi_tool_entry_next( &cfb->cb_db );
6794 config_tool_entry_get( BackendDB *be, ID id )
6796 CfBackInfo *cfb = be->be_private;
6797 BackendInfo *bi = cfb->cb_db.bd_info;
6799 if ( bi && bi->bi_tool_entry_get )
6800 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6805 static int entry_put_got_frontend=0;
6806 static int entry_put_got_config=0;
6808 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6810 CfBackInfo *cfb = be->be_private;
6811 BackendInfo *bi = cfb->cb_db.bd_info;
6813 struct berval rdn, vals[ 2 ];
6815 OperationBuffer opbuf;
6817 Connection conn = {0};
6818 Operation *op = NULL;
6822 /* Create entry for frontend database if it does not exist already */
6823 if ( !entry_put_got_frontend ) {
6824 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6825 STRLENOF( "olcDatabase" ))) {
6826 if ( strncmp( e->e_nname.bv_val +
6827 STRLENOF( "olcDatabase" ), "={-1}frontend",
6828 STRLENOF( "={-1}frontend" )) &&
6829 strncmp( e->e_nname.bv_val +
6830 STRLENOF( "olcDatabase" ), "=frontend",
6831 STRLENOF( "=frontend" ))) {
6833 vals[1].bv_val = NULL;
6834 memset( &ca, 0, sizeof(ConfigArgs));
6836 ca.bi = frontendDB->bd_info;
6837 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6838 rdn.bv_val = ca.log;
6839 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6840 "%s=" SLAP_X_ORDERED_FMT "%s",
6841 cfAd_database->ad_cname.bv_val, -1,
6843 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6844 &CFOC_DATABASE, ca.be->be_cf_ocs );
6845 thrctx = ldap_pvt_thread_pool_context();
6846 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6848 op->o_bd = &cfb->cb_db;
6849 op->o_tag = LDAP_REQ_ADD;
6851 op->o_dn = be->be_rootdn;
6852 op->o_ndn = be->be_rootndn;
6853 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6854 if ( rc != LDAP_SUCCESS ) {
6855 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6856 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6860 if ( ce && bi && bi->bi_tool_entry_put &&
6861 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6862 entry_put_got_frontend++;
6864 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6865 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6869 entry_put_got_frontend++;
6874 /* Create entry for config database if it does not exist already */
6875 if ( !entry_put_got_config && !isFrontend ) {
6876 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6877 STRLENOF( "olcDatabase" ))) {
6878 if ( strncmp( e->e_nname.bv_val +
6879 STRLENOF( "olcDatabase" ), "={0}config",
6880 STRLENOF( "={0}config" )) &&
6881 strncmp( e->e_nname.bv_val +
6882 STRLENOF( "olcDatabase" ), "=config",
6883 STRLENOF( "=config" )) ) {
6885 vals[1].bv_val = NULL;
6886 memset( &ca, 0, sizeof(ConfigArgs));
6887 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6888 ca.bi = ca.be->bd_info;
6889 rdn.bv_val = ca.log;
6890 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6891 "%s=" SLAP_X_ORDERED_FMT "%s",
6892 cfAd_database->ad_cname.bv_val, 0,
6894 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6897 thrctx = ldap_pvt_thread_pool_context();
6898 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6900 op->o_bd = &cfb->cb_db;
6901 op->o_tag = LDAP_REQ_ADD;
6902 op->o_dn = be->be_rootdn;
6903 op->o_ndn = be->be_rootndn;
6906 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6907 if ( rc != LDAP_SUCCESS ) {
6908 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6909 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6912 if (ce && bi && bi->bi_tool_entry_put &&
6913 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6914 entry_put_got_config++;
6916 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6917 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6921 entry_put_got_config++;
6925 if ( bi && bi->bi_tool_entry_put &&
6926 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6927 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6934 AttributeDescription **desc;
6936 { "attribute", &cfAd_attr },
6937 { "backend", &cfAd_backend },
6938 { "database", &cfAd_database },
6939 { "include", &cfAd_include },
6940 { "ldapsyntax", &cfAd_syntax },
6941 { "objectclass", &cfAd_oc },
6942 { "objectidentifier", &cfAd_om },
6943 { "overlay", &cfAd_overlay },
6948 * add / delete: all types that may be added or deleted must use an
6949 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6950 * should automatically renumber the index of any siblings as needed,
6951 * so that no gaps in the numbering sequence exist after the add/delete
6953 * What can be added:
6955 * backend objects for backend-specific config directives
6959 * delete: probably no support this time around.
6961 * modrdn: generally not done. Will be invoked automatically by add/
6962 * delete to update numbering sequence. Perform as an explicit operation
6963 * so that the renumbering effect may be replicated. Subtree rename must
6964 * be supported, since renumbering a database will affect all its child
6967 * modify: must be fully supported.
6971 config_back_initialize( BackendInfo *bi )
6973 ConfigTable *ct = config_back_cf_table;
6977 AttributeDescription *ad = NULL;
6979 static char *controls[] = {
6980 LDAP_CONTROL_MANAGEDSAIT,
6984 /* Make sure we don't exceed the bits reserved for userland */
6985 config_check_userland( CFG_LAST );
6987 bi->bi_controls = controls;
6992 bi->bi_destroy = config_back_destroy;
6994 bi->bi_db_init = config_back_db_init;
6995 bi->bi_db_config = 0;
6996 bi->bi_db_open = config_back_db_open;
6997 bi->bi_db_close = config_back_db_close;
6998 bi->bi_db_destroy = config_back_db_destroy;
7000 bi->bi_op_bind = config_back_bind;
7001 bi->bi_op_unbind = 0;
7002 bi->bi_op_search = config_back_search;
7003 bi->bi_op_compare = 0;
7004 bi->bi_op_modify = config_back_modify;
7005 bi->bi_op_modrdn = config_back_modrdn;
7006 bi->bi_op_add = config_back_add;
7007 bi->bi_op_delete = config_back_delete;
7008 bi->bi_op_abandon = 0;
7010 bi->bi_extended = 0;
7012 bi->bi_chk_referrals = 0;
7014 bi->bi_access_allowed = slap_access_allowed;
7016 bi->bi_connection_init = 0;
7017 bi->bi_connection_destroy = 0;
7019 bi->bi_entry_release_rw = config_entry_release;
7020 bi->bi_entry_get_rw = config_back_entry_get;
7022 bi->bi_tool_entry_open = config_tool_entry_open;
7023 bi->bi_tool_entry_close = config_tool_entry_close;
7024 bi->bi_tool_entry_first = config_tool_entry_first;
7025 bi->bi_tool_entry_next = config_tool_entry_next;
7026 bi->bi_tool_entry_get = config_tool_entry_get;
7027 bi->bi_tool_entry_put = config_tool_entry_put;
7030 argv[ 0 ] = "slapd";
7036 for (i=0; OidMacros[i].name; i++ ) {
7037 argv[1] = OidMacros[i].name;
7038 argv[2] = OidMacros[i].oid;
7039 parse_oidm( &ca, 0, NULL );
7042 bi->bi_cf_ocs = cf_ocs;
7044 i = config_register_schema( ct, cf_ocs );
7047 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7050 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7051 * basically, we don't care if it fails */
7052 i = slap_str2ad( "olcRootPW", &ad, &text );
7054 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7055 "warning, unable to get \"olcRootPW\" "
7056 "attribute description: %d: %s\n",
7059 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7060 ad->ad_type->sat_oid );
7063 /* set up the notable AttributeDescriptions */
7065 for (;ct->name;ct++) {
7066 if (strcmp(ct->name, ads[i].name)) continue;
7067 *ads[i].desc = ct->ad;
7069 if (!ads[i].name) break;