1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2008 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>
32 #include "slapi/slapi.h"
40 #define CONFIG_RDN "cn=config"
41 #define SCHEMA_RDN "cn=schema"
43 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
44 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
46 extern int slap_DN_strict; /* dn.c */
49 typedef struct modpath_s {
50 struct modpath_s *mp_next;
51 struct berval mp_path;
55 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 typedef struct ConfigFile {
59 struct ConfigFile *c_sibs;
60 struct ConfigFile *c_kids;
62 AttributeType *c_at_head, *c_at_tail;
63 ContentRule *c_cr_head, *c_cr_tail;
64 ObjectClass *c_oc_head, *c_oc_tail;
65 OidMacro *c_om_head, *c_om_tail;
70 ConfigFile *cb_config;
72 BackendDB cb_db; /* underlying database */
77 static CfBackInfo cfBackInfo;
79 static char *passwd_salt;
81 static char *logfileName;
82 #ifdef SLAP_AUTH_REWRITE
83 static BerVarray authz_rewrites;
86 static struct berval cfdir;
89 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
90 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om;
92 static ConfigFile *cfn;
94 static Avlnode *CfOcTree;
96 /* System schema state */
97 extern AttributeType *at_sys_tail; /* at.c */
98 extern ObjectClass *oc_sys_tail; /* oc.c */
99 extern OidMacro *om_sys_tail; /* oidm.c */
100 static AttributeType *cf_at_tail;
101 static ObjectClass *cf_oc_tail;
102 static OidMacro *cf_om_tail;
104 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
105 SlapReply *rs, int *renumber, Operation *op );
107 static int config_check_schema( Operation *op, CfBackInfo *cfb );
109 static ConfigDriver config_fname;
110 static ConfigDriver config_cfdir;
111 static ConfigDriver config_generic;
112 static ConfigDriver config_search_base;
113 static ConfigDriver config_passwd_hash;
114 static ConfigDriver config_schema_dn;
115 static ConfigDriver config_sizelimit;
116 static ConfigDriver config_timelimit;
117 static ConfigDriver config_overlay;
118 static ConfigDriver config_subordinate;
119 static ConfigDriver config_suffix;
120 static ConfigDriver config_rootdn;
121 static ConfigDriver config_rootpw;
122 static ConfigDriver config_restrict;
123 static ConfigDriver config_allows;
124 static ConfigDriver config_disallows;
125 static ConfigDriver config_requires;
126 static ConfigDriver config_security;
127 static ConfigDriver config_referral;
128 static ConfigDriver config_loglevel;
129 static ConfigDriver config_updatedn;
130 static ConfigDriver config_updateref;
131 static ConfigDriver config_include;
132 static ConfigDriver config_obsolete;
134 static ConfigDriver config_tls_option;
135 static ConfigDriver config_tls_config;
137 extern ConfigDriver syncrepl_config;
191 static OidRec OidMacros[] = {
192 /* OpenLDAProot:1.12.2 */
193 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
194 { "OLcfgAt", "OLcfg:3" },
195 { "OLcfgGlAt", "OLcfgAt:0" },
196 { "OLcfgBkAt", "OLcfgAt:1" },
197 { "OLcfgDbAt", "OLcfgAt:2" },
198 { "OLcfgOvAt", "OLcfgAt:3" },
199 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
200 { "OLcfgOc", "OLcfg:4" },
201 { "OLcfgGlOc", "OLcfgOc:0" },
202 { "OLcfgBkOc", "OLcfgOc:1" },
203 { "OLcfgDbOc", "OLcfgOc:2" },
204 { "OLcfgOvOc", "OLcfgOc:3" },
205 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
207 /* Syntaxes. We should just start using the standard names and
208 * document that they are predefined and available for users
209 * to reference in their own schema. Defining schema without
210 * OID macros is for masochists...
212 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
213 { "OMsBoolean", "OMsyn:7" },
214 { "OMsDN", "OMsyn:12" },
215 { "OMsDirectoryString", "OMsyn:15" },
216 { "OMsIA5String", "OMsyn:26" },
217 { "OMsInteger", "OMsyn:27" },
218 { "OMsOID", "OMsyn:38" },
219 { "OMsOctetString", "OMsyn:40" },
224 * Backend/Database registry
226 * OLcfg{Bk|Db}{Oc|At}:0 -> common
227 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
228 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
229 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
230 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
231 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
232 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
233 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
239 * OLcfgOv{Oc|At}:1 -> syncprov
240 * OLcfgOv{Oc|At}:2 -> pcache
241 * OLcfgOv{Oc|At}:3 -> chain
242 * OLcfgOv{Oc|At}:4 -> accesslog
243 * OLcfgOv{Oc|At}:5 -> valsort
244 * OLcfgOv{Oc|At}:7 -> distproc
245 * OLcfgOv{Oc|At}:8 -> dynlist
246 * OLcfgOv{Oc|At}:9 -> dds
247 * OLcfgOv{Oc|At}:10 -> unique
248 * OLcfgOv{Oc|At}:11 -> refint
249 * OLcfgOv{Oc|At}:12 -> ppolicy
250 * OLcfgOv{Oc|At}:13 -> constraint
251 * OLcfgOv{Oc|At}:14 -> translucent
252 * OLcfgOv{Oc|At}:15 -> auditlog
253 * OLcfgOv{Oc|At}:16 -> rwm
254 * OLcfgOv{Oc|At}:17 -> dyngroup
255 * OLcfgOv{Oc|At}:18 -> memberof
256 * OLcfgOv{Oc|At}:19 -> collect
257 * OLcfgOv{Oc|At}:20 -> retcode
260 /* alphabetical ordering */
262 static ConfigTable config_back_cf_table[] = {
263 /* This attr is read-only */
264 { "", "", 0, 0, 0, ARG_MAGIC,
265 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
266 "DESC 'File for slapd configuration directives' "
267 "EQUALITY caseIgnoreMatch "
268 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
269 { "", "", 0, 0, 0, ARG_MAGIC,
270 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
271 "DESC 'Directory for slapd configuration backend' "
272 "EQUALITY caseIgnoreMatch "
273 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
274 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
275 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
276 "DESC 'Access Control List' "
277 "EQUALITY caseIgnoreMatch "
278 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
279 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
280 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
281 "DESC 'Allowed set of deprecated features' "
282 "EQUALITY caseIgnoreMatch "
283 "SYNTAX OMsDirectoryString )", NULL, NULL },
284 { "argsfile", "file", 2, 2, 0, ARG_STRING,
285 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
286 "DESC 'File for slapd command line options' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
289 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
290 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString )", NULL, NULL },
293 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
294 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
295 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
296 "DESC 'OpenLDAP attributeTypes' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
300 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
301 #ifdef SLAP_AUTH_REWRITE
302 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
306 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
309 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
310 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
313 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
314 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
317 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
318 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
319 "DESC 'A type of backend' "
320 "EQUALITY caseIgnoreMatch "
321 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
323 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
324 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
325 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
326 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
327 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
328 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
329 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
330 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
331 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
332 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
333 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
334 "DESC 'The backend type for a database instance' "
335 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
336 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
337 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
338 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
339 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
340 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString )", NULL, NULL },
343 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
344 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
345 "DESC 'OpenLDAP DIT content rules' "
346 "EQUALITY caseIgnoreMatch "
347 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
349 { "gentlehup", "on|off", 2, 2, 0,
351 ARG_ON_OFF, &global_gentlehup,
355 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
356 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
357 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
358 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
359 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
360 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
361 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
362 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
363 { "include", "file", 2, 2, 0, ARG_MAGIC,
364 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
365 "SUP labeledURI )", NULL, NULL },
366 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
367 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
368 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
369 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
370 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
371 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
372 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
373 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
374 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
375 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
376 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
377 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
378 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
379 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
380 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
381 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
382 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
383 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
384 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
385 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
386 "EQUALITY caseIgnoreMatch "
387 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
388 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
389 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
390 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
391 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
392 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
393 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
394 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
395 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
396 "EQUALITY caseIgnoreMatch "
397 "SYNTAX OMsDirectoryString )", NULL, NULL },
398 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
399 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
402 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
403 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
404 { "moduleload", "file", 2, 0, 0,
406 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
410 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
411 "EQUALITY caseIgnoreMatch "
412 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
413 { "modulepath", "path", 2, 2, 0,
415 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
419 "( OLcfgGlAt:31 NAME 'olcModulePath' "
420 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
421 { "monitoring", "TRUE|FALSE", 2, 2, 0,
422 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
423 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
424 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
425 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
426 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
427 "DESC 'OpenLDAP object classes' "
428 "EQUALITY caseIgnoreMatch "
429 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
431 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
432 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
433 "EQUALITY caseIgnoreMatch "
434 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
435 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
436 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
437 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
438 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
439 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
440 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
441 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
442 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
443 "EQUALITY caseIgnoreMatch "
444 "SYNTAX OMsDirectoryString )", NULL, NULL },
445 { "pidfile", "file", 2, 2, 0, ARG_STRING,
446 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
447 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
448 { "plugin", NULL, 0, 0, 0,
450 ARG_MAGIC|CFG_PLUGIN, &config_generic,
454 "( OLcfgGlAt:38 NAME 'olcPlugin' "
455 "EQUALITY caseIgnoreMatch "
456 "SYNTAX OMsDirectoryString )", NULL, NULL },
457 { "pluginlog", "filename", 2, 2, 0,
459 ARG_STRING, &slapi_log_file,
463 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
464 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
465 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
466 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
467 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
468 { "referral", "url", 2, 2, 0, ARG_MAGIC,
469 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
470 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
471 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
472 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
473 "EQUALITY caseIgnoreMatch "
474 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
475 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
476 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
477 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
478 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
479 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
480 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
481 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
482 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
483 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
484 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
485 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
486 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
487 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
488 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
489 "EQUALITY caseIgnoreMatch "
490 "SYNTAX OMsDirectoryString )", NULL, NULL },
491 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
492 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
493 "EQUALITY caseIgnoreMatch "
494 "SYNTAX OMsDirectoryString )", NULL, NULL },
495 { "reverse-lookup", "on|off", 2, 2, 0,
496 #ifdef SLAPD_RLOOKUPS
497 ARG_ON_OFF, &use_reverse_lookup,
501 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
502 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
503 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
504 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
505 "EQUALITY distinguishedNameMatch "
506 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
507 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
508 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
509 "EQUALITY caseIgnoreMatch "
510 "SYNTAX OMsDirectoryString )", NULL, NULL },
511 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
512 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
513 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
514 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
515 &config_generic, NULL, NULL, NULL },
516 { "sasl-host", "host", 2, 2, 0,
517 #ifdef HAVE_CYRUS_SASL
518 ARG_STRING|ARG_UNIQUE, &sasl_host,
522 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
523 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
524 { "sasl-realm", "realm", 2, 2, 0,
525 #ifdef HAVE_CYRUS_SASL
526 ARG_STRING|ARG_UNIQUE, &global_realm,
530 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
531 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
532 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
533 &config_generic, NULL, NULL, NULL },
534 { "sasl-secprops", "properties", 2, 2, 0,
535 #ifdef HAVE_CYRUS_SASL
536 ARG_MAGIC|CFG_SASLSECP, &config_generic,
540 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
541 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
542 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
543 &config_generic, NULL, NULL, NULL },
544 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
545 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
546 "EQUALITY distinguishedNameMatch "
547 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
548 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
549 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
550 "EQUALITY caseIgnoreMatch "
551 "SYNTAX OMsDirectoryString )", NULL, NULL },
552 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
553 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
554 "EQUALITY caseIgnoreMatch "
555 "SYNTAX OMsDirectoryString )", NULL, NULL },
556 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
557 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
558 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
559 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
560 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
561 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
562 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
563 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
564 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
565 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
566 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
567 "DESC 'Attributes whose values will always be sorted' "
568 "EQUALITY caseIgnoreMatch "
569 "SYNTAX OMsDirectoryString )", NULL, NULL },
570 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
571 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
574 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
575 "EQUALITY distinguishedNameMatch "
576 "SYNTAX OMsDN )", NULL, NULL },
577 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
578 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
579 "EQUALITY caseIgnoreMatch "
580 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
581 { "threads", "count", 2, 2, 0,
585 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
587 "( OLcfgGlAt:66 NAME 'olcThreads' "
588 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
589 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
590 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
591 "SYNTAX OMsDirectoryString )", NULL, NULL },
592 { "TLSCACertificateFile", NULL, 0, 0, 0,
594 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
598 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
599 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
600 { "TLSCACertificatePath", NULL, 0, 0, 0,
602 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
606 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
607 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
608 { "TLSCertificateFile", NULL, 0, 0, 0,
610 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
614 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
615 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
616 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
618 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
622 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
623 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
624 { "TLSCipherSuite", NULL, 0, 0, 0,
626 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
630 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
631 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
632 { "TLSCRLCheck", NULL, 0, 0, 0,
633 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
634 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
638 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
639 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
640 { "TLSCRLFile", NULL, 0, 0, 0,
641 #if defined(HAVE_GNUTLS)
642 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
646 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
647 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
648 { "TLSRandFile", NULL, 0, 0, 0,
650 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
654 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
655 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
656 { "TLSVerifyClient", NULL, 0, 0, 0,
658 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
662 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
663 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
664 { "TLSDHParamFile", NULL, 0, 0, 0,
666 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
670 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
671 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
672 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
673 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
674 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
675 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
676 NULL, NULL, NULL, NULL },
677 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
678 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
679 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
680 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
681 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
682 "EQUALITY caseIgnoreMatch "
683 "SUP labeledURI )", NULL, NULL },
684 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
685 NULL, NULL, NULL, NULL }
688 /* Routines to check if a child can be added to this type */
689 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
690 cfAddBackend, cfAddModule, cfAddOverlay;
692 /* NOTE: be careful when defining array members
693 * that can be conditionally compiled */
694 #define CFOC_GLOBAL cf_ocs[1]
695 #define CFOC_SCHEMA cf_ocs[2]
696 #define CFOC_BACKEND cf_ocs[3]
697 #define CFOC_DATABASE cf_ocs[4]
698 #define CFOC_OVERLAY cf_ocs[5]
699 #define CFOC_INCLUDE cf_ocs[6]
700 #define CFOC_FRONTEND cf_ocs[7]
702 #define CFOC_MODULE cf_ocs[8]
703 #endif /* SLAPD_MODULES */
705 static ConfigOCs cf_ocs[] = {
708 "DESC 'OpenLDAP configuration object' "
709 "ABSTRACT SUP top )", Cft_Abstract, NULL },
712 "DESC 'OpenLDAP Global configuration options' "
713 "SUP olcConfig STRUCTURAL "
714 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
715 "olcAttributeOptions $ olcAuthIDRewrite $ "
716 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
717 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
718 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
719 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
720 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
721 "olcLocalSSF $ olcLogLevel $ "
722 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
723 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
724 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
726 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
727 "olcSecurity $ olcServerID $ olcSizeLimit $ "
728 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
729 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
730 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
731 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
732 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
733 "olcTLSCRLFile $ olcToolThreads $ "
734 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
735 "olcDitContentRules ) )", Cft_Global },
737 "NAME 'olcSchemaConfig' "
738 "DESC 'OpenLDAP schema object' "
739 "SUP olcConfig STRUCTURAL "
740 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
741 "olcObjectClasses $ olcDitContentRules ) )",
742 Cft_Schema, NULL, cfAddSchema },
744 "NAME 'olcBackendConfig' "
745 "DESC 'OpenLDAP Backend-specific options' "
746 "SUP olcConfig STRUCTURAL "
747 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
749 "NAME 'olcDatabaseConfig' "
750 "DESC 'OpenLDAP Database-specific options' "
751 "SUP olcConfig STRUCTURAL "
753 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
754 "olcLastMod $ olcLimits $ "
755 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
756 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
757 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
758 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
759 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
761 Cft_Database, NULL, cfAddDatabase },
763 "NAME 'olcOverlayConfig' "
764 "DESC 'OpenLDAP Overlay-specific options' "
765 "SUP olcConfig STRUCTURAL "
766 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
768 "NAME 'olcIncludeFile' "
769 "DESC 'OpenLDAP configuration include file' "
770 "SUP olcConfig STRUCTURAL "
772 "MAY ( cn $ olcRootDSE ) )",
773 /* Used to be Cft_Include, that def has been removed */
774 Cft_Abstract, NULL, cfAddInclude },
775 /* This should be STRUCTURAL like all the other database classes, but
776 * that would mean inheriting all of the olcDatabaseConfig attributes,
777 * which causes them to be merged twice in config_build_entry.
780 "NAME 'olcFrontendConfig' "
781 "DESC 'OpenLDAP frontend configuration' "
783 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
784 Cft_Database, NULL, NULL },
787 "NAME 'olcModuleList' "
788 "DESC 'OpenLDAP dynamic module info' "
789 "SUP olcConfig STRUCTURAL "
790 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
791 Cft_Module, NULL, cfAddModule },
796 typedef struct ServerID {
797 struct ServerID *si_next;
798 struct berval si_url;
802 static ServerID *sid_list;
804 typedef struct voidList {
805 struct voidList *vl_next;
809 typedef struct ADlist {
810 struct ADlist *al_next;
811 AttributeDescription *al_desc;
814 static ADlist *sortVals;
817 config_generic(ConfigArgs *c) {
820 if ( c->op == SLAP_CONFIG_EMIT ) {
824 c->value_int = ldap_pvt_thread_get_concurrency();
827 c->value_int = connection_pool_max;
830 c->value_int = slap_tool_thread_max;
834 c->value_string = ch_strdup( passwd_salt );
839 if ( c->be->be_limits ) {
843 for ( i=0; c->be->be_limits[i]; i++ ) {
844 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
845 if ( bv.bv_len >= sizeof( buf ) ) {
846 ber_bvarray_free_x( c->rvalue_vals, NULL );
847 c->rvalue_vals = NULL;
851 bv.bv_val = buf + bv.bv_len;
852 limits_unparse( c->be->be_limits[i], &bv,
853 sizeof( buf ) - ( bv.bv_val - buf ) );
854 bv.bv_len += bv.bv_val - buf;
856 value_add_one( &c->rvalue_vals, &bv );
859 if ( !c->rvalue_vals ) rc = 1;
862 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
863 SLAP_RESTRICT_OP_WRITES;
866 c->value_string = ch_strdup( slap_sasl_getpolicy());
869 slap_sasl_regexp_unparse( &c->rvalue_vals );
870 if ( !c->rvalue_vals ) rc = 1;
872 #ifdef HAVE_CYRUS_SASL
874 struct berval bv = BER_BVNULL;
875 slap_sasl_secprops_unparse( &bv );
876 if ( !BER_BVISNULL( &bv )) {
877 ber_bvarray_add( &c->rvalue_vals, &bv );
885 c->value_int = c->be->be_max_deref_depth;
888 if ( SLAP_DBHIDDEN( c->be )) {
895 ConfigFile *cf = c->ca_private;
897 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
898 else if ( cf->c_om_head )
899 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
901 if ( !c->rvalue_vals )
906 ad_unparse_options( &c->rvalue_vals );
909 ConfigFile *cf = c->ca_private;
911 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
912 else if ( cf->c_oc_head )
913 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
915 if ( !c->rvalue_vals )
920 ConfigFile *cf = c->ca_private;
922 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
923 else if ( cf->c_at_head )
924 at_unparse( &c->rvalue_vals, cf->c_at_head,
926 if ( !c->rvalue_vals )
931 ConfigFile *cf = c->ca_private;
933 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
934 else if ( cf->c_cr_head )
935 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
937 if ( !c->rvalue_vals )
944 char *src, *dst, ibuf[11];
945 struct berval bv, abv;
947 if ( c->be == frontendDB )
950 end = frontendDB->be_acl;
951 for (i=0, a=c->be->be_acl; a && a != end; i++,a=a->acl_next) {
952 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
953 if ( abv.bv_len >= sizeof( ibuf ) ) {
954 ber_bvarray_free_x( c->rvalue_vals, NULL );
955 c->rvalue_vals = NULL;
959 acl_unparse( a, &bv );
960 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
961 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
962 /* Turn TAB / EOL into plain space */
963 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
964 if (isspace((unsigned char)*src)) *dst++ = ' ';
968 if (dst[-1] == ' ') {
972 abv.bv_len = dst - abv.bv_val;
973 ber_bvarray_add( &c->rvalue_vals, &abv );
979 ConfigFile *cf = c->ca_private;
980 if ( cf->c_dseFiles ) {
981 value_add( &c->rvalue_vals, cf->c_dseFiles );
992 for ( si = sid_list; si; si=si->si_next ) {
993 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
994 if ( !BER_BVISEMPTY( &si->si_url )) {
995 bv.bv_len = si->si_url.bv_len + 6;
996 bv.bv_val = ch_malloc( bv.bv_len );
997 sprintf( bv.bv_val, "%d %s", si->si_num,
999 ber_bvarray_add( &c->rvalue_vals, &bv );
1003 bv.bv_len = sprintf( buf, "%d", si->si_num );
1004 value_add_one( &c->rvalue_vals, &bv );
1013 c->value_string = ch_strdup( logfileName );
1018 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1020 case CFG_MIRRORMODE:
1021 if ( SLAP_SHADOW(c->be))
1022 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1026 case CFG_MONITORING:
1027 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1029 case CFG_SSTR_IF_MAX:
1030 c->value_int = index_substr_if_maxlen;
1032 case CFG_SSTR_IF_MIN:
1033 c->value_int = index_substr_if_minlen;
1036 c->value_int = index_intlen;
1038 case CFG_SORTVALS: {
1041 for ( sv = sortVals; sv; sv = sv->al_next ) {
1042 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1046 #ifdef SLAPD_MODULES
1048 ModPaths *mp = c->ca_private;
1051 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1054 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1055 SLAP_X_ORDERED_FMT "%s", i,
1056 mp->mp_loads[i].bv_val );
1057 if ( bv.bv_len >= sizeof( c->log ) ) {
1058 ber_bvarray_free_x( c->rvalue_vals, NULL );
1059 c->rvalue_vals = NULL;
1062 value_add_one( &c->rvalue_vals, &bv );
1066 rc = c->rvalue_vals ? 0 : 1;
1070 ModPaths *mp = c->ca_private;
1071 if ( !BER_BVISNULL( &mp->mp_path ))
1072 value_add_one( &c->rvalue_vals, &mp->mp_path );
1074 rc = c->rvalue_vals ? 0 : 1;
1080 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1081 if ( !c->rvalue_vals ) rc = 1;
1084 #ifdef SLAP_AUTH_REWRITE
1086 if ( authz_rewrites ) {
1087 struct berval bv, idx;
1092 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1093 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1094 if ( idx.bv_len >= sizeof( ibuf ) ) {
1095 ber_bvarray_free_x( c->rvalue_vals, NULL );
1096 c->rvalue_vals = NULL;
1099 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1100 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1101 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1102 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1103 authz_rewrites[i].bv_val,
1104 authz_rewrites[i].bv_len + 1 );
1105 ber_bvarray_add( &c->rvalue_vals, &bv );
1108 if ( !c->rvalue_vals ) rc = 1;
1115 } else if ( c->op == LDAP_MOD_DELETE ) {
1118 /* single-valued attrs, no-ops */
1126 case CFG_MIRRORMODE:
1127 case CFG_MONITORING:
1129 case CFG_SSTR_IF_MAX:
1130 case CFG_SSTR_IF_MIN:
1133 /* no-ops, requires slapd restart */
1138 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1142 ch_free( passwd_salt );
1147 ch_free( logfileName );
1155 case CFG_SERVERID: {
1156 ServerID *si, **sip;
1158 for ( i=0, si = sid_list, sip = &sid_list;
1159 si; si = *sip, i++ ) {
1160 if ( c->valx == -1 || i == c->valx ) {
1172 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1176 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1177 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1178 SLAP_INDEX_INTLEN_DEFAULT );
1182 if ( c->valx < 0 ) {
1184 if ( c->be == frontendDB )
1187 end = frontendDB->be_acl;
1188 acl_destroy( c->be->be_acl, end );
1189 c->be->be_acl = end;
1192 AccessControl **prev, *a;
1194 for (i=0, prev = &c->be->be_acl; i < c->valx;
1197 prev = &a->acl_next;
1200 *prev = a->acl_next;
1207 /* Can be NULL when undoing a failed add */
1208 if ( c->ca_entry ) {
1209 ce = c->ca_entry->e_private;
1210 /* can't modify the hardcoded schema */
1211 if ( ce->ce_parent->ce_type == Cft_Global )
1215 cfn = c->ca_private;
1216 if ( c->valx < 0 ) {
1219 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1221 if ( oc == cfn->c_oc_tail )
1224 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1226 ObjectClass *oc, *prev = NULL;
1228 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1233 if ( cfn->c_oc_tail == oc ) {
1234 cfn->c_oc_tail = prev;
1236 if ( cfn->c_oc_head == oc ) {
1238 cfn->c_oc_head = oc;
1245 /* Can be NULL when undoing a failed add */
1246 if ( c->ca_entry ) {
1247 ce = c->ca_entry->e_private;
1248 /* can't modify the hardcoded schema */
1249 if ( ce->ce_parent->ce_type == Cft_Global )
1253 cfn = c->ca_private;
1254 if ( c->valx < 0 ) {
1257 for( at = cfn->c_at_head; at; at_next( &at )) {
1259 if ( at == cfn->c_at_tail )
1262 cfn->c_at_head = cfn->c_at_tail = NULL;
1264 AttributeType *at, *prev = NULL;
1266 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1271 if ( cfn->c_at_tail == at ) {
1272 cfn->c_at_tail = prev;
1274 if ( cfn->c_at_head == at ) {
1276 cfn->c_at_head = at;
1281 if ( c->valx < 0 ) {
1283 for ( sv = sortVals; sv; sv = sortVals ) {
1284 sortVals = sv->al_next;
1285 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1292 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1293 prev = &sv->al_next;
1296 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1297 *prev = sv->al_next;
1303 /* FIXME: there is no limits_free function */
1305 /* FIXME: there is no ad_option_free function */
1307 /* FIXME: there is no way to remove attributes added by
1321 if(!(c->bi = backend_info(c->argv[1]))) {
1322 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1323 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1324 c->log, c->cr_msg, c->argv[1] );
1331 /* NOTE: config is always the first backend!
1333 if ( !strcasecmp( c->argv[1], "config" )) {
1334 c->be = LDAP_STAILQ_FIRST(&backendDB);
1335 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1338 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1340 if ( c->cr_msg[0] == 0 )
1341 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1342 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1349 ldap_pvt_thread_set_concurrency(c->value_int);
1353 if ( c->value_int < 2 ) {
1354 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1355 "threads=%d smaller than minimum value 2",
1357 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1358 c->log, c->cr_msg, 0 );
1361 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1362 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1363 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1364 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1365 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1366 c->log, c->cr_msg, 0 );
1368 if ( slapMode & SLAP_SERVER_MODE )
1369 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1370 connection_pool_max = c->value_int; /* save for reference */
1374 if ( slapMode & SLAP_TOOL_MODE )
1375 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1376 slap_tool_thread_max = c->value_int; /* save for reference */
1380 if ( passwd_salt ) ch_free( passwd_salt );
1381 passwd_salt = c->value_string;
1382 lutil_salt_format(passwd_salt);
1386 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1392 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1394 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1398 ch_free(c->value_string);
1399 if (slap_sasl_setpolicy( c->argv[1] )) {
1400 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1401 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1402 c->log, c->cr_msg, c->argv[1] );
1408 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1412 #ifdef HAVE_CYRUS_SASL
1415 char *txt = slap_sasl_secprops( c->argv[1] );
1417 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1419 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1427 c->be->be_max_deref_depth = c->value_int;
1433 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1434 cfn = c->ca_private;
1435 if(parse_oidm(c, 1, &om))
1437 if (!cfn->c_om_head) cfn->c_om_head = om;
1438 cfn->c_om_tail = om;
1443 ObjectClass *oc, *prev;
1445 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1446 cfn = c->ca_private;
1447 if ( c->valx < 0 ) {
1448 prev = cfn->c_oc_tail;
1451 /* If adding anything after the first, prev is easy */
1454 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1459 /* If adding the first, and head exists, find its prev */
1460 if (cfn->c_oc_head) {
1461 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1466 /* else prev is NULL, append to end of global list */
1468 if(parse_oc(c, &oc, prev)) return(1);
1469 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1470 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1475 AttributeType *at, *prev;
1477 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1478 cfn = c->ca_private;
1479 if ( c->valx < 0 ) {
1480 prev = cfn->c_at_tail;
1483 /* If adding anything after the first, prev is easy */
1486 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1491 /* If adding the first, and head exists, find its prev */
1492 if (cfn->c_at_head) {
1493 for ( at_start( &at ); at != cfn->c_at_head; ) {
1498 /* else prev is NULL, append to end of global list */
1500 if(parse_at(c, &at, prev)) return(1);
1501 if (!cfn->c_at_head) cfn->c_at_head = at;
1502 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1509 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1510 cfn = c->ca_private;
1511 if(parse_cr(c, &cr)) return(1);
1512 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1513 cfn->c_cr_tail = cr;
1518 ad_define_option(NULL, NULL, 0);
1519 for(i = 1; i < c->argc; i++)
1520 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1525 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1526 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1527 else if ( c->value_int > 255 )
1529 index_intlen = c->value_int;
1530 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1534 case CFG_SORTVALS: {
1535 ADlist *svnew = NULL, *svtail, *sv;
1537 for ( i = 1; i < c->argc; i++ ) {
1538 AttributeDescription *ad = NULL;
1542 rc = slap_str2ad( c->argv[i], &ad, &text );
1544 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1547 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1548 c->log, c->cr_msg, c->argv[i] );
1549 for ( sv = svnew; sv; sv = svnew ) {
1550 svnew = sv->al_next;
1555 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1556 ad->ad_type->sat_single_value ) {
1557 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1559 goto sortval_reject;
1561 sv = ch_malloc( sizeof( ADlist ));
1566 svtail->al_next = sv;
1571 for ( sv = svnew; sv; sv = sv->al_next )
1572 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1573 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1575 sv->al_next = svnew;
1582 /* Don't append to the global ACL if we're on a specific DB */
1584 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1587 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1591 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1597 if(root_dse_read_file(c->argv[1])) {
1598 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1599 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1600 c->log, c->cr_msg, c->argv[1] );
1605 ber_str2bv( c->argv[1], 0, 1, &bv );
1606 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1607 cfn = c->ca_private;
1608 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1614 ServerID *si, **sip;
1617 if ( lutil_atoi( &num, c->argv[1] ) ||
1618 num < 0 || num > SLAP_SYNC_SID_MAX )
1620 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1621 "<%s> illegal server ID", c->argv[0] );
1622 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1623 c->log, c->cr_msg, c->argv[1] );
1626 /* only one value allowed if no URL is given */
1627 if ( c->argc > 2 ) {
1630 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1631 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1632 "<%s> only one server ID allowed now", c->argv[0] );
1633 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1634 c->log, c->cr_msg, c->argv[1] );
1638 if ( ldap_url_parse( c->argv[2], &lud )) {
1639 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1640 "<%s> invalid URL", c->argv[0] );
1641 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1642 c->log, c->cr_msg, c->argv[2] );
1645 len = strlen( c->argv[2] );
1646 si = ch_malloc( sizeof(ServerID) + len + 1 );
1647 si->si_url.bv_val = (char *)(si+1);
1648 si->si_url.bv_len = len;
1649 strcpy( si->si_url.bv_val, c->argv[2] );
1652 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1653 "<%s> unqualified server ID not allowed now", c->argv[0] );
1654 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1655 c->log, c->cr_msg, c->argv[1] );
1658 si = ch_malloc( sizeof(ServerID) );
1659 BER_BVZERO( &si->si_url );
1660 slap_serverID = num;
1661 Debug( LDAP_DEBUG_CONFIG,
1663 c->log, slap_serverID, 0 );
1667 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1670 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1671 /* If hostname is empty, or is localhost, or matches
1672 * our hostname, this serverID refers to this host.
1673 * Compare it against listeners and ports.
1675 if ( !lud->lud_host || !lud->lud_host[0] ||
1676 !strncasecmp("localhost", lud->lud_host,
1677 STRLENOF("localhost")) ||
1678 !strcasecmp( global_host, lud->lud_host )) {
1679 Listener **l = slapd_get_listeners();
1682 for ( i=0; l && l[i]; i++ ) {
1685 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1687 if ( strcasecmp( lud->lud_scheme,
1690 if ( lud->lud_port != lu2->lud_port )
1692 /* Listener on ANY address */
1693 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1697 /* URL on ANY address */
1698 if ( !lud->lud_host || !lud->lud_host[0] ) {
1702 /* Listener has specific host, must
1705 if ( !strcasecmp( lud->lud_host,
1711 ldap_free_urldesc( lu2 );
1713 slap_serverID = si->si_num;
1714 Debug( LDAP_DEBUG_CONFIG,
1715 "%s: SID=%d (listener=%s)\n",
1716 c->log, slap_serverID,
1717 l[i]->sl_url.bv_val );
1724 ldap_free_urldesc( lud );
1728 if ( logfileName ) ch_free( logfileName );
1729 logfileName = c->value_string;
1730 logfile = fopen(logfileName, "w");
1731 if(logfile) lutil_debug_file(logfile);
1735 if(SLAP_NOLASTMODCMD(c->be)) {
1736 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1737 c->argv[0], c->be->bd_info->bi_type );
1738 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1739 c->log, c->cr_msg, 0 );
1743 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1745 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1748 case CFG_MIRRORMODE:
1749 if(!SLAP_SHADOW(c->be)) {
1750 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1752 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1753 c->log, c->cr_msg, 0 );
1757 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1759 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1762 case CFG_MONITORING:
1764 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1766 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1771 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1773 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1776 case CFG_SSTR_IF_MAX:
1777 if (c->value_int < index_substr_if_minlen) {
1778 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1779 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1780 c->log, c->cr_msg, c->value_int );
1783 index_substr_if_maxlen = c->value_int;
1786 case CFG_SSTR_IF_MIN:
1787 if (c->value_int > index_substr_if_maxlen) {
1788 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1789 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1790 c->log, c->cr_msg, c->value_int );
1793 index_substr_if_minlen = c->value_int;
1796 #ifdef SLAPD_MODULES
1798 /* If we're just adding a module on an existing modpath,
1799 * make sure we've selected the current path.
1801 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1802 modcur = c->ca_private;
1803 /* This should never fail */
1804 if ( module_path( modcur->mp_path.bv_val )) {
1805 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1807 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1808 c->log, c->cr_msg, modcur->mp_path.bv_val );
1812 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1814 /* Record this load on the current path */
1818 if ( c->op == SLAP_CONFIG_ADD ) {
1819 ptr = c->line + STRLENOF("moduleload");
1820 while (!isspace((unsigned char) *ptr)) ptr++;
1821 while (isspace((unsigned char) *ptr)) ptr++;
1825 ber_str2bv(ptr, 0, 1, &bv);
1826 ber_bvarray_add( &modcur->mp_loads, &bv );
1828 /* Check for any new hardcoded schema */
1829 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1830 config_check_schema( NULL, &cfBackInfo );
1835 if(module_path(c->argv[1])) return(1);
1836 /* Record which path was used with each module */
1840 if (!modpaths.mp_loads) {
1843 mp = ch_malloc( sizeof( ModPaths ));
1844 modlast->mp_next = mp;
1846 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1848 mp->mp_loads = NULL;
1859 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1861 slapi_plugins_used++;
1865 #ifdef SLAP_AUTH_REWRITE
1870 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1873 if ( c->argc > 1 ) {
1876 /* quote all args but the first */
1877 line = ldap_charray2str( c->argv, "\" \"" );
1878 ber_str2bv( line, 0, 0, &bv );
1879 s = ber_bvchr( &bv, '"' );
1880 assert( s != NULL );
1881 /* move the trailing quote of argv[0] to the end */
1882 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1883 bv.bv_val[ bv.bv_len - 1 ] = '"';
1886 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1889 ber_bvarray_add( &authz_rewrites, &bv );
1896 Debug( LDAP_DEBUG_ANY,
1897 "%s: unknown CFG_TYPE %d.\n",
1898 c->log, c->type, 0 );
1907 config_fname(ConfigArgs *c) {
1908 if(c->op == SLAP_CONFIG_EMIT) {
1909 if (c->ca_private) {
1910 ConfigFile *cf = c->ca_private;
1911 value_add_one( &c->rvalue_vals, &cf->c_file );
1920 config_cfdir(ConfigArgs *c) {
1921 if(c->op == SLAP_CONFIG_EMIT) {
1922 if ( !BER_BVISEMPTY( &cfdir )) {
1923 value_add_one( &c->rvalue_vals, &cfdir );
1932 config_search_base(ConfigArgs *c) {
1933 if(c->op == SLAP_CONFIG_EMIT) {
1935 if (!BER_BVISEMPTY(&default_search_base)) {
1936 value_add_one(&c->rvalue_vals, &default_search_base);
1937 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1941 } else if( c->op == LDAP_MOD_DELETE ) {
1942 ch_free( default_search_base.bv_val );
1943 ch_free( default_search_nbase.bv_val );
1944 BER_BVZERO( &default_search_base );
1945 BER_BVZERO( &default_search_nbase );
1949 if(c->bi || c->be != frontendDB) {
1950 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1951 "prior to any backend or database definition\n",
1956 if(default_search_nbase.bv_len) {
1957 free(default_search_base.bv_val);
1958 free(default_search_nbase.bv_val);
1961 default_search_base = c->value_dn;
1962 default_search_nbase = c->value_ndn;
1966 /* For RE23 compatibility we allow this in the global entry
1967 * but we now defer it to the frontend entry to allow modules
1968 * to load new hash types.
1971 config_passwd_hash(ConfigArgs *c) {
1973 if (c->op == SLAP_CONFIG_EMIT) {
1975 /* Don't generate it in the global entry */
1976 if ( c->table == Cft_Global )
1978 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1979 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1980 value_add_one(&c->rvalue_vals, &bv);
1983 } else if ( c->op == LDAP_MOD_DELETE ) {
1984 /* Deleting from global is a no-op, only the frontendDB entry matters */
1985 if ( c->table == Cft_Global )
1987 if ( c->valx < 0 ) {
1988 ldap_charray_free( default_passwd_hash );
1989 default_passwd_hash = NULL;
1992 ch_free( default_passwd_hash[i] );
1993 for (; default_passwd_hash[i]; i++ )
1994 default_passwd_hash[i] = default_passwd_hash[i+1];
1998 for(i = 1; i < c->argc; i++) {
1999 if(!lutil_passwd_scheme(c->argv[i])) {
2000 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2001 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2002 c->log, c->cr_msg, c->argv[i]);
2004 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2007 if(!default_passwd_hash) {
2008 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2009 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2010 c->log, c->cr_msg, 0 );
2017 config_schema_dn(ConfigArgs *c) {
2018 if ( c->op == SLAP_CONFIG_EMIT ) {
2020 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2021 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2022 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2026 } else if ( c->op == LDAP_MOD_DELETE ) {
2027 ch_free( c->be->be_schemadn.bv_val );
2028 ch_free( c->be->be_schemandn.bv_val );
2029 BER_BVZERO( &c->be->be_schemadn );
2030 BER_BVZERO( &c->be->be_schemandn );
2033 ch_free( c->be->be_schemadn.bv_val );
2034 ch_free( c->be->be_schemandn.bv_val );
2035 c->be->be_schemadn = c->value_dn;
2036 c->be->be_schemandn = c->value_ndn;
2041 config_sizelimit(ConfigArgs *c) {
2043 struct slap_limits_set *lim = &c->be->be_def_limit;
2044 if (c->op == SLAP_CONFIG_EMIT) {
2049 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2050 if ( !BER_BVISEMPTY( &bv ))
2051 value_add_one( &c->rvalue_vals, &bv );
2055 } else if ( c->op == LDAP_MOD_DELETE ) {
2056 /* Reset to defaults */
2057 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2058 lim->lms_s_hard = 0;
2059 lim->lms_s_unchecked = -1;
2061 lim->lms_s_pr_hide = 0;
2062 lim->lms_s_pr_total = 0;
2065 for(i = 1; i < c->argc; i++) {
2066 if(!strncasecmp(c->argv[i], "size", 4)) {
2067 rc = limits_parse_one(c->argv[i], lim);
2069 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2070 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2071 c->log, c->cr_msg, c->argv[i]);
2075 if(!strcasecmp(c->argv[i], "unlimited")) {
2076 lim->lms_s_soft = -1;
2078 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2079 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2080 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2081 c->log, c->cr_msg, c->argv[i]);
2085 lim->lms_s_hard = 0;
2092 config_timelimit(ConfigArgs *c) {
2094 struct slap_limits_set *lim = &c->be->be_def_limit;
2095 if (c->op == SLAP_CONFIG_EMIT) {
2100 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2101 if ( !BER_BVISEMPTY( &bv ))
2102 value_add_one( &c->rvalue_vals, &bv );
2106 } else if ( c->op == LDAP_MOD_DELETE ) {
2107 /* Reset to defaults */
2108 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2109 lim->lms_t_hard = 0;
2112 for(i = 1; i < c->argc; i++) {
2113 if(!strncasecmp(c->argv[i], "time", 4)) {
2114 rc = limits_parse_one(c->argv[i], lim);
2116 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2117 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2118 c->log, c->cr_msg, c->argv[i]);
2122 if(!strcasecmp(c->argv[i], "unlimited")) {
2123 lim->lms_t_soft = -1;
2125 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2126 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2127 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2128 c->log, c->cr_msg, c->argv[i]);
2132 lim->lms_t_hard = 0;
2139 config_overlay(ConfigArgs *c) {
2140 if (c->op == SLAP_CONFIG_EMIT) {
2142 } else if ( c->op == LDAP_MOD_DELETE ) {
2145 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2146 c->valx, &c->bi, &c->reply)) {
2148 Debug( LDAP_DEBUG_ANY,
2149 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2150 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2152 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2159 config_subordinate(ConfigArgs *c)
2165 case SLAP_CONFIG_EMIT:
2166 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2169 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2170 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2173 value_add_one( &c->rvalue_vals, &bv );
2177 case LDAP_MOD_DELETE:
2178 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2179 glue_sub_del( c->be );
2181 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2186 case SLAP_CONFIG_ADD:
2187 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2188 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2195 config_suffix(ConfigArgs *c)
2198 struct berval pdn, ndn;
2199 char *notallowed = NULL;
2201 if ( c->be == frontendDB ) {
2202 notallowed = "frontend";
2204 } else if ( SLAP_MONITOR(c->be) ) {
2205 notallowed = "monitor";
2207 } else if ( SLAP_CONFIG(c->be) ) {
2208 notallowed = "config";
2211 if ( notallowed != NULL ) {
2212 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2216 case LDAP_MOD_DELETE:
2217 case LDAP_MOD_REPLACE:
2218 case LDAP_MOD_INCREMENT:
2219 case SLAP_CONFIG_ADD:
2220 if ( !BER_BVISNULL( &c->value_dn ) ) {
2221 snprintf( buf, sizeof( buf ), "<%s> ",
2222 c->value_dn.bv_val );
2225 Debug(LDAP_DEBUG_ANY,
2226 "%s: suffix %snot allowed in %s database.\n",
2227 c->log, buf, notallowed );
2230 case SLAP_CONFIG_EMIT:
2231 /* don't complain when emitting... */
2235 /* FIXME: don't know what values may be valid;
2236 * please remove assertion, or add legal values
2237 * to either block */
2245 if (c->op == SLAP_CONFIG_EMIT) {
2246 if ( c->be->be_suffix == NULL
2247 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2251 value_add( &c->rvalue_vals, c->be->be_suffix );
2252 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2255 } else if ( c->op == LDAP_MOD_DELETE ) {
2256 if ( c->valx < 0 ) {
2257 ber_bvarray_free( c->be->be_suffix );
2258 ber_bvarray_free( c->be->be_nsuffix );
2259 c->be->be_suffix = NULL;
2260 c->be->be_nsuffix = NULL;
2263 ch_free( c->be->be_suffix[i].bv_val );
2264 ch_free( c->be->be_nsuffix[i].bv_val );
2266 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2267 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2269 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2274 #ifdef SLAPD_MONITOR_DN
2275 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2276 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2278 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2279 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2284 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2285 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2286 c->argv[0], c->be->bd_info->bi_type );
2287 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2288 c->log, c->cr_msg, 0);
2295 if (SLAP_DBHIDDEN( c->be ))
2298 tbe = select_backend(&ndn, 0);
2300 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2306 BackendDB *b2 = tbe;
2308 /* Does tbe precede be? */
2309 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2312 char *type = tbe->bd_info->bi_type;
2314 if ( overlay_is_over( tbe ) ) {
2315 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2316 type = oi->oi_orig->bi_type;
2319 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2320 "already served by a preceding %s database",
2321 c->argv[0], pdn.bv_val, type );
2322 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2323 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2329 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2330 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2331 "base provided \"%s\" (assuming okay)\n",
2332 c->log, default_search_base.bv_val, 0);
2334 ber_bvarray_add(&c->be->be_suffix, &pdn);
2335 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2340 config_rootdn(ConfigArgs *c) {
2341 if (c->op == SLAP_CONFIG_EMIT) {
2342 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2343 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2344 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2349 } else if ( c->op == LDAP_MOD_DELETE ) {
2350 ch_free( c->be->be_rootdn.bv_val );
2351 ch_free( c->be->be_rootndn.bv_val );
2352 BER_BVZERO( &c->be->be_rootdn );
2353 BER_BVZERO( &c->be->be_rootndn );
2356 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2357 ch_free( c->be->be_rootdn.bv_val );
2358 ch_free( c->be->be_rootndn.bv_val );
2360 c->be->be_rootdn = c->value_dn;
2361 c->be->be_rootndn = c->value_ndn;
2366 config_rootpw(ConfigArgs *c) {
2369 if (c->op == SLAP_CONFIG_EMIT) {
2370 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2371 /* don't copy, because "rootpw" is marked
2373 c->value_bv = c->be->be_rootpw;
2377 } else if ( c->op == LDAP_MOD_DELETE ) {
2378 ch_free( c->be->be_rootpw.bv_val );
2379 BER_BVZERO( &c->be->be_rootpw );
2383 tbe = select_backend(&c->be->be_rootndn, 0);
2385 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2387 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2388 c->log, c->cr_msg, 0);
2391 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2392 ch_free( c->be->be_rootpw.bv_val );
2393 c->be->be_rootpw = c->value_bv;
2398 config_restrict(ConfigArgs *c) {
2399 slap_mask_t restrictops = 0;
2401 slap_verbmasks restrictable_ops[] = {
2402 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2403 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2404 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2405 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2406 { BER_BVC("modrdn"), 0 },
2407 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2408 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2409 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2410 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2411 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2412 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2413 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2414 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2415 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2416 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2417 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2421 if (c->op == SLAP_CONFIG_EMIT) {
2422 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2424 } else if ( c->op == LDAP_MOD_DELETE ) {
2426 c->be->be_restrictops = 0;
2428 restrictops = verb_to_mask( c->line, restrictable_ops );
2429 c->be->be_restrictops ^= restrictops;
2433 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2435 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2436 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2437 c->log, c->cr_msg, c->argv[i]);
2440 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2441 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2442 c->be->be_restrictops |= restrictops;
2447 config_allows(ConfigArgs *c) {
2448 slap_mask_t allows = 0;
2450 slap_verbmasks allowable_ops[] = {
2451 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2452 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2453 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2454 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2455 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2458 if (c->op == SLAP_CONFIG_EMIT) {
2459 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2460 } else if ( c->op == LDAP_MOD_DELETE ) {
2464 allows = verb_to_mask( c->line, allowable_ops );
2465 global_allows ^= allows;
2469 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2471 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2472 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2473 c->log, c->cr_msg, c->argv[i]);
2476 global_allows |= allows;
2481 config_disallows(ConfigArgs *c) {
2482 slap_mask_t disallows = 0;
2484 slap_verbmasks disallowable_ops[] = {
2485 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2486 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2487 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2488 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2491 if (c->op == SLAP_CONFIG_EMIT) {
2492 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2493 } else if ( c->op == LDAP_MOD_DELETE ) {
2495 global_disallows = 0;
2497 disallows = verb_to_mask( c->line, disallowable_ops );
2498 global_disallows ^= disallows;
2502 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2504 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2505 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2506 c->log, c->cr_msg, c->argv[i]);
2509 global_disallows |= disallows;
2514 config_requires(ConfigArgs *c) {
2515 slap_mask_t requires = frontendDB->be_requires;
2516 int i, argc = c->argc;
2517 char **argv = c->argv;
2519 slap_verbmasks requires_ops[] = {
2520 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2521 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2522 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2523 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2524 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2527 if (c->op == SLAP_CONFIG_EMIT) {
2528 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2529 } else if ( c->op == LDAP_MOD_DELETE ) {
2531 c->be->be_requires = 0;
2533 requires = verb_to_mask( c->line, requires_ops );
2534 c->be->be_requires ^= requires;
2538 /* "none" can only be first, to wipe out default/global values */
2539 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2544 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2546 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2547 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2548 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2549 c->log, c->cr_msg, 0);
2551 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2552 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2553 c->log, c->cr_msg, c->argv[i]);
2557 c->be->be_requires = requires;
2561 static slap_verbmasks *loglevel_ops;
2564 loglevel_init( void )
2566 slap_verbmasks lo[] = {
2567 { BER_BVC("Any"), -1 },
2568 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2569 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2570 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2571 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2572 { BER_BVC("BER"), LDAP_DEBUG_BER },
2573 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2574 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2575 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2576 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2577 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2578 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2579 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2580 #if 0 /* no longer used (nor supported) */
2581 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2582 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2584 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2585 { BER_BVC("None"), LDAP_DEBUG_NONE },
2589 return slap_verbmasks_init( &loglevel_ops, lo );
2593 loglevel_destroy( void )
2595 if ( loglevel_ops ) {
2596 (void)slap_verbmasks_destroy( loglevel_ops );
2598 loglevel_ops = NULL;
2601 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2604 slap_loglevel_register( slap_mask_t m, struct berval *s )
2608 if ( loglevel_ops == NULL ) {
2612 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2615 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2623 slap_loglevel_get( struct berval *s, int *l )
2628 if ( loglevel_ops == NULL ) {
2632 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2633 m |= loglevel_ops[ i ].mask;
2636 for ( i = 1; m & i; i <<= 1 )
2643 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2646 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2657 str2loglevel( const char *s, int *l )
2661 if ( loglevel_ops == NULL ) {
2665 i = verb_to_mask( s, loglevel_ops );
2667 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2671 *l = loglevel_ops[ i ].mask;
2677 loglevel2str( int l )
2679 struct berval bv = BER_BVNULL;
2681 loglevel2bv( l, &bv );
2687 loglevel2bv( int l, struct berval *bv )
2689 if ( loglevel_ops == NULL ) {
2695 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2699 loglevel2bvarray( int l, BerVarray *bva )
2701 if ( loglevel_ops == NULL ) {
2705 return mask_to_verbs( loglevel_ops, l, bva );
2709 loglevel_print( FILE *out )
2713 if ( loglevel_ops == NULL ) {
2717 fprintf( out, "Installed log subsystems:\n\n" );
2718 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2719 fprintf( out, "\t%-30s (%lu)\n",
2720 loglevel_ops[ i ].word.bv_val,
2721 loglevel_ops[ i ].mask );
2724 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2725 "by specific code\n\n" );
2730 static int config_syslog;
2733 config_loglevel(ConfigArgs *c) {
2736 if ( loglevel_ops == NULL ) {
2740 if (c->op == SLAP_CONFIG_EMIT) {
2741 /* Get default or commandline slapd setting */
2742 if ( ldap_syslog && !config_syslog )
2743 config_syslog = ldap_syslog;
2744 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2746 } else if ( c->op == LDAP_MOD_DELETE ) {
2750 int level = verb_to_mask( c->line, loglevel_ops );
2751 config_syslog ^= level;
2753 if ( slapMode & SLAP_SERVER_MODE ) {
2754 ldap_syslog = config_syslog;
2759 for( i=1; i < c->argc; i++ ) {
2762 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2763 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2764 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2765 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2766 c->log, c->cr_msg, c->argv[i]);
2770 if ( str2loglevel( c->argv[i], &level ) ) {
2771 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2772 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2773 c->log, c->cr_msg, c->argv[i]);
2777 /* Explicitly setting a zero clears all the levels */
2779 config_syslog |= level;
2783 if ( slapMode & SLAP_SERVER_MODE ) {
2784 ldap_syslog = config_syslog;
2790 config_referral(ConfigArgs *c) {
2792 if (c->op == SLAP_CONFIG_EMIT) {
2793 if ( default_referral ) {
2794 value_add( &c->rvalue_vals, default_referral );
2799 } else if ( c->op == LDAP_MOD_DELETE ) {
2800 if ( c->valx < 0 ) {
2801 ber_bvarray_free( default_referral );
2802 default_referral = NULL;
2805 ch_free( default_referral[i].bv_val );
2806 for (; default_referral[i].bv_val; i++ )
2807 default_referral[i] = default_referral[i+1];
2811 if(validate_global_referral(c->argv[1])) {
2812 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2813 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2814 c->log, c->cr_msg, c->argv[1]);
2818 ber_str2bv(c->argv[1], 0, 0, &val);
2819 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2827 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2828 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2829 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2830 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2831 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2832 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2833 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2834 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2835 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2840 config_security(ConfigArgs *c) {
2841 slap_ssf_set_t *set = &c->be->be_ssf_set;
2844 if (c->op == SLAP_CONFIG_EMIT) {
2850 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2851 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2854 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2855 if ( bv.bv_len >= sizeof( numbuf ) ) {
2856 ber_bvarray_free_x( c->rvalue_vals, NULL );
2857 c->rvalue_vals = NULL;
2861 bv.bv_len += sec_keys[i].key.bv_len;
2862 bv.bv_val = ch_malloc( bv.bv_len + 1);
2863 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2864 strcpy( next, numbuf );
2865 ber_bvarray_add( &c->rvalue_vals, &bv );
2870 for(i = 1; i < c->argc; i++) {
2871 slap_ssf_t *tgt = NULL;
2873 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2874 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2875 sec_keys[j].key.bv_len)) {
2876 src = c->argv[i] + sec_keys[j].key.bv_len;
2877 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2882 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2883 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2884 c->log, c->cr_msg, c->argv[i]);
2888 if ( lutil_atou( tgt, src ) != 0 ) {
2889 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2890 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2891 c->log, c->cr_msg, c->argv[i]);
2899 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2903 for (; !BER_BVISNULL( &an->an_name ); an++) {
2904 /* if buflen == 0, assume the buffer size has been
2905 * already checked otherwise */
2906 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2907 if ( comma ) *ptr++ = ',';
2908 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2915 config_updatedn(ConfigArgs *c) {
2916 if (c->op == SLAP_CONFIG_EMIT) {
2917 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2918 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2919 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2923 } else if ( c->op == LDAP_MOD_DELETE ) {
2924 ch_free( c->be->be_update_ndn.bv_val );
2925 BER_BVZERO( &c->be->be_update_ndn );
2926 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2929 if(SLAP_SHADOW(c->be)) {
2930 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
2931 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2932 c->log, c->cr_msg, 0);
2936 ber_memfree_x( c->value_dn.bv_val, NULL );
2937 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2938 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2940 c->be->be_update_ndn = c->value_ndn;
2941 BER_BVZERO( &c->value_dn );
2942 BER_BVZERO( &c->value_ndn );
2944 return config_slurp_shadow( c );
2948 config_shadow( ConfigArgs *c, int flag )
2950 char *notallowed = NULL;
2952 if ( c->be == frontendDB ) {
2953 notallowed = "frontend";
2955 } else if ( SLAP_MONITOR(c->be) ) {
2956 notallowed = "monitor";
2959 if ( notallowed != NULL ) {
2960 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2964 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2970 config_updateref(ConfigArgs *c) {
2972 if (c->op == SLAP_CONFIG_EMIT) {
2973 if ( c->be->be_update_refs ) {
2974 value_add( &c->rvalue_vals, c->be->be_update_refs );
2979 } else if ( c->op == LDAP_MOD_DELETE ) {
2980 if ( c->valx < 0 ) {
2981 ber_bvarray_free( c->be->be_update_refs );
2982 c->be->be_update_refs = NULL;
2985 ch_free( c->be->be_update_refs[i].bv_val );
2986 for (; c->be->be_update_refs[i].bv_val; i++)
2987 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2991 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2992 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
2994 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2995 c->log, c->cr_msg, 0);
2999 if(validate_global_referral(c->argv[1])) {
3000 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3001 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3002 c->log, c->cr_msg, c->argv[1]);
3005 ber_str2bv(c->argv[1], 0, 0, &val);
3006 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3011 config_obsolete(ConfigArgs *c) {
3012 if (c->op == SLAP_CONFIG_EMIT)
3015 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3017 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3022 config_include(ConfigArgs *c) {
3023 int savelineno = c->lineno;
3026 ConfigFile *cfsave = cfn;
3027 ConfigFile *cf2 = NULL;
3029 /* Leftover from RE23. No dynamic config for include files */
3030 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3033 cf = ch_calloc( 1, sizeof(ConfigFile));
3034 if ( cfn->c_kids ) {
3035 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3041 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3042 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3043 c->lineno = savelineno - 1;
3046 if ( cf2 ) cf2->c_sibs = NULL;
3047 else cfn->c_kids = NULL;
3048 ch_free( cf->c_file.bv_val );
3058 config_tls_option(ConfigArgs *c) {
3060 LDAP *ld = slap_tls_ld;
3062 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3063 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3064 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3065 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3066 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3067 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3068 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3070 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3072 default: Debug(LDAP_DEBUG_ANY, "%s: "
3073 "unknown tls_option <0x%x>\n",
3074 c->log, c->type, 0);
3077 if (c->op == SLAP_CONFIG_EMIT) {
3078 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3079 } else if ( c->op == LDAP_MOD_DELETE ) {
3080 return ldap_pvt_tls_set_option( ld, flag, NULL );
3082 ch_free(c->value_string);
3083 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3086 /* FIXME: this ought to be provided by libldap */
3088 config_tls_config(ConfigArgs *c) {
3091 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3092 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3094 Debug(LDAP_DEBUG_ANY, "%s: "
3095 "unknown tls_option <0x%x>\n",
3096 c->log, c->type, 0);
3099 if (c->op == SLAP_CONFIG_EMIT) {
3100 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3101 } else if ( c->op == LDAP_MOD_DELETE ) {
3103 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3105 ch_free( c->value_string );
3106 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3107 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3108 Debug(LDAP_DEBUG_ANY, "%s: "
3109 "unable to parse %s \"%s\"\n",
3110 c->log, c->argv[0], c->argv[1] );
3113 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3115 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3120 static CfEntryInfo *
3121 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3131 if ( dn_match( &root->ce_entry->e_nname, dn ))
3134 c = dn->bv_val+dn->bv_len;
3135 for (;*c != ',';c--);
3139 for (--c;c>dn->bv_val && *c != ',';c--);
3143 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3145 root = root->ce_kids;
3147 for (;root;root=root->ce_sibs) {
3148 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3149 if ( cdn.bv_val == dn->bv_val ) {
3159 typedef struct setup_cookie {
3169 config_ldif_resp( Operation *op, SlapReply *rs )
3171 if ( rs->sr_type == REP_SEARCH ) {
3172 setup_cookie *sc = op->o_callback->sc_private;
3174 sc->cfb->cb_got_ldif = 1;
3175 /* Does the frontend exist? */
3176 if ( !sc->got_frontend ) {
3177 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3178 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3179 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3180 STRLENOF( "olcDatabase" ), "={-1}frontend",
3181 STRLENOF( "={-1}frontend" ))) {
3184 sc->ca->be = frontendDB;
3185 sc->ca->bi = frontendDB->bd_info;
3186 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3187 rdn.bv_val = sc->ca->log;
3188 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3189 "%s=" SLAP_X_ORDERED_FMT "%s",
3190 cfAd_database->ad_cname.bv_val, -1,
3191 sc->ca->bi->bi_type);
3193 sc->frontend = config_build_entry( op, rs,
3194 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3195 sc->ca->be->be_cf_ocs );
3204 /* Does the configDB exist? */
3205 if ( sc->got_frontend && !sc->got_config &&
3206 !strncmp( rs->sr_entry->e_nname.bv_val,
3207 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3208 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3209 STRLENOF( "olcDatabase" ), "={0}config",
3210 STRLENOF( "={0}config" ))) {
3213 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3214 sc->ca->bi = sc->ca->be->bd_info;
3215 rdn.bv_val = sc->ca->log;
3216 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3217 "%s=" SLAP_X_ORDERED_FMT "%s",
3218 cfAd_database->ad_cname.bv_val, 0,
3219 sc->ca->bi->bi_type);
3221 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3222 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3229 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3230 if ( rs->sr_err != LDAP_SUCCESS ) {
3231 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3232 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3238 /* Configure and read the underlying back-ldif store */
3240 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3241 CfBackInfo *cfb = be->be_private;
3247 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3248 Connection conn = {0};
3249 OperationBuffer opbuf;
3251 SlapReply rs = {REP_RESULT};
3252 Filter filter = { LDAP_FILTER_PRESENT };
3253 struct berval filterstr = BER_BVC("(objectclass=*)");
3256 /* Is the config directory available? */
3257 if ( stat( dir, &st ) < 0 ) {
3258 /* No, so don't bother using the backing store.
3259 * All changes will be in-memory only.
3264 cfb->cb_db.bd_info = backend_info( "ldif" );
3265 if ( !cfb->cb_db.bd_info )
3266 return 0; /* FIXME: eventually this will be a fatal error */
3268 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3271 cfb->cb_db.be_suffix = be->be_suffix;
3272 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3274 /* The suffix is always "cn=config". The underlying DB's rootdn
3275 * is always the same as the suffix.
3277 cfb->cb_db.be_rootdn = be->be_suffix[0];
3278 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3280 ber_str2bv( dir, 0, 1, &cfdir );
3285 argv[0] = "directory";
3286 argv[1] = (char *)dir;
3291 c.table = Cft_Database;
3293 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3297 if ( config_add_vals( ct, &c ))
3300 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3304 void *thrctx = ldap_pvt_thread_pool_context();
3307 connection_fake_init( &conn, &opbuf, thrctx );
3310 filter.f_desc = slap_schema.si_ad_objectClass;
3312 op->o_tag = LDAP_REQ_SEARCH;
3314 op->ors_filter = &filter;
3315 op->ors_filterstr = filterstr;
3316 op->ors_scope = LDAP_SCOPE_SUBTREE;
3318 op->o_dn = c.be->be_rootdn;
3319 op->o_ndn = c.be->be_rootndn;
3321 op->o_req_dn = be->be_suffix[0];
3322 op->o_req_ndn = be->be_nsuffix[0];
3324 op->ors_tlimit = SLAP_NO_LIMIT;
3325 op->ors_slimit = SLAP_NO_LIMIT;
3327 op->ors_attrs = slap_anlist_all_attributes;
3328 op->ors_attrsonly = 0;
3330 op->o_callback = &cb;
3333 cb.sc_private = ≻
3334 sc.got_frontend = 0;
3339 op->o_bd = &cfb->cb_db;
3341 /* Allow unknown attrs in DNs */
3342 prev_DN_strict = slap_DN_strict;
3345 rc = op->o_bd->be_search( op, &rs );
3347 /* Restore normal DN validation */
3348 slap_DN_strict = prev_DN_strict;
3350 op->o_tag = LDAP_REQ_ADD;
3351 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3352 op->ora_e = sc.frontend;
3353 rc = op->o_bd->be_add( op, &rs );
3355 if ( rc == LDAP_SUCCESS && sc.config ) {
3356 op->ora_e = sc.config;
3357 rc = op->o_bd->be_add( op, &rs );
3359 ldap_pvt_thread_pool_context_reset( thrctx );
3362 /* ITS#4194 - only use if it's present, or we're converting. */
3363 if ( !readit || rc == LDAP_SUCCESS )
3364 cfb->cb_use_ldif = 1;
3370 CfOc_cmp( const void *c1, const void *c2 ) {
3371 const ConfigOCs *co1 = c1;
3372 const ConfigOCs *co2 = c2;
3374 return ber_bvcmp( co1->co_name, co2->co_name );
3378 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3381 i = init_config_attrs( ct );
3384 /* set up the objectclasses */
3385 i = init_config_ocs( ocs );
3388 for (i=0; ocs[i].co_def; i++) {
3389 if ( ocs[i].co_oc ) {
3390 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3391 if ( !ocs[i].co_table )
3392 ocs[i].co_table = ct;
3393 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3400 read_config(const char *fname, const char *dir) {
3403 const char *cfdir, *cfname;
3406 /* Setup the config backend */
3407 be = backend_db_init( "config", NULL, 0, NULL );
3411 cfb = be->be_private;
3412 be->be_dfltaccess = ACL_NONE;
3414 /* If no .conf, or a dir was specified, setup the dir */
3415 if ( !fname || dir ) {
3417 /* If explicitly given, check for existence */
3420 if ( stat( dir, &st ) < 0 ) {
3421 Debug( LDAP_DEBUG_ANY,
3422 "invalid config directory %s, error %d\n",
3428 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3430 /* if fname is defaulted, try reading .d */
3431 rc = config_setup_ldif( be, cfdir, !fname );
3434 /* It may be OK if the base object doesn't exist yet. */
3435 if ( rc != LDAP_NO_SUCH_OBJECT )
3437 /* ITS#4194: But if dir was specified and no fname,
3438 * then we were supposed to read the dir. Unless we're
3439 * trying to slapadd the dir...
3441 if ( dir && !fname ) {
3442 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3444 /* Assume it's slapadd with a config dir, let it continue */
3446 cfb->cb_got_ldif = 1;
3447 cfb->cb_use_ldif = 1;
3452 /* If we read the config from back-ldif, nothing to do here */
3453 if ( cfb->cb_got_ldif ) {
3462 cfname = SLAPD_DEFAULT_CONFIGFILE;
3464 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3467 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3470 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3471 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3472 &frontendDB->be_schemadn );
3473 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3474 if ( rc != LDAP_SUCCESS ) {
3475 Debug(LDAP_DEBUG_ANY, "read_config: "
3476 "unable to normalize default schema DN \"%s\"\n",
3477 frontendDB->be_schemadn.bv_val, 0, 0 );
3478 /* must not happen */
3486 config_back_bind( Operation *op, SlapReply *rs )
3488 if ( be_isroot_pw( op ) ) {
3489 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3490 /* frontend sends result */
3491 return LDAP_SUCCESS;
3494 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3495 send_ldap_result( op, rs );
3501 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3505 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3507 rs->sr_attrs = op->ors_attrs;
3508 rs->sr_entry = ce->ce_entry;
3510 rc = send_search_entry( op, rs );
3512 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3513 if ( ce->ce_kids ) {
3514 rc = config_send( op, rs, ce->ce_kids, 1 );
3515 if ( rc ) return rc;
3518 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3519 rc = config_send( op, rs, ce, 0 );
3527 static ConfigTable *
3528 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3533 for (j=0; j<nocs; j++) {
3534 for (i=0; colst[j]->co_table[i].name; i++)
3535 if ( colst[j]->co_table[i].ad == ad ) {
3536 ca->table = colst[j]->co_type;
3537 return &colst[j]->co_table[i];
3543 /* Sort the attributes of the entry according to the order defined
3544 * in the objectclass, with required attributes occurring before
3545 * allowed attributes. For any attributes with sequencing dependencies
3546 * (e.g., rootDN must be defined after suffix) the objectclass must
3547 * list the attributes in the desired sequence.
3550 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3552 Attribute *a, *head = NULL, *tail = NULL, **prev;
3555 for (i=0; i<nocs; i++) {
3556 if ( colst[i]->co_oc->soc_required ) {
3557 AttributeType **at = colst[i]->co_oc->soc_required;
3558 for (j=0; at[j]; j++) {
3559 for (a=e->e_attrs, prev=&e->e_attrs; a;
3560 prev = &(*prev)->a_next, a=a->a_next) {
3561 if ( a->a_desc == at[j]->sat_ad ) {
3575 if ( colst[i]->co_oc->soc_allowed ) {
3576 AttributeType **at = colst[i]->co_oc->soc_allowed;
3577 for (j=0; at[j]; j++) {
3578 for (a=e->e_attrs, prev=&e->e_attrs; a;
3579 prev = &(*prev)->a_next, a=a->a_next) {
3580 if ( a->a_desc == at[j]->sat_ad ) {
3596 tail->a_next = e->e_attrs;
3602 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3604 Attribute *a = NULL;
3605 AttributeDescription *ad;
3615 Modifications *ml = ptr;
3617 vals = ml->sml_values;
3620 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3621 rc = ordered_value_sort( a, 1 );
3623 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3624 ad->ad_cname.bv_val );
3628 for ( i=0; vals[i].bv_val; i++ ) {
3629 ca->line = vals[i].bv_val;
3630 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3631 ca->line[0] == '{' ) {
3632 char *idx = strchr( ca->line, '}' );
3633 if ( idx ) ca->line = idx+1;
3635 rc = config_parse_vals( ct, ca, i );
3644 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3647 struct berval rtype, rval;
3649 AttributeDescription *ad = NULL;
3651 dnRdn( &e->e_name, rdn );
3652 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3653 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3654 rtype.bv_val = rdn->bv_val;
3655 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3658 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3659 a = attr_find( e->e_attrs, ad );
3660 if (!a ) return LDAP_NAMING_VIOLATION;
3667 config_rename_kids( CfEntryInfo *ce )
3670 struct berval rdn, nrdn;
3672 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3673 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3674 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3675 free( ce2->ce_entry->e_name.bv_val );
3676 free( ce2->ce_entry->e_nname.bv_val );
3677 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3679 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3681 config_rename_kids( ce2 );
3686 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3687 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3688 struct berval *nnewrdn, int use_ldif )
3692 struct berval odn, ondn;
3696 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3697 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3700 free( a->a_vals[0].bv_val );
3701 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3702 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3703 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3704 strcpy( a->a_vals[0].bv_val, ptr1 );
3706 if ( a->a_nvals != a->a_vals ) {
3707 free( a->a_nvals[0].bv_val );
3708 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3709 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3710 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3711 strcpy( a->a_nvals[0].bv_val, ptr1 );
3714 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3715 BackendDB *be = op->o_bd;
3716 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3717 struct berval dn, ndn, xdn, xndn;
3719 op->o_bd = &cfb->cb_db;
3721 /* Save current rootdn; use the underlying DB's rootdn */
3725 xndn = op->o_req_ndn;
3726 op->o_dn = op->o_bd->be_rootdn;
3727 op->o_ndn = op->o_bd->be_rootndn;
3729 op->o_req_ndn = ondn;
3731 scp = op->o_callback;
3732 op->o_callback = ≻
3733 op->orr_newrdn = *newrdn;
3734 op->orr_nnewrdn = *nnewrdn;
3735 op->orr_newSup = NULL;
3736 op->orr_nnewSup = NULL;
3737 op->orr_deleteoldrdn = 1;
3738 op->orr_modlist = NULL;
3739 slap_modrdn2mods( op, rs );
3740 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3741 rc = op->o_bd->be_modrdn( op, rs );
3742 slap_mods_free( op->orr_modlist, 1 );
3745 op->o_callback = scp;
3749 op->o_req_ndn = xndn;
3752 free( ondn.bv_val );
3754 config_rename_kids( e->e_private );
3759 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3760 Entry *e, int idx, int tailindex, int use_ldif )
3762 struct berval ival, newrdn, nnewrdn;
3765 char ibuf[32], *ptr1, *ptr2 = NULL;
3768 rc = config_rename_attr( rs, e, &rdn, &a );
3769 if ( rc ) return rc;
3772 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3773 if ( ival.bv_len >= sizeof( ibuf ) ) {
3774 return LDAP_NAMING_VIOLATION;
3777 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3778 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3781 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3782 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3785 ptr2 = ber_bvchr( &rdn, '}' );
3789 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3791 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3792 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3793 a->a_desc->ad_cname.bv_len );
3795 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3796 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3800 /* Do the equivalent of ModRDN */
3801 /* Replace DN / NDN */
3802 newrdn.bv_len = ptr1 - newrdn.bv_val;
3803 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3804 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3806 free( nnewrdn.bv_val );
3807 free( newrdn.bv_val );
3812 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3813 SlapReply *rs, int *renum, int *ibase )
3816 int index = -1, gotindex = 0, nsibs, rc = 0;
3817 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3818 char *ptr1, *ptr2 = NULL;
3821 if ( renum ) *renum = 0;
3823 /* These entries don't get indexed/renumbered */
3824 if ( ce_type == Cft_Global ) return 0;
3825 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3827 if ( ce_type == Cft_Module )
3830 /* See if the rdn has an index already */
3831 dnRdn( &e->e_name, &rdn );
3832 if ( ce_type == Cft_Database ) {
3833 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3834 "frontend", STRLENOF("frontend") ))
3836 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3837 "config", STRLENOF("config") ))
3840 ptr1 = ber_bvchr( &e->e_name, '{' );
3841 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3843 ptr2 = strchr( ptr1, '}' );
3844 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3845 return LDAP_NAMING_VIOLATION;
3846 if ( ptr2-ptr1 == 1)
3847 return LDAP_NAMING_VIOLATION;
3849 index = strtol( ptr1 + 1, &next, 10 );
3850 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3851 return LDAP_NAMING_VIOLATION;
3854 /* Special case, we allow -1 for the frontendDB */
3855 if ( index != -1 || !isfrontend )
3856 return LDAP_NAMING_VIOLATION;
3858 if ( isconfig && index != 0 ){
3859 return LDAP_NAMING_VIOLATION;
3863 /* count related kids */
3864 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3865 if ( ce->ce_type == ce_type ) nsibs++;
3868 /* account for -1 frontend */
3869 if ( ce_type == Cft_Database )
3872 if ( index != nsibs ) {
3874 if ( index < nsibs ) {
3875 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3876 /* Siblings need to be renumbered */
3877 if ( index != -1 || !isfrontend )
3881 /* config DB is always "0" */
3882 if ( isconfig && index == -1 ) {
3885 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
3889 /* just make index = nsibs */
3891 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3894 if ( ibase ) *ibase = index;
3895 if ( renum ) *renum = renumber;
3900 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3905 co.co_name = &oc->soc_cname;
3906 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3910 /* check for duplicates */
3911 for ( i = 0; i < *nocs; i++ ) {
3912 if ( *copp && (*copp)[i] == cop ) {
3918 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3919 if ( tmp == NULL ) {
3923 (*copp)[*nocs] = cop;
3928 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3929 if ( count_oc( *sups, copp, nocs ) ) {
3938 count_ocs( Attribute *oc_at, int *nocs )
3941 ConfigOCs **colst = NULL;
3945 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3949 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3951 assert( oc != NULL );
3952 if ( count_oc( oc, &colst, nocs ) ) {
3962 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3964 /* Leftover from RE23. Never parse this entry */
3965 return LDAP_COMPARE_TRUE;
3969 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3973 /* This entry is hardcoded, don't re-parse it */
3974 if ( p->ce_type == Cft_Global ) {
3975 cfn = p->ce_private;
3976 ca->ca_private = cfn;
3977 return LDAP_COMPARE_TRUE;
3979 if ( p->ce_type != Cft_Schema )
3980 return LDAP_CONSTRAINT_VIOLATION;
3982 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3983 ca->ca_private = cfn;
3984 cfo = p->ce_private;
3985 cfn->c_sibs = cfo->c_kids;
3987 return LDAP_SUCCESS;
3991 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3993 if ( p->ce_type != Cft_Global ) {
3994 return LDAP_CONSTRAINT_VIOLATION;
3996 /* config must be {0}, nothing else allowed */
3997 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
3998 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
3999 return LDAP_CONSTRAINT_VIOLATION;
4001 ca->be = frontendDB; /* just to get past check_vals */
4002 return LDAP_SUCCESS;
4006 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4008 if ( p->ce_type != Cft_Global ) {
4009 return LDAP_CONSTRAINT_VIOLATION;
4011 return LDAP_SUCCESS;
4015 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4017 if ( p->ce_type != Cft_Global ) {
4018 return LDAP_CONSTRAINT_VIOLATION;
4020 return LDAP_SUCCESS;
4024 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4026 if ( p->ce_type != Cft_Database ) {
4027 return LDAP_CONSTRAINT_VIOLATION;
4030 return LDAP_SUCCESS;
4034 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4039 AttributeDescription *ad;
4044 if ( cfn->c_cr_head ) {
4045 struct berval bv = BER_BVC("olcDitContentRules");
4047 slap_bv2ad( &bv, &ad, &text );
4048 ct = config_find_table( colst, nocs, ad, ca );
4049 config_del_vals( ct, ca );
4051 if ( cfn->c_oc_head ) {
4052 struct berval bv = BER_BVC("olcObjectClasses");
4054 slap_bv2ad( &bv, &ad, &text );
4055 ct = config_find_table( colst, nocs, ad, ca );
4056 config_del_vals( ct, ca );
4058 if ( cfn->c_at_head ) {
4059 struct berval bv = BER_BVC("olcAttributeTypes");
4061 slap_bv2ad( &bv, &ad, &text );
4062 ct = config_find_table( colst, nocs, ad, ca );
4063 config_del_vals( ct, ca );
4065 if ( cfn->c_om_head ) {
4066 struct berval bv = BER_BVC("olcObjectIdentifier");
4068 slap_bv2ad( &bv, &ad, &text );
4069 ct = config_find_table( colst, nocs, ad, ca );
4070 config_del_vals( ct, ca );
4072 cfo = p->ce_private;
4073 cfo->c_kids = cfn->c_sibs;
4078 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4080 int rc = LDAP_CONSTRAINT_VIOLATION;
4083 if ( (*cop)->co_ldadd ) {
4084 rc = (*cop)->co_ldadd( last, e, ca );
4085 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4090 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4091 ConfigOCs co = { 0 };
4093 co.co_name = &(*ocp)->soc_cname;
4094 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4095 if ( *cop == NULL ) {
4099 rc = config_add_oc( cop, last, e, ca );
4100 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4108 /* Parse an LDAP entry into config directives */
4110 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4111 int *renum, Operation *op )
4113 CfEntryInfo *ce, *last = NULL;
4114 ConfigOCs co, *coptr, **colst;
4115 Attribute *a, *oc_at, *soc_at;
4116 int i, ibase = -1, nocs, rc = 0;
4119 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4121 memset( ca, 0, sizeof(ConfigArgs));
4123 /* Make sure parent exists and entry does not. But allow
4124 * Databases and Overlays to be inserted. Don't do any
4125 * auto-renumbering if manageDSAit control is present.
4127 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4129 if ( ( op && op->o_managedsait ) ||
4130 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4131 ce->ce_type != Cft_Module ) )
4133 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4134 "DN=\"%s\" already exists\n",
4135 log_prefix, e->e_name.bv_val, 0 );
4136 return LDAP_ALREADY_EXISTS;
4140 dnParent( &e->e_nname, &pdn );
4142 /* If last is NULL, the new entry is the root/suffix entry,
4143 * otherwise last should be the parent.
4145 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4147 rs->sr_matched = last->ce_entry->e_name.bv_val;
4149 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4150 "DN=\"%s\" not child of DN=\"%s\"\n",
4151 log_prefix, e->e_name.bv_val,
4152 last->ce_entry->e_name.bv_val );
4153 return LDAP_NO_SUCH_OBJECT;
4157 /* No parent, must be root. This will never happen... */
4158 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4159 return LDAP_NO_SUCH_OBJECT;
4162 if ( last && !access_allowed( op, last->ce_entry,
4163 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4165 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4166 "DN=\"%s\" no write access to \"children\" of parent\n",
4167 log_prefix, e->e_name.bv_val, 0 );
4168 return LDAP_INSUFFICIENT_ACCESS;
4172 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4174 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4175 "DN=\"%s\" no objectClass\n",
4176 log_prefix, e->e_name.bv_val, 0 );
4177 return LDAP_OBJECT_CLASS_VIOLATION;
4180 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4182 ObjectClass *soc = NULL;
4183 char textbuf[ SLAP_TEXT_BUFLEN ];
4184 const char *text = textbuf;
4186 /* FIXME: check result */
4187 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4188 &text, textbuf, sizeof(textbuf), NULL );
4189 if ( rc != LDAP_SUCCESS ) {
4190 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4191 "DN=\"%s\" no structural objectClass (%s)\n",
4192 log_prefix, e->e_name.bv_val, text );
4195 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4196 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4197 if ( soc_at == NULL ) {
4198 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4199 "DN=\"%s\" no structural objectClass; "
4200 "unable to merge computed class %s\n",
4201 log_prefix, e->e_name.bv_val,
4202 soc->soc_cname.bv_val );
4203 return LDAP_OBJECT_CLASS_VIOLATION;
4206 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4207 "DN=\"%s\" no structural objectClass; "
4208 "computed objectClass %s merged\n",
4209 log_prefix, e->e_name.bv_val,
4210 soc->soc_cname.bv_val );
4213 /* Fake the coordinates based on whether we're part of an
4214 * LDAP Add or if reading the config dir
4217 ca->fname = "slapd";
4220 ca->fname = cfdir.bv_val;
4225 co.co_name = &soc_at->a_nvals[0];
4226 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4227 if ( coptr == NULL ) {
4228 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4229 "DN=\"%s\" no structural objectClass in configuration table\n",
4230 log_prefix, e->e_name.bv_val, 0 );
4231 return LDAP_OBJECT_CLASS_VIOLATION;
4234 /* Only the root can be Cft_Global, everything else must
4235 * have a parent. Only limited nesting arrangements are allowed.
4237 rc = LDAP_CONSTRAINT_VIOLATION;
4238 if ( coptr->co_type == Cft_Global && !last ) {
4239 cfn = cfb->cb_config;
4240 ca->ca_private = cfn;
4241 ca->be = frontendDB; /* just to get past check_vals */
4245 colst = count_ocs( oc_at, &nocs );
4247 /* Check whether the Add is allowed by its parent, and do
4248 * any necessary arg setup
4251 rc = config_add_oc( &coptr, last, e, ca );
4252 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4253 for ( i = 0; i<nocs; i++ ) {
4254 /* Already checked these */
4255 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4257 if ( colst[i]->co_ldadd &&
4258 ( rc = colst[i]->co_ldadd( last, e, ca ))
4259 != LDAP_CONSTRAINT_VIOLATION ) {
4265 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4266 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4267 "DN=\"%s\" no structural objectClass add function\n",
4268 log_prefix, e->e_name.bv_val, 0 );
4269 return LDAP_OBJECT_CLASS_VIOLATION;
4273 /* Add the entry but don't parse it, we already have its contents */
4274 if ( rc == LDAP_COMPARE_TRUE ) {
4279 if ( rc != LDAP_SUCCESS )
4282 /* Parse all the values and check for simple syntax errors before
4283 * performing any set actions.
4285 * If doing an LDAPadd, check for indexed names and any necessary
4286 * renaming/renumbering. Entries that don't need indexed names are
4287 * ignored. Entries that need an indexed name and arrive without one
4288 * are assigned to the end. Entries that arrive with an index may
4289 * cause the following entries to be renumbered/bumped down.
4291 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4292 * don't allow Adding an entry with an index that's already in use.
4293 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4295 * These entries can have auto-assigned indexes (appended to the end)
4296 * but only the other types support auto-renumbering of siblings.
4299 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4304 if ( renum && *renum && coptr->co_type != Cft_Database &&
4305 coptr->co_type != Cft_Overlay )
4307 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4308 "operation requires sibling renumbering" );
4309 rc = LDAP_UNWILLING_TO_PERFORM;
4314 init_config_argv( ca );
4316 /* Make sure we process attrs in the required order */
4317 sort_attrs( e, colst, nocs );
4319 for ( a = e->e_attrs; a; a = a->a_next ) {
4320 if ( a == oc_at ) continue;
4321 ct = config_find_table( colst, nocs, a->a_desc, ca );
4322 if ( !ct ) continue; /* user data? */
4323 rc = check_vals( ct, ca, a, 1 );
4324 if ( rc ) goto done_noop;
4327 /* Basic syntax checks are OK. Do the actual settings. */
4328 for ( a=e->e_attrs; a; a=a->a_next ) {
4329 if ( a == oc_at ) continue;
4330 ct = config_find_table( colst, nocs, a->a_desc, ca );
4331 if ( !ct ) continue; /* user data? */
4332 for (i=0; a->a_vals[i].bv_val; i++) {
4334 ca->line = a->a_vals[i].bv_val;
4335 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4336 ptr = strchr( ca->line, '}' );
4338 iptr = strchr( ca->line, '{' );
4342 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4344 ca->valx = strtol( iptr+1, NULL, 0 );
4351 rc = config_parse_add( ct, ca, i );
4359 /* Newly added databases and overlays need to be started up */
4360 if ( CONFIG_ONLINE_ADD( ca )) {
4361 if ( colst[0]->co_type == Cft_Database ) {
4362 rc = backend_startup_one( ca->be, &ca->reply );
4364 } else if ( colst[0]->co_type == Cft_Overlay ) {
4365 if ( ca->bi->bi_db_open ) {
4366 BackendInfo *bi_orig = ca->be->bd_info;
4367 ca->be->bd_info = ca->bi;
4368 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4369 ca->be->bd_info = bi_orig;
4371 } else if ( ca->cleanup ) {
4372 rc = ca->cleanup( ca );
4375 if (ca->cr_msg[0] == '\0')
4376 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4378 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4379 ca->log, ca->cr_msg, ca->argv[1] );
4386 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4387 ce->ce_parent = last;
4388 ce->ce_entry = entry_dup( e );
4389 ce->ce_entry->e_private = ce;
4390 ce->ce_type = colst[0]->co_type;
4393 ce->ce_private = ca->ca_private;
4394 ca->ca_entry = ce->ce_entry;
4397 } else if ( last->ce_kids ) {
4398 CfEntryInfo *c2, **cprev;
4400 /* Advance to first of this type */
4401 cprev = &last->ce_kids;
4402 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4403 cprev = &c2->ce_sibs;
4406 /* Account for the (-1) frontendDB entry */
4407 if ( ce->ce_type == Cft_Database ) {
4408 if ( ca->be == frontendDB )
4410 else if ( ibase != -1 )
4415 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4416 cprev = &c2->ce_sibs;
4422 for ( i=0; i<ibase; i++ ) {
4424 cprev = &c2->ce_sibs;
4427 ce->ce_sibs = *cprev;
4435 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4436 if ( ca->be != frontendDB )
4437 backend_destroy_one( ca->be, 1 );
4438 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4439 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4440 } else if ( colst[0]->co_type == Cft_Schema ) {
4441 schema_destroy_one( ca, colst, nocs, last );
4446 ch_free( ca->argv );
4447 if ( colst ) ch_free( colst );
4451 #define BIGTMP 10000
4453 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4454 int base, int rebase, int max, int use_ldif )
4456 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4457 ConfigType etype = ce->ce_type;
4458 int count = 0, rc = 0;
4460 /* Reverse ce list */
4461 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4462 if (ce2->ce_type != etype) {
4467 ce2->ce_sibs = cetmp;
4470 if ( max && count >= max ) {
4476 /* Move original to a temp name until increments are done */
4478 ce->ce_entry->e_private = NULL;
4479 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4480 base+BIGTMP, 0, use_ldif );
4481 ce->ce_entry->e_private = ce;
4483 /* start incrementing */
4484 for (ce2=cetmp; ce2; ce2=ce3) {
4486 ce2->ce_sibs = cerem;
4489 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4490 count+base, 0, use_ldif );
4494 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4495 base, 0, use_ldif );
4500 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4501 CfEntryInfo *ce2, int old, int use_ldif )
4505 /* Renumber original to a temp value */
4506 ce->ce_entry->e_private = NULL;
4507 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4508 old+BIGTMP, 0, use_ldif );
4509 ce->ce_entry->e_private = ce;
4511 /* start decrementing */
4512 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4513 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4514 count+old, 0, use_ldif );
4517 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4518 count+old, 0, use_ldif );
4521 /* Parse an LDAP entry into config directives, then store in underlying
4525 config_back_add( Operation *op, SlapReply *rs )
4531 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4532 NULL, ACL_WADD, NULL )) {
4533 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4537 cfb = (CfBackInfo *)op->o_bd->be_private;
4539 /* add opattrs for syncprov */
4541 char textbuf[SLAP_TEXT_BUFLEN];
4542 size_t textlen = sizeof textbuf;
4543 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4544 &rs->sr_text, textbuf, sizeof( textbuf ) );
4545 if ( rs->sr_err != LDAP_SUCCESS )
4547 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4548 if ( rs->sr_err != LDAP_SUCCESS ) {
4549 Debug( LDAP_DEBUG_TRACE,
4550 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4551 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4556 ldap_pvt_thread_pool_pause( &connection_pool );
4559 * 1) check for existence of entry
4560 * 2) check for sibling renumbering
4561 * 3) perform internal add
4562 * 4) perform any necessary renumbering
4563 * 5) store entry in underlying database
4565 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4566 if ( rs->sr_err != LDAP_SUCCESS ) {
4567 rs->sr_text = ca.cr_msg;
4572 CfEntryInfo *ce = ca.ca_entry->e_private;
4573 req_add_s addr = op->oq_add;
4574 op->o_tag = LDAP_REQ_MODRDN;
4575 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4576 op->o_tag = LDAP_REQ_ADD;
4578 if ( rs->sr_err != LDAP_SUCCESS ) {
4583 if ( cfb->cb_use_ldif ) {
4584 BackendDB *be = op->o_bd;
4585 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4586 struct berval dn, ndn;
4588 op->o_bd = &cfb->cb_db;
4590 /* Save current rootdn; use the underlying DB's rootdn */
4593 op->o_dn = op->o_bd->be_rootdn;
4594 op->o_ndn = op->o_bd->be_rootndn;
4596 scp = op->o_callback;
4597 op->o_callback = ≻
4598 op->o_bd->be_add( op, rs );
4600 op->o_callback = scp;
4606 ldap_pvt_thread_pool_resume( &connection_pool );
4609 send_ldap_result( op, rs );
4610 slap_graduate_commit_csn( op );
4614 typedef struct delrec {
4615 struct delrec *next;
4621 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4626 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4627 ca->line[0] == '{' )
4629 char *ptr = strchr( ca->line + 1, '}' );
4633 ca->valx = strtol( ca->line + 1, &next, 0 );
4634 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4640 rc = config_parse_add( ct, ca, i );
4648 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4651 int rc = LDAP_UNWILLING_TO_PERFORM;
4653 Entry *e = ce->ce_entry;
4654 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4659 delrec *dels = NULL, *deltail = NULL;
4661 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4662 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4664 colst = count_ocs( oc_at, &nocs );
4666 /* make sure add/del flags are clear; should always be true */
4667 for ( s = save_attrs; s; s = s->a_next ) {
4668 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4671 e->e_attrs = attrs_dup( e->e_attrs );
4673 init_config_argv( ca );
4676 ca->ca_private = ce->ce_private;
4678 ca->fname = "slapd";
4680 strcpy( ca->log, "back-config" );
4682 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4683 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4684 switch (ml->sml_op) {
4685 case LDAP_MOD_DELETE:
4686 case LDAP_MOD_REPLACE: {
4687 BerVarray vals = NULL, nvals = NULL;
4689 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4691 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4692 ml->sml_desc->ad_cname.bv_val );
4695 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4696 vals = ml->sml_values;
4697 nvals = ml->sml_nvalues;
4698 ml->sml_values = NULL;
4699 ml->sml_nvalues = NULL;
4701 /* If we're deleting by values, remember the indexes of the
4702 * values we deleted.
4704 if ( ct && ml->sml_values ) {
4706 i = ml->sml_numvals;
4707 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4718 rc = modify_delete_vindex(e, &ml->sml_mod,
4719 get_permissiveModify(op),
4720 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4721 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4722 ml->sml_values = vals;
4723 ml->sml_nvalues = nvals;
4728 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4731 case SLAP_MOD_SOFTADD: {
4732 int mop = ml->sml_op;
4734 ml->sml_op = LDAP_MOD_ADD;
4736 if ( ct->arg_type & ARG_NO_INSERT ) {
4737 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4739 navals = a->a_numvals;
4742 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4743 if ( ml->sml_values[i].bv_val[0] == '{' &&
4746 char *next, *val = ml->sml_values[i].bv_val + 1;
4749 j = strtol( val, &next, 0 );
4750 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4752 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4753 ml->sml_desc->ad_cname.bv_val );
4757 rc = check_vals( ct, ca, ml, 0 );
4758 if ( rc ) goto out_noop;
4761 rc = modify_add_values(e, &ml->sml_mod,
4762 get_permissiveModify(op),
4763 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4765 /* If value already exists, show success here
4766 * and ignore this operation down below.
4768 if ( mop == SLAP_MOD_SOFTADD ) {
4769 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4779 case LDAP_MOD_INCREMENT: /* FIXME */
4784 if(rc != LDAP_SUCCESS) break;
4787 if ( rc == LDAP_SUCCESS) {
4788 /* check that the entry still obeys the schema */
4789 rc = entry_schema_check(op, e, NULL, 0, 0,
4790 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4792 if ( rc ) goto out_noop;
4794 /* Basic syntax checks are OK. Do the actual settings. */
4795 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4796 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4797 if ( !ct ) continue;
4799 s = attr_find( save_attrs, ml->sml_desc );
4800 a = attr_find( e->e_attrs, ml->sml_desc );
4802 switch (ml->sml_op) {
4803 case LDAP_MOD_DELETE:
4804 case LDAP_MOD_REPLACE: {
4805 BerVarray vals = NULL, nvals = NULL;
4808 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4809 vals = ml->sml_values;
4810 nvals = ml->sml_nvalues;
4811 ml->sml_values = NULL;
4812 ml->sml_nvalues = NULL;
4815 if ( ml->sml_values )
4818 /* If we didn't delete the whole attribute */
4819 if ( ml->sml_values && a ) {
4820 struct berval *mvals;
4823 if ( ml->sml_nvalues )
4824 mvals = ml->sml_nvalues;
4826 mvals = ml->sml_values;
4828 /* use the indexes we saved up above */
4829 for (i=0; i < d->nidx; i++) {
4830 struct berval bv = *mvals++;
4831 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4832 bv.bv_val[0] == '{' ) {
4833 ptr = strchr( bv.bv_val, '}' ) + 1;
4834 bv.bv_len -= ptr - bv.bv_val;
4837 ca->line = bv.bv_val;
4838 ca->valx = d->idx[i];
4839 rc = config_del_vals( ct, ca );
4840 if ( rc != LDAP_SUCCESS ) break;
4842 s->a_flags |= SLAP_ATTR_IXDEL;
4843 for (j=i+1; j < d->nidx; j++)
4844 if ( d->idx[j] >d->idx[i] )
4850 rc = config_del_vals( ct, ca );
4851 if ( rc ) rc = LDAP_OTHER;
4853 s->a_flags |= SLAP_ATTR_IXDEL;
4855 if ( ml->sml_values ) {
4860 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4861 ml->sml_values = vals;
4862 ml->sml_nvalues = nvals;
4864 if ( !vals || rc != LDAP_SUCCESS )
4867 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4870 for (i=0; ml->sml_values[i].bv_val; i++) {
4871 ca->line = ml->sml_values[i].bv_val;
4873 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4876 a->a_flags |= SLAP_ATTR_IXADD;
4883 /* Undo for a failed operation */
4884 if ( rc != LDAP_SUCCESS ) {
4885 ConfigReply msg = ca->reply;
4886 for ( s = save_attrs; s; s = s->a_next ) {
4887 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4888 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4889 ct = config_find_table( colst, nocs, s->a_desc, ca );
4890 a = attr_find( e->e_attrs, s->a_desc );
4892 /* clear the flag so the add check below will skip it */
4893 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4896 config_del_vals( ct, ca );
4898 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4899 ca->line = s->a_vals[i].bv_val;
4901 config_modify_add( ct, ca, s->a_desc, i );
4905 for ( a = e->e_attrs; a; a = a->a_next ) {
4906 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4907 ct = config_find_table( colst, nocs, a->a_desc, ca );
4910 config_del_vals( ct, ca );
4911 s = attr_find( save_attrs, a->a_desc );
4913 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4914 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4915 ca->line = s->a_vals[i].bv_val;
4917 config_modify_add( ct, ca, s->a_desc, i );
4928 if ( rc == LDAP_SUCCESS ) {
4929 attrs_free( save_attrs );
4931 attrs_free( e->e_attrs );
4932 e->e_attrs = save_attrs;
4934 ch_free( ca->argv );
4935 if ( colst ) ch_free( colst );
4937 deltail = dels->next;
4946 config_back_modify( Operation *op, SlapReply *rs )
4949 CfEntryInfo *ce, *last;
4951 ConfigArgs ca = {0};
4954 AttributeDescription *rad = NULL;
4957 cfb = (CfBackInfo *)op->o_bd->be_private;
4959 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4962 rs->sr_matched = last->ce_entry->e_name.bv_val;
4963 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4967 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4968 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4972 /* Get type of RDN */
4973 rdn = ce->ce_entry->e_nname;
4974 ptr = strchr( rdn.bv_val, '=' );
4975 rdn.bv_len = ptr - rdn.bv_val;
4976 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4978 /* Some basic validation... */
4979 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4980 /* Don't allow Modify of RDN; must use ModRdn for that. */
4981 if ( ml->sml_desc == rad ) {
4982 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4983 rs->sr_text = "Use modrdn to change the entry name";
4986 /* Internal update of contextCSN? */
4987 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
4993 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4996 ldap_pvt_thread_pool_pause( &connection_pool );
4999 * 1) perform the Modify on the cached Entry.
5000 * 2) verify that the Entry still satisfies the schema.
5001 * 3) perform the individual config operations.
5002 * 4) store Modified entry in underlying LDIF backend.
5004 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5006 rs->sr_text = ca.cr_msg;
5007 } else if ( cfb->cb_use_ldif ) {
5008 BackendDB *be = op->o_bd;
5009 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5010 struct berval dn, ndn;
5012 op->o_bd = &cfb->cb_db;
5016 op->o_dn = op->o_bd->be_rootdn;
5017 op->o_ndn = op->o_bd->be_rootndn;
5019 scp = op->o_callback;
5020 op->o_callback = ≻
5021 op->o_bd->be_modify( op, rs );
5023 op->o_callback = scp;
5029 ldap_pvt_thread_pool_resume( &connection_pool );
5031 send_ldap_result( op, rs );
5032 slap_graduate_commit_csn( op );
5037 config_back_modrdn( Operation *op, SlapReply *rs )
5040 CfEntryInfo *ce, *last;
5044 cfb = (CfBackInfo *)op->o_bd->be_private;
5046 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5049 rs->sr_matched = last->ce_entry->e_name.bv_val;
5050 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5053 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5054 NULL, ACL_WRITE, NULL )) {
5055 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5059 if ( ce->ce_parent )
5060 parent = ce->ce_parent->ce_entry;
5062 parent = (Entry *)&slap_entry_root;
5063 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5064 NULL, ACL_WRITE, NULL )) {
5065 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5070 /* We don't allow moving objects to new parents.
5071 * Generally we only allow reordering a set of ordered entries.
5073 if ( op->orr_newSup ) {
5074 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5078 /* If newRDN == oldRDN, quietly succeed */
5079 dnRdn( &op->o_req_ndn, &rdn );
5080 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5081 rs->sr_err = LDAP_SUCCESS;
5085 /* Current behavior, subject to change as needed:
5087 * For backends and overlays, we only allow renumbering.
5088 * For schema, we allow renaming with the same number.
5089 * Otherwise, the op is not allowed.
5092 if ( ce->ce_type == Cft_Schema ) {
5096 /* Can't alter the main cn=schema entry */
5097 if ( ce->ce_parent->ce_type == Cft_Global ) {
5098 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5099 rs->sr_text = "renaming not allowed for this entry";
5103 /* We could support this later if desired */
5104 ptr1 = ber_bvchr( &rdn, '}' );
5105 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5106 len = ptr1 - rdn.bv_val;
5107 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5108 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5109 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5110 rs->sr_text = "schema reordering not supported";
5113 } else if ( ce->ce_type == Cft_Database ||
5114 ce->ce_type == Cft_Overlay ) {
5115 char *ptr1, *ptr2, *iptr1, *iptr2;
5118 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5119 if ( *iptr2 != '{' ) {
5120 rs->sr_err = LDAP_NAMING_VIOLATION;
5121 rs->sr_text = "new ordering index is required";
5125 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5126 ptr1 = ber_bvchr( &rdn, '}' );
5127 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5129 rs->sr_err = LDAP_NAMING_VIOLATION;
5130 rs->sr_text = "new ordering index is required";
5134 len1 = ptr1 - rdn.bv_val;
5135 len2 = ptr2 - op->orr_newrdn.bv_val;
5137 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5138 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5139 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5140 rs->sr_text = "changing database/overlay type not allowed";
5143 ixold = strtol( iptr1, NULL, 0 );
5144 ixnew = strtol( iptr2, &ptr1, 0 );
5145 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5146 rs->sr_err = LDAP_NAMING_VIOLATION;
5149 /* config DB is always 0, cannot be changed */
5150 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5151 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5155 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5156 rs->sr_text = "renaming not supported for this entry";
5160 ldap_pvt_thread_pool_pause( &connection_pool );
5162 if ( ce->ce_type == Cft_Schema ) {
5163 req_modrdn_s modr = op->oq_modrdn;
5166 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5167 if ( rs->sr_err == LDAP_SUCCESS ) {
5168 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5169 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5172 op->oq_modrdn = modr;
5174 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5175 req_modrdn_s modr = op->oq_modrdn;
5178 /* Advance to first of this type */
5179 cprev = &ce->ce_parent->ce_kids;
5180 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5181 cprev = &ce2->ce_sibs;
5184 /* Skip the -1 entry */
5185 if ( ce->ce_type == Cft_Database ) {
5186 cprev = &ce2->ce_sibs;
5192 /* Remove from old slot */
5193 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5194 cprev = &ce2->ce_sibs;
5195 *cprev = ce->ce_sibs;
5196 ceold = ce->ce_sibs;
5198 /* Insert into new slot */
5200 for ( i=0; i<ixnew; i++ ) {
5204 cprev = &ce2->ce_sibs;
5206 ce->ce_sibs = *cprev;
5211 /* NOTE: These should be encoded in the OC tables, not inline here */
5212 if ( ce->ce_type == Cft_Database )
5213 backend_db_move( ce->ce_be, ixnew );
5214 else if ( ce->ce_type == Cft_Overlay )
5215 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5217 if ( ixold < ixnew ) {
5218 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5221 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5222 ixold - ixnew, cfb->cb_use_ldif );
5224 op->oq_modrdn = modr;
5227 ldap_pvt_thread_pool_resume( &connection_pool );
5229 send_ldap_result( op, rs );
5234 config_back_delete( Operation *op, SlapReply *rs )
5236 #ifdef SLAP_CONFIG_DELETE
5238 CfEntryInfo *ce, *last, *ce2;
5242 cfb = (CfBackInfo *)op->o_bd->be_private;
5244 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5247 rs->sr_matched = last->ce_entry->e_name.bv_val;
5248 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5249 } else if ( ce->ce_kids ) {
5250 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5251 } else if ( ce->ce_type == Cft_Overlay ){
5253 int count, ixold, rc;
5255 ldap_pvt_thread_pool_pause( &connection_pool );
5257 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5259 /* remove CfEntryInfo from the siblings list */
5260 if ( ce->ce_parent->ce_kids == ce ) {
5261 ce->ce_parent->ce_kids = ce->ce_sibs;
5263 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5264 if ( ce2->ce_sibs == ce ) {
5265 ce2->ce_sibs = ce->ce_sibs;
5271 /* remove from underlying database */
5272 if ( cfb->cb_use_ldif ) {
5273 BackendDB *be = op->o_bd;
5274 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5275 struct berval dn, ndn, req_dn, req_ndn;
5277 op->o_bd = &cfb->cb_db;
5281 req_dn = op->o_req_dn;
5282 req_ndn = op->o_req_ndn;
5284 op->o_dn = op->o_bd->be_rootdn;
5285 op->o_ndn = op->o_bd->be_rootndn;
5286 op->o_req_dn = ce->ce_entry->e_name;
5287 op->o_req_ndn = ce->ce_entry->e_nname;
5289 scp = op->o_callback;
5290 op->o_callback = ≻
5291 op->o_bd->be_delete( op, rs );
5293 op->o_callback = scp;
5296 op->o_req_dn = req_dn;
5297 op->o_req_ndn = req_ndn;
5300 /* renumber siblings */
5301 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5302 ixold = strtol( iptr, NULL, 0 );
5303 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5304 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5305 count+ixold, 0, cfb->cb_use_ldif );
5309 ce->ce_entry->e_private=NULL;
5310 entry_free(ce->ce_entry);
5312 ldap_pvt_thread_pool_resume( &connection_pool );
5314 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5317 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5318 #endif /* SLAP_CONFIG_DELETE */
5319 send_ldap_result( op, rs );
5324 config_back_search( Operation *op, SlapReply *rs )
5327 CfEntryInfo *ce, *last;
5330 cfb = (CfBackInfo *)op->o_bd->be_private;
5332 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5335 rs->sr_matched = last->ce_entry->e_name.bv_val;
5336 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5339 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5340 ACL_SEARCH, NULL, &mask ))
5342 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5343 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5345 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5349 switch ( op->ors_scope ) {
5350 case LDAP_SCOPE_BASE:
5351 case LDAP_SCOPE_SUBTREE:
5352 config_send( op, rs, ce, 0 );
5355 case LDAP_SCOPE_ONELEVEL:
5356 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5357 config_send( op, rs, ce, 1 );
5362 rs->sr_err = LDAP_SUCCESS;
5364 send_ldap_result( op, rs );
5368 /* no-op, we never free entries */
5369 int config_entry_release(
5374 if ( !e->e_private ) {
5377 return LDAP_SUCCESS;
5380 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5382 int config_back_entry_get(
5386 AttributeDescription *at,
5391 CfEntryInfo *ce, *last;
5392 int rc = LDAP_NO_SUCH_OBJECT;
5394 cfb = (CfBackInfo *)op->o_bd->be_private;
5396 ce = config_find_base( cfb->cb_root, ndn, &last );
5398 *ent = ce->ce_entry;
5401 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5402 rc = LDAP_NO_SUCH_ATTRIBUTE;
5412 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5413 ConfigTable *ct, ConfigArgs *c )
5417 for (; at && *at; at++) {
5418 /* Skip the naming attr */
5419 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5421 for (i=0;ct[i].name;i++) {
5422 if (ct[i].ad == (*at)->sat_ad) {
5423 rc = config_get_vals(&ct[i], c);
5424 /* NOTE: tolerate that config_get_vals()
5425 * returns success with no values */
5426 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5427 if ( c->rvalue_nvals )
5428 attr_merge(e, ct[i].ad, c->rvalue_vals,
5431 attr_merge_normalize(e, ct[i].ad,
5432 c->rvalue_vals, NULL);
5433 ber_bvarray_free( c->rvalue_nvals );
5434 ber_bvarray_free( c->rvalue_vals );
5443 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5444 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5446 Entry *e = entry_alloc();
5447 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5449 struct berval ad_name;
5450 AttributeDescription *ad = NULL;
5457 CfEntryInfo *ceprev = NULL;
5459 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5462 ce->ce_type = main->co_type;
5463 ce->ce_parent = parent;
5465 pdn = parent->ce_entry->e_nname;
5466 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5467 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5468 ceprev->ce_type <= ce->ce_type;
5469 ceprev = ceprev->ce_sibs );
5474 ce->ce_private = c->ca_private;
5478 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5479 ber_dupbv( &e->e_nname, &e->e_name );
5481 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5482 main->co_name, NULL );
5484 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5485 extra->co_name, NULL );
5486 ptr = strchr(rdn->bv_val, '=');
5487 ad_name.bv_val = rdn->bv_val;
5488 ad_name.bv_len = ptr - rdn->bv_val;
5489 rc = slap_bv2ad( &ad_name, &ad, &text );
5494 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5495 attr_merge_normalize_one(e, ad, &val, NULL );
5498 c->table = main->co_type;
5499 if ( oc->soc_required )
5500 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5502 if ( oc->soc_allowed )
5503 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5507 c->table = extra->co_type;
5508 if ( oc->soc_required )
5509 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5511 if ( oc->soc_allowed )
5512 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5515 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5516 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5517 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5518 if ( rc != LDAP_SUCCESS ) {
5519 Debug( LDAP_DEBUG_ANY,
5520 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5521 rdn->bv_val, text, 0);
5524 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5527 op->ora_modlist = NULL;
5528 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5529 if ( !op->o_noop ) {
5530 op->o_bd->be_add( op, rs );
5531 if ( ( rs->sr_err != LDAP_SUCCESS )
5532 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5538 ce->ce_sibs = ceprev->ce_sibs;
5539 ceprev->ce_sibs = ce;
5540 } else if ( parent ) {
5541 ce->ce_sibs = parent->ce_kids;
5542 parent->ce_kids = ce;
5549 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5550 Operation *op, SlapReply *rs )
5553 ConfigFile *cf = c->ca_private;
5557 for (; cf; cf=cf->c_sibs, c->depth++) {
5558 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5559 !cf->c_om_head ) continue;
5560 c->value_dn.bv_val = c->log;
5561 LUTIL_SLASHPATH( cf->c_file.bv_val );
5562 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5567 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5569 ptr = strchr( bv.bv_val, '.' );
5571 bv.bv_len = ptr - bv.bv_val;
5572 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5573 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5574 /* FIXME: how can indicate error? */
5577 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5579 c->value_dn.bv_len += bv.bv_len;
5580 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5583 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5584 &CFOC_SCHEMA, NULL );
5587 } else if ( e && cf->c_kids ) {
5588 c->ca_private = cf->c_kids;
5589 config_build_schema_inc( c, e->e_private, op, rs );
5595 #ifdef SLAPD_MODULES
5598 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5599 Operation *op, SlapReply *rs )
5604 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5605 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5607 c->value_dn.bv_val = c->log;
5608 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5609 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5610 /* FIXME: how can indicate error? */
5614 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5623 config_check_schema(Operation *op, CfBackInfo *cfb)
5625 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5627 CfEntryInfo *ce, *last;
5630 /* If there's no root entry, we must be in the midst of converting */
5631 if ( !cfb->cb_root )
5634 /* Make sure the main schema entry exists */
5635 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5642 /* Make sure it's up to date */
5643 if ( cf_om_tail != om_sys_tail ) {
5644 a = attr_find( e->e_attrs, cfAd_om );
5646 if ( a->a_nvals != a->a_vals )
5647 ber_bvarray_free( a->a_nvals );
5648 ber_bvarray_free( a->a_vals );
5653 oidm_unparse( &bv, NULL, NULL, 1 );
5654 attr_merge_normalize( e, cfAd_om, bv, NULL );
5655 ber_bvarray_free( bv );
5656 cf_om_tail = om_sys_tail;
5658 if ( cf_at_tail != at_sys_tail ) {
5659 a = attr_find( e->e_attrs, cfAd_attr );
5661 if ( a->a_nvals != a->a_vals )
5662 ber_bvarray_free( a->a_nvals );
5663 ber_bvarray_free( a->a_vals );
5668 at_unparse( &bv, NULL, NULL, 1 );
5669 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5670 ber_bvarray_free( bv );
5671 cf_at_tail = at_sys_tail;
5673 if ( cf_oc_tail != oc_sys_tail ) {
5674 a = attr_find( e->e_attrs, cfAd_oc );
5676 if ( a->a_nvals != a->a_vals )
5677 ber_bvarray_free( a->a_nvals );
5678 ber_bvarray_free( a->a_vals );
5683 oc_unparse( &bv, NULL, NULL, 1 );
5684 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5685 ber_bvarray_free( bv );
5686 cf_oc_tail = oc_sys_tail;
5689 SlapReply rs = {REP_RESULT};
5690 c.ca_private = NULL;
5691 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5692 &CFOC_SCHEMA, NULL );
5697 ce->ce_private = cfb->cb_config;
5698 cf_at_tail = at_sys_tail;
5699 cf_oc_tail = oc_sys_tail;
5700 cf_om_tail = om_sys_tail;
5705 static const char *defacl[] = {
5706 NULL, "to", "*", "by", "*", "none", NULL
5710 config_back_db_open( BackendDB *be, ConfigReply *cr )
5712 CfBackInfo *cfb = be->be_private;
5715 CfEntryInfo *ce, *ceparent;
5719 Connection conn = {0};
5720 OperationBuffer opbuf;
5722 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5723 SlapReply rs = {REP_RESULT};
5724 void *thrctx = NULL;
5726 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5728 /* If we have no explicitly configured ACLs, don't just use
5729 * the global ACLs. Explicitly deny access to everything.
5731 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5732 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5735 thrctx = ldap_pvt_thread_pool_context();
5736 connection_fake_init( &conn, &opbuf, thrctx );
5739 op->o_tag = LDAP_REQ_ADD;
5740 op->o_callback = &cb;
5741 op->o_bd = &cfb->cb_db;
5742 op->o_dn = op->o_bd->be_rootdn;
5743 op->o_ndn = op->o_bd->be_rootndn;
5745 if ( !cfb->cb_use_ldif ) {
5749 /* If we read the config from back-ldif, do some quick sanity checks */
5750 if ( cfb->cb_got_ldif ) {
5751 return config_check_schema( op, cfb );
5754 /* create root of tree */
5756 c.ca_private = cfb->cb_config;
5758 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5768 #ifdef SLAPD_MODULES
5769 /* Create Module nodes... */
5770 if ( modpaths.mp_loads ) {
5771 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5777 /* Create schema nodes... cn=schema will contain the hardcoded core
5778 * schema, read-only. Child objects will contain runtime loaded schema
5782 c.ca_private = NULL;
5783 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5788 ce->ce_private = cfb->cb_config;
5789 cf_at_tail = at_sys_tail;
5790 cf_oc_tail = oc_sys_tail;
5791 cf_om_tail = om_sys_tail;
5793 /* Create schema nodes for included schema... */
5794 if ( cfb->cb_config->c_kids ) {
5796 c.ca_private = cfb->cb_config->c_kids;
5797 if (config_build_schema_inc( &c, ce, op, &rs )) {
5802 /* Create backend nodes. Skip if they don't provide a cf_table.
5803 * There usually aren't any of these.
5807 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5808 if (!bi->bi_cf_ocs) {
5809 /* If it only supports the old config mech, complain. */
5810 if ( bi->bi_config ) {
5811 Debug( LDAP_DEBUG_ANY,
5812 "WARNING: No dynamic config support for backend %s.\n",
5813 bi->bi_type, 0, 0 );
5818 if (!bi->bi_private) continue;
5821 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5822 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5823 if ( rdn.bv_len >= sizeof( c.log ) ) {
5824 /* FIXME: holler ... */ ;
5827 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5834 /* Create database nodes... */
5835 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5836 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5837 for ( i = -1, be = frontendDB ; be;
5838 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5839 slap_overinfo *oi = NULL;
5841 if ( overlay_is_over( be )) {
5842 oi = be->bd_info->bi_private;
5848 /* If this backend supports the old config mechanism, but not
5849 * the new mech, complain.
5851 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5852 Debug( LDAP_DEBUG_ANY,
5853 "WARNING: No dynamic config support for database %s.\n",
5854 bi->bi_type, 0, 0 );
5858 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5859 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5861 if ( rdn.bv_len >= sizeof( c.log ) ) {
5862 /* FIXME: holler ... */ ;
5866 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5872 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5873 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5874 /* Iterate through overlays */
5879 voidList *vl, *v0 = NULL;
5881 /* overlays are in LIFO order, must reverse stack */
5882 for (on=oi->oi_list; on; on=on->on_next) {
5883 vl = ch_malloc( sizeof( voidList ));
5888 for (j=0; vl; j++,vl=v0) {
5892 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5893 Debug( LDAP_DEBUG_ANY,
5894 "WARNING: No dynamic config support for overlay %s.\n",
5895 on->on_bi.bi_type, 0, 0 );
5899 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5900 "%s=" SLAP_X_ORDERED_FMT "%s",
5901 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5902 if ( rdn.bv_len >= sizeof( c.log ) ) {
5903 /* FIXME: holler ... */ ;
5907 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5908 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5912 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5913 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5918 ldap_pvt_thread_pool_context_reset( thrctx );
5920 if ( unsupp && cfb->cb_use_ldif ) {
5921 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5922 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5929 cfb_free_cffile( ConfigFile *cf )
5933 for (; cf; cf=next) {
5936 cfb_free_cffile( cf->c_kids );
5937 ch_free( cf->c_file.bv_val );
5938 ber_bvarray_free( cf->c_dseFiles );
5944 cfb_free_entries( CfEntryInfo *ce )
5948 for (; ce; ce=next) {
5951 cfb_free_entries( ce->ce_kids );
5952 ce->ce_entry->e_private = NULL;
5953 entry_free( ce->ce_entry );
5959 config_back_db_close( BackendDB *be, ConfigReply *cr )
5961 CfBackInfo *cfb = be->be_private;
5963 cfb_free_entries( cfb->cb_root );
5964 cfb->cb_root = NULL;
5966 if ( cfb->cb_db.bd_info ) {
5967 backend_shutdown( &cfb->cb_db );
5974 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
5976 CfBackInfo *cfb = be->be_private;
5978 cfb_free_cffile( cfb->cb_config );
5980 ch_free( cfdir.bv_val );
5982 avl_free( CfOcTree, NULL );
5984 if ( cfb->cb_db.bd_info ) {
5985 cfb->cb_db.be_suffix = NULL;
5986 cfb->cb_db.be_nsuffix = NULL;
5987 BER_BVZERO( &cfb->cb_db.be_rootdn );
5988 BER_BVZERO( &cfb->cb_db.be_rootndn );
5990 backend_destroy_one( &cfb->cb_db, 0 );
5999 config_back_db_init( BackendDB *be, ConfigReply* cr )
6005 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6006 cfn = cfb->cb_config;
6007 be->be_private = cfb;
6009 ber_dupbv( &be->be_rootdn, &config_rdn );
6010 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6011 ber_dupbv( &dn, &be->be_rootdn );
6012 ber_bvarray_add( &be->be_suffix, &dn );
6013 ber_dupbv( &dn, &be->be_rootdn );
6014 ber_bvarray_add( &be->be_nsuffix, &dn );
6016 /* Hide from namingContexts */
6017 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6023 config_back_destroy( BackendInfo *bi )
6025 ldif_must_b64_encode_release();
6030 config_tool_entry_open( BackendDB *be, int mode )
6032 CfBackInfo *cfb = be->be_private;
6033 BackendInfo *bi = cfb->cb_db.bd_info;
6035 if ( bi && bi->bi_tool_entry_open )
6036 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6043 config_tool_entry_close( BackendDB *be )
6045 CfBackInfo *cfb = be->be_private;
6046 BackendInfo *bi = cfb->cb_db.bd_info;
6048 if ( bi && bi->bi_tool_entry_close )
6049 return bi->bi_tool_entry_close( &cfb->cb_db );
6055 config_tool_entry_first( BackendDB *be )
6057 CfBackInfo *cfb = be->be_private;
6058 BackendInfo *bi = cfb->cb_db.bd_info;
6060 if ( bi && bi->bi_tool_entry_first )
6061 return bi->bi_tool_entry_first( &cfb->cb_db );
6067 config_tool_entry_next( BackendDB *be )
6069 CfBackInfo *cfb = be->be_private;
6070 BackendInfo *bi = cfb->cb_db.bd_info;
6072 if ( bi && bi->bi_tool_entry_next )
6073 return bi->bi_tool_entry_next( &cfb->cb_db );
6079 config_tool_entry_get( BackendDB *be, ID id )
6081 CfBackInfo *cfb = be->be_private;
6082 BackendInfo *bi = cfb->cb_db.bd_info;
6084 if ( bi && bi->bi_tool_entry_get )
6085 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6090 static int entry_put_got_frontend=0;
6091 static int entry_put_got_config=0;
6093 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6095 CfBackInfo *cfb = be->be_private;
6096 BackendInfo *bi = cfb->cb_db.bd_info;
6098 struct berval rdn, vals[ 2 ];
6100 OperationBuffer opbuf;
6102 Connection conn = {0};
6103 Operation *op = NULL;
6107 /* Create entry for frontend database if it does not exist already */
6108 if ( !entry_put_got_frontend ) {
6109 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6110 STRLENOF( "olcDatabase" ))) {
6111 if ( strncmp( e->e_nname.bv_val +
6112 STRLENOF( "olcDatabase" ), "={-1}frontend",
6113 STRLENOF( "={-1}frontend" )) &&
6114 strncmp( e->e_nname.bv_val +
6115 STRLENOF( "olcDatabase" ), "=frontend",
6116 STRLENOF( "=frontend" ))) {
6118 vals[1].bv_val = NULL;
6119 memset( &ca, 0, sizeof(ConfigArgs));
6121 ca.bi = frontendDB->bd_info;
6122 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6123 rdn.bv_val = ca.log;
6124 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6125 "%s=" SLAP_X_ORDERED_FMT "%s",
6126 cfAd_database->ad_cname.bv_val, -1,
6128 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6129 &CFOC_DATABASE, ca.be->be_cf_ocs );
6130 thrctx = ldap_pvt_thread_pool_context();
6131 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6133 op->o_bd = &cfb->cb_db;
6134 op->o_tag = LDAP_REQ_ADD;
6136 op->o_dn = be->be_rootdn;
6137 op->o_ndn = be->be_rootndn;
6138 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6139 if ( rc != LDAP_SUCCESS ) {
6140 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6141 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6145 if ( ce && bi && bi->bi_tool_entry_put &&
6146 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6147 entry_put_got_frontend++;
6149 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6150 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6154 entry_put_got_frontend++;
6159 /* Create entry for config database if it does not exist already */
6160 if ( !entry_put_got_config && !isFrontend ) {
6161 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6162 STRLENOF( "olcDatabase" ))) {
6163 if ( strncmp( e->e_nname.bv_val +
6164 STRLENOF( "olcDatabase" ), "={0}config",
6165 STRLENOF( "={0}config" )) &&
6166 strncmp( e->e_nname.bv_val +
6167 STRLENOF( "olcDatabase" ), "=config",
6168 STRLENOF( "=config" )) ) {
6170 vals[1].bv_val = NULL;
6171 memset( &ca, 0, sizeof(ConfigArgs));
6172 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6173 ca.bi = ca.be->bd_info;
6174 rdn.bv_val = ca.log;
6175 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6176 "%s=" SLAP_X_ORDERED_FMT "%s",
6177 cfAd_database->ad_cname.bv_val, 0,
6179 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6182 thrctx = ldap_pvt_thread_pool_context();
6183 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6185 op->o_bd = &cfb->cb_db;
6186 op->o_tag = LDAP_REQ_ADD;
6187 op->o_dn = be->be_rootdn;
6188 op->o_ndn = be->be_rootndn;
6191 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6192 if ( rc != LDAP_SUCCESS ) {
6193 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6194 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6197 if (ce && bi && bi->bi_tool_entry_put &&
6198 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6199 entry_put_got_config++;
6201 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6202 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6206 entry_put_got_config++;
6210 if ( bi && bi->bi_tool_entry_put &&
6211 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6212 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6219 AttributeDescription **desc;
6221 { "attribute", &cfAd_attr },
6222 { "backend", &cfAd_backend },
6223 { "database", &cfAd_database },
6224 { "include", &cfAd_include },
6225 { "objectclass", &cfAd_oc },
6226 { "objectidentifier", &cfAd_om },
6227 { "overlay", &cfAd_overlay },
6232 * add / delete: all types that may be added or deleted must use an
6233 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6234 * should automatically renumber the index of any siblings as needed,
6235 * so that no gaps in the numbering sequence exist after the add/delete
6237 * What can be added:
6239 * backend objects for backend-specific config directives
6243 * delete: probably no support this time around.
6245 * modrdn: generally not done. Will be invoked automatically by add/
6246 * delete to update numbering sequence. Perform as an explicit operation
6247 * so that the renumbering effect may be replicated. Subtree rename must
6248 * be supported, since renumbering a database will affect all its child
6251 * modify: must be fully supported.
6255 config_back_initialize( BackendInfo *bi )
6257 ConfigTable *ct = config_back_cf_table;
6261 AttributeDescription *ad = NULL;
6263 static char *controls[] = {
6264 LDAP_CONTROL_MANAGEDSAIT,
6268 /* Make sure we don't exceed the bits reserved for userland */
6269 config_check_userland( CFG_LAST );
6271 bi->bi_controls = controls;
6276 bi->bi_destroy = config_back_destroy;
6278 bi->bi_db_init = config_back_db_init;
6279 bi->bi_db_config = 0;
6280 bi->bi_db_open = config_back_db_open;
6281 bi->bi_db_close = config_back_db_close;
6282 bi->bi_db_destroy = config_back_db_destroy;
6284 bi->bi_op_bind = config_back_bind;
6285 bi->bi_op_unbind = 0;
6286 bi->bi_op_search = config_back_search;
6287 bi->bi_op_compare = 0;
6288 bi->bi_op_modify = config_back_modify;
6289 bi->bi_op_modrdn = config_back_modrdn;
6290 bi->bi_op_add = config_back_add;
6291 bi->bi_op_delete = config_back_delete;
6292 bi->bi_op_abandon = 0;
6294 bi->bi_extended = 0;
6296 bi->bi_chk_referrals = 0;
6298 bi->bi_access_allowed = slap_access_allowed;
6300 bi->bi_connection_init = 0;
6301 bi->bi_connection_destroy = 0;
6303 bi->bi_entry_release_rw = config_entry_release;
6304 bi->bi_entry_get_rw = config_back_entry_get;
6306 bi->bi_tool_entry_open = config_tool_entry_open;
6307 bi->bi_tool_entry_close = config_tool_entry_close;
6308 bi->bi_tool_entry_first = config_tool_entry_first;
6309 bi->bi_tool_entry_next = config_tool_entry_next;
6310 bi->bi_tool_entry_get = config_tool_entry_get;
6311 bi->bi_tool_entry_put = config_tool_entry_put;
6314 argv[ 0 ] = "slapd";
6320 for (i=0; OidMacros[i].name; i++ ) {
6321 argv[1] = OidMacros[i].name;
6322 argv[2] = OidMacros[i].oid;
6323 parse_oidm( &ca, 0, NULL );
6326 bi->bi_cf_ocs = cf_ocs;
6328 i = config_register_schema( ct, cf_ocs );
6331 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6332 * basically, we don't care if it fails */
6333 i = slap_str2ad( "olcRootPW", &ad, &text );
6335 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6336 "warning, unable to get \"olcRootPW\" "
6337 "attribute description: %d: %s\n",
6340 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6341 ad->ad_type->sat_oid );
6344 /* set up the notable AttributeDescriptions */
6346 for (;ct->name;ct++) {
6347 if (strcmp(ct->name, ads[i].name)) continue;
6348 *ads[i].desc = ct->ad;
6350 if (!ads[i].name) break;