1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2006 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 static struct berval config_rdn = BER_BVC("cn=config");
41 static struct berval schema_rdn = BER_BVC("cn=schema");
43 extern int slap_DN_strict; /* dn.c */
46 typedef struct modpath_s {
47 struct modpath_s *mp_next;
48 struct berval mp_path;
52 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
55 typedef struct ConfigFile {
56 struct ConfigFile *c_sibs;
57 struct ConfigFile *c_kids;
59 AttributeType *c_at_head, *c_at_tail;
60 ContentRule *c_cr_head, *c_cr_tail;
61 ObjectClass *c_oc_head, *c_oc_tail;
62 OidMacro *c_om_head, *c_om_tail;
67 ConfigFile *cb_config;
69 BackendDB cb_db; /* underlying database */
74 static char *passwd_salt;
75 static char *logfileName;
76 #ifdef SLAP_AUTH_REWRITE
77 static BerVarray authz_rewrites;
80 static struct berval cfdir;
83 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
86 static ConfigFile *cfn;
88 static Avlnode *CfOcTree;
90 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
91 SlapReply *rs, int *renumber, Operation *op );
93 static ConfigDriver config_fname;
94 static ConfigDriver config_cfdir;
95 static ConfigDriver config_generic;
96 static ConfigDriver config_search_base;
97 static ConfigDriver config_passwd_hash;
98 static ConfigDriver config_schema_dn;
99 static ConfigDriver config_sizelimit;
100 static ConfigDriver config_timelimit;
101 static ConfigDriver config_overlay;
102 static ConfigDriver config_subordinate;
103 static ConfigDriver config_suffix;
104 static ConfigDriver config_rootdn;
105 static ConfigDriver config_rootpw;
106 static ConfigDriver config_restrict;
107 static ConfigDriver config_allows;
108 static ConfigDriver config_disallows;
109 static ConfigDriver config_requires;
110 static ConfigDriver config_security;
111 static ConfigDriver config_referral;
112 static ConfigDriver config_loglevel;
113 static ConfigDriver config_replica;
114 static ConfigDriver config_updatedn;
115 static ConfigDriver config_updateref;
116 static ConfigDriver config_include;
118 static ConfigDriver config_tls_option;
119 static ConfigDriver config_tls_config;
121 extern ConfigDriver syncrepl_config;
148 CFG_REPLICA_ARGSFILE,
150 CFG_REPLICATIONINTERVAL,
174 static OidRec OidMacros[] = {
175 /* OpenLDAProot:666.11.1 */
176 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
177 { "OLcfgAt", "OLcfg:3" },
178 { "OLcfgGlAt", "OLcfgAt:0" },
179 { "OLcfgBkAt", "OLcfgAt:1" },
180 { "OLcfgDbAt", "OLcfgAt:2" },
181 { "OLcfgOvAt", "OLcfgAt:3" },
182 { "OLcfgOc", "OLcfg:4" },
183 { "OLcfgGlOc", "OLcfgOc:0" },
184 { "OLcfgBkOc", "OLcfgOc:1" },
185 { "OLcfgDbOc", "OLcfgOc:2" },
186 { "OLcfgOvOc", "OLcfgOc:3" },
187 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
188 { "OMsBoolean", "OMsyn:7" },
189 { "OMsDN", "OMsyn:12" },
190 { "OMsDirectoryString", "OMsyn:15" },
191 { "OMsInteger", "OMsyn:27" },
192 { "OMsOID", "OMsyn:38" },
193 { "OMsOctetString", "OMsyn:40" },
198 * Backend/Database registry
200 * OLcfg{Bk|Db}{Oc|At}:0 -> common
201 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
202 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
203 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
209 * OLcfgOv{Oc|At}:1 -> syncprov
210 * OLcfgOv{Oc|At}:2 -> pcache
211 * OLcfgOv{Oc|At}:3 -> chain
212 * OLcfgOv{Oc|At}:4 -> accesslog
213 * OLcfgOv{Oc|At}:5 -> valsort
214 * (FIXME: separate arc for contribware?)
215 * OLcfgOv{Oc|At}:6 -> smbk5pwd
216 * OLcfgOv{Oc|At}:7 -> distproc
217 * OLcfgOv{Oc|At}:8 -> dynlist
218 * OLcfgOv{Oc|At}:9 -> dds
219 * OLcfgOv{Oc|At}:10 -> unique
220 * OLcfgOv{Oc|At}:11 -> refint
221 * OLcfgOv{Oc|At}:12 -> ppolicy
222 * OLcfgOv{Oc|At}:13 -> constraint
223 * OLcfgOv{Oc|At}:14 -> translucent
226 /* alphabetical ordering */
228 static ConfigTable config_back_cf_table[] = {
229 /* This attr is read-only */
230 { "", "", 0, 0, 0, ARG_MAGIC,
231 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
232 "DESC 'File for slapd configuration directives' "
233 "EQUALITY caseIgnoreMatch "
234 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
235 { "", "", 0, 0, 0, ARG_MAGIC,
236 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
237 "DESC 'Directory for slapd configuration backend' "
238 "EQUALITY caseIgnoreMatch "
239 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
240 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
241 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
242 "DESC 'Access Control List' "
243 "EQUALITY caseIgnoreMatch "
244 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
245 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
246 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
247 "DESC 'Allowed set of deprecated features' "
248 "EQUALITY caseIgnoreMatch "
249 "SYNTAX OMsDirectoryString )", NULL, NULL },
250 { "argsfile", "file", 2, 2, 0, ARG_STRING,
251 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
252 "DESC 'File for slapd command line options' "
253 "EQUALITY caseIgnoreMatch "
254 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
255 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
256 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString )", NULL, NULL },
259 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
260 ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT,
261 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
262 "DESC 'OpenLDAP attributeTypes' "
263 "EQUALITY caseIgnoreMatch "
264 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
266 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
267 #ifdef SLAP_AUTH_REWRITE
268 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
272 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
273 "EQUALITY caseIgnoreMatch "
274 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
275 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
276 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
277 "EQUALITY caseIgnoreMatch "
278 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
279 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
280 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
283 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
284 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
285 "DESC 'A type of backend' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
289 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
290 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
291 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
292 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
293 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
294 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
295 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
296 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
297 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
298 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
299 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
300 "DESC 'The backend type for a database instance' "
301 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
302 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
303 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
304 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
305 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
306 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString )", NULL, NULL },
309 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
310 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
311 "DESC 'OpenLDAP DIT content rules' "
312 "EQUALITY caseIgnoreMatch "
313 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
315 { "gentlehup", "on|off", 2, 2, 0,
317 ARG_ON_OFF, &global_gentlehup,
321 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
322 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
323 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
324 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
325 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
326 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
327 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
328 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
329 { "include", "file", 2, 2, 0, ARG_MAGIC,
330 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
331 "SUP labeledURI )", NULL, NULL },
332 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
333 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
334 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
335 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
336 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
337 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
338 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
339 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
340 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
341 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
342 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
343 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
344 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
345 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
346 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
347 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
348 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
349 "EQUALITY caseIgnoreMatch "
350 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
351 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
352 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
353 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
354 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
355 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
356 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
357 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
358 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
359 "EQUALITY caseIgnoreMatch "
360 "SYNTAX OMsDirectoryString )", NULL, NULL },
361 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
362 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
363 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
364 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
365 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
366 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
367 { "moduleload", "file", 2, 0, 0,
369 ARG_MAGIC|CFG_MODLOAD, &config_generic,
373 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
374 "EQUALITY caseIgnoreMatch "
375 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
376 { "modulepath", "path", 2, 2, 0,
378 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
382 "( OLcfgGlAt:31 NAME 'olcModulePath' "
383 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
384 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT,
385 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
386 "DESC 'OpenLDAP object classes' "
387 "EQUALITY caseIgnoreMatch "
388 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
390 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
391 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
392 "EQUALITY caseIgnoreMatch "
393 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
394 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
395 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
396 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
397 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
398 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
399 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
400 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
401 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
402 "EQUALITY caseIgnoreMatch "
403 "SYNTAX OMsDirectoryString )", NULL, NULL },
404 { "pidfile", "file", 2, 2, 0, ARG_STRING,
405 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
406 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
407 { "plugin", NULL, 0, 0, 0,
409 ARG_MAGIC|CFG_PLUGIN, &config_generic,
413 "( OLcfgGlAt:38 NAME 'olcPlugin' "
414 "EQUALITY caseIgnoreMatch "
415 "SYNTAX OMsDirectoryString )", NULL, NULL },
416 { "pluginlog", "filename", 2, 2, 0,
418 ARG_STRING, &slapi_log_file,
422 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
423 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
424 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
425 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
426 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
427 { "referral", "url", 2, 2, 0, ARG_MAGIC,
428 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
429 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
430 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
431 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
432 "EQUALITY caseIgnoreMatch "
433 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
434 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLICA_ARGSFILE,
435 &config_generic, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
436 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
437 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLICA_PIDFILE,
438 &config_generic, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
439 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
440 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_INT|CFG_REPLICATIONINTERVAL,
441 &config_generic, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
442 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
443 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
444 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
445 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
446 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
447 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
448 "EQUALITY caseIgnoreMatch "
449 "SYNTAX OMsDirectoryString )", NULL, NULL },
450 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
451 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
452 "EQUALITY caseIgnoreMatch "
453 "SYNTAX OMsDirectoryString )", NULL, NULL },
454 { "reverse-lookup", "on|off", 2, 2, 0,
455 #ifdef SLAPD_RLOOKUPS
456 ARG_ON_OFF, &use_reverse_lookup,
460 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
461 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
462 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
463 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
464 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
465 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
466 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
467 "EQUALITY caseIgnoreMatch "
468 "SYNTAX OMsDirectoryString )", NULL, NULL },
469 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
470 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
471 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
472 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
473 &config_generic, NULL, NULL, NULL },
474 { "sasl-host", "host", 2, 2, 0,
475 #ifdef HAVE_CYRUS_SASL
476 ARG_STRING|ARG_UNIQUE, &global_host,
480 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
481 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
482 { "sasl-realm", "realm", 2, 2, 0,
483 #ifdef HAVE_CYRUS_SASL
484 ARG_STRING|ARG_UNIQUE, &global_realm,
488 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
489 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
490 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
491 &config_generic, NULL, NULL, NULL },
492 { "sasl-secprops", "properties", 2, 2, 0,
493 #ifdef HAVE_CYRUS_SASL
494 ARG_MAGIC|CFG_SASLSECP, &config_generic,
498 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
499 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
500 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
501 &config_generic, NULL, NULL, NULL },
502 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
503 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
504 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
505 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
506 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
507 "EQUALITY caseIgnoreMatch "
508 "SYNTAX OMsDirectoryString )", NULL, NULL },
509 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
510 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
511 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
512 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
513 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
514 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
515 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
516 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
517 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
518 { "srvtab", "file", 2, 2, 0,
519 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
520 ARG_STRING, &ldap_srvtab,
524 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
525 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
526 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
527 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
528 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
529 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
530 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
531 "EQUALITY distinguishedNameMatch "
532 "SYNTAX OMsDN )", NULL, NULL },
533 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
534 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
535 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
536 { "threads", "count", 2, 2, 0,
540 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
542 "( OLcfgGlAt:66 NAME 'olcThreads' "
543 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
544 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
545 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
546 "SYNTAX OMsDirectoryString )", NULL, NULL },
547 { "TLSCACertificateFile", NULL, 0, 0, 0,
549 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
553 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
554 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
555 { "TLSCACertificatePath", NULL, 0, 0, 0,
557 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
561 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
562 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
563 { "TLSCertificateFile", NULL, 0, 0, 0,
565 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
569 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
570 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
571 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
573 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
577 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
578 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
579 { "TLSCipherSuite", NULL, 0, 0, 0,
581 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
585 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
586 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
587 { "TLSCRLCheck", NULL, 0, 0, 0,
588 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
589 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
593 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
594 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
595 { "TLSRandFile", NULL, 0, 0, 0,
597 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
601 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
602 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
603 { "TLSVerifyClient", NULL, 0, 0, 0,
605 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
609 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
610 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
611 { "TLSDHParamFile", NULL, 0, 0, 0,
613 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
617 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
618 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
619 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
620 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
621 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
622 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
623 NULL, NULL, NULL, NULL },
624 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
625 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
626 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
627 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
628 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
629 "EQUALITY caseIgnoreMatch "
630 "SUP labeledURI )", NULL, NULL },
631 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
632 NULL, NULL, NULL, NULL }
635 /* Routines to check if a child can be added to this type */
636 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
637 cfAddBackend, cfAddModule, cfAddOverlay;
639 /* NOTE: be careful when defining array members
640 * that can be conditionally compiled */
641 #define CFOC_GLOBAL cf_ocs[1]
642 #define CFOC_SCHEMA cf_ocs[2]
643 #define CFOC_BACKEND cf_ocs[3]
644 #define CFOC_DATABASE cf_ocs[4]
645 #define CFOC_OVERLAY cf_ocs[5]
646 #define CFOC_INCLUDE cf_ocs[6]
647 #define CFOC_FRONTEND cf_ocs[7]
649 #define CFOC_MODULE cf_ocs[8]
650 #endif /* SLAPD_MODULES */
652 static ConfigOCs cf_ocs[] = {
655 "DESC 'OpenLDAP configuration object' "
656 "ABSTRACT SUP top )", Cft_Abstract, NULL },
659 "DESC 'OpenLDAP Global configuration options' "
660 "SUP olcConfig STRUCTURAL "
661 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
662 "olcAttributeOptions $ olcAuthIDRewrite $ "
663 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
664 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
665 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
666 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
667 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
669 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
670 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
671 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
673 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
674 "olcSecurity $ olcSizeLimit $ "
675 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
676 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
677 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
678 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
679 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
681 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
682 "olcDitContentRules ) )", Cft_Global },
684 "NAME 'olcSchemaConfig' "
685 "DESC 'OpenLDAP schema object' "
686 "SUP olcConfig STRUCTURAL "
687 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
688 "olcObjectClasses $ olcDitContentRules ) )",
689 Cft_Schema, NULL, cfAddSchema },
691 "NAME 'olcBackendConfig' "
692 "DESC 'OpenLDAP Backend-specific options' "
693 "SUP olcConfig STRUCTURAL "
694 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
696 "NAME 'olcDatabaseConfig' "
697 "DESC 'OpenLDAP Database-specific options' "
698 "SUP olcConfig STRUCTURAL "
700 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
701 "olcLastMod $ olcLimits $ "
702 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
703 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
704 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
705 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
706 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode ) )",
707 Cft_Database, NULL, cfAddDatabase },
709 "NAME 'olcOverlayConfig' "
710 "DESC 'OpenLDAP Overlay-specific options' "
711 "SUP olcConfig STRUCTURAL "
712 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
714 "NAME 'olcIncludeFile' "
715 "DESC 'OpenLDAP configuration include file' "
716 "SUP olcConfig STRUCTURAL "
718 "MAY ( cn $ olcRootDSE ) )",
719 Cft_Include, NULL, cfAddInclude },
720 /* This should be STRUCTURAL like all the other database classes, but
721 * that would mean inheriting all of the olcDatabaseConfig attributes,
722 * which causes them to be merged twice in config_build_entry.
725 "NAME 'olcFrontendConfig' "
726 "DESC 'OpenLDAP frontend configuration' "
728 "MAY olcDefaultSearchBase )",
729 Cft_Database, NULL, NULL },
732 "NAME 'olcModuleList' "
733 "DESC 'OpenLDAP dynamic module info' "
734 "SUP olcConfig STRUCTURAL "
735 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
736 Cft_Module, NULL, cfAddModule },
742 config_generic(ConfigArgs *c) {
746 if ( c->op == SLAP_CONFIG_EMIT ) {
750 c->value_int = ldap_pvt_thread_get_concurrency();
753 c->value_int = connection_pool_max;
756 c->value_int = slap_tool_thread_max;
760 c->value_string = ch_strdup( passwd_salt );
765 if ( c->be->be_limits ) {
770 for ( i=0; c->be->be_limits[i]; i++ ) {
771 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
772 if ( bv.bv_len >= sizeof( buf ) ) {
773 ber_bvarray_free_x( c->rvalue_vals, NULL );
774 c->rvalue_vals = NULL;
778 bv.bv_val = buf + bv.bv_len;
779 limits_unparse( c->be->be_limits[i], &bv,
780 sizeof( buf ) - ( bv.bv_val - buf ) );
781 bv.bv_len += bv.bv_val - buf;
783 value_add_one( &c->rvalue_vals, &bv );
786 if ( !c->rvalue_vals ) rc = 1;
789 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
790 SLAP_RESTRICT_OP_WRITES;
793 c->value_string = ch_strdup( slap_sasl_getpolicy());
796 slap_sasl_regexp_unparse( &c->rvalue_vals );
797 if ( !c->rvalue_vals ) rc = 1;
799 #ifdef HAVE_CYRUS_SASL
801 struct berval bv = BER_BVNULL;
802 slap_sasl_secprops_unparse( &bv );
803 if ( !BER_BVISNULL( &bv )) {
804 ber_bvarray_add( &c->rvalue_vals, &bv );
812 c->value_int = c->be->be_max_deref_depth;
815 if ( SLAP_DBHIDDEN( c->be )) {
822 ConfigFile *cf = c->private;
824 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
825 else if ( cf->c_om_head )
826 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
828 if ( !c->rvalue_vals )
833 ad_unparse_options( &c->rvalue_vals );
836 ConfigFile *cf = c->private;
838 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
839 else if ( cf->c_oc_head )
840 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
842 if ( !c->rvalue_vals )
847 ConfigFile *cf = c->private;
849 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
850 else if ( cf->c_at_head )
851 at_unparse( &c->rvalue_vals, cf->c_at_head,
853 if ( !c->rvalue_vals )
858 ConfigFile *cf = c->private;
860 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
861 else if ( cf->c_cr_head )
862 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
864 if ( !c->rvalue_vals )
871 char *src, *dst, ibuf[11];
872 struct berval bv, abv;
873 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
874 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
875 if ( abv.bv_len >= sizeof( ibuf ) ) {
876 ber_bvarray_free_x( c->rvalue_vals, NULL );
877 c->rvalue_vals = NULL;
881 acl_unparse( a, &bv );
882 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
883 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
884 /* Turn TAB / EOL into plain space */
885 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
886 if (isspace((unsigned char)*src)) *dst++ = ' ';
890 if (dst[-1] == ' ') {
894 abv.bv_len = dst - abv.bv_val;
895 ber_bvarray_add( &c->rvalue_vals, &abv );
900 case CFG_REPLICA_ARGSFILE:
901 if ( c->be->be_replica_argsfile )
902 c->value_string = ch_strdup( c->be->be_replica_argsfile );
904 case CFG_REPLICA_PIDFILE:
905 if ( c->be->be_replica_pidfile )
906 c->value_string = ch_strdup( c->be->be_replica_pidfile );
908 case CFG_REPLICATIONINTERVAL:
909 if ( c->be->be_replicationinterval > 0 ) {
910 c->value_int = c->be->be_replicationinterval;
916 if ( c->be->be_replogfile )
917 c->value_string = ch_strdup( c->be->be_replogfile );
920 ConfigFile *cf = c->private;
921 if ( cf->c_dseFiles ) {
922 value_add( &c->rvalue_vals, cf->c_dseFiles );
930 c->value_string = ch_strdup( logfileName );
935 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
938 if ( SLAP_SHADOW(c->be))
939 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
943 case CFG_SSTR_IF_MAX:
944 c->value_int = index_substr_if_maxlen;
946 case CFG_SSTR_IF_MIN:
947 c->value_int = index_substr_if_minlen;
951 ModPaths *mp = c->private;
954 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
957 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
958 SLAP_X_ORDERED_FMT "%s", i,
959 mp->mp_loads[i].bv_val );
960 if ( bv.bv_len >= sizeof( c->log ) ) {
961 ber_bvarray_free_x( c->rvalue_vals, NULL );
962 c->rvalue_vals = NULL;
965 value_add_one( &c->rvalue_vals, &bv );
969 rc = c->rvalue_vals ? 0 : 1;
973 ModPaths *mp = c->private;
974 if ( !BER_BVISNULL( &mp->mp_path ))
975 value_add_one( &c->rvalue_vals, &mp->mp_path );
977 rc = c->rvalue_vals ? 0 : 1;
983 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
984 if ( !c->rvalue_vals ) rc = 1;
987 #ifdef SLAP_AUTH_REWRITE
989 if ( authz_rewrites ) {
990 struct berval bv, idx;
995 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
996 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
997 if ( idx.bv_len >= sizeof( ibuf ) ) {
998 ber_bvarray_free_x( c->rvalue_vals, NULL );
999 c->rvalue_vals = NULL;
1002 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1003 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1004 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1005 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1006 authz_rewrites[i].bv_val,
1007 authz_rewrites[i].bv_len + 1 );
1008 ber_bvarray_add( &c->rvalue_vals, &bv );
1011 if ( !c->rvalue_vals ) rc = 1;
1018 } else if ( c->op == LDAP_MOD_DELETE ) {
1021 /* single-valued attrs, no-ops */
1029 case CFG_MIRRORMODE:
1031 case CFG_SSTR_IF_MAX:
1032 case CFG_SSTR_IF_MIN:
1035 /* no-ops, requires slapd restart */
1040 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1044 ch_free( passwd_salt );
1048 case CFG_REPLICA_ARGSFILE:
1049 ch_free( c->be->be_replica_argsfile );
1050 c->be->be_replica_argsfile = NULL;
1053 case CFG_REPLICA_PIDFILE:
1054 ch_free( c->be->be_replica_pidfile );
1055 c->be->be_replica_pidfile = NULL;
1058 case CFG_REPLICATIONINTERVAL:
1059 c->be->be_replicationinterval = 0;
1063 ch_free( c->be->be_replogfile );
1064 c->be->be_replogfile = NULL;
1068 ch_free( logfileName );
1073 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1077 if ( c->valx < 0 ) {
1079 if ( c->be == frontendDB )
1082 end = frontendDB->be_acl;
1083 acl_destroy( c->be->be_acl, end );
1084 c->be->be_acl = end;
1087 AccessControl **prev, *a;
1089 for (i=0, prev = &c->be->be_acl; i < c->valx;
1092 prev = &a->acl_next;
1095 *prev = a->acl_next;
1101 /* FIXME: there is no limits_free function */
1103 /* FIXME: there is no ad_option_free function */
1105 /* FIXME: there is no way to remove attributes added by
1119 p = strchr(c->line,'(' /*')'*/);
1123 if(!(c->bi = backend_info(c->argv[1]))) {
1124 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1125 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1126 c->log, c->msg, c->argv[1] );
1133 /* NOTE: config is always the first backend!
1135 if ( !strcasecmp( c->argv[1], "config" )) {
1136 c->be = LDAP_STAILQ_FIRST(&backendDB);
1137 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1140 c->be = backend_db_init(c->argv[1], NULL);
1142 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1143 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1144 c->log, c->msg, c->argv[1] );
1151 ldap_pvt_thread_set_concurrency(c->value_int);
1155 if ( c->value_int < 2 ) {
1156 snprintf( c->msg, sizeof( c->msg ),
1157 "threads=%d smaller than minimum value 2",
1159 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1160 c->log, c->msg, 0 );
1163 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1164 snprintf( c->msg, sizeof( c->msg ),
1165 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1166 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1167 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1168 c->log, c->msg, 0 );
1170 if ( slapMode & SLAP_SERVER_MODE )
1171 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1172 connection_pool_max = c->value_int; /* save for reference */
1176 if ( slapMode & SLAP_TOOL_MODE )
1177 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1178 slap_tool_thread_max = c->value_int; /* save for reference */
1182 if ( passwd_salt ) ch_free( passwd_salt );
1183 passwd_salt = c->value_string;
1184 lutil_salt_format(passwd_salt);
1188 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1194 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1196 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1200 ch_free(c->value_string);
1201 if (slap_sasl_setpolicy( c->argv[1] )) {
1202 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1203 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1204 c->log, c->msg, c->argv[1] );
1210 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1214 #ifdef HAVE_CYRUS_SASL
1217 char *txt = slap_sasl_secprops( c->argv[1] );
1219 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1221 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1229 c->be->be_max_deref_depth = c->value_int;
1235 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1237 if (!cfn->c_om_head) cfn->c_om_head = om;
1238 cfn->c_om_tail = om;
1245 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1246 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1247 cfn->c_oc_tail = oc;
1254 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1255 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1256 cfn->c_cr_tail = cr;
1263 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1264 if (!cfn->c_at_head) cfn->c_at_head = at;
1265 cfn->c_at_tail = at;
1270 ad_define_option(NULL, NULL, 0);
1271 for(i = 1; i < c->argc; i++)
1272 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1277 /* Don't append to the global ACL if we're on a specific DB */
1279 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1282 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1286 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1291 case CFG_REPLICA_ARGSFILE:
1292 if(SLAP_MONITOR(c->be)) {
1293 Debug(LDAP_DEBUG_ANY, "%s: "
1294 "\"replica-argsfile\" should not be used "
1295 "inside monitor database\n",
1297 /* FIXME: should this be an error? */
1301 if ( c->be->be_replica_argsfile != NULL ) {
1303 Debug(LDAP_DEBUG_ANY, "%s: "
1304 "\"replica-argsfile\" already provided; "
1305 "replacing \"%s\" with \"%s\".\n",
1306 c->log, c->be->be_replica_argsfile, c->value_string );
1307 ch_free( c->be->be_replica_argsfile );
1310 c->be->be_replica_argsfile = c->value_string;
1313 case CFG_REPLICA_PIDFILE:
1314 if(SLAP_MONITOR(c->be)) {
1315 Debug(LDAP_DEBUG_ANY, "%s: "
1316 "\"replica-pidfile\" should not be used "
1317 "inside monitor database\n",
1319 /* FIXME: should this be an error? */
1323 if ( c->be->be_replica_pidfile != NULL ) {
1325 Debug(LDAP_DEBUG_ANY, "%s: "
1326 "\"replica-pidfile\" already provided; "
1327 "replacing \"%s\" with \"%s\".\n",
1328 c->log, c->be->be_replica_pidfile, c->value_string );
1329 ch_free( c->be->be_replica_pidfile );
1332 c->be->be_replica_pidfile = c->value_string;
1335 case CFG_REPLICATIONINTERVAL:
1336 if(SLAP_MONITOR(c->be)) {
1337 Debug(LDAP_DEBUG_ANY, "%s: "
1338 "\"replicationinterval\" should not be used "
1339 "inside monitor database\n",
1341 /* FIXME: should this be an error? */
1345 c->be->be_replicationinterval = c->value_int;
1349 if(SLAP_MONITOR(c->be)) {
1350 Debug(LDAP_DEBUG_ANY, "%s: "
1351 "\"replogfile\" should not be used "
1352 "inside monitor database\n",
1354 /* FIXME: should this be an error? */
1358 if ( c->be->be_replogfile != NULL ) {
1360 Debug(LDAP_DEBUG_ANY, "%s: "
1361 "\"replogfile\" already provided; "
1362 "replacing \"%s\" with \"%s\".\n",
1363 c->log, c->be->be_replogfile, c->value_string );
1364 ch_free( c->be->be_replogfile );
1367 c->be->be_replogfile = c->value_string;
1371 if(read_root_dse_file(c->argv[1])) {
1372 snprintf( c->msg, sizeof( c->msg ), "<%s> could not read file", c->argv[0] );
1373 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1374 c->log, c->msg, c->argv[1] );
1379 ber_str2bv( c->argv[1], 0, 1, &bv );
1380 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1386 if ( logfileName ) ch_free( logfileName );
1387 logfileName = c->value_string;
1388 logfile = fopen(logfileName, "w");
1389 if(logfile) lutil_debug_file(logfile);
1393 if(SLAP_NOLASTMODCMD(c->be)) {
1394 snprintf( c->msg, sizeof( c->msg ), "<%s> not available for %s database",
1395 c->argv[0], c->be->bd_info->bi_type );
1396 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1397 c->log, c->msg, 0 );
1401 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1403 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1406 case CFG_MIRRORMODE:
1407 if(!SLAP_SHADOW(c->be)) {
1408 snprintf( c->msg, sizeof( c->msg ), "<%s> database is not a shadow",
1410 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1411 c->log, c->msg, 0 );
1415 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1417 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1422 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1424 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1427 case CFG_SSTR_IF_MAX:
1428 if (c->value_int < index_substr_if_minlen) {
1429 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1430 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1431 c->log, c->msg, c->value_int );
1434 index_substr_if_maxlen = c->value_int;
1437 case CFG_SSTR_IF_MIN:
1438 if (c->value_int > index_substr_if_maxlen) {
1439 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1440 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1441 c->log, c->msg, c->value_int );
1444 index_substr_if_minlen = c->value_int;
1447 #ifdef SLAPD_MODULES
1449 /* If we're just adding a module on an existing modpath,
1450 * make sure we've selected the current path.
1452 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1453 modcur = c->private;
1454 /* This should never fail */
1455 if ( module_path( modcur->mp_path.bv_val )) {
1456 snprintf( c->msg, sizeof( c->msg ), "<%s> module path no longer valid",
1458 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1459 c->log, c->msg, modcur->mp_path.bv_val );
1463 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1465 /* Record this load on the current path */
1469 if ( c->op == SLAP_CONFIG_ADD ) {
1470 ptr = c->line + STRLENOF("moduleload");
1471 while (!isspace((unsigned char) *ptr)) ptr++;
1472 while (isspace((unsigned char) *ptr)) ptr++;
1476 ber_str2bv(ptr, 0, 1, &bv);
1477 ber_bvarray_add( &modcur->mp_loads, &bv );
1482 if(module_path(c->argv[1])) return(1);
1483 /* Record which path was used with each module */
1487 if (!modpaths.mp_loads) {
1490 mp = ch_malloc( sizeof( ModPaths ));
1491 modlast->mp_next = mp;
1493 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1495 mp->mp_loads = NULL;
1506 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1508 slapi_plugins_used++;
1512 #ifdef SLAP_AUTH_REWRITE
1517 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1520 if ( c->argc > 1 ) {
1523 /* quote all args but the first */
1524 line = ldap_charray2str( c->argv, "\" \"" );
1525 ber_str2bv( line, 0, 0, &bv );
1526 s = ber_bvchr( &bv, '"' );
1527 assert( s != NULL );
1528 /* move the trailing quote of argv[0] to the end */
1529 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1530 bv.bv_val[ bv.bv_len - 1 ] = '"';
1533 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1536 ber_bvarray_add( &authz_rewrites, &bv );
1543 Debug( LDAP_DEBUG_ANY,
1544 "%s: unknown CFG_TYPE %d.\n",
1545 c->log, c->type, 0 );
1554 config_fname(ConfigArgs *c) {
1555 if(c->op == SLAP_CONFIG_EMIT) {
1557 ConfigFile *cf = c->private;
1558 value_add_one( &c->rvalue_vals, &cf->c_file );
1567 config_cfdir(ConfigArgs *c) {
1568 if(c->op == SLAP_CONFIG_EMIT) {
1569 if ( !BER_BVISEMPTY( &cfdir )) {
1570 value_add_one( &c->rvalue_vals, &cfdir );
1579 config_search_base(ConfigArgs *c) {
1580 if(c->op == SLAP_CONFIG_EMIT) {
1582 if (!BER_BVISEMPTY(&default_search_base)) {
1583 value_add_one(&c->rvalue_vals, &default_search_base);
1584 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1588 } else if( c->op == LDAP_MOD_DELETE ) {
1589 ch_free( default_search_base.bv_val );
1590 ch_free( default_search_nbase.bv_val );
1591 BER_BVZERO( &default_search_base );
1592 BER_BVZERO( &default_search_nbase );
1596 if(c->bi || c->be != frontendDB) {
1597 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1598 "prior to any backend or database definition\n",
1603 if(default_search_nbase.bv_len) {
1604 free(default_search_base.bv_val);
1605 free(default_search_nbase.bv_val);
1608 default_search_base = c->value_dn;
1609 default_search_nbase = c->value_ndn;
1614 config_passwd_hash(ConfigArgs *c) {
1616 if (c->op == SLAP_CONFIG_EMIT) {
1618 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1619 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1620 value_add_one(&c->rvalue_vals, &bv);
1623 } else if ( c->op == LDAP_MOD_DELETE ) {
1624 if ( c->valx < 0 ) {
1625 ldap_charray_free( default_passwd_hash );
1626 default_passwd_hash = NULL;
1629 ch_free( default_passwd_hash[i] );
1630 for (; default_passwd_hash[i]; i++ )
1631 default_passwd_hash[i] = default_passwd_hash[i+1];
1635 if(default_passwd_hash) {
1636 Debug(LDAP_DEBUG_ANY, "%s: "
1637 "already set default password_hash\n",
1641 for(i = 1; i < c->argc; i++) {
1642 if(!lutil_passwd_scheme(c->argv[i])) {
1643 snprintf( c->msg, sizeof( c->msg ), "<%s> scheme not available", c->argv[0] );
1644 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1645 c->log, c->msg, c->argv[i]);
1647 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1649 if(!default_passwd_hash) {
1650 snprintf( c->msg, sizeof( c->msg ), "<%s> no valid hashes found", c->argv[0] );
1651 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1652 c->log, c->msg, 0 );
1660 config_schema_dn(ConfigArgs *c) {
1661 if ( c->op == SLAP_CONFIG_EMIT ) {
1663 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1664 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1665 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1669 } else if ( c->op == LDAP_MOD_DELETE ) {
1670 ch_free( c->be->be_schemadn.bv_val );
1671 ch_free( c->be->be_schemandn.bv_val );
1672 BER_BVZERO( &c->be->be_schemadn );
1673 BER_BVZERO( &c->be->be_schemandn );
1676 ch_free( c->be->be_schemadn.bv_val );
1677 ch_free( c->be->be_schemandn.bv_val );
1678 c->be->be_schemadn = c->value_dn;
1679 c->be->be_schemandn = c->value_ndn;
1684 config_sizelimit(ConfigArgs *c) {
1686 struct slap_limits_set *lim = &c->be->be_def_limit;
1687 if (c->op == SLAP_CONFIG_EMIT) {
1692 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
1693 if ( !BER_BVISEMPTY( &bv ))
1694 value_add_one( &c->rvalue_vals, &bv );
1698 } else if ( c->op == LDAP_MOD_DELETE ) {
1699 /* Reset to defaults */
1700 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1701 lim->lms_s_hard = 0;
1702 lim->lms_s_unchecked = -1;
1704 lim->lms_s_pr_hide = 0;
1705 lim->lms_s_pr_total = 0;
1708 for(i = 1; i < c->argc; i++) {
1709 if(!strncasecmp(c->argv[i], "size", 4)) {
1710 rc = limits_parse_one(c->argv[i], lim);
1712 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1713 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1714 c->log, c->msg, c->argv[i]);
1718 if(!strcasecmp(c->argv[i], "unlimited")) {
1719 lim->lms_s_soft = -1;
1721 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
1722 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
1723 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1724 c->log, c->msg, c->argv[i]);
1728 lim->lms_s_hard = 0;
1735 config_timelimit(ConfigArgs *c) {
1737 struct slap_limits_set *lim = &c->be->be_def_limit;
1738 if (c->op == SLAP_CONFIG_EMIT) {
1743 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
1744 if ( !BER_BVISEMPTY( &bv ))
1745 value_add_one( &c->rvalue_vals, &bv );
1749 } else if ( c->op == LDAP_MOD_DELETE ) {
1750 /* Reset to defaults */
1751 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1752 lim->lms_t_hard = 0;
1755 for(i = 1; i < c->argc; i++) {
1756 if(!strncasecmp(c->argv[i], "time", 4)) {
1757 rc = limits_parse_one(c->argv[i], lim);
1759 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1760 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1761 c->log, c->msg, c->argv[i]);
1765 if(!strcasecmp(c->argv[i], "unlimited")) {
1766 lim->lms_t_soft = -1;
1768 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
1769 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
1770 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1771 c->log, c->msg, c->argv[i]);
1775 lim->lms_t_hard = 0;
1782 config_overlay(ConfigArgs *c) {
1784 if (c->op == SLAP_CONFIG_EMIT) {
1786 } else if ( c->op == LDAP_MOD_DELETE ) {
1789 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1791 Debug( LDAP_DEBUG_ANY,
1792 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
1793 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
1795 } else if(overlay_config(c->be, c->argv[1])) {
1798 /* Setup context for subsequent config directives.
1799 * The newly added overlay is at the head of the list.
1801 oi = (slap_overinfo *)c->be->bd_info;
1802 c->bi = &oi->oi_list->on_bi;
1807 config_subordinate(ConfigArgs *c)
1813 case SLAP_CONFIG_EMIT:
1814 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
1817 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
1818 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
1821 value_add_one( &c->rvalue_vals, &bv );
1825 case LDAP_MOD_DELETE:
1826 if ( !c->line || strcasecmp( c->line, "advertise" )) {
1827 glue_sub_del( c->be );
1829 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
1834 case SLAP_CONFIG_ADD:
1835 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
1836 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
1843 config_suffix(ConfigArgs *c)
1846 struct berval pdn, ndn;
1847 char *notallowed = NULL;
1849 if ( c->be == frontendDB ) {
1850 notallowed = "frontend";
1852 } else if ( SLAP_MONITOR(c->be) ) {
1853 notallowed = "monitor";
1855 } else if ( SLAP_CONFIG(c->be) ) {
1856 notallowed = "config";
1859 if ( notallowed != NULL ) {
1860 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
1864 case LDAP_MOD_DELETE:
1865 case LDAP_MOD_REPLACE:
1866 case LDAP_MOD_INCREMENT:
1867 case SLAP_CONFIG_ADD:
1868 if ( !BER_BVISNULL( &c->value_dn ) ) {
1869 snprintf( buf, sizeof( buf ), "<%s> ",
1870 c->value_dn.bv_val );
1873 Debug(LDAP_DEBUG_ANY,
1874 "%s: suffix %snot allowed in %s database.\n",
1875 c->log, buf, notallowed );
1878 case SLAP_CONFIG_EMIT:
1879 /* don't complain when emitting... */
1883 /* FIXME: don't know what values may be valid;
1884 * please remove assertion, or add legal values
1885 * to either block */
1893 if (c->op == SLAP_CONFIG_EMIT) {
1894 if ( c->be->be_suffix == NULL
1895 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1899 value_add( &c->rvalue_vals, c->be->be_suffix );
1900 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1903 } else if ( c->op == LDAP_MOD_DELETE ) {
1904 if ( c->valx < 0 ) {
1905 ber_bvarray_free( c->be->be_suffix );
1906 ber_bvarray_free( c->be->be_nsuffix );
1907 c->be->be_suffix = NULL;
1908 c->be->be_nsuffix = NULL;
1911 ch_free( c->be->be_suffix[i].bv_val );
1912 ch_free( c->be->be_nsuffix[i].bv_val );
1914 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1915 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1917 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
1922 #ifdef SLAPD_MONITOR_DN
1923 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1924 snprintf( c->msg, sizeof( c->msg ), "<%s> DN is reserved for monitoring slapd",
1926 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1927 c->log, c->msg, SLAPD_MONITOR_DN);
1934 if (SLAP_DBHIDDEN( c->be ))
1937 tbe = select_backend(&ndn, 0, 0);
1939 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
1945 char *type = tbe->bd_info->bi_type;
1947 if ( overlay_is_over( tbe ) ) {
1948 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
1949 type = oi->oi_orig->bi_type;
1952 snprintf( c->msg, sizeof( c->msg ), "<%s> namingContext \"%s\" already served by "
1953 "a preceding %s database serving namingContext",
1954 c->argv[0], pdn.bv_val, type );
1955 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1956 c->log, c->msg, tbe->be_suffix[0].bv_val);
1960 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1961 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1962 "base provided \"%s\" (assuming okay)\n",
1963 c->log, default_search_base.bv_val, 0);
1965 ber_bvarray_add(&c->be->be_suffix, &pdn);
1966 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1971 config_rootdn(ConfigArgs *c) {
1972 if (c->op == SLAP_CONFIG_EMIT) {
1973 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1974 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1975 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1980 } else if ( c->op == LDAP_MOD_DELETE ) {
1981 ch_free( c->be->be_rootdn.bv_val );
1982 ch_free( c->be->be_rootndn.bv_val );
1983 BER_BVZERO( &c->be->be_rootdn );
1984 BER_BVZERO( &c->be->be_rootndn );
1987 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1988 ch_free( c->be->be_rootdn.bv_val );
1989 ch_free( c->be->be_rootndn.bv_val );
1991 c->be->be_rootdn = c->value_dn;
1992 c->be->be_rootndn = c->value_ndn;
1997 config_rootpw(ConfigArgs *c) {
2000 if (c->op == SLAP_CONFIG_EMIT) {
2001 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2002 /* don't copy, because "rootpw" is marked
2004 c->value_bv = c->be->be_rootpw;
2008 } else if ( c->op == LDAP_MOD_DELETE ) {
2009 ch_free( c->be->be_rootpw.bv_val );
2010 BER_BVZERO( &c->be->be_rootpw );
2014 tbe = select_backend(&c->be->be_rootndn, 0, 0);
2016 snprintf( c->msg, sizeof( c->msg ), "<%s> can only be set when rootdn is under suffix",
2018 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2022 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2023 ch_free( c->be->be_rootpw.bv_val );
2024 c->be->be_rootpw = c->value_bv;
2029 config_restrict(ConfigArgs *c) {
2030 slap_mask_t restrictops = 0;
2032 slap_verbmasks restrictable_ops[] = {
2033 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2034 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2035 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2036 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2037 { BER_BVC("modrdn"), 0 },
2038 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2039 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2040 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2041 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2042 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2043 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2044 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2045 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2046 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2047 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2048 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2052 if (c->op == SLAP_CONFIG_EMIT) {
2053 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2055 } else if ( c->op == LDAP_MOD_DELETE ) {
2057 c->be->be_restrictops = 0;
2059 restrictops = verb_to_mask( c->line, restrictable_ops );
2060 c->be->be_restrictops ^= restrictops;
2064 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2066 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown operation", c->argv[0] );
2067 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2068 c->log, c->msg, c->argv[i]);
2071 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2072 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2073 c->be->be_restrictops |= restrictops;
2078 config_allows(ConfigArgs *c) {
2079 slap_mask_t allows = 0;
2081 slap_verbmasks allowable_ops[] = {
2082 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2083 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2084 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2085 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2086 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2089 if (c->op == SLAP_CONFIG_EMIT) {
2090 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2091 } else if ( c->op == LDAP_MOD_DELETE ) {
2095 allows = verb_to_mask( c->line, allowable_ops );
2096 global_allows ^= allows;
2100 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2102 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2103 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2104 c->log, c->msg, c->argv[i]);
2107 global_allows |= allows;
2112 config_disallows(ConfigArgs *c) {
2113 slap_mask_t disallows = 0;
2115 slap_verbmasks disallowable_ops[] = {
2116 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2117 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2118 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
2119 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2120 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2123 if (c->op == SLAP_CONFIG_EMIT) {
2124 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2125 } else if ( c->op == LDAP_MOD_DELETE ) {
2127 global_disallows = 0;
2129 disallows = verb_to_mask( c->line, disallowable_ops );
2130 global_disallows ^= disallows;
2134 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2136 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2137 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2138 c->log, c->msg, c->argv[i]);
2141 global_disallows |= disallows;
2146 config_requires(ConfigArgs *c) {
2147 slap_mask_t requires = 0;
2149 slap_verbmasks requires_ops[] = {
2150 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2151 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2152 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2153 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2154 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2157 if (c->op == SLAP_CONFIG_EMIT) {
2158 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2159 } else if ( c->op == LDAP_MOD_DELETE ) {
2161 c->be->be_requires = 0;
2163 requires = verb_to_mask( c->line, requires_ops );
2164 c->be->be_requires ^= requires;
2168 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
2170 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2171 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2172 c->log, c->msg, c->argv[i]);
2175 c->be->be_requires = requires;
2179 static slap_verbmasks *loglevel_ops;
2182 loglevel_init( void )
2184 slap_verbmasks lo[] = {
2185 { BER_BVC("Any"), -1 },
2186 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2187 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2188 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2189 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2190 { BER_BVC("BER"), LDAP_DEBUG_BER },
2191 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2192 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2193 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2194 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2195 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2196 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2197 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2198 #if 0 /* no longer used (nor supported) */
2199 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2200 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2202 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2203 { BER_BVC("None"), LDAP_DEBUG_NONE },
2207 return slap_verbmasks_init( &loglevel_ops, lo );
2211 loglevel_destroy( void )
2213 if ( loglevel_ops ) {
2214 (void)slap_verbmasks_destroy( loglevel_ops );
2216 loglevel_ops = NULL;
2219 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2222 slap_loglevel_register( slap_mask_t m, struct berval *s )
2226 if ( loglevel_ops == NULL ) {
2230 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2233 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2241 slap_loglevel_get( struct berval *s, int *l )
2247 if ( loglevel_ops == NULL ) {
2251 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2252 m |= loglevel_ops[ i ].mask;
2257 for ( i = 1; i <= ( 1 << ( sizeof( int ) * 8 - 1 ) ) && !( m & i ); i <<= 1 )
2264 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2267 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2278 str2loglevel( const char *s, int *l )
2282 if ( loglevel_ops == NULL ) {
2286 i = verb_to_mask( s, loglevel_ops );
2288 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2292 *l = loglevel_ops[ i ].mask;
2298 loglevel2str( int l )
2300 struct berval bv = BER_BVNULL;
2302 loglevel2bv( l, &bv );
2308 loglevel2bv( int l, struct berval *bv )
2310 if ( loglevel_ops == NULL ) {
2316 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2320 loglevel2bvarray( int l, BerVarray *bva )
2322 if ( loglevel_ops == NULL ) {
2326 return mask_to_verbs( loglevel_ops, l, bva );
2329 static int config_syslog;
2332 config_loglevel(ConfigArgs *c) {
2335 if ( loglevel_ops == NULL ) {
2339 if (c->op == SLAP_CONFIG_EMIT) {
2340 /* Get default or commandline slapd setting */
2341 if ( ldap_syslog && !config_syslog )
2342 config_syslog = ldap_syslog;
2343 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2345 } else if ( c->op == LDAP_MOD_DELETE ) {
2349 int level = verb_to_mask( c->line, loglevel_ops );
2350 config_syslog ^= level;
2352 if ( slapMode & SLAP_SERVER_MODE ) {
2353 ldap_syslog = config_syslog;
2360 for( i=1; i < c->argc; i++ ) {
2363 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2364 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2365 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse level", c->argv[0] );
2366 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2367 c->log, c->msg, c->argv[i]);
2371 if ( str2loglevel( c->argv[i], &level ) ) {
2372 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown level", c->argv[0] );
2373 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2374 c->log, c->msg, c->argv[i]);
2378 config_syslog |= level;
2380 if ( slapMode & SLAP_SERVER_MODE ) {
2381 ldap_syslog = config_syslog;
2387 config_referral(ConfigArgs *c) {
2389 if (c->op == SLAP_CONFIG_EMIT) {
2390 if ( default_referral ) {
2391 value_add( &c->rvalue_vals, default_referral );
2396 } else if ( c->op == LDAP_MOD_DELETE ) {
2397 if ( c->valx < 0 ) {
2398 ber_bvarray_free( default_referral );
2399 default_referral = NULL;
2402 ch_free( default_referral[i].bv_val );
2403 for (; default_referral[i].bv_val; i++ )
2404 default_referral[i] = default_referral[i+1];
2408 if(validate_global_referral(c->argv[1])) {
2409 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
2410 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2411 c->log, c->msg, c->argv[1]);
2415 ber_str2bv(c->argv[1], 0, 0, &val);
2416 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2424 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2425 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2426 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2427 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2428 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2429 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2430 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2431 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2432 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2437 config_security(ConfigArgs *c) {
2438 slap_ssf_set_t *set = &c->be->be_ssf_set;
2441 if (c->op == SLAP_CONFIG_EMIT) {
2447 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2448 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2451 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2452 if ( bv.bv_len >= sizeof( numbuf ) ) {
2453 ber_bvarray_free_x( c->rvalue_vals, NULL );
2454 c->rvalue_vals = NULL;
2458 bv.bv_len += sec_keys[i].key.bv_len;
2459 bv.bv_val = ch_malloc( bv.bv_len + 1);
2460 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2461 strcpy( next, numbuf );
2462 ber_bvarray_add( &c->rvalue_vals, &bv );
2467 for(i = 1; i < c->argc; i++) {
2468 slap_ssf_t *tgt = NULL;
2470 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2471 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2472 sec_keys[j].key.bv_len)) {
2473 src = c->argv[i] + sec_keys[j].key.bv_len;
2474 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2479 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown factor", c->argv[0] );
2480 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2481 c->log, c->msg, c->argv[i]);
2485 if ( lutil_atou( tgt, src ) != 0 ) {
2486 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse factor", c->argv[0] );
2487 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2488 c->log, c->msg, c->argv[i]);
2496 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2500 for (; !BER_BVISNULL( &an->an_name ); an++) {
2501 /* if buflen == 0, assume the buffer size has been
2502 * already checked otherwise */
2503 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2504 if ( comma ) *ptr++ = ',';
2505 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2512 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2516 struct berval bc = BER_BVNULL;
2519 assert( !BER_BVISNULL( &ri->ri_bindconf.sb_uri ) );
2523 len = snprintf(numbuf, sizeof( numbuf ), SLAP_X_ORDERED_FMT, i );
2524 if ( len >= sizeof( numbuf ) ) {
2525 /* FIXME: how can indicate error? */
2529 if ( ri->ri_nsuffix ) {
2530 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2531 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2534 if ( ri->ri_attrs ) {
2535 len += STRLENOF(" attrs");
2536 if ( ri->ri_exclude ) len++;
2537 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2538 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2541 bindconf_unparse( &ri->ri_bindconf, &bc );
2544 bv->bv_val = ch_malloc(len + 1);
2547 ptr = lutil_strcopy( bv->bv_val, numbuf );
2549 /* start with URI from bindconf */
2550 assert( !BER_BVISNULL( &bc ) );
2552 strcpy( ptr, bc.bv_val );
2553 ch_free( bc.bv_val );
2556 if ( ri->ri_nsuffix ) {
2557 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2558 ptr = lutil_strcopy( ptr, " suffix=\"" );
2559 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2563 if ( ri->ri_attrs ) {
2564 ptr = lutil_strcopy( ptr, " attrs" );
2565 if ( ri->ri_exclude ) *ptr++ = '!';
2567 ptr = anlist_unparse( ri->ri_attrs, ptr, 0 );
2572 config_replica(ConfigArgs *c) {
2574 char *replicahost = NULL, *replicauri = NULL;
2577 if (c->op == SLAP_CONFIG_EMIT) {
2578 if (c->be->be_replica) {
2580 for (i=0;c->be->be_replica[i]; i++) {
2581 replica_unparse( c->be->be_replica[i], i, &bv );
2582 ber_bvarray_add( &c->rvalue_vals, &bv );
2587 } else if ( c->op == LDAP_MOD_DELETE ) {
2588 /* FIXME: there is no replica_free function */
2589 if ( c->valx < 0 ) {
2593 if(SLAP_MONITOR(c->be)) {
2594 Debug(LDAP_DEBUG_ANY, "%s: "
2595 "\"replica\" should not be used inside monitor database\n",
2597 return(0); /* FIXME: should this be an error? */
2600 for(i = 1; i < c->argc; i++) {
2601 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2605 snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] );
2606 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2610 replicahost = c->argv[i] + STRLENOF("host=");
2611 len = strlen( replicahost ) + STRLENOF("ldap://");
2612 replicauri = ch_malloc( len + 1 );
2613 snprintf( replicauri, len + 1, "ldap://%s", replicahost );
2614 replicahost = replicauri + STRLENOF( "ldap://");
2615 nr = add_replica_info(c->be, replicauri, replicahost);
2617 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2619 snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] );
2620 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2624 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2625 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid uri", c->argv[0] );
2626 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2629 if(!ludp->lud_host) {
2630 ldap_free_urldesc(ludp);
2631 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid uri - missing hostname",
2633 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2636 ldap_free_urldesc(ludp);
2637 replicauri = c->argv[i] + STRLENOF("uri=");
2638 replicauri = ch_strdup( replicauri );
2639 replicahost = strchr( replicauri, '/' );
2641 nr = add_replica_info(c->be, replicauri, replicahost);
2646 snprintf( c->msg, sizeof( c->msg ), "<%s> missing host or uri", c->argv[0] );
2647 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2649 } else if(nr == -1) {
2650 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to add replica", c->argv[0] );
2651 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg,
2652 replicauri ? replicauri : "" );
2655 for(i = 1; i < c->argc; i++) {
2656 if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2657 /* dealt with separately; don't let it get to bindconf */
2660 } else if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2661 /* dealt with separately; don't let it get to bindconf */
2664 } else if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2665 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2667 Debug( LDAP_DEBUG_ANY, "%s: "
2668 "suffix \"%s\" in \"replica\" line is not valid for backend.\n",
2669 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2673 Debug( LDAP_DEBUG_ANY, "%s: "
2674 "unable to normalize suffix in \"replica\" line.\n",
2680 } else if (!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))
2681 || !strncasecmp(c->argv[i], "attrs", STRLENOF("attrs")))
2684 char *arg = c->argv[i] + STRLENOF("attr");
2685 if (arg[0] == 's') {
2688 Debug( LDAP_DEBUG_ANY,
2690 "is deprecated (and undocumented); "
2691 "use \"attrs\" instead.\n",
2701 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2702 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown attribute", c->argv[0] );
2703 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2704 c->log, c->msg, arg + 1);
2707 } else if ( bindconf_parse( c->argv[i],
2708 &c->be->be_replica[nr]->ri_bindconf ) ) {
2717 config_updatedn(ConfigArgs *c) {
2718 if (c->op == SLAP_CONFIG_EMIT) {
2719 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2720 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2721 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2725 } else if ( c->op == LDAP_MOD_DELETE ) {
2726 ch_free( c->be->be_update_ndn.bv_val );
2727 BER_BVZERO( &c->be->be_update_ndn );
2728 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2731 if(SLAP_SHADOW(c->be)) {
2732 snprintf( c->msg, sizeof( c->msg ), "<%s> database already shadowed", c->argv[0] );
2733 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2738 ber_memfree_x( c->value_dn.bv_val, NULL );
2739 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2740 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2742 c->be->be_update_ndn = c->value_ndn;
2743 BER_BVZERO( &c->value_dn );
2744 BER_BVZERO( &c->value_ndn );
2746 return config_slurp_shadow( c );
2750 config_shadow( ConfigArgs *c, int flag )
2752 char *notallowed = NULL;
2754 if ( c->be == frontendDB ) {
2755 notallowed = "frontend";
2757 } else if ( SLAP_MONITOR(c->be) ) {
2758 notallowed = "monitor";
2760 } else if ( SLAP_CONFIG(c->be) ) {
2761 notallowed = "config";
2764 if ( notallowed != NULL ) {
2765 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2769 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2775 config_updateref(ConfigArgs *c) {
2777 if (c->op == SLAP_CONFIG_EMIT) {
2778 if ( c->be->be_update_refs ) {
2779 value_add( &c->rvalue_vals, c->be->be_update_refs );
2784 } else if ( c->op == LDAP_MOD_DELETE ) {
2785 if ( c->valx < 0 ) {
2786 ber_bvarray_free( c->be->be_update_refs );
2787 c->be->be_update_refs = NULL;
2790 ch_free( c->be->be_update_refs[i].bv_val );
2791 for (; c->be->be_update_refs[i].bv_val; i++)
2792 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2796 if(!SLAP_SHADOW(c->be)) {
2797 snprintf( c->msg, sizeof( c->msg ), "<%s> must appear after syncrepl or updatedn",
2799 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2804 if(validate_global_referral(c->argv[1])) {
2805 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
2806 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2807 c->log, c->msg, c->argv[1]);
2810 ber_str2bv(c->argv[1], 0, 0, &val);
2811 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2816 config_include(ConfigArgs *c) {
2817 int savelineno = c->lineno;
2820 ConfigFile *cfsave = cfn;
2821 ConfigFile *cf2 = NULL;
2822 if (c->op == SLAP_CONFIG_EMIT) {
2824 ConfigFile *cf = c->private;
2825 value_add_one( &c->rvalue_vals, &cf->c_file );
2829 } else if ( c->op == LDAP_MOD_DELETE ) {
2831 cf = ch_calloc( 1, sizeof(ConfigFile));
2832 if ( cfn->c_kids ) {
2833 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2839 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2840 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2841 c->lineno = savelineno - 1;
2844 if ( cf2 ) cf2->c_sibs = NULL;
2845 else cfn->c_kids = NULL;
2846 ch_free( cf->c_file.bv_val );
2856 config_tls_option(ConfigArgs *c) {
2858 LDAP *ld = slap_tls_ld;
2860 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
2861 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2862 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2863 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2864 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2865 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2866 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
2867 default: Debug(LDAP_DEBUG_ANY, "%s: "
2868 "unknown tls_option <0x%x>\n",
2869 c->log, c->type, 0);
2872 if (c->op == SLAP_CONFIG_EMIT) {
2873 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
2874 } else if ( c->op == LDAP_MOD_DELETE ) {
2875 return ldap_pvt_tls_set_option( ld, flag, NULL );
2877 ch_free(c->value_string);
2878 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
2881 /* FIXME: this ought to be provided by libldap */
2883 config_tls_config(ConfigArgs *c) {
2885 slap_verbmasks crlkeys[] = {
2886 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2887 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2888 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2891 slap_verbmasks vfykeys[] = {
2892 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2893 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2894 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2895 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2899 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2900 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2902 Debug(LDAP_DEBUG_ANY, "%s: "
2903 "unknown tls_option <0x%x>\n",
2904 c->log, c->type, 0);
2907 if (c->op == SLAP_CONFIG_EMIT) {
2908 ldap_pvt_tls_get_option( slap_tls_ld, flag, &c->value_int );
2909 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2910 if (keys[i].mask == c->value_int) {
2911 c->value_string = ch_strdup( keys[i].word.bv_val );
2916 } else if ( c->op == LDAP_MOD_DELETE ) {
2918 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
2920 ch_free( c->value_string );
2921 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
2922 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
2923 Debug(LDAP_DEBUG_ANY, "%s: "
2924 "unable to parse %s \"%s\"\n",
2925 c->log, c->argv[0], c->argv[1] );
2928 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
2930 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
2935 static CfEntryInfo *
2936 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2946 if ( dn_match( &root->ce_entry->e_nname, dn ))
2949 c = dn->bv_val+dn->bv_len;
2950 for (;*c != ',';c--);
2954 for (--c;c>dn->bv_val && *c != ',';c--);
2958 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2960 root = root->ce_kids;
2962 for (;root;root=root->ce_sibs) {
2963 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2964 if ( cdn.bv_val == dn->bv_val ) {
2974 typedef struct setup_cookie {
2980 config_ldif_resp( Operation *op, SlapReply *rs )
2982 if ( rs->sr_type == REP_SEARCH ) {
2983 setup_cookie *sc = op->o_callback->sc_private;
2985 sc->cfb->cb_got_ldif = 1;
2986 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
2987 if ( rs->sr_err != LDAP_SUCCESS ) {
2988 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
2989 rs->sr_entry->e_name.bv_val, sc->ca->msg, 0 );
2995 /* Configure and read the underlying back-ldif store */
2997 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
2998 CfBackInfo *cfb = be->be_private;
3004 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3005 Connection conn = {0};
3006 OperationBuffer opbuf;
3008 SlapReply rs = {REP_RESULT};
3009 Filter filter = { LDAP_FILTER_PRESENT };
3010 struct berval filterstr = BER_BVC("(objectclass=*)");
3013 /* Is the config directory available? */
3014 if ( stat( dir, &st ) < 0 ) {
3015 /* No, so don't bother using the backing store.
3016 * All changes will be in-memory only.
3021 cfb->cb_db.bd_info = backend_info( "ldif" );
3022 if ( !cfb->cb_db.bd_info )
3023 return 0; /* FIXME: eventually this will be a fatal error */
3025 if ( backend_db_init( "ldif", &cfb->cb_db ) == NULL )
3028 cfb->cb_db.be_suffix = be->be_suffix;
3029 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3031 /* The suffix is always "cn=config". The underlying DB's rootdn
3032 * is always the same as the suffix.
3034 cfb->cb_db.be_rootdn = be->be_suffix[0];
3035 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3037 ber_str2bv( dir, 0, 1, &cfdir );
3042 argv[0] = "directory";
3043 argv[1] = (char *)dir;
3047 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3051 if ( config_add_vals( ct, &c ))
3054 if ( backend_startup_one( &cfb->cb_db ))
3058 void *thrctx = ldap_pvt_thread_pool_context();
3061 op = (Operation *) &opbuf;
3062 connection_fake_init( &conn, op, thrctx );
3064 filter.f_desc = slap_schema.si_ad_objectClass;
3066 op->o_tag = LDAP_REQ_SEARCH;
3068 op->ors_filter = &filter;
3069 op->ors_filterstr = filterstr;
3070 op->ors_scope = LDAP_SCOPE_SUBTREE;
3072 op->o_dn = c.be->be_rootdn;
3073 op->o_ndn = c.be->be_rootndn;
3075 op->o_req_dn = be->be_suffix[0];
3076 op->o_req_ndn = be->be_nsuffix[0];
3078 op->ors_tlimit = SLAP_NO_LIMIT;
3079 op->ors_slimit = SLAP_NO_LIMIT;
3081 op->ors_attrs = slap_anlist_all_attributes;
3082 op->ors_attrsonly = 0;
3084 op->o_callback = &cb;
3087 cb.sc_private = ≻
3089 op->o_bd = &cfb->cb_db;
3091 /* Allow unknown attrs in DNs */
3092 prev_DN_strict = slap_DN_strict;
3095 rc = op->o_bd->be_search( op, &rs );
3097 /* Restore normal DN validation */
3098 slap_DN_strict = prev_DN_strict;
3100 ldap_pvt_thread_pool_context_reset( thrctx );
3103 /* ITS#4194 - only use if it's present, or we're converting. */
3104 if ( !readit || rc == LDAP_SUCCESS )
3105 cfb->cb_use_ldif = 1;
3111 CfOc_cmp( const void *c1, const void *c2 ) {
3112 const ConfigOCs *co1 = c1;
3113 const ConfigOCs *co2 = c2;
3115 return ber_bvcmp( co1->co_name, co2->co_name );
3119 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3122 i = init_config_attrs( ct );
3125 /* set up the objectclasses */
3126 i = init_config_ocs( ocs );
3129 for (i=0; ocs[i].co_def; i++) {
3130 if ( ocs[i].co_oc ) {
3131 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3132 if ( !ocs[i].co_table )
3133 ocs[i].co_table = ct;
3134 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3141 read_config(const char *fname, const char *dir) {
3144 const char *cfdir, *cfname;
3147 /* Setup the config backend */
3148 be = backend_db_init( "config", NULL );
3152 cfb = be->be_private;
3153 be->be_dfltaccess = ACL_NONE;
3155 /* If no .conf, or a dir was specified, setup the dir */
3156 if ( !fname || dir ) {
3158 /* If explicitly given, check for existence */
3161 if ( stat( dir, &st ) < 0 ) {
3162 Debug( LDAP_DEBUG_ANY,
3163 "invalid config directory %s, error %d\n",
3169 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3171 /* if fname is defaulted, try reading .d */
3172 rc = config_setup_ldif( be, cfdir, !fname );
3175 /* It may be OK if the base object doesn't exist yet. */
3176 if ( rc != LDAP_NO_SUCH_OBJECT )
3178 /* ITS#4194: But if dir was specified and no fname,
3179 * then we were supposed to read the dir. Unless we're
3180 * trying to slapadd the dir...
3182 if ( dir && !fname ) {
3183 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3185 /* Assume it's slapadd with a config dir, let it continue */
3187 cfb->cb_got_ldif = 1;
3188 cfb->cb_use_ldif = 1;
3193 /* If we read the config from back-ldif, nothing to do here */
3194 if ( cfb->cb_got_ldif ) {
3203 cfname = SLAPD_DEFAULT_CONFIGFILE;
3205 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3208 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3211 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3212 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3213 &frontendDB->be_schemadn );
3214 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3215 if ( rc != LDAP_SUCCESS ) {
3216 Debug(LDAP_DEBUG_ANY, "read_config: "
3217 "unable to normalize default schema DN \"%s\"\n",
3218 frontendDB->be_schemadn.bv_val, 0, 0 );
3219 /* must not happen */
3227 config_back_bind( Operation *op, SlapReply *rs )
3229 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
3230 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3231 /* frontend sends result */
3232 return LDAP_SUCCESS;
3235 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3236 send_ldap_result( op, rs );
3242 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3246 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3248 rs->sr_attrs = op->ors_attrs;
3249 rs->sr_entry = ce->ce_entry;
3251 rc = send_search_entry( op, rs );
3253 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3254 if ( ce->ce_kids ) {
3255 rc = config_send( op, rs, ce->ce_kids, 1 );
3256 if ( rc ) return rc;
3259 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3260 rc = config_send( op, rs, ce, 0 );
3268 static ConfigTable *
3269 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
3273 for (j=0; j<nocs; j++) {
3274 for (i=0; colst[j]->co_table[i].name; i++)
3275 if ( colst[j]->co_table[i].ad == ad )
3276 return &colst[j]->co_table[i];
3281 /* Sort the attributes of the entry according to the order defined
3282 * in the objectclass, with required attributes occurring before
3283 * allowed attributes. For any attributes with sequencing dependencies
3284 * (e.g., rootDN must be defined after suffix) the objectclass must
3285 * list the attributes in the desired sequence.
3288 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3290 Attribute *a, *head = NULL, *tail = NULL, **prev;
3293 for (i=0; i<nocs; i++) {
3294 if ( colst[i]->co_oc->soc_required ) {
3295 AttributeType **at = colst[i]->co_oc->soc_required;
3296 for (j=0; at[j]; j++) {
3297 for (a=e->e_attrs, prev=&e->e_attrs; a;
3298 prev = &(*prev)->a_next, a=a->a_next) {
3299 if ( a->a_desc == at[j]->sat_ad ) {
3313 if ( colst[i]->co_oc->soc_allowed ) {
3314 AttributeType **at = colst[i]->co_oc->soc_allowed;
3315 for (j=0; at[j]; j++) {
3316 for (a=e->e_attrs, prev=&e->e_attrs; a;
3317 prev = &(*prev)->a_next, a=a->a_next) {
3318 if ( a->a_desc == at[j]->sat_ad ) {
3334 tail->a_next = e->e_attrs;
3340 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3342 Attribute *a = NULL;
3343 AttributeDescription *ad;
3346 int i, rc = 0, sort = 0;
3353 Modifications *ml = ptr;
3355 vals = ml->sml_values;
3358 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3360 rc = ordered_value_sort( a, 1 );
3362 snprintf(ca->msg, sizeof( ca->msg ), "ordered_value_sort failed on attr %s\n",
3363 ad->ad_cname.bv_val );
3367 for ( i=0; vals[i].bv_val; i++ ) {
3368 ca->line = vals[i].bv_val;
3370 char *idx = strchr( ca->line, '}' );
3371 if ( idx ) ca->line = idx+1;
3373 rc = config_parse_vals( ct, ca, i );
3382 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3383 SlapReply *rs, int *renum )
3386 int index = -1, gotindex = 0, nsibs;
3387 int renumber = 0, tailindex = 0;
3388 char *ptr1, *ptr2 = NULL;
3391 if ( renum ) *renum = 0;
3393 /* These entries don't get indexed/renumbered */
3394 if ( ce_type == Cft_Global ) return 0;
3395 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3397 if ( ce_type == Cft_Include || ce_type == Cft_Module )
3400 /* See if the rdn has an index already */
3401 dnRdn( &e->e_name, &rdn );
3402 ptr1 = ber_bvchr( &e->e_name, '{' );
3403 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3405 ptr2 = strchr( ptr1, '}' );
3406 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3407 return LDAP_NAMING_VIOLATION;
3408 if ( ptr2-ptr1 == 1)
3409 return LDAP_NAMING_VIOLATION;
3411 index = strtol( ptr1 + 1, &next, 10 );
3412 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3413 return LDAP_NAMING_VIOLATION;
3416 /* Special case, we allow -1 for the frontendDB */
3417 if ( index != -1 || ce_type != Cft_Database ||
3418 strncmp( ptr2+1, "frontend,", STRLENOF("frontend,") ))
3420 return LDAP_NAMING_VIOLATION;
3424 /* count related kids */
3425 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3426 if ( ce->ce_type == ce_type ) nsibs++;
3429 if ( index != nsibs ) {
3431 if ( index < nsibs ) {
3432 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3433 /* Siblings need to be renumbered */
3438 struct berval ival, newrdn, nnewrdn;
3439 struct berval rtype, rval;
3441 AttributeDescription *ad = NULL;
3445 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
3446 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
3447 rtype.bv_val = rdn.bv_val;
3448 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3451 slap_bv2ad( &rtype, &ad, &text );
3452 a = attr_find( e->e_attrs, ad );
3453 if (!a ) return LDAP_NAMING_VIOLATION;
3456 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, nsibs );
3457 if ( ival.bv_len >= sizeof( ibuf ) ) {
3458 return LDAP_NAMING_VIOLATION;
3461 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3462 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3465 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3466 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3473 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3475 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
3478 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3479 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3483 /* Do the equivalent of ModRDN */
3484 /* Replace DN / NDN */
3485 newrdn.bv_len = ptr1 - newrdn.bv_val;
3486 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3487 free( e->e_name.bv_val );
3488 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
3490 free( e->e_nname.bv_val );
3491 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
3495 free( a->a_vals[0].bv_val );
3496 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
3497 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
3498 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3499 strcpy( a->a_vals[0].bv_val, ptr1 );
3501 if ( a->a_nvals != a->a_vals ) {
3502 free( a->a_nvals[0].bv_val );
3503 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
3504 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
3505 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3506 strcpy( a->a_nvals[0].bv_val, ptr1 );
3508 free( nnewrdn.bv_val );
3509 free( newrdn.bv_val );
3512 if ( renum ) *renum = renumber;
3517 count_ocs( Attribute *oc_at, int *nocs )
3520 ConfigOCs co, *coptr, **colst;
3522 /* count the objectclasses */
3523 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
3525 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
3527 for ( i=0, j=0; i<n; i++) {
3528 co.co_name = &oc_at->a_nvals[i];
3529 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
3531 /* ignore non-config objectclasses. probably should be
3532 * an error, general data doesn't belong here.
3534 if ( !coptr ) continue;
3536 /* Ignore the root objectclass, it has no implementation.
3538 if ( coptr->co_type == Cft_Abstract ) continue;
3546 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3548 if ( p->ce_type != Cft_Global && p->ce_type != Cft_Include )
3549 return LDAP_CONSTRAINT_VIOLATION;
3551 /* If we're reading from a configdir, don't parse this entry */
3553 return LDAP_COMPARE_TRUE;
3555 cfn = p->ce_private;
3557 return LDAP_SUCCESS;
3561 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3565 /* This entry is hardcoded, don't re-parse it */
3566 if ( p->ce_type == Cft_Global ) {
3567 cfn = p->ce_private;
3569 return LDAP_COMPARE_TRUE;
3571 if ( p->ce_type != Cft_Schema )
3572 return LDAP_CONSTRAINT_VIOLATION;
3574 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3576 cfo = p->ce_private;
3577 cfn->c_sibs = cfo->c_kids;
3579 return LDAP_SUCCESS;
3583 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3585 if ( p->ce_type != Cft_Global )
3586 return LDAP_CONSTRAINT_VIOLATION;
3587 ca->be = frontendDB; /* just to get past check_vals */
3588 return LDAP_SUCCESS;
3592 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3594 if ( p->ce_type != Cft_Global )
3595 return LDAP_CONSTRAINT_VIOLATION;
3596 return LDAP_SUCCESS;
3600 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3602 if ( p->ce_type != Cft_Global )
3603 return LDAP_CONSTRAINT_VIOLATION;
3604 return LDAP_SUCCESS;
3608 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3610 if ( p->ce_type != Cft_Database )
3611 return LDAP_CONSTRAINT_VIOLATION;
3613 return LDAP_SUCCESS;
3616 /* Parse an LDAP entry into config directives */
3618 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
3619 int *renum, Operation *op )
3621 CfEntryInfo *ce, *last;
3623 Attribute *a, *oc_at;
3624 int i, nocs, rc = 0;
3629 /* Make sure parent exists and entry does not */
3630 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3632 return LDAP_ALREADY_EXISTS;
3634 dnParent( &e->e_nname, &pdn );
3636 /* If last is NULL, the new entry is the root/suffix entry,
3637 * otherwise last should be the parent.
3639 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3641 rs->sr_matched = last->ce_entry->e_name.bv_val;
3642 return LDAP_NO_SUCH_OBJECT;
3646 /* No parent, must be root. This will never happen... */
3647 if ( !last && !be_isroot( op ) && !be_shadow_update( op ))
3648 return LDAP_NO_SUCH_OBJECT;
3649 if ( last && !access_allowed( op, last->ce_entry,
3650 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ))
3651 return LDAP_INSUFFICIENT_ACCESS;
3654 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3655 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3657 memset( ca, 0, sizeof(ConfigArgs));
3659 /* Fake the coordinates based on whether we're part of an
3660 * LDAP Add or if reading the config dir
3663 ca->fname = "slapd";
3666 ca->fname = cfdir.bv_val;
3670 colst = count_ocs( oc_at, &nocs );
3672 /* Only the root can be Cft_Global, everything else must
3673 * have a parent. Only limited nesting arrangements are allowed.
3675 rc = LDAP_CONSTRAINT_VIOLATION;
3676 if ( colst[0]->co_type == Cft_Global && !last ) {
3677 cfn = cfb->cb_config;
3679 ca->be = frontendDB; /* just to get past check_vals */
3683 /* Check whether the Add is allowed by its parent, and do
3684 * any necessary arg setup
3687 for ( i=0; i<nocs; i++ ) {
3688 if ( colst[i]->co_ldadd &&
3689 ( rc = colst[i]->co_ldadd( last, e, ca ))
3690 != LDAP_CONSTRAINT_VIOLATION ) {
3696 /* Add the entry but don't parse it, we already have its contents */
3697 if ( rc == LDAP_COMPARE_TRUE ) {
3702 if ( rc != LDAP_SUCCESS )
3705 /* Parse all the values and check for simple syntax errors before
3706 * performing any set actions.
3708 * If doing an LDAPadd, check for indexed names and any necessary
3709 * renaming/renumbering. Entries that don't need indexed names are
3710 * ignored. Entries that need an indexed name and arrive without one
3711 * are assigned to the end. Entries that arrive with an index may
3712 * cause the following entries to be renumbered/bumped down.
3714 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3715 * don't allow Adding an entry with an index that's already in use.
3716 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3718 * These entries can have auto-assigned indexes (appended to the end)
3719 * but only the other types support auto-renumbering of siblings.
3722 int renumber = renum ? *renum : 0;
3723 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3727 if ( renum && *renum && renumber == -1 ) {
3728 snprintf( ca->msg, sizeof( ca->msg ),
3729 "operation requires sibling renumbering" );
3730 rc = LDAP_UNWILLING_TO_PERFORM;
3735 init_config_argv( ca );
3737 /* Make sure we process attrs in the required order */
3738 sort_attrs( e, colst, nocs );
3740 for ( a=e->e_attrs; a; a=a->a_next ) {
3741 if ( a == oc_at ) continue;
3742 ct = config_find_table( colst, nocs, a->a_desc );
3743 if ( !ct ) continue; /* user data? */
3744 rc = check_vals( ct, ca, a, 1 );
3745 if ( rc ) goto done;
3748 /* Basic syntax checks are OK. Do the actual settings. */
3749 for ( a=e->e_attrs; a; a=a->a_next ) {
3750 if ( a == oc_at ) continue;
3751 ct = config_find_table( colst, nocs, a->a_desc );
3752 if ( !ct ) continue; /* user data? */
3753 for (i=0; a->a_vals[i].bv_val; i++) {
3754 ca->line = a->a_vals[i].bv_val;
3755 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3756 ptr = strchr( ca->line, '}' );
3757 if ( ptr ) ca->line = ptr+1;
3760 rc = config_parse_add( ct, ca );
3768 /* Newly added databases and overlays need to be started up */
3769 if ( CONFIG_ONLINE_ADD( ca )) {
3770 if ( colst[0]->co_type == Cft_Database ) {
3771 rc = backend_startup_one( ca->be );
3773 } else if ( colst[0]->co_type == Cft_Overlay ) {
3774 if ( ca->bi->bi_db_open ) {
3775 BackendInfo *bi_orig = ca->be->bd_info;
3776 ca->be->bd_info = ca->bi;
3777 rc = ca->bi->bi_db_open( ca->be );
3778 ca->be->bd_info = bi_orig;
3782 snprintf( ca->msg, sizeof( ca->msg ), "<%s> failed startup", ca->argv[0] );
3783 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
3784 ca->log, ca->msg, ca->argv[1] );
3790 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3791 ce->ce_parent = last;
3792 ce->ce_entry = entry_dup( e );
3793 ce->ce_entry->e_private = ce;
3794 ce->ce_type = colst[0]->co_type;
3797 ce->ce_private = ca->private;
3800 } else if ( last->ce_kids ) {
3803 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3812 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
3813 if ( ca->be != frontendDB )
3814 backend_destroy_one( ca->be, 1 );
3815 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
3816 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
3820 ch_free( ca->argv );
3821 if ( colst ) ch_free( colst );
3825 /* Parse an LDAP entry into config directives, then store in underlying
3829 config_back_add( Operation *op, SlapReply *rs )
3835 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
3836 NULL, ACL_WADD, NULL )) {
3837 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3841 cfb = (CfBackInfo *)op->o_bd->be_private;
3843 ldap_pvt_thread_pool_pause( &connection_pool );
3846 * 1) check for existence of entry
3847 * 2) check for sibling renumbering
3848 * 3) perform internal add
3849 * 4) store entry in underlying database
3850 * 5) perform any necessary renumbering
3852 /* NOTE: by now we do not accept adds that require renumbering */
3854 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
3855 if ( rs->sr_err != LDAP_SUCCESS ) {
3856 rs->sr_text = ca.msg;
3860 if ( cfb->cb_use_ldif ) {
3861 BackendDB *be = op->o_bd;
3862 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3863 struct berval dn, ndn;
3865 op->o_bd = &cfb->cb_db;
3867 /* Save current rootdn; use the underlying DB's rootdn */
3870 op->o_dn = op->o_bd->be_rootdn;
3871 op->o_ndn = op->o_bd->be_rootndn;
3873 sc.sc_next = op->o_callback;
3874 op->o_callback = ≻
3875 op->o_bd->be_add( op, rs );
3877 op->o_callback = sc.sc_next;
3887 ldap_pvt_thread_pool_resume( &connection_pool );
3890 send_ldap_result( op, rs );
3894 typedef struct delrec {
3895 struct delrec *next;
3901 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3904 int rc = LDAP_UNWILLING_TO_PERFORM;
3906 Entry *e = ce->ce_entry;
3907 Attribute *save_attrs = e->e_attrs, *oc_at;
3912 delrec *dels = NULL, *deltail = NULL;
3914 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3915 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3917 colst = count_ocs( oc_at, &nocs );
3919 e->e_attrs = attrs_dup( e->e_attrs );
3921 init_config_argv( ca );
3924 ca->private = ce->ce_private;
3926 ca->fname = "slapd";
3927 strcpy( ca->log, "back-config" );
3929 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3930 ct = config_find_table( colst, nocs, ml->sml_desc );
3931 switch (ml->sml_op) {
3932 case LDAP_MOD_DELETE:
3933 case LDAP_MOD_REPLACE: {
3934 BerVarray vals = NULL, nvals = NULL;
3936 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3938 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3939 ml->sml_desc->ad_cname.bv_val );
3942 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3943 vals = ml->sml_values;
3944 nvals = ml->sml_nvalues;
3945 ml->sml_values = NULL;
3946 ml->sml_nvalues = NULL;
3948 /* If we're deleting by values, remember the indexes of the
3949 * values we deleted.
3951 if ( ct && ml->sml_values ) {
3953 for (i=0; ml->sml_values[i].bv_val; i++);
3954 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
3965 rc = modify_delete_vindex(e, &ml->sml_mod,
3966 get_permissiveModify(op),
3967 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3968 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3969 ml->sml_values = vals;
3970 ml->sml_nvalues = nvals;
3975 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3978 case SLAP_MOD_SOFTADD: {
3979 int mop = ml->sml_op;
3981 ml->sml_op = LDAP_MOD_ADD;
3983 if ( ct->arg_type & ARG_NO_INSERT ) {
3984 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3986 for (i = 0; a->a_vals[i].bv_val; i++ );
3990 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3991 if ( ml->sml_values[i].bv_val[0] == '{' &&
3994 char *next, *val = ml->sml_values[i].bv_val + 1;
3997 j = strtol( val, &next, 0 );
3998 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4000 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
4001 ml->sml_desc->ad_cname.bv_val );
4005 rc = check_vals( ct, ca, ml, 0 );
4009 rc = modify_add_values(e, &ml->sml_mod,
4010 get_permissiveModify(op),
4011 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4013 /* If value already exists, show success here
4014 * and ignore this operation down below.
4016 if ( mop == SLAP_MOD_SOFTADD ) {
4017 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4027 case LDAP_MOD_INCREMENT: /* FIXME */
4032 if(rc != LDAP_SUCCESS) break;
4035 if(rc == LDAP_SUCCESS) {
4036 /* check that the entry still obeys the schema */
4037 rc = entry_schema_check(op, e, NULL, 0,
4038 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4040 if ( rc == LDAP_SUCCESS ) {
4041 /* Basic syntax checks are OK. Do the actual settings. */
4042 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4043 ct = config_find_table( colst, nocs, ml->sml_desc );
4044 if ( !ct ) continue;
4046 switch (ml->sml_op) {
4047 case LDAP_MOD_DELETE:
4048 case LDAP_MOD_REPLACE: {
4049 BerVarray vals = NULL, nvals = NULL;
4053 a = attr_find( e->e_attrs, ml->sml_desc );
4055 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4056 vals = ml->sml_values;
4057 nvals = ml->sml_nvalues;
4058 ml->sml_values = NULL;
4059 ml->sml_nvalues = NULL;
4062 if ( ml->sml_values )
4065 /* If we didn't delete the whole attribute */
4066 if ( ml->sml_values && a ) {
4067 struct berval *mvals;
4070 if ( ml->sml_nvalues )
4071 mvals = ml->sml_nvalues;
4073 mvals = ml->sml_values;
4075 /* use the indexes we saved up above */
4076 for (i=0; i < d->nidx; i++) {
4077 struct berval bv = *mvals++;
4078 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4079 bv.bv_val[0] == '{' ) {
4080 ptr = strchr( bv.bv_val, '}' ) + 1;
4081 bv.bv_len -= ptr - bv.bv_val;
4084 ca->line = bv.bv_val;
4085 ca->valx = d->idx[i];
4086 rc = config_del_vals( ct, ca );
4087 if ( rc != LDAP_SUCCESS ) break;
4088 for (j=i+1; j < d->nidx; j++)
4089 if ( d->idx[j] >d->idx[i] )
4095 rc = config_del_vals( ct, ca );
4096 if ( rc ) rc = LDAP_OTHER;
4098 if ( ml->sml_values ) {
4102 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4103 ml->sml_values = vals;
4104 ml->sml_nvalues = nvals;
4106 if ( !vals || rc != LDAP_SUCCESS )
4109 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4112 for (i=0; ml->sml_values[i].bv_val; i++) {
4113 ca->line = ml->sml_values[i].bv_val;
4115 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4116 ca->line[0] == '{' )
4118 ptr = strchr( ca->line + 1, '}' );
4122 ca->valx = strtol( ca->line + 1, &next, 0 );
4123 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4130 rc = config_parse_add( ct, ca );
4145 if ( rc == LDAP_SUCCESS ) {
4146 attrs_free( save_attrs );
4148 attrs_free( e->e_attrs );
4149 e->e_attrs = save_attrs;
4151 ch_free( ca->argv );
4152 if ( colst ) ch_free( colst );
4154 deltail = dels->next;
4163 config_back_modify( Operation *op, SlapReply *rs )
4166 CfEntryInfo *ce, *last;
4168 ConfigArgs ca = {0};
4171 AttributeDescription *rad = NULL;
4173 cfb = (CfBackInfo *)op->o_bd->be_private;
4175 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4178 rs->sr_matched = last->ce_entry->e_name.bv_val;
4179 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4183 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4184 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4188 /* Get type of RDN */
4189 rdn = ce->ce_entry->e_nname;
4190 ptr = strchr( rdn.bv_val, '=' );
4191 rdn.bv_len = ptr - rdn.bv_val;
4192 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4194 /* Some basic validation... */
4195 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4196 /* Don't allow Modify of RDN; must use ModRdn for that. */
4197 if ( ml->sml_desc == rad ) {
4198 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4199 rs->sr_text = "Use modrdn to change the entry name";
4204 ldap_pvt_thread_pool_pause( &connection_pool );
4207 * 1) perform the Modify on the cached Entry.
4208 * 2) verify that the Entry still satisfies the schema.
4209 * 3) perform the individual config operations.
4210 * 4) store Modified entry in underlying LDIF backend.
4212 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4214 rs->sr_text = ca.msg;
4215 } else if ( cfb->cb_use_ldif ) {
4216 BackendDB *be = op->o_bd;
4217 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
4218 struct berval dn, ndn;
4220 op->o_bd = &cfb->cb_db;
4224 op->o_dn = op->o_bd->be_rootdn;
4225 op->o_ndn = op->o_bd->be_rootndn;
4227 sc.sc_next = op->o_callback;
4228 op->o_callback = ≻
4229 op->o_bd->be_modify( op, rs );
4231 op->o_callback = sc.sc_next;
4236 ldap_pvt_thread_pool_resume( &connection_pool );
4238 send_ldap_result( op, rs );
4243 config_back_modrdn( Operation *op, SlapReply *rs )
4246 CfEntryInfo *ce, *last;
4248 cfb = (CfBackInfo *)op->o_bd->be_private;
4250 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4253 rs->sr_matched = last->ce_entry->e_name.bv_val;
4254 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4257 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4258 NULL, ACL_WRITE, NULL )) {
4259 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4263 if ( ce->ce_parent )
4264 parent = ce->ce_parent->ce_entry;
4266 parent = (Entry *)&slap_entry_root;
4267 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
4268 NULL, ACL_WRITE, NULL )) {
4269 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4274 /* We don't allow moving objects to new parents.
4275 * Generally we only allow reordering a set of ordered entries.
4277 if ( op->orr_newSup ) {
4278 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4281 ldap_pvt_thread_pool_pause( &connection_pool );
4283 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4284 rs->sr_text = "renaming not implemented yet within naming context";
4286 ldap_pvt_thread_pool_resume( &connection_pool );
4288 send_ldap_result( op, rs );
4293 config_back_search( Operation *op, SlapReply *rs )
4296 CfEntryInfo *ce, *last;
4299 cfb = (CfBackInfo *)op->o_bd->be_private;
4301 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4304 rs->sr_matched = last->ce_entry->e_name.bv_val;
4305 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4308 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
4309 ACL_SEARCH, NULL, &mask ))
4311 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
4312 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4314 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4318 switch ( op->ors_scope ) {
4319 case LDAP_SCOPE_BASE:
4320 case LDAP_SCOPE_SUBTREE:
4321 config_send( op, rs, ce, 0 );
4324 case LDAP_SCOPE_ONELEVEL:
4325 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
4326 config_send( op, rs, ce, 1 );
4331 rs->sr_err = LDAP_SUCCESS;
4333 send_ldap_result( op, rs );
4338 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
4339 ConfigTable *ct, ConfigArgs *c )
4343 for (; at && *at; at++) {
4344 /* Skip the naming attr */
4345 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
4347 for (i=0;ct[i].name;i++) {
4348 if (ct[i].ad == (*at)->sat_ad) {
4349 rc = config_get_vals(&ct[i], c);
4350 /* NOTE: tolerate that config_get_vals()
4351 * returns success with no values */
4352 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
4353 if ( c->rvalue_nvals )
4354 attr_merge(e, ct[i].ad, c->rvalue_vals,
4357 attr_merge_normalize(e, ct[i].ad,
4358 c->rvalue_vals, NULL);
4359 ber_bvarray_free( c->rvalue_nvals );
4360 ber_bvarray_free( c->rvalue_vals );
4369 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4370 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
4372 Entry *e = ch_calloc( 1, sizeof(Entry) );
4373 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4375 struct berval ad_name;
4376 AttributeDescription *ad = NULL;
4383 CfEntryInfo *ceprev = NULL;
4385 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
4388 ce->ce_parent = parent;
4390 pdn = parent->ce_entry->e_nname;
4391 if ( parent->ce_kids )
4392 for ( ceprev = parent->ce_kids; ceprev->ce_sibs;
4393 ceprev = ceprev->ce_sibs );
4398 ce->ce_type = main->co_type;
4399 ce->ce_private = c->private;
4403 build_new_dn( &e->e_name, &pdn, rdn, NULL );
4404 ber_dupbv( &e->e_nname, &e->e_name );
4406 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
4407 main->co_name, NULL );
4409 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
4410 extra->co_name, NULL );
4411 ptr = strchr(rdn->bv_val, '=');
4412 ad_name.bv_val = rdn->bv_val;
4413 ad_name.bv_len = ptr - rdn->bv_val;
4414 rc = slap_bv2ad( &ad_name, &ad, &text );
4419 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
4420 attr_merge_normalize_one(e, ad, &val, NULL );
4423 if ( oc->soc_required )
4424 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
4426 if ( oc->soc_allowed )
4427 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
4431 if ( oc->soc_required )
4432 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
4434 if ( oc->soc_allowed )
4435 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
4438 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4439 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
4441 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
4444 op->o_bd->be_add( op, rs );
4445 if ( ( rs->sr_err != LDAP_SUCCESS )
4446 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
4451 ceprev->ce_sibs = ce;
4452 } else if ( parent ) {
4453 parent->ce_kids = ce;
4460 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
4461 Operation *op, SlapReply *rs )
4464 ConfigFile *cf = c->private;
4468 for (; cf; cf=cf->c_sibs, c->depth++) {
4469 c->value_dn.bv_val = c->log;
4470 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
4475 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
4477 ptr = strchr( bv.bv_val, '.' );
4479 bv.bv_len = ptr - bv.bv_val;
4480 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
4481 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
4482 /* FIXME: how can indicate error? */
4485 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
4487 c->value_dn.bv_len += bv.bv_len;
4488 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
4491 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
4492 &CFOC_SCHEMA, NULL );
4495 } else if ( e && cf->c_kids ) {
4496 c->private = cf->c_kids;
4497 config_build_schema_inc( c, e->e_private, op, rs );
4504 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
4505 Operation *op, SlapReply *rs )
4509 ConfigFile *cf = c->private;
4511 for (i=0; cf; cf=cf->c_sibs, i++) {
4512 c->value_dn.bv_val = c->log;
4513 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=include" SLAP_X_ORDERED_FMT, i);
4514 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
4515 /* FIXME: how can indicate error? */
4519 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
4520 &CFOC_INCLUDE, NULL );
4523 } else if ( e && cf->c_kids ) {
4524 c->private = cf->c_kids;
4525 config_build_includes( c, e->e_private, op, rs );
4531 #ifdef SLAPD_MODULES
4534 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
4535 Operation *op, SlapReply *rs )
4540 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
4541 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
4543 c->value_dn.bv_val = c->log;
4544 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
4545 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
4546 /* FIXME: how can indicate error? */
4550 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
4558 static const char *defacl[] = {
4559 NULL, "to", "*", "by", "*", "none", NULL
4563 config_back_db_open( BackendDB *be )
4565 CfBackInfo *cfb = be->be_private;
4568 CfEntryInfo *ce, *ceparent;
4572 Connection conn = {0};
4573 OperationBuffer opbuf;
4575 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
4576 SlapReply rs = {REP_RESULT};
4577 void *thrctx = NULL;
4579 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
4581 /* If we have no explicitly configured ACLs, don't just use
4582 * the global ACLs. Explicitly deny access to everything.
4584 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
4585 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
4588 /* If we read the config from back-ldif, nothing to do here */
4589 if ( cfb->cb_got_ldif )
4592 if ( cfb->cb_use_ldif ) {
4593 thrctx = ldap_pvt_thread_pool_context();
4594 op = (Operation *) &opbuf;
4595 connection_fake_init( &conn, op, thrctx );
4597 op->o_tag = LDAP_REQ_ADD;
4598 op->o_callback = &cb;
4599 op->o_bd = &cfb->cb_db;
4600 op->o_dn = op->o_bd->be_rootdn;
4601 op->o_ndn = op->o_bd->be_rootndn;
4606 /* create root of tree */
4608 c.private = cfb->cb_config;
4610 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
4620 /* Create includeFile nodes */
4621 if ( cfb->cb_config->c_kids ) {
4623 c.private = cfb->cb_config->c_kids;
4624 if ( config_build_includes( &c, ceparent, op, &rs ) ) {
4629 #ifdef SLAPD_MODULES
4630 /* Create Module nodes... */
4631 if ( modpaths.mp_loads ) {
4632 if ( config_build_modules( &c, ceparent, op, &rs ) ){
4638 /* Create schema nodes... cn=schema will contain the hardcoded core
4639 * schema, read-only. Child objects will contain runtime loaded schema
4644 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
4650 /* Create schema nodes for included schema... */
4651 if ( cfb->cb_config->c_kids ) {
4653 c.private = cfb->cb_config->c_kids;
4654 if (config_build_schema_inc( &c, ce, op, &rs )) {
4659 /* Create backend nodes. Skip if they don't provide a cf_table.
4660 * There usually aren't any of these.
4664 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
4665 if (!bi->bi_cf_ocs) {
4666 /* If it only supports the old config mech, complain. */
4667 if ( bi->bi_config ) {
4668 Debug( LDAP_DEBUG_ANY,
4669 "WARNING: No dynamic config support for backend %s.\n",
4670 bi->bi_type, 0, 0 );
4675 if (!bi->bi_private) continue;
4678 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
4679 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
4680 if ( rdn.bv_len >= sizeof( c.log ) ) {
4681 /* FIXME: holler ... */ ;
4684 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
4691 /* Create database nodes... */
4692 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4693 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
4694 for ( i = -1, be = frontendDB ; be;
4695 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
4696 slap_overinfo *oi = NULL;
4698 if ( overlay_is_over( be )) {
4699 oi = be->bd_info->bi_private;
4705 /* If this backend supports the old config mechanism, but not
4706 * the new mech, complain.
4708 if ( !be->be_cf_ocs && bi->bi_db_config ) {
4709 Debug( LDAP_DEBUG_ANY,
4710 "WARNING: No dynamic config support for database %s.\n",
4711 bi->bi_type, 0, 0 );
4715 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
4716 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
4718 if ( rdn.bv_len >= sizeof( c.log ) ) {
4719 /* FIXME: holler ... */ ;
4723 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
4729 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
4730 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
4731 /* Iterate through overlays */
4737 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
4738 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
4739 Debug( LDAP_DEBUG_ANY,
4740 "WARNING: No dynamic config support for overlay %s.\n",
4741 on->on_bi.bi_type, 0, 0 );
4745 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
4746 "%s=" SLAP_X_ORDERED_FMT "%s",
4747 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
4748 if ( rdn.bv_len >= sizeof( c.log ) ) {
4749 /* FIXME: holler ... */ ;
4753 oe = config_build_entry( op, &rs, ce, &c, &rdn,
4754 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
4758 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
4759 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
4764 ldap_pvt_thread_pool_context_reset( thrctx );
4766 if ( unsupp && cfb->cb_use_ldif ) {
4767 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
4768 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
4775 cfb_free_cffile( ConfigFile *cf )
4779 for (; cf; cf=next) {
4782 cfb_free_cffile( cf->c_kids );
4783 ch_free( cf->c_file.bv_val );
4784 ber_bvarray_free( cf->c_dseFiles );
4790 cfb_free_entries( CfEntryInfo *ce )
4794 for (; ce; ce=next) {
4797 cfb_free_entries( ce->ce_kids );
4798 ce->ce_entry->e_private = NULL;
4799 entry_free( ce->ce_entry );
4805 config_back_db_close( BackendDB *be )
4807 CfBackInfo *cfb = be->be_private;
4809 cfb_free_entries( cfb->cb_root );
4810 cfb->cb_root = NULL;
4812 if ( cfb->cb_db.bd_info ) {
4813 backend_shutdown( &cfb->cb_db );
4820 config_back_db_destroy( BackendDB *be )
4822 CfBackInfo *cfb = be->be_private;
4824 cfb_free_cffile( cfb->cb_config );
4826 ch_free( cfdir.bv_val );
4828 avl_free( CfOcTree, NULL );
4830 if ( cfb->cb_db.bd_info ) {
4831 cfb->cb_db.be_suffix = NULL;
4832 cfb->cb_db.be_nsuffix = NULL;
4833 BER_BVZERO( &cfb->cb_db.be_rootdn );
4834 BER_BVZERO( &cfb->cb_db.be_rootndn );
4836 backend_destroy_one( &cfb->cb_db, 0 );
4839 free( be->be_private );
4847 config_back_db_init( BackendDB *be )
4852 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4853 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
4854 cfn = cfb->cb_config;
4855 be->be_private = cfb;
4857 ber_dupbv( &be->be_rootdn, &config_rdn );
4858 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4859 ber_dupbv( &dn, &be->be_rootdn );
4860 ber_bvarray_add( &be->be_suffix, &dn );
4861 ber_dupbv( &dn, &be->be_rootdn );
4862 ber_bvarray_add( &be->be_nsuffix, &dn );
4864 /* Hide from namingContexts */
4865 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4871 config_back_destroy( BackendInfo *bi )
4873 ldif_must_b64_encode_release();
4878 config_tool_entry_open( BackendDB *be, int mode )
4880 CfBackInfo *cfb = be->be_private;
4881 BackendInfo *bi = cfb->cb_db.bd_info;
4883 if ( bi && bi->bi_tool_entry_open )
4884 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
4891 config_tool_entry_close( BackendDB *be )
4893 CfBackInfo *cfb = be->be_private;
4894 BackendInfo *bi = cfb->cb_db.bd_info;
4896 if ( bi && bi->bi_tool_entry_close )
4897 return bi->bi_tool_entry_close( &cfb->cb_db );
4903 config_tool_entry_first( BackendDB *be )
4905 CfBackInfo *cfb = be->be_private;
4906 BackendInfo *bi = cfb->cb_db.bd_info;
4908 if ( bi && bi->bi_tool_entry_first )
4909 return bi->bi_tool_entry_first( &cfb->cb_db );
4915 config_tool_entry_next( BackendDB *be )
4917 CfBackInfo *cfb = be->be_private;
4918 BackendInfo *bi = cfb->cb_db.bd_info;
4920 if ( bi && bi->bi_tool_entry_next )
4921 return bi->bi_tool_entry_next( &cfb->cb_db );
4927 config_tool_entry_get( BackendDB *be, ID id )
4929 CfBackInfo *cfb = be->be_private;
4930 BackendInfo *bi = cfb->cb_db.bd_info;
4932 if ( bi && bi->bi_tool_entry_get )
4933 return bi->bi_tool_entry_get( &cfb->cb_db, id );
4939 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
4941 CfBackInfo *cfb = be->be_private;
4942 BackendInfo *bi = cfb->cb_db.bd_info;
4945 if ( bi && bi->bi_tool_entry_put &&
4946 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
4947 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
4954 AttributeDescription **desc;
4956 { "backend", &cfAd_backend },
4957 { "database", &cfAd_database },
4958 { "include", &cfAd_include },
4959 { "overlay", &cfAd_overlay },
4964 * add / delete: all types that may be added or deleted must use an
4965 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4966 * should automatically renumber the index of any siblings as needed,
4967 * so that no gaps in the numbering sequence exist after the add/delete
4969 * What can be added:
4971 * backend objects for backend-specific config directives
4975 * delete: probably no support this time around.
4977 * modrdn: generally not done. Will be invoked automatically by add/
4978 * delete to update numbering sequence. Perform as an explicit operation
4979 * so that the renumbering effect may be replicated. Subtree rename must
4980 * be supported, since renumbering a database will affect all its child
4983 * modify: must be fully supported.
4987 config_back_initialize( BackendInfo *bi )
4989 ConfigTable *ct = config_back_cf_table;
4992 AttributeDescription *ad = NULL;
4994 static char *controls[] = {
4995 LDAP_CONTROL_MANAGEDSAIT,
4999 /* Make sure we don't exceed the bits reserved for userland */
5000 config_check_userland( CFG_LAST );
5002 bi->bi_controls = controls;
5007 bi->bi_destroy = config_back_destroy;
5009 bi->bi_db_init = config_back_db_init;
5010 bi->bi_db_config = 0;
5011 bi->bi_db_open = config_back_db_open;
5012 bi->bi_db_close = config_back_db_close;
5013 bi->bi_db_destroy = config_back_db_destroy;
5015 bi->bi_op_bind = config_back_bind;
5016 bi->bi_op_unbind = 0;
5017 bi->bi_op_search = config_back_search;
5018 bi->bi_op_compare = 0;
5019 bi->bi_op_modify = config_back_modify;
5020 bi->bi_op_modrdn = config_back_modrdn;
5021 bi->bi_op_add = config_back_add;
5022 bi->bi_op_delete = 0;
5023 bi->bi_op_abandon = 0;
5025 bi->bi_extended = 0;
5027 bi->bi_chk_referrals = 0;
5029 bi->bi_access_allowed = slap_access_allowed;
5031 bi->bi_connection_init = 0;
5032 bi->bi_connection_destroy = 0;
5034 bi->bi_tool_entry_open = config_tool_entry_open;
5035 bi->bi_tool_entry_close = config_tool_entry_close;
5036 bi->bi_tool_entry_first = config_tool_entry_first;
5037 bi->bi_tool_entry_next = config_tool_entry_next;
5038 bi->bi_tool_entry_get = config_tool_entry_get;
5039 bi->bi_tool_entry_put = config_tool_entry_put;
5042 for (i=0; OidMacros[i].name; i++ ) {
5043 argv[1] = OidMacros[i].name;
5044 argv[2] = OidMacros[i].oid;
5045 parse_oidm( "slapd", i, 3, argv, 0, NULL );
5048 bi->bi_cf_ocs = cf_ocs;
5050 i = config_register_schema( ct, cf_ocs );
5053 /* setup olcRootPW to be base64-encoded when written in LDIF form;
5054 * basically, we don't care if it fails */
5055 i = slap_str2ad( "olcRootPW", &ad, &text );
5057 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
5058 "warning, unable to get \"olcRootPW\" "
5059 "attribute description: %d: %s\n",
5062 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
5063 ad->ad_type->sat_oid );
5066 /* set up the notable AttributeDescriptions */
5068 for (;ct->name;ct++) {
5069 if (strcmp(ct->name, ads[i].name)) continue;
5070 *ads[i].desc = ct->ad;
5072 if (!ads[i].name) break;