1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2007 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;
80 static char *logfileName;
81 #ifdef SLAP_AUTH_REWRITE
82 static BerVarray authz_rewrites;
85 static struct berval cfdir;
88 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
89 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om;
91 static ConfigFile *cfn;
93 static Avlnode *CfOcTree;
95 /* System schema state */
96 extern AttributeType *at_sys_tail; /* at.c */
97 extern ObjectClass *oc_sys_tail; /* oc.c */
98 extern OidMacro *om_sys_tail; /* oidm.c */
99 static AttributeType *cf_at_tail;
100 static ObjectClass *cf_oc_tail;
101 static OidMacro *cf_om_tail;
103 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
104 SlapReply *rs, int *renumber, Operation *op );
106 static int config_check_schema( Operation *op, CfBackInfo *cfb );
108 static ConfigDriver config_fname;
109 static ConfigDriver config_cfdir;
110 static ConfigDriver config_generic;
111 static ConfigDriver config_search_base;
112 static ConfigDriver config_passwd_hash;
113 static ConfigDriver config_schema_dn;
114 static ConfigDriver config_sizelimit;
115 static ConfigDriver config_timelimit;
116 static ConfigDriver config_overlay;
117 static ConfigDriver config_subordinate;
118 static ConfigDriver config_suffix;
119 static ConfigDriver config_rootdn;
120 static ConfigDriver config_rootpw;
121 static ConfigDriver config_restrict;
122 static ConfigDriver config_allows;
123 static ConfigDriver config_disallows;
124 static ConfigDriver config_requires;
125 static ConfigDriver config_security;
126 static ConfigDriver config_referral;
127 static ConfigDriver config_loglevel;
128 static ConfigDriver config_replica;
129 static ConfigDriver config_updatedn;
130 static ConfigDriver config_updateref;
131 static ConfigDriver config_include;
133 static ConfigDriver config_tls_option;
134 static ConfigDriver config_tls_config;
136 extern ConfigDriver syncrepl_config;
163 CFG_REPLICA_ARGSFILE,
165 CFG_REPLICATIONINTERVAL,
191 static OidRec OidMacros[] = {
192 /* OpenLDAProot:666.11.1 */
193 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
194 { "OLcfgAt", "OLcfg:3" },
195 { "OLcfgGlAt", "OLcfgAt:0" },
196 { "OLcfgBkAt", "OLcfgAt:1" },
197 { "OLcfgDbAt", "OLcfgAt:2" },
198 { "OLcfgOvAt", "OLcfgAt:3" },
199 { "OLcfgOc", "OLcfg:4" },
200 { "OLcfgGlOc", "OLcfgOc:0" },
201 { "OLcfgBkOc", "OLcfgOc:1" },
202 { "OLcfgDbOc", "OLcfgOc:2" },
203 { "OLcfgOvOc", "OLcfgOc:3" },
205 /* Syntaxes. We should just start using the standard names and
206 * document that they are predefined and available for users
207 * to reference in their own schema. Defining schema without
208 * OID macros is for masochists...
210 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
211 { "OMsBoolean", "OMsyn:7" },
212 { "OMsDN", "OMsyn:12" },
213 { "OMsDirectoryString", "OMsyn:15" },
214 { "OMsInteger", "OMsyn:27" },
215 { "OMsOID", "OMsyn:38" },
216 { "OMsOctetString", "OMsyn:40" },
221 * Backend/Database registry
223 * OLcfg{Bk|Db}{Oc|At}:0 -> common
224 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
225 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
226 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
232 * OLcfgOv{Oc|At}:1 -> syncprov
233 * OLcfgOv{Oc|At}:2 -> pcache
234 * OLcfgOv{Oc|At}:3 -> chain
235 * OLcfgOv{Oc|At}:4 -> accesslog
236 * OLcfgOv{Oc|At}:5 -> valsort
237 * (FIXME: separate arc for contribware?)
238 * OLcfgOv{Oc|At}:6 -> smbk5pwd
239 * OLcfgOv{Oc|At}:7 -> distproc
240 * OLcfgOv{Oc|At}:8 -> dynlist
241 * OLcfgOv{Oc|At}:9 -> dds
242 * OLcfgOv{Oc|At}:10 -> unique
243 * OLcfgOv{Oc|At}:11 -> refint
244 * OLcfgOv{Oc|At}:12 -> ppolicy
245 * OLcfgOv{Oc|At}:13 -> constraint
246 * OLcfgOv{Oc|At}:14 -> translucent
247 * OLcfgOv{Oc|At}:15 -> auditlog
250 /* alphabetical ordering */
252 static ConfigTable config_back_cf_table[] = {
253 /* This attr is read-only */
254 { "", "", 0, 0, 0, ARG_MAGIC,
255 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
256 "DESC 'File for slapd configuration directives' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
259 { "", "", 0, 0, 0, ARG_MAGIC,
260 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
261 "DESC 'Directory for slapd configuration backend' "
262 "EQUALITY caseIgnoreMatch "
263 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
264 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
265 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
266 "DESC 'Access Control List' "
267 "EQUALITY caseIgnoreMatch "
268 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
269 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
270 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
271 "DESC 'Allowed set of deprecated features' "
272 "EQUALITY caseIgnoreMatch "
273 "SYNTAX OMsDirectoryString )", NULL, NULL },
274 { "argsfile", "file", 2, 2, 0, ARG_STRING,
275 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
276 "DESC 'File for slapd command line options' "
277 "EQUALITY caseIgnoreMatch "
278 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
279 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
280 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString )", NULL, NULL },
283 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
284 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
285 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
286 "DESC 'OpenLDAP attributeTypes' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
290 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
291 #ifdef SLAP_AUTH_REWRITE
292 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
296 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
299 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
300 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
303 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
304 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
307 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
308 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
309 "DESC 'A type of backend' "
310 "EQUALITY caseIgnoreMatch "
311 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
313 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
314 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
315 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
316 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
317 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
318 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
319 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
320 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
321 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
322 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
323 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
324 "DESC 'The backend type for a database instance' "
325 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
326 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
327 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
328 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
329 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
330 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
331 "EQUALITY caseIgnoreMatch "
332 "SYNTAX OMsDirectoryString )", NULL, NULL },
333 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
334 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
335 "DESC 'OpenLDAP DIT content rules' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
339 { "gentlehup", "on|off", 2, 2, 0,
341 ARG_ON_OFF, &global_gentlehup,
345 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
346 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
347 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
348 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
349 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
350 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
351 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
352 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
353 { "include", "file", 2, 2, 0, ARG_MAGIC,
354 &config_include, NULL, NULL, NULL },
355 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
356 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
357 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
358 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
359 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
360 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
361 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
362 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
363 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
364 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
365 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
366 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
367 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
368 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
369 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
370 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
371 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
372 "EQUALITY caseIgnoreMatch "
373 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
374 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
375 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
376 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
377 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
378 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
379 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
380 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
381 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
382 "EQUALITY caseIgnoreMatch "
383 "SYNTAX OMsDirectoryString )", NULL, NULL },
384 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
385 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
386 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
387 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
388 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
389 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
390 { "moduleload", "file", 2, 0, 0,
392 ARG_MAGIC|CFG_MODLOAD, &config_generic,
396 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
397 "EQUALITY caseIgnoreMatch "
398 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
399 { "modulepath", "path", 2, 2, 0,
401 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
405 "( OLcfgGlAt:31 NAME 'olcModulePath' "
406 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
407 { "monitoring", "TRUE|FALSE", 2, 2, 0,
408 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
409 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
410 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
411 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
412 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
413 "DESC 'OpenLDAP object classes' "
414 "EQUALITY caseIgnoreMatch "
415 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
417 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
418 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
419 "EQUALITY caseIgnoreMatch "
420 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
421 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
422 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
423 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
424 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
425 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
426 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
427 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
428 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
429 "EQUALITY caseIgnoreMatch "
430 "SYNTAX OMsDirectoryString )", NULL, NULL },
431 { "pidfile", "file", 2, 2, 0, ARG_STRING,
432 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
433 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
434 { "plugin", NULL, 0, 0, 0,
436 ARG_MAGIC|CFG_PLUGIN, &config_generic,
440 "( OLcfgGlAt:38 NAME 'olcPlugin' "
441 "EQUALITY caseIgnoreMatch "
442 "SYNTAX OMsDirectoryString )", NULL, NULL },
443 { "pluginlog", "filename", 2, 2, 0,
445 ARG_STRING, &slapi_log_file,
449 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
450 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
451 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
452 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
453 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
454 { "referral", "url", 2, 2, 0, ARG_MAGIC,
455 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
456 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
457 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
458 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
459 "EQUALITY caseIgnoreMatch "
460 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
461 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLICA_ARGSFILE,
462 &config_generic, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
463 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
464 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLICA_PIDFILE,
465 &config_generic, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
466 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
467 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_INT|CFG_REPLICATIONINTERVAL,
468 &config_generic, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
469 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
470 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
471 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
472 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
473 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
474 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
475 "EQUALITY caseIgnoreMatch "
476 "SYNTAX OMsDirectoryString )", NULL, NULL },
477 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
478 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
479 "EQUALITY caseIgnoreMatch "
480 "SYNTAX OMsDirectoryString )", NULL, NULL },
481 { "reverse-lookup", "on|off", 2, 2, 0,
482 #ifdef SLAPD_RLOOKUPS
483 ARG_ON_OFF, &use_reverse_lookup,
487 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
488 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
489 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
490 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
491 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
492 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
493 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
494 "EQUALITY caseIgnoreMatch "
495 "SYNTAX OMsDirectoryString )", NULL, NULL },
496 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
497 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
498 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
499 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
500 &config_generic, NULL, NULL, NULL },
501 { "sasl-host", "host", 2, 2, 0,
502 #ifdef HAVE_CYRUS_SASL
503 ARG_STRING|ARG_UNIQUE, &global_host,
507 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
508 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
509 { "sasl-realm", "realm", 2, 2, 0,
510 #ifdef HAVE_CYRUS_SASL
511 ARG_STRING|ARG_UNIQUE, &global_realm,
515 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
516 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
517 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
518 &config_generic, NULL, NULL, NULL },
519 { "sasl-secprops", "properties", 2, 2, 0,
520 #ifdef HAVE_CYRUS_SASL
521 ARG_MAGIC|CFG_SASLSECP, &config_generic,
525 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
526 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
527 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
528 &config_generic, NULL, NULL, NULL },
529 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
530 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
531 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
532 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
533 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
534 "EQUALITY caseIgnoreMatch "
535 "SYNTAX OMsDirectoryString )", NULL, NULL },
536 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
537 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
538 "EQUALITY caseIgnoreMatch "
539 "SYNTAX OMsDirectoryString )", NULL, NULL },
540 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
541 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
542 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
543 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
544 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
545 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
546 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
547 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
548 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
549 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
550 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
551 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
552 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
553 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
554 "EQUALITY distinguishedNameMatch "
555 "SYNTAX OMsDN )", NULL, NULL },
556 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
557 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
558 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
559 { "threads", "count", 2, 2, 0,
563 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
565 "( OLcfgGlAt:66 NAME 'olcThreads' "
566 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
567 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
568 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
569 "SYNTAX OMsDirectoryString )", NULL, NULL },
570 { "TLSCACertificateFile", NULL, 0, 0, 0,
572 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
576 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
577 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
578 { "TLSCACertificatePath", NULL, 0, 0, 0,
580 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
584 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
585 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
586 { "TLSCertificateFile", NULL, 0, 0, 0,
588 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
592 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
593 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
594 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
596 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
600 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
601 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
602 { "TLSCipherSuite", NULL, 0, 0, 0,
604 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
608 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
609 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
610 { "TLSCRLCheck", NULL, 0, 0, 0,
611 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
612 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
616 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
617 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
618 { "TLSRandFile", NULL, 0, 0, 0,
620 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
624 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
625 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
626 { "TLSVerifyClient", NULL, 0, 0, 0,
628 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
632 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
633 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
634 { "TLSDHParamFile", NULL, 0, 0, 0,
636 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
640 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
641 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
642 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
643 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
644 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
645 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
646 NULL, NULL, NULL, NULL },
647 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
648 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
649 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
650 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
651 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
652 "EQUALITY caseIgnoreMatch "
653 "SUP labeledURI )", NULL, NULL },
654 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
655 NULL, NULL, NULL, NULL }
658 /* Routines to check if a child can be added to this type */
659 static ConfigLDAPadd cfAddSchema, cfAddDatabase,
660 cfAddBackend, cfAddModule, cfAddOverlay;
662 /* NOTE: be careful when defining array members
663 * that can be conditionally compiled */
664 #define CFOC_GLOBAL cf_ocs[1]
665 #define CFOC_SCHEMA cf_ocs[2]
666 #define CFOC_BACKEND cf_ocs[3]
667 #define CFOC_DATABASE cf_ocs[4]
668 #define CFOC_OVERLAY cf_ocs[5]
669 #define CFOC_FRONTEND cf_ocs[6]
671 #define CFOC_MODULE cf_ocs[7]
672 #endif /* SLAPD_MODULES */
674 static ConfigOCs cf_ocs[] = {
677 "DESC 'OpenLDAP configuration object' "
678 "ABSTRACT SUP top )", Cft_Abstract, NULL },
681 "DESC 'OpenLDAP Global configuration options' "
682 "SUP olcConfig STRUCTURAL "
683 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
684 "olcAttributeOptions $ olcAuthIDRewrite $ "
685 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
686 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
687 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
688 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
689 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
691 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
692 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
693 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
695 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
696 "olcSecurity $ olcServerID $ olcSizeLimit $ "
697 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
698 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
699 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
700 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
701 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
703 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
704 "olcDitContentRules ) )", Cft_Global },
706 "NAME 'olcSchemaConfig' "
707 "DESC 'OpenLDAP schema object' "
708 "SUP olcConfig STRUCTURAL "
709 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
710 "olcObjectClasses $ olcDitContentRules ) )",
711 Cft_Schema, NULL, cfAddSchema },
713 "NAME 'olcBackendConfig' "
714 "DESC 'OpenLDAP Backend-specific options' "
715 "SUP olcConfig STRUCTURAL "
716 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
718 "NAME 'olcDatabaseConfig' "
719 "DESC 'OpenLDAP Database-specific options' "
720 "SUP olcConfig STRUCTURAL "
722 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
723 "olcLastMod $ olcLimits $ "
724 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
725 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
726 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
727 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
728 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
730 Cft_Database, NULL, cfAddDatabase },
732 "NAME 'olcOverlayConfig' "
733 "DESC 'OpenLDAP Overlay-specific options' "
734 "SUP olcConfig STRUCTURAL "
735 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
736 /* This should be STRUCTURAL like all the other database classes, but
737 * that would mean inheriting all of the olcDatabaseConfig attributes,
738 * which causes them to be merged twice in config_build_entry.
741 "NAME 'olcFrontendConfig' "
742 "DESC 'OpenLDAP frontend configuration' "
744 "MAY olcDefaultSearchBase )",
745 Cft_Database, NULL, NULL },
748 "NAME 'olcModuleList' "
749 "DESC 'OpenLDAP dynamic module info' "
750 "SUP olcConfig STRUCTURAL "
751 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
752 Cft_Module, NULL, cfAddModule },
757 typedef struct ServerID {
758 struct ServerID *si_next;
759 struct berval si_url;
763 static ServerID *sid_list;
766 config_generic(ConfigArgs *c) {
769 if ( c->op == SLAP_CONFIG_EMIT ) {
773 c->value_int = ldap_pvt_thread_get_concurrency();
776 c->value_int = connection_pool_max;
779 c->value_int = slap_tool_thread_max;
783 c->value_string = ch_strdup( passwd_salt );
788 if ( c->be->be_limits ) {
793 for ( i=0; c->be->be_limits[i]; i++ ) {
794 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
795 if ( bv.bv_len >= sizeof( buf ) ) {
796 ber_bvarray_free_x( c->rvalue_vals, NULL );
797 c->rvalue_vals = NULL;
801 bv.bv_val = buf + bv.bv_len;
802 limits_unparse( c->be->be_limits[i], &bv,
803 sizeof( buf ) - ( bv.bv_val - buf ) );
804 bv.bv_len += bv.bv_val - buf;
806 value_add_one( &c->rvalue_vals, &bv );
809 if ( !c->rvalue_vals ) rc = 1;
812 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
813 SLAP_RESTRICT_OP_WRITES;
816 c->value_string = ch_strdup( slap_sasl_getpolicy());
819 slap_sasl_regexp_unparse( &c->rvalue_vals );
820 if ( !c->rvalue_vals ) rc = 1;
822 #ifdef HAVE_CYRUS_SASL
824 struct berval bv = BER_BVNULL;
825 slap_sasl_secprops_unparse( &bv );
826 if ( !BER_BVISNULL( &bv )) {
827 ber_bvarray_add( &c->rvalue_vals, &bv );
835 c->value_int = c->be->be_max_deref_depth;
838 if ( SLAP_DBHIDDEN( c->be )) {
845 ConfigFile *cf = c->private;
847 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
848 else if ( cf->c_om_head )
849 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
851 if ( !c->rvalue_vals )
856 ad_unparse_options( &c->rvalue_vals );
859 ConfigFile *cf = c->private;
861 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
862 else if ( cf->c_oc_head )
863 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
865 if ( !c->rvalue_vals )
870 ConfigFile *cf = c->private;
872 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
873 else if ( cf->c_at_head )
874 at_unparse( &c->rvalue_vals, cf->c_at_head,
876 if ( !c->rvalue_vals )
881 ConfigFile *cf = c->private;
883 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
884 else if ( cf->c_cr_head )
885 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
887 if ( !c->rvalue_vals )
894 char *src, *dst, ibuf[11];
895 struct berval bv, abv;
896 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
897 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
898 if ( abv.bv_len >= sizeof( ibuf ) ) {
899 ber_bvarray_free_x( c->rvalue_vals, NULL );
900 c->rvalue_vals = NULL;
904 acl_unparse( a, &bv );
905 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
906 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
907 /* Turn TAB / EOL into plain space */
908 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
909 if (isspace((unsigned char)*src)) *dst++ = ' ';
913 if (dst[-1] == ' ') {
917 abv.bv_len = dst - abv.bv_val;
918 ber_bvarray_add( &c->rvalue_vals, &abv );
923 case CFG_REPLICA_ARGSFILE:
924 if ( c->be->be_replica_argsfile )
925 c->value_string = ch_strdup( c->be->be_replica_argsfile );
927 case CFG_REPLICA_PIDFILE:
928 if ( c->be->be_replica_pidfile )
929 c->value_string = ch_strdup( c->be->be_replica_pidfile );
931 case CFG_REPLICATIONINTERVAL:
932 if ( c->be->be_replicationinterval > 0 ) {
933 c->value_int = c->be->be_replicationinterval;
939 if ( c->be->be_replogfile )
940 c->value_string = ch_strdup( c->be->be_replogfile );
943 ConfigFile *cf = c->private;
944 if ( cf->c_dseFiles ) {
945 value_add( &c->rvalue_vals, cf->c_dseFiles );
957 for ( si = sid_list; si; si=si->si_next ) {
958 if ( !BER_BVISEMPTY( &si->si_url )) {
959 bv.bv_len = si->si_url.bv_len + 6;
960 bv.bv_val = ch_malloc( bv.bv_len );
961 sprintf( bv.bv_val, "%d %s", si->si_num,
963 ber_bvarray_add( &c->rvalue_vals, &bv );
967 bv.bv_len = sprintf( buf, "%d", si->si_num );
968 value_add_one( &c->rvalue_vals, &bv );
977 c->value_string = ch_strdup( logfileName );
982 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
985 if ( SLAP_SHADOW(c->be))
986 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
991 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
993 case CFG_SSTR_IF_MAX:
994 c->value_int = index_substr_if_maxlen;
996 case CFG_SSTR_IF_MIN:
997 c->value_int = index_substr_if_minlen;
1001 ModPaths *mp = c->private;
1004 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1007 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1008 SLAP_X_ORDERED_FMT "%s", i,
1009 mp->mp_loads[i].bv_val );
1010 if ( bv.bv_len >= sizeof( c->log ) ) {
1011 ber_bvarray_free_x( c->rvalue_vals, NULL );
1012 c->rvalue_vals = NULL;
1015 value_add_one( &c->rvalue_vals, &bv );
1019 rc = c->rvalue_vals ? 0 : 1;
1023 ModPaths *mp = c->private;
1024 if ( !BER_BVISNULL( &mp->mp_path ))
1025 value_add_one( &c->rvalue_vals, &mp->mp_path );
1027 rc = c->rvalue_vals ? 0 : 1;
1033 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1034 if ( !c->rvalue_vals ) rc = 1;
1037 #ifdef SLAP_AUTH_REWRITE
1039 if ( authz_rewrites ) {
1040 struct berval bv, idx;
1045 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1046 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1047 if ( idx.bv_len >= sizeof( ibuf ) ) {
1048 ber_bvarray_free_x( c->rvalue_vals, NULL );
1049 c->rvalue_vals = NULL;
1052 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1053 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1054 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1055 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1056 authz_rewrites[i].bv_val,
1057 authz_rewrites[i].bv_len + 1 );
1058 ber_bvarray_add( &c->rvalue_vals, &bv );
1061 if ( !c->rvalue_vals ) rc = 1;
1068 } else if ( c->op == LDAP_MOD_DELETE ) {
1071 /* single-valued attrs, no-ops */
1079 case CFG_MIRRORMODE:
1080 case CFG_MONITORING:
1082 case CFG_SSTR_IF_MAX:
1083 case CFG_SSTR_IF_MIN:
1086 /* no-ops, requires slapd restart */
1091 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1095 ch_free( passwd_salt );
1099 case CFG_REPLICA_ARGSFILE:
1100 ch_free( c->be->be_replica_argsfile );
1101 c->be->be_replica_argsfile = NULL;
1104 case CFG_REPLICA_PIDFILE:
1105 ch_free( c->be->be_replica_pidfile );
1106 c->be->be_replica_pidfile = NULL;
1109 case CFG_REPLICATIONINTERVAL:
1110 c->be->be_replicationinterval = 0;
1114 ch_free( c->be->be_replogfile );
1115 c->be->be_replogfile = NULL;
1119 ch_free( logfileName );
1123 case CFG_SERVERID: {
1125 ServerID *si, **sip;
1127 for ( i=0, si = sid_list, sip = &sid_list;
1128 si; si = *sip, i++ ) {
1129 if ( c->valx == -1 || i == c->valx ) {
1141 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1145 if ( c->valx < 0 ) {
1147 if ( c->be == frontendDB )
1150 end = frontendDB->be_acl;
1151 acl_destroy( c->be->be_acl, end );
1152 c->be->be_acl = end;
1155 AccessControl **prev, *a;
1157 for (i=0, prev = &c->be->be_acl; i < c->valx;
1160 prev = &a->acl_next;
1163 *prev = a->acl_next;
1169 CfEntryInfo *ce = c->ca_entry->e_private;
1170 /* can't modify the hardcoded schema */
1171 if ( ce->ce_parent->ce_type == Cft_Global )
1175 if ( c->valx < 0 ) {
1178 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1180 if ( oc == cfn->c_oc_tail )
1183 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1185 ObjectClass *oc, *prev = NULL;
1188 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1193 if ( cfn->c_oc_tail == oc ) {
1194 cfn->c_oc_tail = prev;
1196 if ( cfn->c_oc_head == oc ) {
1198 cfn->c_oc_head = oc;
1204 CfEntryInfo *ce = c->ca_entry->e_private;
1205 /* can't modify the hardcoded schema */
1206 if ( ce->ce_parent->ce_type == Cft_Global )
1210 if ( c->valx < 0 ) {
1213 for( at = cfn->c_at_head; at; at_next( &at )) {
1215 if ( at == cfn->c_at_tail )
1218 cfn->c_at_head = cfn->c_at_tail = NULL;
1220 AttributeType *at, *prev = NULL;
1223 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1228 if ( cfn->c_at_tail == at ) {
1229 cfn->c_at_tail = prev;
1231 if ( cfn->c_at_head == at ) {
1233 cfn->c_at_head = at;
1239 /* FIXME: there is no limits_free function */
1241 /* FIXME: there is no ad_option_free function */
1243 /* FIXME: there is no way to remove attributes added by
1257 if(!(c->bi = backend_info(c->argv[1]))) {
1258 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1259 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1260 c->log, c->msg, c->argv[1] );
1267 /* NOTE: config is always the first backend!
1269 if ( !strcasecmp( c->argv[1], "config" )) {
1270 c->be = LDAP_STAILQ_FIRST(&backendDB);
1271 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1274 c->be = backend_db_init(c->argv[1], NULL, c->valx);
1276 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1277 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1278 c->log, c->msg, c->argv[1] );
1285 ldap_pvt_thread_set_concurrency(c->value_int);
1289 if ( c->value_int < 2 ) {
1290 snprintf( c->msg, sizeof( c->msg ),
1291 "threads=%d smaller than minimum value 2",
1293 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1294 c->log, c->msg, 0 );
1297 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1298 snprintf( c->msg, sizeof( c->msg ),
1299 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1300 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1301 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1302 c->log, c->msg, 0 );
1304 if ( slapMode & SLAP_SERVER_MODE )
1305 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1306 connection_pool_max = c->value_int; /* save for reference */
1310 if ( slapMode & SLAP_TOOL_MODE )
1311 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1312 slap_tool_thread_max = c->value_int; /* save for reference */
1316 if ( passwd_salt ) ch_free( passwd_salt );
1317 passwd_salt = c->value_string;
1318 lutil_salt_format(passwd_salt);
1322 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1328 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1330 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1334 ch_free(c->value_string);
1335 if (slap_sasl_setpolicy( c->argv[1] )) {
1336 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1337 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1338 c->log, c->msg, c->argv[1] );
1344 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1348 #ifdef HAVE_CYRUS_SASL
1351 char *txt = slap_sasl_secprops( c->argv[1] );
1353 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1355 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1363 c->be->be_max_deref_depth = c->value_int;
1369 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1371 if(parse_oidm(c, 1, &om))
1373 if (!cfn->c_om_head) cfn->c_om_head = om;
1374 cfn->c_om_tail = om;
1379 ObjectClass *oc, *prev;
1381 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1383 if ( c->valx < 0 ) {
1384 prev = cfn->c_oc_tail;
1387 /* If adding anything after the first, prev is easy */
1390 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1395 /* If adding the first, and head exists, find its prev */
1396 if (cfn->c_oc_head) {
1397 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1402 /* else prev is NULL, append to end of global list */
1404 if(parse_oc(c, &oc, prev)) return(1);
1405 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1406 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1411 AttributeType *at, *prev;
1413 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1415 if ( c->valx < 0 ) {
1416 prev = cfn->c_at_tail;
1419 /* If adding anything after the first, prev is easy */
1422 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1427 /* If adding the first, and head exists, find its prev */
1428 if (cfn->c_at_head) {
1429 for ( at_start( &at ); at != cfn->c_at_head; ) {
1434 /* else prev is NULL, append to end of global list */
1436 if(parse_at(c, &at, prev)) return(1);
1437 if (!cfn->c_at_head) cfn->c_at_head = at;
1438 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1445 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1447 if(parse_cr(c, &cr)) return(1);
1448 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1449 cfn->c_cr_tail = cr;
1454 ad_define_option(NULL, NULL, 0);
1455 for(i = 1; i < c->argc; i++)
1456 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1461 /* Don't append to the global ACL if we're on a specific DB */
1463 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1466 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1470 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1475 case CFG_REPLICA_ARGSFILE:
1476 if(SLAP_MONITOR(c->be)) {
1477 Debug(LDAP_DEBUG_ANY, "%s: "
1478 "\"replica-argsfile\" should not be used "
1479 "inside monitor database\n",
1481 /* FIXME: should this be an error? */
1485 if ( c->be->be_replica_argsfile != NULL ) {
1487 Debug(LDAP_DEBUG_ANY, "%s: "
1488 "\"replica-argsfile\" already provided; "
1489 "replacing \"%s\" with \"%s\".\n",
1490 c->log, c->be->be_replica_argsfile, c->value_string );
1491 ch_free( c->be->be_replica_argsfile );
1494 c->be->be_replica_argsfile = c->value_string;
1497 case CFG_REPLICA_PIDFILE:
1498 if(SLAP_MONITOR(c->be)) {
1499 Debug(LDAP_DEBUG_ANY, "%s: "
1500 "\"replica-pidfile\" should not be used "
1501 "inside monitor database\n",
1503 /* FIXME: should this be an error? */
1507 if ( c->be->be_replica_pidfile != NULL ) {
1509 Debug(LDAP_DEBUG_ANY, "%s: "
1510 "\"replica-pidfile\" already provided; "
1511 "replacing \"%s\" with \"%s\".\n",
1512 c->log, c->be->be_replica_pidfile, c->value_string );
1513 ch_free( c->be->be_replica_pidfile );
1516 c->be->be_replica_pidfile = c->value_string;
1519 case CFG_REPLICATIONINTERVAL:
1520 if(SLAP_MONITOR(c->be)) {
1521 Debug(LDAP_DEBUG_ANY, "%s: "
1522 "\"replicationinterval\" should not be used "
1523 "inside monitor database\n",
1525 /* FIXME: should this be an error? */
1529 c->be->be_replicationinterval = c->value_int;
1533 if(SLAP_MONITOR(c->be)) {
1534 Debug(LDAP_DEBUG_ANY, "%s: "
1535 "\"replogfile\" should not be used "
1536 "inside monitor database\n",
1538 /* FIXME: should this be an error? */
1542 if ( c->be->be_replogfile != NULL ) {
1544 Debug(LDAP_DEBUG_ANY, "%s: "
1545 "\"replogfile\" already provided; "
1546 "replacing \"%s\" with \"%s\".\n",
1547 c->log, c->be->be_replogfile, c->value_string );
1548 ch_free( c->be->be_replogfile );
1551 c->be->be_replogfile = c->value_string;
1555 if(root_dse_read_file(c->argv[1])) {
1556 snprintf( c->msg, sizeof( c->msg ), "<%s> could not read file", c->argv[0] );
1557 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1558 c->log, c->msg, c->argv[1] );
1563 ber_str2bv( c->argv[1], 0, 1, &bv );
1564 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1566 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1572 ServerID *si, **sip;
1574 int num = atoi( c->argv[1] );
1575 if ( num < 0 || num > SLAP_SYNC_SID_MAX ) {
1576 snprintf( c->msg, sizeof( c->msg ),
1577 "<%s> illegal server ID", c->argv[0] );
1578 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1579 c->log, c->msg, c->argv[1] );
1582 /* only one value allowed if no URL is given */
1583 if ( c->argc > 2 ) {
1586 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1587 snprintf( c->msg, sizeof( c->msg ),
1588 "<%s> only one server ID allowed now", c->argv[0] );
1589 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1590 c->log, c->msg, c->argv[1] );
1594 if ( ldap_url_parse( c->argv[2], &lud )) {
1595 snprintf( c->msg, sizeof( c->msg ),
1596 "<%s> invalid URL", c->argv[0] );
1597 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1598 c->log, c->msg, c->argv[2] );
1601 len = strlen( c->argv[2] );
1602 si = ch_malloc( sizeof(ServerID) + len + 1 );
1603 si->si_url.bv_val = (char *)(si+1);
1604 si->si_url.bv_len = len;
1605 strcpy( si->si_url.bv_val, c->argv[3] );
1608 snprintf( c->msg, sizeof( c->msg ),
1609 "<%s> unqualified server ID not allowed now", c->argv[0] );
1610 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1611 c->log, c->msg, c->argv[1] );
1614 si = ch_malloc( sizeof(ServerID) );
1615 slap_serverID = num;
1619 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1622 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1623 /* If hostname is empty, or is localhost, or matches
1624 * our hostname, this serverID refers to this host.
1625 * Compare it against listeners and ports.
1627 if ( !lud->lud_host || !lud->lud_host[0] ||
1628 !strncasecmp("localhost", lud->lud_host,
1629 STRLENOF("localhost")) ||
1630 !strcasecmp( global_host, lud->lud_host )) {
1631 Listener **l = slapd_get_listeners();
1634 for ( i=0; l[i]; i++ ) {
1637 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1639 if ( strcasecmp( lud->lud_scheme,
1642 if ( lud->lud_port != lu2->lud_port )
1644 /* Listener on ANY address */
1645 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1649 /* URL on ANY address */
1650 if ( !lud->lud_host || !lud->lud_host[0] ) {
1654 /* Listener has specific host, must
1657 if ( !strcasecmp( lud->lud_host,
1663 ldap_free_urldesc( lu2 );
1665 slap_serverID = si->si_num;
1672 ldap_free_urldesc( lud );
1677 if ( logfileName ) ch_free( logfileName );
1678 logfileName = c->value_string;
1679 logfile = fopen(logfileName, "w");
1680 if(logfile) lutil_debug_file(logfile);
1684 if(SLAP_NOLASTMODCMD(c->be)) {
1685 snprintf( c->msg, sizeof( c->msg ), "<%s> not available for %s database",
1686 c->argv[0], c->be->bd_info->bi_type );
1687 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1688 c->log, c->msg, 0 );
1692 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1694 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1697 case CFG_MIRRORMODE:
1698 if(!SLAP_SHADOW(c->be)) {
1699 snprintf( c->msg, sizeof( c->msg ), "<%s> database is not a shadow",
1701 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1702 c->log, c->msg, 0 );
1706 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1708 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1711 case CFG_MONITORING:
1713 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1715 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1720 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1722 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1725 case CFG_SSTR_IF_MAX:
1726 if (c->value_int < index_substr_if_minlen) {
1727 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1728 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1729 c->log, c->msg, c->value_int );
1732 index_substr_if_maxlen = c->value_int;
1735 case CFG_SSTR_IF_MIN:
1736 if (c->value_int > index_substr_if_maxlen) {
1737 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1738 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1739 c->log, c->msg, c->value_int );
1742 index_substr_if_minlen = c->value_int;
1745 #ifdef SLAPD_MODULES
1747 /* If we're just adding a module on an existing modpath,
1748 * make sure we've selected the current path.
1750 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1751 modcur = c->private;
1752 /* This should never fail */
1753 if ( module_path( modcur->mp_path.bv_val )) {
1754 snprintf( c->msg, sizeof( c->msg ), "<%s> module path no longer valid",
1756 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1757 c->log, c->msg, modcur->mp_path.bv_val );
1761 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1763 /* Record this load on the current path */
1767 if ( c->op == SLAP_CONFIG_ADD ) {
1768 ptr = c->line + STRLENOF("moduleload");
1769 while (!isspace((unsigned char) *ptr)) ptr++;
1770 while (isspace((unsigned char) *ptr)) ptr++;
1774 ber_str2bv(ptr, 0, 1, &bv);
1775 ber_bvarray_add( &modcur->mp_loads, &bv );
1777 /* Check for any new hardcoded schema */
1778 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1779 config_check_schema( NULL, &cfBackInfo );
1784 if(module_path(c->argv[1])) return(1);
1785 /* Record which path was used with each module */
1789 if (!modpaths.mp_loads) {
1792 mp = ch_malloc( sizeof( ModPaths ));
1793 modlast->mp_next = mp;
1795 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1797 mp->mp_loads = NULL;
1808 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1810 slapi_plugins_used++;
1814 #ifdef SLAP_AUTH_REWRITE
1819 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1822 if ( c->argc > 1 ) {
1825 /* quote all args but the first */
1826 line = ldap_charray2str( c->argv, "\" \"" );
1827 ber_str2bv( line, 0, 0, &bv );
1828 s = ber_bvchr( &bv, '"' );
1829 assert( s != NULL );
1830 /* move the trailing quote of argv[0] to the end */
1831 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1832 bv.bv_val[ bv.bv_len - 1 ] = '"';
1835 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1838 ber_bvarray_add( &authz_rewrites, &bv );
1845 Debug( LDAP_DEBUG_ANY,
1846 "%s: unknown CFG_TYPE %d.\n",
1847 c->log, c->type, 0 );
1856 config_fname(ConfigArgs *c) {
1857 if(c->op == SLAP_CONFIG_EMIT) {
1859 ConfigFile *cf = c->private;
1860 value_add_one( &c->rvalue_vals, &cf->c_file );
1869 config_cfdir(ConfigArgs *c) {
1870 if(c->op == SLAP_CONFIG_EMIT) {
1871 if ( !BER_BVISEMPTY( &cfdir )) {
1872 value_add_one( &c->rvalue_vals, &cfdir );
1881 config_search_base(ConfigArgs *c) {
1882 if(c->op == SLAP_CONFIG_EMIT) {
1884 if (!BER_BVISEMPTY(&default_search_base)) {
1885 value_add_one(&c->rvalue_vals, &default_search_base);
1886 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1890 } else if( c->op == LDAP_MOD_DELETE ) {
1891 ch_free( default_search_base.bv_val );
1892 ch_free( default_search_nbase.bv_val );
1893 BER_BVZERO( &default_search_base );
1894 BER_BVZERO( &default_search_nbase );
1898 if(c->bi || c->be != frontendDB) {
1899 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1900 "prior to any backend or database definition\n",
1905 if(default_search_nbase.bv_len) {
1906 free(default_search_base.bv_val);
1907 free(default_search_nbase.bv_val);
1910 default_search_base = c->value_dn;
1911 default_search_nbase = c->value_ndn;
1916 config_passwd_hash(ConfigArgs *c) {
1918 if (c->op == SLAP_CONFIG_EMIT) {
1920 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1921 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1922 value_add_one(&c->rvalue_vals, &bv);
1925 } else if ( c->op == LDAP_MOD_DELETE ) {
1926 if ( c->valx < 0 ) {
1927 ldap_charray_free( default_passwd_hash );
1928 default_passwd_hash = NULL;
1931 ch_free( default_passwd_hash[i] );
1932 for (; default_passwd_hash[i]; i++ )
1933 default_passwd_hash[i] = default_passwd_hash[i+1];
1937 if(default_passwd_hash) {
1938 Debug(LDAP_DEBUG_ANY, "%s: "
1939 "already set default password_hash\n",
1943 for(i = 1; i < c->argc; i++) {
1944 if(!lutil_passwd_scheme(c->argv[i])) {
1945 snprintf( c->msg, sizeof( c->msg ), "<%s> scheme not available", c->argv[0] );
1946 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1947 c->log, c->msg, c->argv[i]);
1949 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1951 if(!default_passwd_hash) {
1952 snprintf( c->msg, sizeof( c->msg ), "<%s> no valid hashes found", c->argv[0] );
1953 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1954 c->log, c->msg, 0 );
1962 config_schema_dn(ConfigArgs *c) {
1963 if ( c->op == SLAP_CONFIG_EMIT ) {
1965 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1966 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1967 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1971 } else if ( c->op == LDAP_MOD_DELETE ) {
1972 ch_free( c->be->be_schemadn.bv_val );
1973 ch_free( c->be->be_schemandn.bv_val );
1974 BER_BVZERO( &c->be->be_schemadn );
1975 BER_BVZERO( &c->be->be_schemandn );
1978 ch_free( c->be->be_schemadn.bv_val );
1979 ch_free( c->be->be_schemandn.bv_val );
1980 c->be->be_schemadn = c->value_dn;
1981 c->be->be_schemandn = c->value_ndn;
1986 config_sizelimit(ConfigArgs *c) {
1988 struct slap_limits_set *lim = &c->be->be_def_limit;
1989 if (c->op == SLAP_CONFIG_EMIT) {
1994 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
1995 if ( !BER_BVISEMPTY( &bv ))
1996 value_add_one( &c->rvalue_vals, &bv );
2000 } else if ( c->op == LDAP_MOD_DELETE ) {
2001 /* Reset to defaults */
2002 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2003 lim->lms_s_hard = 0;
2004 lim->lms_s_unchecked = -1;
2006 lim->lms_s_pr_hide = 0;
2007 lim->lms_s_pr_total = 0;
2010 for(i = 1; i < c->argc; i++) {
2011 if(!strncasecmp(c->argv[i], "size", 4)) {
2012 rc = limits_parse_one(c->argv[i], lim);
2014 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
2015 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2016 c->log, c->msg, c->argv[i]);
2020 if(!strcasecmp(c->argv[i], "unlimited")) {
2021 lim->lms_s_soft = -1;
2023 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2024 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
2025 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2026 c->log, c->msg, c->argv[i]);
2030 lim->lms_s_hard = 0;
2037 config_timelimit(ConfigArgs *c) {
2039 struct slap_limits_set *lim = &c->be->be_def_limit;
2040 if (c->op == SLAP_CONFIG_EMIT) {
2045 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2046 if ( !BER_BVISEMPTY( &bv ))
2047 value_add_one( &c->rvalue_vals, &bv );
2051 } else if ( c->op == LDAP_MOD_DELETE ) {
2052 /* Reset to defaults */
2053 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2054 lim->lms_t_hard = 0;
2057 for(i = 1; i < c->argc; i++) {
2058 if(!strncasecmp(c->argv[i], "time", 4)) {
2059 rc = limits_parse_one(c->argv[i], lim);
2061 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
2062 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2063 c->log, c->msg, c->argv[i]);
2067 if(!strcasecmp(c->argv[i], "unlimited")) {
2068 lim->lms_t_soft = -1;
2070 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2071 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
2072 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2073 c->log, c->msg, c->argv[i]);
2077 lim->lms_t_hard = 0;
2084 config_overlay(ConfigArgs *c) {
2085 if (c->op == SLAP_CONFIG_EMIT) {
2087 } else if ( c->op == LDAP_MOD_DELETE ) {
2090 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2093 Debug( LDAP_DEBUG_ANY,
2094 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2095 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2097 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
2104 config_subordinate(ConfigArgs *c)
2110 case SLAP_CONFIG_EMIT:
2111 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2114 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2115 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2118 value_add_one( &c->rvalue_vals, &bv );
2122 case LDAP_MOD_DELETE:
2123 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2124 glue_sub_del( c->be );
2126 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2131 case SLAP_CONFIG_ADD:
2132 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2133 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2140 config_suffix(ConfigArgs *c)
2143 struct berval pdn, ndn;
2144 char *notallowed = NULL;
2146 if ( c->be == frontendDB ) {
2147 notallowed = "frontend";
2149 } else if ( SLAP_MONITOR(c->be) ) {
2150 notallowed = "monitor";
2152 } else if ( SLAP_CONFIG(c->be) ) {
2153 notallowed = "config";
2156 if ( notallowed != NULL ) {
2157 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2161 case LDAP_MOD_DELETE:
2162 case LDAP_MOD_REPLACE:
2163 case LDAP_MOD_INCREMENT:
2164 case SLAP_CONFIG_ADD:
2165 if ( !BER_BVISNULL( &c->value_dn ) ) {
2166 snprintf( buf, sizeof( buf ), "<%s> ",
2167 c->value_dn.bv_val );
2170 Debug(LDAP_DEBUG_ANY,
2171 "%s: suffix %snot allowed in %s database.\n",
2172 c->log, buf, notallowed );
2175 case SLAP_CONFIG_EMIT:
2176 /* don't complain when emitting... */
2180 /* FIXME: don't know what values may be valid;
2181 * please remove assertion, or add legal values
2182 * to either block */
2190 if (c->op == SLAP_CONFIG_EMIT) {
2191 if ( c->be->be_suffix == NULL
2192 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2196 value_add( &c->rvalue_vals, c->be->be_suffix );
2197 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2200 } else if ( c->op == LDAP_MOD_DELETE ) {
2201 if ( c->valx < 0 ) {
2202 ber_bvarray_free( c->be->be_suffix );
2203 ber_bvarray_free( c->be->be_nsuffix );
2204 c->be->be_suffix = NULL;
2205 c->be->be_nsuffix = NULL;
2208 ch_free( c->be->be_suffix[i].bv_val );
2209 ch_free( c->be->be_nsuffix[i].bv_val );
2211 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2212 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2214 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2219 #ifdef SLAPD_MONITOR_DN
2220 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2221 snprintf( c->msg, sizeof( c->msg ), "<%s> DN is reserved for monitoring slapd",
2223 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2224 c->log, c->msg, SLAPD_MONITOR_DN);
2231 if (SLAP_DBHIDDEN( c->be ))
2234 tbe = select_backend(&ndn, 0, 0);
2236 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2242 BackendDB *b2 = tbe;
2244 /* Does tbe precede be? */
2245 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2248 char *type = tbe->bd_info->bi_type;
2250 if ( overlay_is_over( tbe ) ) {
2251 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2252 type = oi->oi_orig->bi_type;
2255 snprintf( c->msg, sizeof( c->msg ), "<%s> namingContext \"%s\" "
2256 "already served by a preceding %s database",
2257 c->argv[0], pdn.bv_val, type );
2258 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2259 c->log, c->msg, tbe->be_suffix[0].bv_val);
2265 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2266 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2267 "base provided \"%s\" (assuming okay)\n",
2268 c->log, default_search_base.bv_val, 0);
2270 ber_bvarray_add(&c->be->be_suffix, &pdn);
2271 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2276 config_rootdn(ConfigArgs *c) {
2277 if (c->op == SLAP_CONFIG_EMIT) {
2278 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2279 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2280 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2285 } else if ( c->op == LDAP_MOD_DELETE ) {
2286 ch_free( c->be->be_rootdn.bv_val );
2287 ch_free( c->be->be_rootndn.bv_val );
2288 BER_BVZERO( &c->be->be_rootdn );
2289 BER_BVZERO( &c->be->be_rootndn );
2292 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2293 ch_free( c->be->be_rootdn.bv_val );
2294 ch_free( c->be->be_rootndn.bv_val );
2296 c->be->be_rootdn = c->value_dn;
2297 c->be->be_rootndn = c->value_ndn;
2302 config_rootpw(ConfigArgs *c) {
2305 if (c->op == SLAP_CONFIG_EMIT) {
2306 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2307 /* don't copy, because "rootpw" is marked
2309 c->value_bv = c->be->be_rootpw;
2313 } else if ( c->op == LDAP_MOD_DELETE ) {
2314 ch_free( c->be->be_rootpw.bv_val );
2315 BER_BVZERO( &c->be->be_rootpw );
2319 tbe = select_backend(&c->be->be_rootndn, 0, 0);
2321 snprintf( c->msg, sizeof( c->msg ), "<%s> can only be set when rootdn is under suffix",
2323 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2327 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2328 ch_free( c->be->be_rootpw.bv_val );
2329 c->be->be_rootpw = c->value_bv;
2334 config_restrict(ConfigArgs *c) {
2335 slap_mask_t restrictops = 0;
2337 slap_verbmasks restrictable_ops[] = {
2338 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2339 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2340 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2341 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2342 { BER_BVC("modrdn"), 0 },
2343 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2344 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2345 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2346 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2347 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2348 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2349 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2350 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2351 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2352 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2353 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2357 if (c->op == SLAP_CONFIG_EMIT) {
2358 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2360 } else if ( c->op == LDAP_MOD_DELETE ) {
2362 c->be->be_restrictops = 0;
2364 restrictops = verb_to_mask( c->line, restrictable_ops );
2365 c->be->be_restrictops ^= restrictops;
2369 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2371 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown operation", c->argv[0] );
2372 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2373 c->log, c->msg, c->argv[i]);
2376 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2377 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2378 c->be->be_restrictops |= restrictops;
2383 config_allows(ConfigArgs *c) {
2384 slap_mask_t allows = 0;
2386 slap_verbmasks allowable_ops[] = {
2387 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2388 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2389 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2390 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2391 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2394 if (c->op == SLAP_CONFIG_EMIT) {
2395 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2396 } else if ( c->op == LDAP_MOD_DELETE ) {
2400 allows = verb_to_mask( c->line, allowable_ops );
2401 global_allows ^= allows;
2405 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2407 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2408 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2409 c->log, c->msg, c->argv[i]);
2412 global_allows |= allows;
2417 config_disallows(ConfigArgs *c) {
2418 slap_mask_t disallows = 0;
2420 slap_verbmasks disallowable_ops[] = {
2421 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2422 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2423 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2424 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2427 if (c->op == SLAP_CONFIG_EMIT) {
2428 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2429 } else if ( c->op == LDAP_MOD_DELETE ) {
2431 global_disallows = 0;
2433 disallows = verb_to_mask( c->line, disallowable_ops );
2434 global_disallows ^= disallows;
2438 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2440 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2441 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2442 c->log, c->msg, c->argv[i]);
2445 global_disallows |= disallows;
2450 config_requires(ConfigArgs *c) {
2451 slap_mask_t requires = frontendDB->be_requires;
2452 int i, argc = c->argc;
2453 char **argv = c->argv;
2455 slap_verbmasks requires_ops[] = {
2456 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2457 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2458 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2459 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2460 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2463 if (c->op == SLAP_CONFIG_EMIT) {
2464 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2465 } else if ( c->op == LDAP_MOD_DELETE ) {
2467 c->be->be_requires = 0;
2469 requires = verb_to_mask( c->line, requires_ops );
2470 c->be->be_requires ^= requires;
2474 /* "none" can only be first, to wipe out default/global values */
2475 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2480 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2482 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2483 snprintf( c->msg, sizeof( c->msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2484 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2487 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2488 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2489 c->log, c->msg, c->argv[i]);
2493 c->be->be_requires = requires;
2497 static slap_verbmasks *loglevel_ops;
2500 loglevel_init( void )
2502 slap_verbmasks lo[] = {
2503 { BER_BVC("Any"), -1 },
2504 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2505 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2506 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2507 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2508 { BER_BVC("BER"), LDAP_DEBUG_BER },
2509 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2510 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2511 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2512 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2513 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2514 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2515 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2516 #if 0 /* no longer used (nor supported) */
2517 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2518 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2520 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2521 { BER_BVC("None"), LDAP_DEBUG_NONE },
2525 return slap_verbmasks_init( &loglevel_ops, lo );
2529 loglevel_destroy( void )
2531 if ( loglevel_ops ) {
2532 (void)slap_verbmasks_destroy( loglevel_ops );
2534 loglevel_ops = NULL;
2537 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2540 slap_loglevel_register( slap_mask_t m, struct berval *s )
2544 if ( loglevel_ops == NULL ) {
2548 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2551 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2559 slap_loglevel_get( struct berval *s, int *l )
2565 if ( loglevel_ops == NULL ) {
2569 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2570 m |= loglevel_ops[ i ].mask;
2575 for ( i = 1; i <= ( 1 << ( sizeof( int ) * 8 - 1 ) ) && !( m & i ); i <<= 1 )
2582 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2585 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2596 str2loglevel( const char *s, int *l )
2600 if ( loglevel_ops == NULL ) {
2604 i = verb_to_mask( s, loglevel_ops );
2606 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2610 *l = loglevel_ops[ i ].mask;
2616 loglevel2str( int l )
2618 struct berval bv = BER_BVNULL;
2620 loglevel2bv( l, &bv );
2626 loglevel2bv( int l, struct berval *bv )
2628 if ( loglevel_ops == NULL ) {
2634 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2638 loglevel2bvarray( int l, BerVarray *bva )
2640 if ( loglevel_ops == NULL ) {
2644 return mask_to_verbs( loglevel_ops, l, bva );
2648 loglevel_print( FILE *out )
2652 if ( loglevel_ops == NULL ) {
2656 fprintf( out, "Installed log subsystems:\n\n" );
2657 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2658 fprintf( out, "\t%-30s (%lu)\n",
2659 loglevel_ops[ i ].word.bv_val,
2660 loglevel_ops[ i ].mask );
2663 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2664 "by specific code\n\n" );
2669 static int config_syslog;
2672 config_loglevel(ConfigArgs *c) {
2675 if ( loglevel_ops == NULL ) {
2679 if (c->op == SLAP_CONFIG_EMIT) {
2680 /* Get default or commandline slapd setting */
2681 if ( ldap_syslog && !config_syslog )
2682 config_syslog = ldap_syslog;
2683 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2685 } else if ( c->op == LDAP_MOD_DELETE ) {
2689 int level = verb_to_mask( c->line, loglevel_ops );
2690 config_syslog ^= level;
2692 if ( slapMode & SLAP_SERVER_MODE ) {
2693 ldap_syslog = config_syslog;
2700 for( i=1; i < c->argc; i++ ) {
2703 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2704 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2705 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse level", c->argv[0] );
2706 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2707 c->log, c->msg, c->argv[i]);
2711 if ( str2loglevel( c->argv[i], &level ) ) {
2712 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown level", c->argv[0] );
2713 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2714 c->log, c->msg, c->argv[i]);
2718 config_syslog |= level;
2720 if ( slapMode & SLAP_SERVER_MODE ) {
2721 ldap_syslog = config_syslog;
2727 config_referral(ConfigArgs *c) {
2729 if (c->op == SLAP_CONFIG_EMIT) {
2730 if ( default_referral ) {
2731 value_add( &c->rvalue_vals, default_referral );
2736 } else if ( c->op == LDAP_MOD_DELETE ) {
2737 if ( c->valx < 0 ) {
2738 ber_bvarray_free( default_referral );
2739 default_referral = NULL;
2742 ch_free( default_referral[i].bv_val );
2743 for (; default_referral[i].bv_val; i++ )
2744 default_referral[i] = default_referral[i+1];
2748 if(validate_global_referral(c->argv[1])) {
2749 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
2750 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2751 c->log, c->msg, c->argv[1]);
2755 ber_str2bv(c->argv[1], 0, 0, &val);
2756 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2764 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2765 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2766 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2767 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2768 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2769 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2770 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2771 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2772 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2777 config_security(ConfigArgs *c) {
2778 slap_ssf_set_t *set = &c->be->be_ssf_set;
2781 if (c->op == SLAP_CONFIG_EMIT) {
2787 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2788 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2791 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2792 if ( bv.bv_len >= sizeof( numbuf ) ) {
2793 ber_bvarray_free_x( c->rvalue_vals, NULL );
2794 c->rvalue_vals = NULL;
2798 bv.bv_len += sec_keys[i].key.bv_len;
2799 bv.bv_val = ch_malloc( bv.bv_len + 1);
2800 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2801 strcpy( next, numbuf );
2802 ber_bvarray_add( &c->rvalue_vals, &bv );
2807 for(i = 1; i < c->argc; i++) {
2808 slap_ssf_t *tgt = NULL;
2810 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2811 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2812 sec_keys[j].key.bv_len)) {
2813 src = c->argv[i] + sec_keys[j].key.bv_len;
2814 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2819 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown factor", c->argv[0] );
2820 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2821 c->log, c->msg, c->argv[i]);
2825 if ( lutil_atou( tgt, src ) != 0 ) {
2826 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse factor", c->argv[0] );
2827 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2828 c->log, c->msg, c->argv[i]);
2836 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2840 for (; !BER_BVISNULL( &an->an_name ); an++) {
2841 /* if buflen == 0, assume the buffer size has been
2842 * already checked otherwise */
2843 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2844 if ( comma ) *ptr++ = ',';
2845 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2852 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2856 struct berval bc = BER_BVNULL;
2859 assert( !BER_BVISNULL( &ri->ri_bindconf.sb_uri ) );
2863 len = snprintf(numbuf, sizeof( numbuf ), SLAP_X_ORDERED_FMT, i );
2864 if ( len >= sizeof( numbuf ) ) {
2865 /* FIXME: how can indicate error? */
2869 if ( ri->ri_nsuffix ) {
2870 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2871 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2874 if ( ri->ri_attrs ) {
2875 len += STRLENOF(" attrs");
2876 if ( ri->ri_exclude ) len++;
2877 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2878 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2881 bindconf_unparse( &ri->ri_bindconf, &bc );
2884 bv->bv_val = ch_malloc(len + 1);
2887 ptr = lutil_strcopy( bv->bv_val, numbuf );
2889 /* start with URI from bindconf */
2890 assert( !BER_BVISNULL( &bc ) );
2892 strcpy( ptr, bc.bv_val );
2893 ch_free( bc.bv_val );
2896 if ( ri->ri_nsuffix ) {
2897 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2898 ptr = lutil_strcopy( ptr, " suffix=\"" );
2899 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2903 if ( ri->ri_attrs ) {
2904 ptr = lutil_strcopy( ptr, " attrs" );
2905 if ( ri->ri_exclude ) *ptr++ = '!';
2907 ptr = anlist_unparse( ri->ri_attrs, ptr, 0 );
2912 config_replica(ConfigArgs *c) {
2914 char *replicahost = NULL, *replicauri = NULL;
2917 if (c->op == SLAP_CONFIG_EMIT) {
2918 if (c->be->be_replica) {
2920 for (i=0;c->be->be_replica[i]; i++) {
2921 replica_unparse( c->be->be_replica[i], i, &bv );
2922 ber_bvarray_add( &c->rvalue_vals, &bv );
2927 } else if ( c->op == LDAP_MOD_DELETE ) {
2928 /* FIXME: there is no replica_free function */
2929 if ( c->valx < 0 ) {
2933 if(SLAP_MONITOR(c->be)) {
2934 Debug(LDAP_DEBUG_ANY, "%s: "
2935 "\"replica\" should not be used inside monitor database\n",
2937 return(0); /* FIXME: should this be an error? */
2940 for(i = 1; i < c->argc; i++) {
2941 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2945 snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] );
2946 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2950 replicahost = c->argv[i] + STRLENOF("host=");
2951 len = strlen( replicahost ) + STRLENOF("ldap://");
2952 replicauri = ch_malloc( len + 1 );
2953 snprintf( replicauri, len + 1, "ldap://%s", replicahost );
2954 replicahost = replicauri + STRLENOF( "ldap://");
2955 nr = add_replica_info(c->be, replicauri, replicahost);
2957 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2961 snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] );
2962 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2966 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2967 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid uri", c->argv[0] );
2968 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2971 if(!ludp->lud_host) {
2972 ldap_free_urldesc(ludp);
2973 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid uri - missing hostname",
2975 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2979 len = strlen(ludp->lud_scheme) + strlen(ludp->lud_host) +
2980 STRLENOF("://") + 1;
2981 if (ludp->lud_port != LDAP_PORT) {
2982 if (ludp->lud_port < 1 || ludp->lud_port > 65535) {
2983 ldap_free_urldesc(ludp);
2984 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid port",
2986 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2989 len += STRLENOF(":65535");
2991 replicauri = ch_malloc( len );
2992 replicahost = lutil_strcopy( replicauri, ludp->lud_scheme );
2993 replicahost = lutil_strcopy( replicahost, "://" );
2994 if (ludp->lud_port == LDAP_PORT) {
2995 strcpy( replicahost, ludp->lud_host );
2997 sprintf( replicahost, "%s:%d",ludp->lud_host,ludp->lud_port );
2999 ldap_free_urldesc(ludp);
3000 nr = add_replica_info(c->be, replicauri, replicahost);
3005 snprintf( c->msg, sizeof( c->msg ), "<%s> missing host or uri", c->argv[0] );
3006 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
3008 } else if(nr == -1) {
3009 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to add replica", c->argv[0] );
3010 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg,
3011 replicauri ? replicauri : "" );
3014 for(i = 1; i < c->argc; i++) {
3015 if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
3016 /* dealt with separately; don't let it get to bindconf */
3019 } else if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
3020 /* dealt with separately; don't let it get to bindconf */
3023 } else if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
3024 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
3026 Debug( LDAP_DEBUG_ANY, "%s: "
3027 "suffix \"%s\" in \"replica\" line is not valid for backend.\n",
3028 c->log, c->argv[i] + STRLENOF("suffix="), 0);
3032 Debug( LDAP_DEBUG_ANY, "%s: "
3033 "unable to normalize suffix in \"replica\" line.\n",
3039 } else if (!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))
3040 || !strncasecmp(c->argv[i], "attrs", STRLENOF("attrs")))
3043 char *arg = c->argv[i] + STRLENOF("attr");
3044 if (arg[0] == 's') {
3047 Debug( LDAP_DEBUG_ANY,
3049 "is deprecated (and undocumented); "
3050 "use \"attrs\" instead.\n",
3060 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
3061 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown attribute", c->argv[0] );
3062 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3063 c->log, c->msg, arg + 1);
3066 } else if ( bindconf_parse( c->argv[i],
3067 &c->be->be_replica[nr]->ri_bindconf ) ) {
3076 config_updatedn(ConfigArgs *c) {
3077 if (c->op == SLAP_CONFIG_EMIT) {
3078 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3079 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3080 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3084 } else if ( c->op == LDAP_MOD_DELETE ) {
3085 ch_free( c->be->be_update_ndn.bv_val );
3086 BER_BVZERO( &c->be->be_update_ndn );
3087 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3090 if(SLAP_SHADOW(c->be)) {
3091 snprintf( c->msg, sizeof( c->msg ), "<%s> database already shadowed", c->argv[0] );
3092 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3097 ber_memfree_x( c->value_dn.bv_val, NULL );
3098 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3099 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3101 c->be->be_update_ndn = c->value_ndn;
3102 BER_BVZERO( &c->value_dn );
3103 BER_BVZERO( &c->value_ndn );
3105 return config_slurp_shadow( c );
3109 config_shadow( ConfigArgs *c, int flag )
3111 char *notallowed = NULL;
3113 if ( c->be == frontendDB ) {
3114 notallowed = "frontend";
3116 } else if ( SLAP_MONITOR(c->be) ) {
3117 notallowed = "monitor";
3120 if ( notallowed != NULL ) {
3121 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3125 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3131 config_updateref(ConfigArgs *c) {
3133 if (c->op == SLAP_CONFIG_EMIT) {
3134 if ( c->be->be_update_refs ) {
3135 value_add( &c->rvalue_vals, c->be->be_update_refs );
3140 } else if ( c->op == LDAP_MOD_DELETE ) {
3141 if ( c->valx < 0 ) {
3142 ber_bvarray_free( c->be->be_update_refs );
3143 c->be->be_update_refs = NULL;
3146 ch_free( c->be->be_update_refs[i].bv_val );
3147 for (; c->be->be_update_refs[i].bv_val; i++)
3148 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3152 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3153 snprintf( c->msg, sizeof( c->msg ), "<%s> must appear after syncrepl or updatedn",
3155 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3160 if(validate_global_referral(c->argv[1])) {
3161 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
3162 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3163 c->log, c->msg, c->argv[1]);
3166 ber_str2bv(c->argv[1], 0, 0, &val);
3167 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3172 config_include(ConfigArgs *c) {
3173 int savelineno = c->lineno;
3176 ConfigFile *cfsave = cfn;
3177 ConfigFile *cf2 = NULL;
3179 /* No dynamic config for include files */
3180 cf = ch_calloc( 1, sizeof(ConfigFile));
3181 if ( cfn->c_kids ) {
3182 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3188 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3189 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3190 c->lineno = savelineno - 1;
3193 if ( cf2 ) cf2->c_sibs = NULL;
3194 else cfn->c_kids = NULL;
3195 ch_free( cf->c_file.bv_val );
3205 config_tls_option(ConfigArgs *c) {
3207 LDAP *ld = slap_tls_ld;
3209 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3210 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3211 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3212 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3213 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3214 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3215 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3216 default: Debug(LDAP_DEBUG_ANY, "%s: "
3217 "unknown tls_option <0x%x>\n",
3218 c->log, c->type, 0);
3221 if (c->op == SLAP_CONFIG_EMIT) {
3222 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3223 } else if ( c->op == LDAP_MOD_DELETE ) {
3224 return ldap_pvt_tls_set_option( ld, flag, NULL );
3226 ch_free(c->value_string);
3227 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3230 /* FIXME: this ought to be provided by libldap */
3232 config_tls_config(ConfigArgs *c) {
3235 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3236 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3238 Debug(LDAP_DEBUG_ANY, "%s: "
3239 "unknown tls_option <0x%x>\n",
3240 c->log, c->type, 0);
3243 if (c->op == SLAP_CONFIG_EMIT) {
3244 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3245 } else if ( c->op == LDAP_MOD_DELETE ) {
3247 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3249 ch_free( c->value_string );
3250 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3251 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3252 Debug(LDAP_DEBUG_ANY, "%s: "
3253 "unable to parse %s \"%s\"\n",
3254 c->log, c->argv[0], c->argv[1] );
3257 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3259 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3264 static CfEntryInfo *
3265 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3275 if ( dn_match( &root->ce_entry->e_nname, dn ))
3278 c = dn->bv_val+dn->bv_len;
3279 for (;*c != ',';c--);
3283 for (--c;c>dn->bv_val && *c != ',';c--);
3287 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3289 root = root->ce_kids;
3291 for (;root;root=root->ce_sibs) {
3292 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3293 if ( cdn.bv_val == dn->bv_val ) {
3303 typedef struct setup_cookie {
3313 config_ldif_resp( Operation *op, SlapReply *rs )
3315 if ( rs->sr_type == REP_SEARCH ) {
3316 setup_cookie *sc = op->o_callback->sc_private;
3318 sc->cfb->cb_got_ldif = 1;
3319 /* Does the frontend exist? */
3320 if ( !sc->got_frontend ) {
3321 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3322 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3323 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3324 STRLENOF( "olcDatabase" ), "={-1}frontend",
3325 STRLENOF( "={-1}frontend" ))) {
3328 sc->ca->be = frontendDB;
3329 sc->ca->bi = frontendDB->bd_info;
3330 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3331 rdn.bv_val = sc->ca->log;
3332 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3333 "%s=" SLAP_X_ORDERED_FMT "%s",
3334 cfAd_database->ad_cname.bv_val, -1,
3335 sc->ca->bi->bi_type);
3337 sc->frontend = config_build_entry( op, rs,
3338 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3339 sc->ca->be->be_cf_ocs );
3348 /* Does the configDB exist? */
3349 if ( sc->got_frontend && !sc->got_config &&
3350 !strncmp( rs->sr_entry->e_nname.bv_val,
3351 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3352 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3353 STRLENOF( "olcDatabase" ), "={0}config",
3354 STRLENOF( "={0}config" ))) {
3357 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3358 sc->ca->bi = sc->ca->be->bd_info;
3359 rdn.bv_val = sc->ca->log;
3360 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3361 "%s=" SLAP_X_ORDERED_FMT "%s",
3362 cfAd_database->ad_cname.bv_val, 0,
3363 sc->ca->bi->bi_type);
3365 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3366 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3373 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3374 if ( rs->sr_err != LDAP_SUCCESS ) {
3375 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3376 rs->sr_entry->e_name.bv_val, sc->ca->msg, 0 );
3382 /* Configure and read the underlying back-ldif store */
3384 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3385 CfBackInfo *cfb = be->be_private;
3391 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3392 Connection conn = {0};
3393 OperationBuffer opbuf;
3395 SlapReply rs = {REP_RESULT};
3396 Filter filter = { LDAP_FILTER_PRESENT };
3397 struct berval filterstr = BER_BVC("(objectclass=*)");
3400 /* Is the config directory available? */
3401 if ( stat( dir, &st ) < 0 ) {
3402 /* No, so don't bother using the backing store.
3403 * All changes will be in-memory only.
3408 cfb->cb_db.bd_info = backend_info( "ldif" );
3409 if ( !cfb->cb_db.bd_info )
3410 return 0; /* FIXME: eventually this will be a fatal error */
3412 if ( backend_db_init( "ldif", &cfb->cb_db, -1 ) == NULL )
3415 cfb->cb_db.be_suffix = be->be_suffix;
3416 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3418 /* The suffix is always "cn=config". The underlying DB's rootdn
3419 * is always the same as the suffix.
3421 cfb->cb_db.be_rootdn = be->be_suffix[0];
3422 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3424 ber_str2bv( dir, 0, 1, &cfdir );
3429 argv[0] = "directory";
3430 argv[1] = (char *)dir;
3434 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3438 if ( config_add_vals( ct, &c ))
3441 if ( backend_startup_one( &cfb->cb_db ))
3445 void *thrctx = ldap_pvt_thread_pool_context();
3448 op = (Operation *) &opbuf;
3449 connection_fake_init( &conn, op, thrctx );
3451 filter.f_desc = slap_schema.si_ad_objectClass;
3453 op->o_tag = LDAP_REQ_SEARCH;
3455 op->ors_filter = &filter;
3456 op->ors_filterstr = filterstr;
3457 op->ors_scope = LDAP_SCOPE_SUBTREE;
3459 op->o_dn = c.be->be_rootdn;
3460 op->o_ndn = c.be->be_rootndn;
3462 op->o_req_dn = be->be_suffix[0];
3463 op->o_req_ndn = be->be_nsuffix[0];
3465 op->ors_tlimit = SLAP_NO_LIMIT;
3466 op->ors_slimit = SLAP_NO_LIMIT;
3468 op->ors_attrs = slap_anlist_all_attributes;
3469 op->ors_attrsonly = 0;
3471 op->o_callback = &cb;
3474 cb.sc_private = ≻
3475 sc.got_frontend = 0;
3480 op->o_bd = &cfb->cb_db;
3482 /* Allow unknown attrs in DNs */
3483 prev_DN_strict = slap_DN_strict;
3486 rc = op->o_bd->be_search( op, &rs );
3488 /* Restore normal DN validation */
3489 slap_DN_strict = prev_DN_strict;
3491 op->o_tag = LDAP_REQ_ADD;
3492 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3493 op->ora_e = sc.frontend;
3494 rc = op->o_bd->be_add( op, &rs );
3496 if ( rc == LDAP_SUCCESS && sc.config ) {
3497 op->ora_e = sc.config;
3498 rc = op->o_bd->be_add( op, &rs );
3500 ldap_pvt_thread_pool_context_reset( thrctx );
3503 /* ITS#4194 - only use if it's present, or we're converting. */
3504 if ( !readit || rc == LDAP_SUCCESS )
3505 cfb->cb_use_ldif = 1;
3511 CfOc_cmp( const void *c1, const void *c2 ) {
3512 const ConfigOCs *co1 = c1;
3513 const ConfigOCs *co2 = c2;
3515 return ber_bvcmp( co1->co_name, co2->co_name );
3519 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3522 i = init_config_attrs( ct );
3525 /* set up the objectclasses */
3526 i = init_config_ocs( ocs );
3529 for (i=0; ocs[i].co_def; i++) {
3530 if ( ocs[i].co_oc ) {
3531 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3532 if ( !ocs[i].co_table )
3533 ocs[i].co_table = ct;
3534 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3541 read_config(const char *fname, const char *dir) {
3544 const char *cfdir, *cfname;
3547 /* Setup the config backend */
3548 be = backend_db_init( "config", NULL, 0 );
3552 cfb = be->be_private;
3553 be->be_dfltaccess = ACL_NONE;
3555 /* If no .conf, or a dir was specified, setup the dir */
3556 if ( !fname || dir ) {
3558 /* If explicitly given, check for existence */
3561 if ( stat( dir, &st ) < 0 ) {
3562 Debug( LDAP_DEBUG_ANY,
3563 "invalid config directory %s, error %d\n",
3569 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3571 /* if fname is defaulted, try reading .d */
3572 rc = config_setup_ldif( be, cfdir, !fname );
3575 /* It may be OK if the base object doesn't exist yet. */
3576 if ( rc != LDAP_NO_SUCH_OBJECT )
3578 /* ITS#4194: But if dir was specified and no fname,
3579 * then we were supposed to read the dir. Unless we're
3580 * trying to slapadd the dir...
3582 if ( dir && !fname ) {
3583 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3585 /* Assume it's slapadd with a config dir, let it continue */
3587 cfb->cb_got_ldif = 1;
3588 cfb->cb_use_ldif = 1;
3593 /* If we read the config from back-ldif, nothing to do here */
3594 if ( cfb->cb_got_ldif ) {
3603 cfname = SLAPD_DEFAULT_CONFIGFILE;
3605 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3608 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3611 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3612 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3613 &frontendDB->be_schemadn );
3614 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3615 if ( rc != LDAP_SUCCESS ) {
3616 Debug(LDAP_DEBUG_ANY, "read_config: "
3617 "unable to normalize default schema DN \"%s\"\n",
3618 frontendDB->be_schemadn.bv_val, 0, 0 );
3619 /* must not happen */
3627 config_back_bind( Operation *op, SlapReply *rs )
3629 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
3630 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3631 /* frontend sends result */
3632 return LDAP_SUCCESS;
3635 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3636 send_ldap_result( op, rs );
3642 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3646 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3648 rs->sr_attrs = op->ors_attrs;
3649 rs->sr_entry = ce->ce_entry;
3651 rc = send_search_entry( op, rs );
3653 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3654 if ( ce->ce_kids ) {
3655 rc = config_send( op, rs, ce->ce_kids, 1 );
3656 if ( rc ) return rc;
3659 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3660 rc = config_send( op, rs, ce, 0 );
3668 static ConfigTable *
3669 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
3673 for (j=0; j<nocs; j++) {
3674 for (i=0; colst[j]->co_table[i].name; i++)
3675 if ( colst[j]->co_table[i].ad == ad )
3676 return &colst[j]->co_table[i];
3681 /* Sort the attributes of the entry according to the order defined
3682 * in the objectclass, with required attributes occurring before
3683 * allowed attributes. For any attributes with sequencing dependencies
3684 * (e.g., rootDN must be defined after suffix) the objectclass must
3685 * list the attributes in the desired sequence.
3688 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3690 Attribute *a, *head = NULL, *tail = NULL, **prev;
3693 for (i=0; i<nocs; i++) {
3694 if ( colst[i]->co_oc->soc_required ) {
3695 AttributeType **at = colst[i]->co_oc->soc_required;
3696 for (j=0; at[j]; j++) {
3697 for (a=e->e_attrs, prev=&e->e_attrs; a;
3698 prev = &(*prev)->a_next, a=a->a_next) {
3699 if ( a->a_desc == at[j]->sat_ad ) {
3713 if ( colst[i]->co_oc->soc_allowed ) {
3714 AttributeType **at = colst[i]->co_oc->soc_allowed;
3715 for (j=0; at[j]; j++) {
3716 for (a=e->e_attrs, prev=&e->e_attrs; a;
3717 prev = &(*prev)->a_next, a=a->a_next) {
3718 if ( a->a_desc == at[j]->sat_ad ) {
3734 tail->a_next = e->e_attrs;
3740 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3742 Attribute *a = NULL;
3743 AttributeDescription *ad;
3753 Modifications *ml = ptr;
3755 vals = ml->sml_values;
3758 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3759 rc = ordered_value_sort( a, 1 );
3761 snprintf(ca->msg, sizeof( ca->msg ), "ordered_value_sort failed on attr %s\n",
3762 ad->ad_cname.bv_val );
3766 for ( i=0; vals[i].bv_val; i++ ) {
3767 ca->line = vals[i].bv_val;
3768 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3769 ca->line[0] == '{' ) {
3770 char *idx = strchr( ca->line, '}' );
3771 if ( idx ) ca->line = idx+1;
3773 rc = config_parse_vals( ct, ca, i );
3782 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3785 struct berval rtype, rval;
3787 AttributeDescription *ad = NULL;
3789 dnRdn( &e->e_name, rdn );
3790 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3791 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3792 rtype.bv_val = rdn->bv_val;
3793 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3796 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3797 a = attr_find( e->e_attrs, ad );
3798 if (!a ) return LDAP_NAMING_VIOLATION;
3805 config_rename_kids( CfEntryInfo *ce )
3808 struct berval rdn, nrdn;
3810 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3811 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3812 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3813 free( ce2->ce_entry->e_name.bv_val );
3814 free( ce2->ce_entry->e_nname.bv_val );
3815 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3817 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3819 config_rename_kids( ce2 );
3824 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3825 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3826 struct berval *nnewrdn, int use_ldif )
3830 struct berval odn, ondn;
3834 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3835 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3838 free( a->a_vals[0].bv_val );
3839 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3840 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3841 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3842 strcpy( a->a_vals[0].bv_val, ptr1 );
3844 if ( a->a_nvals != a->a_vals ) {
3845 free( a->a_nvals[0].bv_val );
3846 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3847 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3848 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3849 strcpy( a->a_nvals[0].bv_val, ptr1 );
3852 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3853 BackendDB *be = op->o_bd;
3854 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3855 struct berval dn, ndn, xdn, xndn;
3857 op->o_bd = &cfb->cb_db;
3859 /* Save current rootdn; use the underlying DB's rootdn */
3863 xndn = op->o_req_ndn;
3864 op->o_dn = op->o_bd->be_rootdn;
3865 op->o_ndn = op->o_bd->be_rootndn;
3867 op->o_req_ndn = ondn;
3869 scp = op->o_callback;
3870 op->o_callback = ≻
3871 op->orr_newrdn = *newrdn;
3872 op->orr_nnewrdn = *nnewrdn;
3873 op->orr_deleteoldrdn = 1;
3874 op->orr_modlist = NULL;
3875 slap_modrdn2mods( op, rs );
3876 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3877 rc = op->o_bd->be_modrdn( op, rs );
3878 slap_mods_free( op->orr_modlist, 1 );
3881 op->o_callback = scp;
3885 op->o_req_ndn = xndn;
3888 free( ondn.bv_val );
3890 config_rename_kids( e->e_private );
3895 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3896 Entry *e, int idx, int tailindex, int use_ldif )
3898 struct berval ival, newrdn, nnewrdn;
3901 char ibuf[32], *ptr1, *ptr2 = NULL;
3904 rc = config_rename_attr( rs, e, &rdn, &a );
3905 if ( rc ) return rc;
3908 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3909 if ( ival.bv_len >= sizeof( ibuf ) ) {
3910 return LDAP_NAMING_VIOLATION;
3913 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3914 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3917 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3918 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3921 ptr2 = ber_bvchr( &rdn, '}' );
3925 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3927 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3928 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3929 a->a_desc->ad_cname.bv_len );
3931 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3932 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3936 /* Do the equivalent of ModRDN */
3937 /* Replace DN / NDN */
3938 newrdn.bv_len = ptr1 - newrdn.bv_val;
3939 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3940 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3942 free( nnewrdn.bv_val );
3943 free( newrdn.bv_val );
3948 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3949 SlapReply *rs, int *renum, int *ibase )
3952 int index = -1, gotindex = 0, nsibs, rc = 0;
3953 int renumber = 0, tailindex = 0, isfrontend = 0;
3954 char *ptr1, *ptr2 = NULL;
3957 if ( renum ) *renum = 0;
3959 /* These entries don't get indexed/renumbered */
3960 if ( ce_type == Cft_Global ) return 0;
3961 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3963 if ( ce_type == Cft_Module )
3966 /* See if the rdn has an index already */
3967 dnRdn( &e->e_name, &rdn );
3968 if ( ce_type == Cft_Database && !strncmp( rdn.bv_val + rdn.bv_len -
3969 STRLENOF("frontend"), "frontend", STRLENOF("frontend") ))
3971 ptr1 = ber_bvchr( &e->e_name, '{' );
3972 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3974 ptr2 = strchr( ptr1, '}' );
3975 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3976 return LDAP_NAMING_VIOLATION;
3977 if ( ptr2-ptr1 == 1)
3978 return LDAP_NAMING_VIOLATION;
3980 index = strtol( ptr1 + 1, &next, 10 );
3981 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3982 return LDAP_NAMING_VIOLATION;
3985 /* Special case, we allow -1 for the frontendDB */
3986 if ( index != -1 || !isfrontend )
3987 return LDAP_NAMING_VIOLATION;
3991 /* count related kids */
3992 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3993 if ( ce->ce_type == ce_type ) nsibs++;
3996 if ( index != nsibs ) {
3998 if ( index < nsibs ) {
3999 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4000 /* Siblings need to be renumbered */
4001 if ( index != -1 || !isfrontend )
4005 if ( !isfrontend && index == -1 )
4008 /* just make index = nsibs */
4010 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4013 if ( ibase ) *ibase = index;
4014 if ( renum ) *renum = renumber;
4019 count_ocs( Attribute *oc_at, int *nocs )
4022 ConfigOCs co, *coptr, **colst;
4024 /* count the objectclasses */
4025 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
4027 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
4029 for ( i=0, j=0; i<n; i++) {
4030 co.co_name = &oc_at->a_nvals[i];
4031 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4033 /* ignore non-config objectclasses. probably should be
4034 * an error, general data doesn't belong here.
4036 if ( !coptr ) continue;
4038 /* Ignore the root objectclass, it has no implementation.
4040 if ( coptr->co_type == Cft_Abstract ) continue;
4048 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4052 /* This entry is hardcoded, don't re-parse it */
4053 if ( p->ce_type == Cft_Global ) {
4054 cfn = p->ce_private;
4056 return LDAP_COMPARE_TRUE;
4058 if ( p->ce_type != Cft_Schema )
4059 return LDAP_CONSTRAINT_VIOLATION;
4061 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4063 cfo = p->ce_private;
4064 cfn->c_sibs = cfo->c_kids;
4066 return LDAP_SUCCESS;
4070 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4072 if ( p->ce_type != Cft_Global )
4073 return LDAP_CONSTRAINT_VIOLATION;
4074 ca->be = frontendDB; /* just to get past check_vals */
4075 return LDAP_SUCCESS;
4079 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4081 if ( p->ce_type != Cft_Global )
4082 return LDAP_CONSTRAINT_VIOLATION;
4083 return LDAP_SUCCESS;
4087 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4089 if ( p->ce_type != Cft_Global )
4090 return LDAP_CONSTRAINT_VIOLATION;
4091 return LDAP_SUCCESS;
4095 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4097 if ( p->ce_type != Cft_Database )
4098 return LDAP_CONSTRAINT_VIOLATION;
4100 return LDAP_SUCCESS;
4103 /* Parse an LDAP entry into config directives */
4105 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4106 int *renum, Operation *op )
4108 CfEntryInfo *ce, *last;
4110 Attribute *a, *oc_at;
4111 int i, ibase = -1, nocs, rc = 0;
4116 /* Make sure parent exists and entry does not. But allow
4117 * Databases and Overlays to be inserted. Don't do any
4118 * auto-renumbering if manageDSAit control is present.
4120 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4122 if (( op && op->o_managedsait ) ||
4123 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4124 ce->ce_type != Cft_Module ))
4125 return LDAP_ALREADY_EXISTS;
4128 dnParent( &e->e_nname, &pdn );
4130 /* If last is NULL, the new entry is the root/suffix entry,
4131 * otherwise last should be the parent.
4133 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
4135 rs->sr_matched = last->ce_entry->e_name.bv_val;
4136 return LDAP_NO_SUCH_OBJECT;
4140 /* No parent, must be root. This will never happen... */
4141 if ( !last && !be_isroot( op ) && !be_shadow_update( op ))
4142 return LDAP_NO_SUCH_OBJECT;
4143 if ( last && !access_allowed( op, last->ce_entry,
4144 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ))
4145 return LDAP_INSUFFICIENT_ACCESS;
4148 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4149 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4151 memset( ca, 0, sizeof(ConfigArgs));
4153 /* Fake the coordinates based on whether we're part of an
4154 * LDAP Add or if reading the config dir
4157 ca->fname = "slapd";
4160 ca->fname = cfdir.bv_val;
4165 colst = count_ocs( oc_at, &nocs );
4167 /* Only the root can be Cft_Global, everything else must
4168 * have a parent. Only limited nesting arrangements are allowed.
4170 rc = LDAP_CONSTRAINT_VIOLATION;
4171 if ( colst[0]->co_type == Cft_Global && !last ) {
4172 cfn = cfb->cb_config;
4174 ca->be = frontendDB; /* just to get past check_vals */
4178 /* Check whether the Add is allowed by its parent, and do
4179 * any necessary arg setup
4182 for ( i=0; i<nocs; i++ ) {
4183 if ( colst[i]->co_ldadd &&
4184 ( rc = colst[i]->co_ldadd( last, e, ca ))
4185 != LDAP_CONSTRAINT_VIOLATION ) {
4191 /* Add the entry but don't parse it, we already have its contents */
4192 if ( rc == LDAP_COMPARE_TRUE ) {
4197 if ( rc != LDAP_SUCCESS )
4200 /* Parse all the values and check for simple syntax errors before
4201 * performing any set actions.
4203 * If doing an LDAPadd, check for indexed names and any necessary
4204 * renaming/renumbering. Entries that don't need indexed names are
4205 * ignored. Entries that need an indexed name and arrive without one
4206 * are assigned to the end. Entries that arrive with an index may
4207 * cause the following entries to be renumbered/bumped down.
4209 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4210 * don't allow Adding an entry with an index that's already in use.
4211 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4213 * These entries can have auto-assigned indexes (appended to the end)
4214 * but only the other types support auto-renumbering of siblings.
4217 rc = check_name_index( last, colst[0]->co_type, e, rs, renum,
4222 if ( renum && *renum && colst[0]->co_type != Cft_Database &&
4223 colst[0]->co_type != Cft_Overlay ) {
4224 snprintf( ca->msg, sizeof( ca->msg ),
4225 "operation requires sibling renumbering" );
4226 rc = LDAP_UNWILLING_TO_PERFORM;
4231 init_config_argv( ca );
4233 /* Make sure we process attrs in the required order */
4234 sort_attrs( e, colst, nocs );
4236 for ( a=e->e_attrs; a; a=a->a_next ) {
4237 if ( a == oc_at ) continue;
4238 ct = config_find_table( colst, nocs, a->a_desc );
4239 if ( !ct ) continue; /* user data? */
4240 rc = check_vals( ct, ca, a, 1 );
4241 if ( rc ) goto done;
4244 /* Basic syntax checks are OK. Do the actual settings. */
4245 for ( a=e->e_attrs; a; a=a->a_next ) {
4246 if ( a == oc_at ) continue;
4247 ct = config_find_table( colst, nocs, a->a_desc );
4248 if ( !ct ) continue; /* user data? */
4249 for (i=0; a->a_vals[i].bv_val; i++) {
4251 ca->line = a->a_vals[i].bv_val;
4252 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4253 ptr = strchr( ca->line, '}' );
4255 iptr = strchr( ca->line, '{' );
4259 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4261 ca->valx = strtol( iptr+1, NULL, 0 );
4268 rc = config_parse_add( ct, ca, i );
4276 /* Newly added databases and overlays need to be started up */
4277 if ( CONFIG_ONLINE_ADD( ca )) {
4278 if ( colst[0]->co_type == Cft_Database ) {
4279 rc = backend_startup_one( ca->be );
4281 } else if ( colst[0]->co_type == Cft_Overlay ) {
4282 if ( ca->bi->bi_db_open ) {
4283 BackendInfo *bi_orig = ca->be->bd_info;
4284 ca->be->bd_info = ca->bi;
4285 rc = ca->bi->bi_db_open( ca->be );
4286 ca->be->bd_info = bi_orig;
4290 snprintf( ca->msg, sizeof( ca->msg ), "<%s> failed startup", ca->argv[0] );
4291 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4292 ca->log, ca->msg, ca->argv[1] );
4299 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4300 ce->ce_parent = last;
4301 ce->ce_entry = entry_dup( e );
4302 ce->ce_entry->e_private = ce;
4303 ce->ce_type = colst[0]->co_type;
4306 ce->ce_private = ca->private;
4307 ca->ca_entry = ce->ce_entry;
4310 } else if ( last->ce_kids ) {
4311 CfEntryInfo *c2, **cprev;
4313 /* Advance to first of this type */
4314 cprev = &last->ce_kids;
4315 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4316 cprev = &c2->ce_sibs;
4319 /* Account for the (-1) frontendDB entry */
4320 if ( ce->ce_type == Cft_Database ) {
4321 if ( ca->be == frontendDB )
4323 else if ( ibase != -1 )
4328 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4329 cprev = &c2->ce_sibs;
4335 for ( i=0; i<ibase; i++ ) {
4337 cprev = &c2->ce_sibs;
4340 ce->ce_sibs = *cprev;
4348 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4349 if ( ca->be != frontendDB )
4350 backend_destroy_one( ca->be, 1 );
4351 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4352 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4356 ch_free( ca->argv );
4357 if ( colst ) ch_free( colst );
4361 #define BIGTMP 10000
4363 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4364 int base, int rebase, int max, int use_ldif )
4366 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4367 ConfigType etype = ce->ce_type;
4368 int count = 0, rc = 0;
4370 /* Reverse ce list */
4371 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4372 if (ce2->ce_type != etype) {
4377 ce2->ce_sibs = cetmp;
4380 if ( max && count >= max ) {
4386 /* Move original to a temp name until increments are done */
4388 ce->ce_entry->e_private = NULL;
4389 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4390 base+BIGTMP, 0, use_ldif );
4391 ce->ce_entry->e_private = ce;
4393 /* start incrementing */
4394 for (ce2=cetmp; ce2; ce2=ce3) {
4396 ce2->ce_sibs = cerem;
4399 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4400 count+base, 0, use_ldif );
4404 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4405 base, 0, use_ldif );
4410 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4411 CfEntryInfo *ce2, int old, int use_ldif )
4415 /* Renumber original to a temp value */
4416 ce->ce_entry->e_private = NULL;
4417 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4418 old+BIGTMP, 0, use_ldif );
4419 ce->ce_entry->e_private = ce;
4421 /* start decrementing */
4422 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4423 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4424 count+old, 0, use_ldif );
4427 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4428 count+old, 0, use_ldif );
4431 /* Parse an LDAP entry into config directives, then store in underlying
4435 config_back_add( Operation *op, SlapReply *rs )
4441 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4442 NULL, ACL_WADD, NULL )) {
4443 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4447 cfb = (CfBackInfo *)op->o_bd->be_private;
4449 /* add opattrs for syncprov */
4451 char textbuf[SLAP_TEXT_BUFLEN];
4452 size_t textlen = sizeof textbuf;
4453 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4454 &rs->sr_text, textbuf, sizeof( textbuf ) );
4455 if ( rs->sr_err != LDAP_SUCCESS )
4457 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4458 if ( rs->sr_err != LDAP_SUCCESS ) {
4459 Debug( LDAP_DEBUG_TRACE,
4460 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4461 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4466 ldap_pvt_thread_pool_pause( &connection_pool );
4469 * 1) check for existence of entry
4470 * 2) check for sibling renumbering
4471 * 3) perform internal add
4472 * 4) perform any necessary renumbering
4473 * 5) store entry in underlying database
4475 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4476 if ( rs->sr_err != LDAP_SUCCESS ) {
4477 rs->sr_text = ca.msg;
4482 CfEntryInfo *ce = ca.ca_entry->e_private;
4483 req_add_s addr = op->oq_add;
4484 op->o_tag = LDAP_REQ_MODRDN;
4485 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4486 op->o_tag = LDAP_REQ_ADD;
4488 if ( rs->sr_err != LDAP_SUCCESS ) {
4493 if ( cfb->cb_use_ldif ) {
4494 BackendDB *be = op->o_bd;
4495 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4496 struct berval dn, ndn;
4498 op->o_bd = &cfb->cb_db;
4500 /* Save current rootdn; use the underlying DB's rootdn */
4503 op->o_dn = op->o_bd->be_rootdn;
4504 op->o_ndn = op->o_bd->be_rootndn;
4506 scp = op->o_callback;
4507 op->o_callback = ≻
4508 op->o_bd->be_add( op, rs );
4510 op->o_callback = scp;
4516 ldap_pvt_thread_pool_resume( &connection_pool );
4519 send_ldap_result( op, rs );
4520 slap_graduate_commit_csn( op );
4524 typedef struct delrec {
4525 struct delrec *next;
4531 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4534 int rc = LDAP_UNWILLING_TO_PERFORM;
4536 Entry *e = ce->ce_entry;
4537 Attribute *save_attrs = e->e_attrs, *oc_at;
4542 delrec *dels = NULL, *deltail = NULL;
4544 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4545 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4547 colst = count_ocs( oc_at, &nocs );
4549 e->e_attrs = attrs_dup( e->e_attrs );
4551 init_config_argv( ca );
4554 ca->private = ce->ce_private;
4556 ca->fname = "slapd";
4558 strcpy( ca->log, "back-config" );
4560 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4561 ct = config_find_table( colst, nocs, ml->sml_desc );
4562 switch (ml->sml_op) {
4563 case LDAP_MOD_DELETE:
4564 case LDAP_MOD_REPLACE: {
4565 BerVarray vals = NULL, nvals = NULL;
4567 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4569 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
4570 ml->sml_desc->ad_cname.bv_val );
4573 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4574 vals = ml->sml_values;
4575 nvals = ml->sml_nvalues;
4576 ml->sml_values = NULL;
4577 ml->sml_nvalues = NULL;
4579 /* If we're deleting by values, remember the indexes of the
4580 * values we deleted.
4582 if ( ct && ml->sml_values ) {
4584 for (i=0; ml->sml_values[i].bv_val; i++);
4585 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4596 rc = modify_delete_vindex(e, &ml->sml_mod,
4597 get_permissiveModify(op),
4598 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
4599 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4600 ml->sml_values = vals;
4601 ml->sml_nvalues = nvals;
4606 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4609 case SLAP_MOD_SOFTADD: {
4610 int mop = ml->sml_op;
4612 ml->sml_op = LDAP_MOD_ADD;
4614 if ( ct->arg_type & ARG_NO_INSERT ) {
4615 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4617 for (i = 0; a->a_vals[i].bv_val; i++ );
4621 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4622 if ( ml->sml_values[i].bv_val[0] == '{' &&
4625 char *next, *val = ml->sml_values[i].bv_val + 1;
4628 j = strtol( val, &next, 0 );
4629 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4631 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
4632 ml->sml_desc->ad_cname.bv_val );
4636 rc = check_vals( ct, ca, ml, 0 );
4640 rc = modify_add_values(e, &ml->sml_mod,
4641 get_permissiveModify(op),
4642 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4644 /* If value already exists, show success here
4645 * and ignore this operation down below.
4647 if ( mop == SLAP_MOD_SOFTADD ) {
4648 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4658 case LDAP_MOD_INCREMENT: /* FIXME */
4663 if(rc != LDAP_SUCCESS) break;
4666 if(rc == LDAP_SUCCESS) {
4667 /* check that the entry still obeys the schema */
4668 rc = entry_schema_check(op, e, NULL, 0, 0,
4669 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4671 if ( rc == LDAP_SUCCESS ) {
4672 /* Basic syntax checks are OK. Do the actual settings. */
4673 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4674 ct = config_find_table( colst, nocs, ml->sml_desc );
4675 if ( !ct ) continue;
4677 switch (ml->sml_op) {
4678 case LDAP_MOD_DELETE:
4679 case LDAP_MOD_REPLACE: {
4680 BerVarray vals = NULL, nvals = NULL;
4684 a = attr_find( e->e_attrs, ml->sml_desc );
4686 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4687 vals = ml->sml_values;
4688 nvals = ml->sml_nvalues;
4689 ml->sml_values = NULL;
4690 ml->sml_nvalues = NULL;
4693 if ( ml->sml_values )
4696 /* If we didn't delete the whole attribute */
4697 if ( ml->sml_values && a ) {
4698 struct berval *mvals;
4701 if ( ml->sml_nvalues )
4702 mvals = ml->sml_nvalues;
4704 mvals = ml->sml_values;
4706 /* use the indexes we saved up above */
4707 for (i=0; i < d->nidx; i++) {
4708 struct berval bv = *mvals++;
4709 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4710 bv.bv_val[0] == '{' ) {
4711 ptr = strchr( bv.bv_val, '}' ) + 1;
4712 bv.bv_len -= ptr - bv.bv_val;
4715 ca->line = bv.bv_val;
4716 ca->valx = d->idx[i];
4717 rc = config_del_vals( ct, ca );
4718 if ( rc != LDAP_SUCCESS ) break;
4719 for (j=i+1; j < d->nidx; j++)
4720 if ( d->idx[j] >d->idx[i] )
4726 rc = config_del_vals( ct, ca );
4727 if ( rc ) rc = LDAP_OTHER;
4729 if ( ml->sml_values ) {
4734 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4735 ml->sml_values = vals;
4736 ml->sml_nvalues = nvals;
4738 if ( !vals || rc != LDAP_SUCCESS )
4741 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4744 for (i=0; ml->sml_values[i].bv_val; i++) {
4745 ca->line = ml->sml_values[i].bv_val;
4747 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4748 ca->line[0] == '{' )
4750 ptr = strchr( ca->line + 1, '}' );
4754 ca->valx = strtol( ca->line + 1, &next, 0 );
4755 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4762 rc = config_parse_add( ct, ca, i );
4777 if ( rc == LDAP_SUCCESS ) {
4778 attrs_free( save_attrs );
4780 attrs_free( e->e_attrs );
4781 e->e_attrs = save_attrs;
4783 ch_free( ca->argv );
4784 if ( colst ) ch_free( colst );
4786 deltail = dels->next;
4795 config_back_modify( Operation *op, SlapReply *rs )
4798 CfEntryInfo *ce, *last;
4800 ConfigArgs ca = {0};
4803 AttributeDescription *rad = NULL;
4805 cfb = (CfBackInfo *)op->o_bd->be_private;
4807 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4810 rs->sr_matched = last->ce_entry->e_name.bv_val;
4811 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4815 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4816 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4820 /* Get type of RDN */
4821 rdn = ce->ce_entry->e_nname;
4822 ptr = strchr( rdn.bv_val, '=' );
4823 rdn.bv_len = ptr - rdn.bv_val;
4824 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4826 /* Some basic validation... */
4827 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4828 /* Don't allow Modify of RDN; must use ModRdn for that. */
4829 if ( ml->sml_desc == rad ) {
4830 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4831 rs->sr_text = "Use modrdn to change the entry name";
4836 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4838 if ( !slapd_shutdown )
4839 ldap_pvt_thread_pool_pause( &connection_pool );
4842 * 1) perform the Modify on the cached Entry.
4843 * 2) verify that the Entry still satisfies the schema.
4844 * 3) perform the individual config operations.
4845 * 4) store Modified entry in underlying LDIF backend.
4847 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4849 rs->sr_text = ca.msg;
4850 } else if ( cfb->cb_use_ldif ) {
4851 BackendDB *be = op->o_bd;
4852 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4853 struct berval dn, ndn;
4855 op->o_bd = &cfb->cb_db;
4859 op->o_dn = op->o_bd->be_rootdn;
4860 op->o_ndn = op->o_bd->be_rootndn;
4862 scp = op->o_callback;
4863 op->o_callback = ≻
4864 op->o_bd->be_modify( op, rs );
4866 op->o_callback = scp;
4871 if ( !slapd_shutdown )
4872 ldap_pvt_thread_pool_resume( &connection_pool );
4874 send_ldap_result( op, rs );
4875 slap_graduate_commit_csn( op );
4880 config_back_modrdn( Operation *op, SlapReply *rs )
4883 CfEntryInfo *ce, *last;
4887 cfb = (CfBackInfo *)op->o_bd->be_private;
4889 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4892 rs->sr_matched = last->ce_entry->e_name.bv_val;
4893 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4896 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4897 NULL, ACL_WRITE, NULL )) {
4898 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4902 if ( ce->ce_parent )
4903 parent = ce->ce_parent->ce_entry;
4905 parent = (Entry *)&slap_entry_root;
4906 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
4907 NULL, ACL_WRITE, NULL )) {
4908 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4913 /* We don't allow moving objects to new parents.
4914 * Generally we only allow reordering a set of ordered entries.
4916 if ( op->orr_newSup ) {
4917 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4921 /* If newRDN == oldRDN, quietly succeed */
4922 dnRdn( &op->o_req_ndn, &rdn );
4923 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
4924 rs->sr_err = LDAP_SUCCESS;
4928 /* Current behavior, subject to change as needed:
4930 * For backends and overlays, we only allow renumbering.
4931 * For schema, we allow renaming with the same number.
4932 * Otherwise, the op is not allowed.
4935 if ( ce->ce_type == Cft_Schema ) {
4939 /* Can't alter the main cn=schema entry */
4940 if ( ce->ce_parent->ce_type == Cft_Global ) {
4941 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4942 rs->sr_text = "renaming not allowed for this entry";
4946 /* We could support this later if desired */
4947 ptr1 = ber_bvchr( &rdn, '}' );
4948 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4949 len = ptr1 - rdn.bv_val;
4950 if ( len != ptr2 - op->orr_newrdn.bv_val ||
4951 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
4952 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4953 rs->sr_text = "schema reordering not supported";
4956 } else if ( ce->ce_type == Cft_Database ||
4957 ce->ce_type == Cft_Overlay ) {
4958 char *ptr1, *ptr2, *iptr1, *iptr2;
4961 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
4962 if ( *iptr2 != '{' ) {
4963 rs->sr_err = LDAP_NAMING_VIOLATION;
4964 rs->sr_text = "new ordering index is required";
4968 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
4969 ptr1 = ber_bvchr( &rdn, '}' );
4970 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4972 rs->sr_err = LDAP_NAMING_VIOLATION;
4973 rs->sr_text = "new ordering index is required";
4977 len1 = ptr1 - rdn.bv_val;
4978 len2 = ptr2 - op->orr_newrdn.bv_val;
4980 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
4981 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
4982 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4983 rs->sr_text = "changing database/overlay type not allowed";
4986 ixold = strtol( iptr1, NULL, 0 );
4987 ixnew = strtol( iptr2, &ptr1, 0 );
4988 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
4989 rs->sr_err = LDAP_NAMING_VIOLATION;
4992 /* config DB is always 0, cannot be changed */
4993 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
4994 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
4998 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4999 rs->sr_text = "renaming not supported for this entry";
5003 ldap_pvt_thread_pool_pause( &connection_pool );
5005 if ( ce->ce_type == Cft_Schema ) {
5006 req_modrdn_s modr = op->oq_modrdn;
5009 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5010 if ( rs->sr_err == LDAP_SUCCESS ) {
5011 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5012 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5015 op->oq_modrdn = modr;
5017 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5018 req_modrdn_s modr = op->oq_modrdn;
5021 /* Advance to first of this type */
5022 cprev = &ce->ce_parent->ce_kids;
5023 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5024 cprev = &ce2->ce_sibs;
5027 /* Skip the -1 entry */
5028 if ( ce->ce_type == Cft_Database ) {
5029 cprev = &ce2->ce_sibs;
5035 /* Remove from old slot */
5036 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5037 cprev = &ce2->ce_sibs;
5038 *cprev = ce->ce_sibs;
5039 ceold = ce->ce_sibs;
5041 /* Insert into new slot */
5043 for ( i=0; i<ixnew; i++ ) {
5047 cprev = &ce2->ce_sibs;
5049 ce->ce_sibs = *cprev;
5054 /* NOTE: These should be encoded in the OC tables, not inline here */
5055 if ( ce->ce_type == Cft_Database )
5056 backend_db_move( ce->ce_be, ixnew );
5057 else if ( ce->ce_type == Cft_Overlay )
5058 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5060 if ( ixold < ixnew ) {
5061 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5064 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5065 ixold - ixnew, cfb->cb_use_ldif );
5067 op->oq_modrdn = modr;
5070 ldap_pvt_thread_pool_resume( &connection_pool );
5072 send_ldap_result( op, rs );
5077 config_back_delete( Operation *op, SlapReply *rs )
5079 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5084 config_back_search( Operation *op, SlapReply *rs )
5087 CfEntryInfo *ce, *last;
5090 cfb = (CfBackInfo *)op->o_bd->be_private;
5092 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5095 rs->sr_matched = last->ce_entry->e_name.bv_val;
5096 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5099 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5100 ACL_SEARCH, NULL, &mask ))
5102 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5103 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5105 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5109 switch ( op->ors_scope ) {
5110 case LDAP_SCOPE_BASE:
5111 case LDAP_SCOPE_SUBTREE:
5112 config_send( op, rs, ce, 0 );
5115 case LDAP_SCOPE_ONELEVEL:
5116 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5117 config_send( op, rs, ce, 1 );
5122 rs->sr_err = LDAP_SUCCESS;
5124 send_ldap_result( op, rs );
5128 /* no-op, we never free entries */
5129 int config_entry_release(
5134 return LDAP_SUCCESS;
5137 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5139 int config_back_entry_get(
5143 AttributeDescription *at,
5148 CfEntryInfo *ce, *last;
5150 cfb = (CfBackInfo *)op->o_bd->be_private;
5152 ce = config_find_base( cfb->cb_root, ndn, &last );
5154 *ent = ce->ce_entry;
5155 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5160 return ( *ent == NULL ? 1 : 0 );
5164 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5165 ConfigTable *ct, ConfigArgs *c )
5169 for (; at && *at; at++) {
5170 /* Skip the naming attr */
5171 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5173 for (i=0;ct[i].name;i++) {
5174 if (ct[i].ad == (*at)->sat_ad) {
5175 rc = config_get_vals(&ct[i], c);
5176 /* NOTE: tolerate that config_get_vals()
5177 * returns success with no values */
5178 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5179 if ( c->rvalue_nvals )
5180 attr_merge(e, ct[i].ad, c->rvalue_vals,
5183 attr_merge_normalize(e, ct[i].ad,
5184 c->rvalue_vals, NULL);
5185 ber_bvarray_free( c->rvalue_nvals );
5186 ber_bvarray_free( c->rvalue_vals );
5195 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5196 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5198 Entry *e = entry_alloc();
5199 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5201 struct berval ad_name;
5202 AttributeDescription *ad = NULL;
5209 CfEntryInfo *ceprev = NULL;
5211 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5214 ce->ce_type = main->co_type;
5215 ce->ce_parent = parent;
5217 pdn = parent->ce_entry->e_nname;
5218 if ( parent->ce_kids && parent->ce_kids->ce_type < ce->ce_type )
5219 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5220 ceprev->ce_type < ce->ce_type;
5221 ceprev = ceprev->ce_sibs );
5226 ce->ce_private = c->private;
5230 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5231 ber_dupbv( &e->e_nname, &e->e_name );
5233 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5234 main->co_name, NULL );
5236 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5237 extra->co_name, NULL );
5238 ptr = strchr(rdn->bv_val, '=');
5239 ad_name.bv_val = rdn->bv_val;
5240 ad_name.bv_len = ptr - rdn->bv_val;
5241 rc = slap_bv2ad( &ad_name, &ad, &text );
5246 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5247 attr_merge_normalize_one(e, ad, &val, NULL );
5250 if ( oc->soc_required )
5251 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5253 if ( oc->soc_allowed )
5254 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5258 if ( oc->soc_required )
5259 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5261 if ( oc->soc_allowed )
5262 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5265 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5266 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->msg,
5267 sizeof(c->msg), op ? op->o_tmpmemctx : NULL );
5268 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5269 if ( op && !op->o_noop ) {
5271 op->ora_modlist = NULL;
5272 op->o_bd->be_add( op, rs );
5273 if ( ( rs->sr_err != LDAP_SUCCESS )
5274 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5279 ce->ce_sibs = ceprev->ce_sibs;
5280 ceprev->ce_sibs = ce;
5281 } else if ( parent ) {
5282 ce->ce_sibs = parent->ce_kids;
5283 parent->ce_kids = ce;
5290 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5291 Operation *op, SlapReply *rs )
5294 ConfigFile *cf = c->private;
5298 for (; cf; cf=cf->c_sibs, c->depth++) {
5299 c->value_dn.bv_val = c->log;
5300 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5305 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5307 ptr = strchr( bv.bv_val, '.' );
5309 bv.bv_len = ptr - bv.bv_val;
5310 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5311 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5312 /* FIXME: how can indicate error? */
5315 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5317 c->value_dn.bv_len += bv.bv_len;
5318 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5321 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5322 &CFOC_SCHEMA, NULL );
5325 } else if ( e && cf->c_kids ) {
5326 c->private = cf->c_kids;
5327 config_build_schema_inc( c, e->e_private, op, rs );
5333 #ifdef SLAPD_MODULES
5336 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5337 Operation *op, SlapReply *rs )
5342 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5343 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5345 c->value_dn.bv_val = c->log;
5346 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5347 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5348 /* FIXME: how can indicate error? */
5352 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5361 config_check_schema(Operation *op, CfBackInfo *cfb)
5363 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5365 CfEntryInfo *ce, *last;
5368 /* If there's no root entry, we must be in the midst of converting */
5369 if ( !cfb->cb_root )
5372 /* Make sure the main schema entry exists */
5373 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5380 /* Make sure it's up to date */
5381 if ( cf_om_tail != om_sys_tail ) {
5382 a = attr_find( e->e_attrs, cfAd_om );
5384 if ( a->a_nvals != a->a_vals )
5385 ber_bvarray_free( a->a_nvals );
5386 ber_bvarray_free( a->a_vals );
5390 oidm_unparse( &bv, NULL, NULL, 1 );
5391 attr_merge_normalize( e, cfAd_om, bv, NULL );
5392 ber_bvarray_free( bv );
5393 cf_om_tail = om_sys_tail;
5395 if ( cf_at_tail != at_sys_tail ) {
5396 a = attr_find( e->e_attrs, cfAd_attr );
5398 if ( a->a_nvals != a->a_vals )
5399 ber_bvarray_free( a->a_nvals );
5400 ber_bvarray_free( a->a_vals );
5404 at_unparse( &bv, NULL, NULL, 1 );
5405 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5406 ber_bvarray_free( bv );
5407 cf_at_tail = at_sys_tail;
5409 if ( cf_oc_tail != oc_sys_tail ) {
5410 a = attr_find( e->e_attrs, cfAd_oc );
5412 if ( a->a_nvals != a->a_vals )
5413 ber_bvarray_free( a->a_nvals );
5414 ber_bvarray_free( a->a_vals );
5418 oc_unparse( &bv, NULL, NULL, 1 );
5419 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5420 ber_bvarray_free( bv );
5421 cf_oc_tail = oc_sys_tail;
5424 SlapReply rs = {REP_RESULT};
5426 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5427 &CFOC_SCHEMA, NULL );
5432 ce->ce_private = cfb->cb_config;
5433 cf_at_tail = at_sys_tail;
5434 cf_oc_tail = oc_sys_tail;
5435 cf_om_tail = om_sys_tail;
5440 static const char *defacl[] = {
5441 NULL, "to", "*", "by", "*", "none", NULL
5445 config_back_db_open( BackendDB *be )
5447 CfBackInfo *cfb = be->be_private;
5450 CfEntryInfo *ce, *ceparent;
5454 Connection conn = {0};
5455 OperationBuffer opbuf;
5457 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5458 SlapReply rs = {REP_RESULT};
5459 void *thrctx = NULL;
5461 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5463 /* If we have no explicitly configured ACLs, don't just use
5464 * the global ACLs. Explicitly deny access to everything.
5466 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5467 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5470 thrctx = ldap_pvt_thread_pool_context();
5471 op = (Operation *) &opbuf;
5472 connection_fake_init( &conn, op, thrctx );
5474 op->o_tag = LDAP_REQ_ADD;
5475 op->o_callback = &cb;
5476 op->o_bd = &cfb->cb_db;
5477 op->o_dn = op->o_bd->be_rootdn;
5478 op->o_ndn = op->o_bd->be_rootndn;
5480 if ( !cfb->cb_use_ldif ) {
5484 /* If we read the config from back-ldif, do some quick sanity checks */
5485 if ( cfb->cb_got_ldif ) {
5486 return config_check_schema( op, cfb );
5489 /* create root of tree */
5491 c.private = cfb->cb_config;
5493 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5503 #ifdef SLAPD_MODULES
5504 /* Create Module nodes... */
5505 if ( modpaths.mp_loads ) {
5506 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5512 /* Create schema nodes... cn=schema will contain the hardcoded core
5513 * schema, read-only. Child objects will contain runtime loaded schema
5518 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5523 ce->ce_private = cfb->cb_config;
5524 cf_at_tail = at_sys_tail;
5525 cf_oc_tail = oc_sys_tail;
5526 cf_om_tail = om_sys_tail;
5528 /* Create schema nodes for included schema... */
5529 if ( cfb->cb_config->c_kids ) {
5531 c.private = cfb->cb_config->c_kids;
5532 if (config_build_schema_inc( &c, ce, op, &rs )) {
5537 /* Create backend nodes. Skip if they don't provide a cf_table.
5538 * There usually aren't any of these.
5542 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5543 if (!bi->bi_cf_ocs) {
5544 /* If it only supports the old config mech, complain. */
5545 if ( bi->bi_config ) {
5546 Debug( LDAP_DEBUG_ANY,
5547 "WARNING: No dynamic config support for backend %s.\n",
5548 bi->bi_type, 0, 0 );
5553 if (!bi->bi_private) continue;
5556 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5557 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5558 if ( rdn.bv_len >= sizeof( c.log ) ) {
5559 /* FIXME: holler ... */ ;
5562 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5569 /* Create database nodes... */
5570 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5571 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5572 for ( i = -1, be = frontendDB ; be;
5573 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5574 slap_overinfo *oi = NULL;
5576 if ( overlay_is_over( be )) {
5577 oi = be->bd_info->bi_private;
5583 /* If this backend supports the old config mechanism, but not
5584 * the new mech, complain.
5586 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5587 Debug( LDAP_DEBUG_ANY,
5588 "WARNING: No dynamic config support for database %s.\n",
5589 bi->bi_type, 0, 0 );
5593 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5594 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5596 if ( rdn.bv_len >= sizeof( c.log ) ) {
5597 /* FIXME: holler ... */ ;
5601 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5607 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5608 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5609 /* Iterate through overlays */
5615 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5616 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5617 Debug( LDAP_DEBUG_ANY,
5618 "WARNING: No dynamic config support for overlay %s.\n",
5619 on->on_bi.bi_type, 0, 0 );
5623 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5624 "%s=" SLAP_X_ORDERED_FMT "%s",
5625 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5626 if ( rdn.bv_len >= sizeof( c.log ) ) {
5627 /* FIXME: holler ... */ ;
5631 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5632 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5636 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5637 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5642 ldap_pvt_thread_pool_context_reset( thrctx );
5644 if ( unsupp && cfb->cb_use_ldif ) {
5645 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5646 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5653 cfb_free_cffile( ConfigFile *cf )
5657 for (; cf; cf=next) {
5660 cfb_free_cffile( cf->c_kids );
5661 ch_free( cf->c_file.bv_val );
5662 ber_bvarray_free( cf->c_dseFiles );
5668 cfb_free_entries( CfEntryInfo *ce )
5672 for (; ce; ce=next) {
5675 cfb_free_entries( ce->ce_kids );
5676 ce->ce_entry->e_private = NULL;
5677 entry_free( ce->ce_entry );
5683 config_back_db_close( BackendDB *be )
5685 CfBackInfo *cfb = be->be_private;
5687 cfb_free_entries( cfb->cb_root );
5688 cfb->cb_root = NULL;
5690 if ( cfb->cb_db.bd_info ) {
5691 backend_shutdown( &cfb->cb_db );
5698 config_back_db_destroy( BackendDB *be )
5700 CfBackInfo *cfb = be->be_private;
5702 cfb_free_cffile( cfb->cb_config );
5704 ch_free( cfdir.bv_val );
5706 avl_free( CfOcTree, NULL );
5708 if ( cfb->cb_db.bd_info ) {
5709 cfb->cb_db.be_suffix = NULL;
5710 cfb->cb_db.be_nsuffix = NULL;
5711 BER_BVZERO( &cfb->cb_db.be_rootdn );
5712 BER_BVZERO( &cfb->cb_db.be_rootndn );
5714 backend_destroy_one( &cfb->cb_db, 0 );
5723 config_back_db_init( BackendDB *be )
5729 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5730 cfn = cfb->cb_config;
5731 be->be_private = cfb;
5733 ber_dupbv( &be->be_rootdn, &config_rdn );
5734 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5735 ber_dupbv( &dn, &be->be_rootdn );
5736 ber_bvarray_add( &be->be_suffix, &dn );
5737 ber_dupbv( &dn, &be->be_rootdn );
5738 ber_bvarray_add( &be->be_nsuffix, &dn );
5740 /* Hide from namingContexts */
5741 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5747 config_back_destroy( BackendInfo *bi )
5749 ldif_must_b64_encode_release();
5754 config_tool_entry_open( BackendDB *be, int mode )
5756 CfBackInfo *cfb = be->be_private;
5757 BackendInfo *bi = cfb->cb_db.bd_info;
5759 if ( bi && bi->bi_tool_entry_open )
5760 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5767 config_tool_entry_close( BackendDB *be )
5769 CfBackInfo *cfb = be->be_private;
5770 BackendInfo *bi = cfb->cb_db.bd_info;
5772 if ( bi && bi->bi_tool_entry_close )
5773 return bi->bi_tool_entry_close( &cfb->cb_db );
5779 config_tool_entry_first( BackendDB *be )
5781 CfBackInfo *cfb = be->be_private;
5782 BackendInfo *bi = cfb->cb_db.bd_info;
5784 if ( bi && bi->bi_tool_entry_first )
5785 return bi->bi_tool_entry_first( &cfb->cb_db );
5791 config_tool_entry_next( BackendDB *be )
5793 CfBackInfo *cfb = be->be_private;
5794 BackendInfo *bi = cfb->cb_db.bd_info;
5796 if ( bi && bi->bi_tool_entry_next )
5797 return bi->bi_tool_entry_next( &cfb->cb_db );
5803 config_tool_entry_get( BackendDB *be, ID id )
5805 CfBackInfo *cfb = be->be_private;
5806 BackendInfo *bi = cfb->cb_db.bd_info;
5808 if ( bi && bi->bi_tool_entry_get )
5809 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5815 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5817 CfBackInfo *cfb = be->be_private;
5818 BackendInfo *bi = cfb->cb_db.bd_info;
5821 if ( bi && bi->bi_tool_entry_put &&
5822 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
5823 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
5830 AttributeDescription **desc;
5832 { "attribute", &cfAd_attr },
5833 { "backend", &cfAd_backend },
5834 { "database", &cfAd_database },
5835 { "include", &cfAd_include },
5836 { "objectclass", &cfAd_oc },
5837 { "objectidentifier", &cfAd_om },
5838 { "overlay", &cfAd_overlay },
5843 * add / delete: all types that may be added or deleted must use an
5844 * X-ORDERED attributeType for their RDN. Adding and deleting entries
5845 * should automatically renumber the index of any siblings as needed,
5846 * so that no gaps in the numbering sequence exist after the add/delete
5848 * What can be added:
5850 * backend objects for backend-specific config directives
5854 * delete: probably no support this time around.
5856 * modrdn: generally not done. Will be invoked automatically by add/
5857 * delete to update numbering sequence. Perform as an explicit operation
5858 * so that the renumbering effect may be replicated. Subtree rename must
5859 * be supported, since renumbering a database will affect all its child
5862 * modify: must be fully supported.
5866 config_back_initialize( BackendInfo *bi )
5868 ConfigTable *ct = config_back_cf_table;
5872 AttributeDescription *ad = NULL;
5874 static char *controls[] = {
5875 LDAP_CONTROL_MANAGEDSAIT,
5879 /* Make sure we don't exceed the bits reserved for userland */
5880 config_check_userland( CFG_LAST );
5882 bi->bi_controls = controls;
5887 bi->bi_destroy = config_back_destroy;
5889 bi->bi_db_init = config_back_db_init;
5890 bi->bi_db_config = 0;
5891 bi->bi_db_open = config_back_db_open;
5892 bi->bi_db_close = config_back_db_close;
5893 bi->bi_db_destroy = config_back_db_destroy;
5895 bi->bi_op_bind = config_back_bind;
5896 bi->bi_op_unbind = 0;
5897 bi->bi_op_search = config_back_search;
5898 bi->bi_op_compare = 0;
5899 bi->bi_op_modify = config_back_modify;
5900 bi->bi_op_modrdn = config_back_modrdn;
5901 bi->bi_op_add = config_back_add;
5902 bi->bi_op_delete = config_back_delete;
5903 bi->bi_op_abandon = 0;
5905 bi->bi_extended = 0;
5907 bi->bi_chk_referrals = 0;
5909 bi->bi_access_allowed = slap_access_allowed;
5911 bi->bi_connection_init = 0;
5912 bi->bi_connection_destroy = 0;
5914 bi->bi_entry_release_rw = config_entry_release;
5915 bi->bi_entry_get_rw = config_back_entry_get;
5917 bi->bi_tool_entry_open = config_tool_entry_open;
5918 bi->bi_tool_entry_close = config_tool_entry_close;
5919 bi->bi_tool_entry_first = config_tool_entry_first;
5920 bi->bi_tool_entry_next = config_tool_entry_next;
5921 bi->bi_tool_entry_get = config_tool_entry_get;
5922 bi->bi_tool_entry_put = config_tool_entry_put;
5925 argv[ 0 ] = "slapd";
5931 for (i=0; OidMacros[i].name; i++ ) {
5932 argv[1] = OidMacros[i].name;
5933 argv[2] = OidMacros[i].oid;
5934 parse_oidm( &ca, 0, NULL );
5937 bi->bi_cf_ocs = cf_ocs;
5939 i = config_register_schema( ct, cf_ocs );
5942 /* setup olcRootPW to be base64-encoded when written in LDIF form;
5943 * basically, we don't care if it fails */
5944 i = slap_str2ad( "olcRootPW", &ad, &text );
5946 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
5947 "warning, unable to get \"olcRootPW\" "
5948 "attribute description: %d: %s\n",
5951 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
5952 ad->ad_type->sat_oid );
5955 /* set up the notable AttributeDescriptions */
5957 for (;ct->name;ct++) {
5958 if (strcmp(ct->name, ads[i].name)) continue;
5959 *ads[i].desc = ct->ad;
5961 if (!ads[i].name) break;