1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 #define CONFIG_RDN "cn=config"
41 #define SCHEMA_RDN "cn=schema"
43 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
44 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
46 extern int slap_DN_strict; /* dn.c */
49 typedef struct modpath_s {
50 struct modpath_s *mp_next;
51 struct berval mp_path;
55 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 typedef struct ConfigFile {
59 struct ConfigFile *c_sibs;
60 struct ConfigFile *c_kids;
62 AttributeType *c_at_head, *c_at_tail;
63 ContentRule *c_cr_head, *c_cr_tail;
64 ObjectClass *c_oc_head, *c_oc_tail;
65 OidMacro *c_om_head, *c_om_tail;
70 ConfigFile *cb_config;
72 BackendDB cb_db; /* underlying database */
77 static CfBackInfo cfBackInfo;
79 static char *passwd_salt;
80 static char *logfileName;
81 #ifdef SLAP_AUTH_REWRITE
82 static BerVarray authz_rewrites;
85 static struct berval cfdir;
88 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
89 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om;
91 static ConfigFile *cfn;
93 static Avlnode *CfOcTree;
95 /* System schema state */
96 extern AttributeType *at_sys_tail; /* at.c */
97 extern ObjectClass *oc_sys_tail; /* oc.c */
98 extern OidMacro *om_sys_tail; /* oidm.c */
99 static AttributeType *cf_at_tail;
100 static ObjectClass *cf_oc_tail;
101 static OidMacro *cf_om_tail;
103 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
104 SlapReply *rs, int *renumber, Operation *op );
106 static int config_check_schema( Operation *op, CfBackInfo *cfb );
108 static ConfigDriver config_fname;
109 static ConfigDriver config_cfdir;
110 static ConfigDriver config_generic;
111 static ConfigDriver config_search_base;
112 static ConfigDriver config_passwd_hash;
113 static ConfigDriver config_schema_dn;
114 static ConfigDriver config_sizelimit;
115 static ConfigDriver config_timelimit;
116 static ConfigDriver config_overlay;
117 static ConfigDriver config_subordinate;
118 static ConfigDriver config_suffix;
119 static ConfigDriver config_rootdn;
120 static ConfigDriver config_rootpw;
121 static ConfigDriver config_restrict;
122 static ConfigDriver config_allows;
123 static ConfigDriver config_disallows;
124 static ConfigDriver config_requires;
125 static ConfigDriver config_security;
126 static ConfigDriver config_referral;
127 static ConfigDriver config_loglevel;
128 static ConfigDriver config_replica;
129 static ConfigDriver config_updatedn;
130 static ConfigDriver config_updateref;
131 static ConfigDriver config_include;
133 static ConfigDriver config_tls_option;
134 static ConfigDriver config_tls_config;
136 extern ConfigDriver syncrepl_config;
163 CFG_REPLICA_ARGSFILE,
165 CFG_REPLICATIONINTERVAL,
191 static OidRec OidMacros[] = {
192 /* OpenLDAProot:666.11.1 */
193 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
194 { "OLcfgAt", "OLcfg:3" },
195 { "OLcfgGlAt", "OLcfgAt:0" },
196 { "OLcfgBkAt", "OLcfgAt:1" },
197 { "OLcfgDbAt", "OLcfgAt:2" },
198 { "OLcfgOvAt", "OLcfgAt:3" },
199 { "OLcfgOc", "OLcfg:4" },
200 { "OLcfgGlOc", "OLcfgOc:0" },
201 { "OLcfgBkOc", "OLcfgOc:1" },
202 { "OLcfgDbOc", "OLcfgOc:2" },
203 { "OLcfgOvOc", "OLcfgOc:3" },
205 /* Syntaxes. We should just start using the standard names and
206 * document that they are predefined and available for users
207 * to reference in their own schema. Defining schema without
208 * OID macros is for masochists...
210 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
211 { "OMsBoolean", "OMsyn:7" },
212 { "OMsDN", "OMsyn:12" },
213 { "OMsDirectoryString", "OMsyn:15" },
214 { "OMsInteger", "OMsyn:27" },
215 { "OMsOID", "OMsyn:38" },
216 { "OMsOctetString", "OMsyn:40" },
221 * Backend/Database registry
223 * OLcfg{Bk|Db}{Oc|At}:0 -> common
224 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
225 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
226 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
232 * OLcfgOv{Oc|At}:1 -> syncprov
233 * OLcfgOv{Oc|At}:2 -> pcache
234 * OLcfgOv{Oc|At}:3 -> chain
235 * OLcfgOv{Oc|At}:4 -> accesslog
236 * OLcfgOv{Oc|At}:5 -> valsort
237 * (FIXME: separate arc for contribware?)
238 * OLcfgOv{Oc|At}:6 -> smbk5pwd
239 * OLcfgOv{Oc|At}:7 -> distproc
240 * OLcfgOv{Oc|At}:8 -> dynlist
241 * OLcfgOv{Oc|At}:9 -> dds
242 * OLcfgOv{Oc|At}:10 -> unique
243 * OLcfgOv{Oc|At}:11 -> refint
244 * OLcfgOv{Oc|At}:12 -> ppolicy
245 * OLcfgOv{Oc|At}:13 -> constraint
246 * OLcfgOv{Oc|At}:14 -> translucent
247 * OLcfgOv{Oc|At}:15 -> auditlog
250 /* alphabetical ordering */
252 static ConfigTable config_back_cf_table[] = {
253 /* This attr is read-only */
254 { "", "", 0, 0, 0, ARG_MAGIC,
255 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
256 "DESC 'File for slapd configuration directives' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
259 { "", "", 0, 0, 0, ARG_MAGIC,
260 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
261 "DESC 'Directory for slapd configuration backend' "
262 "EQUALITY caseIgnoreMatch "
263 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
264 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
265 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
266 "DESC 'Access Control List' "
267 "EQUALITY caseIgnoreMatch "
268 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
269 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
270 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
271 "DESC 'Allowed set of deprecated features' "
272 "EQUALITY caseIgnoreMatch "
273 "SYNTAX OMsDirectoryString )", NULL, NULL },
274 { "argsfile", "file", 2, 2, 0, ARG_STRING,
275 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
276 "DESC 'File for slapd command line options' "
277 "EQUALITY caseIgnoreMatch "
278 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
279 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
280 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString )", NULL, NULL },
283 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
284 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
285 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
286 "DESC 'OpenLDAP attributeTypes' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
290 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
291 #ifdef SLAP_AUTH_REWRITE
292 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
296 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
299 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
300 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
303 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
304 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
307 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
308 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
309 "DESC 'A type of backend' "
310 "EQUALITY caseIgnoreMatch "
311 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
313 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
314 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
315 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
316 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
317 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
318 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
319 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
320 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
321 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
322 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
323 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
324 "DESC 'The backend type for a database instance' "
325 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
326 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
327 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
328 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
329 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
330 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
331 "EQUALITY caseIgnoreMatch "
332 "SYNTAX OMsDirectoryString )", NULL, NULL },
333 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
334 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
335 "DESC 'OpenLDAP DIT content rules' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
339 { "gentlehup", "on|off", 2, 2, 0,
341 ARG_ON_OFF, &global_gentlehup,
345 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
346 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
347 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
348 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
349 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
350 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
351 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
352 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
353 { "include", "file", 2, 2, 0, ARG_MAGIC,
354 &config_include, NULL, NULL, NULL },
355 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
356 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
357 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
358 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
359 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
360 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
361 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
362 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
363 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
364 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
365 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
366 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
367 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
368 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
369 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
370 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
371 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
372 "EQUALITY caseIgnoreMatch "
373 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
374 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
375 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
376 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
377 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
378 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
379 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
380 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
381 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
382 "EQUALITY caseIgnoreMatch "
383 "SYNTAX OMsDirectoryString )", NULL, NULL },
384 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
385 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
386 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
387 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
388 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
389 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
390 { "moduleload", "file", 2, 0, 0,
392 ARG_MAGIC|CFG_MODLOAD, &config_generic,
396 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
397 "EQUALITY caseIgnoreMatch "
398 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
399 { "modulepath", "path", 2, 2, 0,
401 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
405 "( OLcfgGlAt:31 NAME 'olcModulePath' "
406 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
407 { "monitoring", "TRUE|FALSE", 2, 2, 0,
408 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
409 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
410 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
411 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
412 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
413 "DESC 'OpenLDAP object classes' "
414 "EQUALITY caseIgnoreMatch "
415 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
417 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
418 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
419 "EQUALITY caseIgnoreMatch "
420 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
421 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
422 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
423 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
424 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
425 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
426 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
427 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
428 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
429 "EQUALITY caseIgnoreMatch "
430 "SYNTAX OMsDirectoryString )", NULL, NULL },
431 { "pidfile", "file", 2, 2, 0, ARG_STRING,
432 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
433 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
434 { "plugin", NULL, 0, 0, 0,
436 ARG_MAGIC|CFG_PLUGIN, &config_generic,
440 "( OLcfgGlAt:38 NAME 'olcPlugin' "
441 "EQUALITY caseIgnoreMatch "
442 "SYNTAX OMsDirectoryString )", NULL, NULL },
443 { "pluginlog", "filename", 2, 2, 0,
445 ARG_STRING, &slapi_log_file,
449 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
450 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
451 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
452 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
453 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
454 { "referral", "url", 2, 2, 0, ARG_MAGIC,
455 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
456 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
457 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
458 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
459 "EQUALITY caseIgnoreMatch "
460 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
461 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLICA_ARGSFILE,
462 &config_generic, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
463 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
464 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLICA_PIDFILE,
465 &config_generic, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
466 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
467 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|ARG_INT|CFG_REPLICATIONINTERVAL,
468 &config_generic, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
469 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
470 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
471 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
472 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
473 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
474 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
475 "EQUALITY caseIgnoreMatch "
476 "SYNTAX OMsDirectoryString )", NULL, NULL },
477 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
478 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
479 "EQUALITY caseIgnoreMatch "
480 "SYNTAX OMsDirectoryString )", NULL, NULL },
481 { "reverse-lookup", "on|off", 2, 2, 0,
482 #ifdef SLAPD_RLOOKUPS
483 ARG_ON_OFF, &use_reverse_lookup,
487 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
488 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
489 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
490 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
491 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
492 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
493 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
494 "EQUALITY caseIgnoreMatch "
495 "SYNTAX OMsDirectoryString )", NULL, NULL },
496 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
497 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
498 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
499 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
500 &config_generic, NULL, NULL, NULL },
501 { "sasl-host", "host", 2, 2, 0,
502 #ifdef HAVE_CYRUS_SASL
503 ARG_STRING|ARG_UNIQUE, &global_host,
507 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
508 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
509 { "sasl-realm", "realm", 2, 2, 0,
510 #ifdef HAVE_CYRUS_SASL
511 ARG_STRING|ARG_UNIQUE, &global_realm,
515 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
516 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
517 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
518 &config_generic, NULL, NULL, NULL },
519 { "sasl-secprops", "properties", 2, 2, 0,
520 #ifdef HAVE_CYRUS_SASL
521 ARG_MAGIC|CFG_SASLSECP, &config_generic,
525 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
526 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
527 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
528 &config_generic, NULL, NULL, NULL },
529 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
530 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
531 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
532 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
533 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
534 "EQUALITY caseIgnoreMatch "
535 "SYNTAX OMsDirectoryString )", NULL, NULL },
536 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
537 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
538 "EQUALITY caseIgnoreMatch "
539 "SYNTAX OMsDirectoryString )", NULL, NULL },
540 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
541 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
542 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
543 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
544 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
545 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
546 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
547 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
548 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
549 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
550 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
551 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
552 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
553 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
554 "EQUALITY distinguishedNameMatch "
555 "SYNTAX OMsDN )", NULL, NULL },
556 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
557 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
558 "EQUALITY caseIgnoreMatch "
559 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
560 { "threads", "count", 2, 2, 0,
564 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
566 "( OLcfgGlAt:66 NAME 'olcThreads' "
567 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
568 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
569 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
570 "SYNTAX OMsDirectoryString )", NULL, NULL },
571 { "TLSCACertificateFile", NULL, 0, 0, 0,
573 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
577 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
578 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
579 { "TLSCACertificatePath", NULL, 0, 0, 0,
581 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
585 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
586 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
587 { "TLSCertificateFile", NULL, 0, 0, 0,
589 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
593 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
594 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
595 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
597 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
601 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
602 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
603 { "TLSCipherSuite", NULL, 0, 0, 0,
605 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
609 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
610 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
611 { "TLSCRLCheck", NULL, 0, 0, 0,
612 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
613 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
617 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
618 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
619 { "TLSRandFile", NULL, 0, 0, 0,
621 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
625 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
626 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
627 { "TLSVerifyClient", NULL, 0, 0, 0,
629 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
633 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
634 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
635 { "TLSDHParamFile", NULL, 0, 0, 0,
637 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
641 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
642 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
643 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
644 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
645 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
646 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
647 NULL, NULL, NULL, NULL },
648 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
649 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
650 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
651 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
652 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
653 "EQUALITY caseIgnoreMatch "
654 "SUP labeledURI )", NULL, NULL },
655 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
656 NULL, NULL, NULL, NULL }
659 /* Routines to check if a child can be added to this type */
660 static ConfigLDAPadd cfAddSchema, cfAddDatabase,
661 cfAddBackend, cfAddModule, cfAddOverlay;
663 /* NOTE: be careful when defining array members
664 * that can be conditionally compiled */
665 #define CFOC_GLOBAL cf_ocs[1]
666 #define CFOC_SCHEMA cf_ocs[2]
667 #define CFOC_BACKEND cf_ocs[3]
668 #define CFOC_DATABASE cf_ocs[4]
669 #define CFOC_OVERLAY cf_ocs[5]
670 #define CFOC_FRONTEND cf_ocs[6]
672 #define CFOC_MODULE cf_ocs[7]
673 #endif /* SLAPD_MODULES */
675 static ConfigOCs cf_ocs[] = {
678 "DESC 'OpenLDAP configuration object' "
679 "ABSTRACT SUP top )", Cft_Abstract, NULL },
682 "DESC 'OpenLDAP Global configuration options' "
683 "SUP olcConfig STRUCTURAL "
684 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
685 "olcAttributeOptions $ olcAuthIDRewrite $ "
686 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
687 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
688 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
689 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
690 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
692 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
693 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
694 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
696 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
697 "olcSecurity $ olcServerID $ olcSizeLimit $ "
698 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
699 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
700 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
701 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
702 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
704 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
705 "olcDitContentRules ) )", Cft_Global },
707 "NAME 'olcSchemaConfig' "
708 "DESC 'OpenLDAP schema object' "
709 "SUP olcConfig STRUCTURAL "
710 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
711 "olcObjectClasses $ olcDitContentRules ) )",
712 Cft_Schema, NULL, cfAddSchema },
714 "NAME 'olcBackendConfig' "
715 "DESC 'OpenLDAP Backend-specific options' "
716 "SUP olcConfig STRUCTURAL "
717 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
719 "NAME 'olcDatabaseConfig' "
720 "DESC 'OpenLDAP Database-specific options' "
721 "SUP olcConfig STRUCTURAL "
723 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
724 "olcLastMod $ olcLimits $ "
725 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
726 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
727 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
728 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
729 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
731 Cft_Database, NULL, cfAddDatabase },
733 "NAME 'olcOverlayConfig' "
734 "DESC 'OpenLDAP Overlay-specific options' "
735 "SUP olcConfig STRUCTURAL "
736 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
737 /* This should be STRUCTURAL like all the other database classes, but
738 * that would mean inheriting all of the olcDatabaseConfig attributes,
739 * which causes them to be merged twice in config_build_entry.
742 "NAME 'olcFrontendConfig' "
743 "DESC 'OpenLDAP frontend configuration' "
745 "MAY olcDefaultSearchBase )",
746 Cft_Database, NULL, NULL },
749 "NAME 'olcModuleList' "
750 "DESC 'OpenLDAP dynamic module info' "
751 "SUP olcConfig STRUCTURAL "
752 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
753 Cft_Module, NULL, cfAddModule },
758 typedef struct ServerID {
759 struct ServerID *si_next;
760 struct berval si_url;
764 static ServerID *sid_list;
767 config_generic(ConfigArgs *c) {
770 if ( c->op == SLAP_CONFIG_EMIT ) {
774 c->value_int = ldap_pvt_thread_get_concurrency();
777 c->value_int = connection_pool_max;
780 c->value_int = slap_tool_thread_max;
784 c->value_string = ch_strdup( passwd_salt );
789 if ( c->be->be_limits ) {
794 for ( i=0; c->be->be_limits[i]; i++ ) {
795 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
796 if ( bv.bv_len >= sizeof( buf ) ) {
797 ber_bvarray_free_x( c->rvalue_vals, NULL );
798 c->rvalue_vals = NULL;
802 bv.bv_val = buf + bv.bv_len;
803 limits_unparse( c->be->be_limits[i], &bv,
804 sizeof( buf ) - ( bv.bv_val - buf ) );
805 bv.bv_len += bv.bv_val - buf;
807 value_add_one( &c->rvalue_vals, &bv );
810 if ( !c->rvalue_vals ) rc = 1;
813 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
814 SLAP_RESTRICT_OP_WRITES;
817 c->value_string = ch_strdup( slap_sasl_getpolicy());
820 slap_sasl_regexp_unparse( &c->rvalue_vals );
821 if ( !c->rvalue_vals ) rc = 1;
823 #ifdef HAVE_CYRUS_SASL
825 struct berval bv = BER_BVNULL;
826 slap_sasl_secprops_unparse( &bv );
827 if ( !BER_BVISNULL( &bv )) {
828 ber_bvarray_add( &c->rvalue_vals, &bv );
836 c->value_int = c->be->be_max_deref_depth;
839 if ( SLAP_DBHIDDEN( c->be )) {
846 ConfigFile *cf = c->private;
848 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
849 else if ( cf->c_om_head )
850 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
852 if ( !c->rvalue_vals )
857 ad_unparse_options( &c->rvalue_vals );
860 ConfigFile *cf = c->private;
862 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
863 else if ( cf->c_oc_head )
864 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
866 if ( !c->rvalue_vals )
871 ConfigFile *cf = c->private;
873 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
874 else if ( cf->c_at_head )
875 at_unparse( &c->rvalue_vals, cf->c_at_head,
877 if ( !c->rvalue_vals )
882 ConfigFile *cf = c->private;
884 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
885 else if ( cf->c_cr_head )
886 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
888 if ( !c->rvalue_vals )
895 char *src, *dst, ibuf[11];
896 struct berval bv, abv;
897 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
898 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
899 if ( abv.bv_len >= sizeof( ibuf ) ) {
900 ber_bvarray_free_x( c->rvalue_vals, NULL );
901 c->rvalue_vals = NULL;
905 acl_unparse( a, &bv );
906 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
907 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
908 /* Turn TAB / EOL into plain space */
909 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
910 if (isspace((unsigned char)*src)) *dst++ = ' ';
914 if (dst[-1] == ' ') {
918 abv.bv_len = dst - abv.bv_val;
919 ber_bvarray_add( &c->rvalue_vals, &abv );
924 case CFG_REPLICA_ARGSFILE:
925 if ( c->be->be_replica_argsfile )
926 c->value_string = ch_strdup( c->be->be_replica_argsfile );
928 case CFG_REPLICA_PIDFILE:
929 if ( c->be->be_replica_pidfile )
930 c->value_string = ch_strdup( c->be->be_replica_pidfile );
932 case CFG_REPLICATIONINTERVAL:
933 if ( c->be->be_replicationinterval > 0 ) {
934 c->value_int = c->be->be_replicationinterval;
940 if ( c->be->be_replogfile )
941 c->value_string = ch_strdup( c->be->be_replogfile );
944 ConfigFile *cf = c->private;
945 if ( cf->c_dseFiles ) {
946 value_add( &c->rvalue_vals, cf->c_dseFiles );
958 for ( si = sid_list; si; si=si->si_next ) {
959 if ( !BER_BVISEMPTY( &si->si_url )) {
960 bv.bv_len = si->si_url.bv_len + 6;
961 bv.bv_val = ch_malloc( bv.bv_len );
962 sprintf( bv.bv_val, "%d %s", si->si_num,
964 ber_bvarray_add( &c->rvalue_vals, &bv );
968 bv.bv_len = sprintf( buf, "%d", si->si_num );
969 value_add_one( &c->rvalue_vals, &bv );
978 c->value_string = ch_strdup( logfileName );
983 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
986 if ( SLAP_SHADOW(c->be))
987 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
992 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
994 case CFG_SSTR_IF_MAX:
995 c->value_int = index_substr_if_maxlen;
997 case CFG_SSTR_IF_MIN:
998 c->value_int = index_substr_if_minlen;
1000 #ifdef SLAPD_MODULES
1002 ModPaths *mp = c->private;
1005 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1008 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1009 SLAP_X_ORDERED_FMT "%s", i,
1010 mp->mp_loads[i].bv_val );
1011 if ( bv.bv_len >= sizeof( c->log ) ) {
1012 ber_bvarray_free_x( c->rvalue_vals, NULL );
1013 c->rvalue_vals = NULL;
1016 value_add_one( &c->rvalue_vals, &bv );
1020 rc = c->rvalue_vals ? 0 : 1;
1024 ModPaths *mp = c->private;
1025 if ( !BER_BVISNULL( &mp->mp_path ))
1026 value_add_one( &c->rvalue_vals, &mp->mp_path );
1028 rc = c->rvalue_vals ? 0 : 1;
1034 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1035 if ( !c->rvalue_vals ) rc = 1;
1038 #ifdef SLAP_AUTH_REWRITE
1040 if ( authz_rewrites ) {
1041 struct berval bv, idx;
1046 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1047 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1048 if ( idx.bv_len >= sizeof( ibuf ) ) {
1049 ber_bvarray_free_x( c->rvalue_vals, NULL );
1050 c->rvalue_vals = NULL;
1053 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1054 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1055 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1056 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1057 authz_rewrites[i].bv_val,
1058 authz_rewrites[i].bv_len + 1 );
1059 ber_bvarray_add( &c->rvalue_vals, &bv );
1062 if ( !c->rvalue_vals ) rc = 1;
1069 } else if ( c->op == LDAP_MOD_DELETE ) {
1072 /* single-valued attrs, no-ops */
1080 case CFG_MIRRORMODE:
1081 case CFG_MONITORING:
1083 case CFG_SSTR_IF_MAX:
1084 case CFG_SSTR_IF_MIN:
1087 /* no-ops, requires slapd restart */
1092 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1096 ch_free( passwd_salt );
1100 case CFG_REPLICA_ARGSFILE:
1101 ch_free( c->be->be_replica_argsfile );
1102 c->be->be_replica_argsfile = NULL;
1105 case CFG_REPLICA_PIDFILE:
1106 ch_free( c->be->be_replica_pidfile );
1107 c->be->be_replica_pidfile = NULL;
1110 case CFG_REPLICATIONINTERVAL:
1111 c->be->be_replicationinterval = 0;
1115 ch_free( c->be->be_replogfile );
1116 c->be->be_replogfile = NULL;
1120 ch_free( logfileName );
1124 case CFG_SERVERID: {
1126 ServerID *si, **sip;
1128 for ( i=0, si = sid_list, sip = &sid_list;
1129 si; si = *sip, i++ ) {
1130 if ( c->valx == -1 || i == c->valx ) {
1142 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1146 if ( c->valx < 0 ) {
1148 if ( c->be == frontendDB )
1151 end = frontendDB->be_acl;
1152 acl_destroy( c->be->be_acl, end );
1153 c->be->be_acl = end;
1156 AccessControl **prev, *a;
1158 for (i=0, prev = &c->be->be_acl; i < c->valx;
1161 prev = &a->acl_next;
1164 *prev = a->acl_next;
1170 CfEntryInfo *ce = c->ca_entry->e_private;
1171 /* can't modify the hardcoded schema */
1172 if ( ce->ce_parent->ce_type == Cft_Global )
1176 if ( c->valx < 0 ) {
1179 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1181 if ( oc == cfn->c_oc_tail )
1184 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1186 ObjectClass *oc, *prev = NULL;
1189 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1194 if ( cfn->c_oc_tail == oc ) {
1195 cfn->c_oc_tail = prev;
1197 if ( cfn->c_oc_head == oc ) {
1199 cfn->c_oc_head = oc;
1205 CfEntryInfo *ce = c->ca_entry->e_private;
1206 /* can't modify the hardcoded schema */
1207 if ( ce->ce_parent->ce_type == Cft_Global )
1211 if ( c->valx < 0 ) {
1214 for( at = cfn->c_at_head; at; at_next( &at )) {
1216 if ( at == cfn->c_at_tail )
1219 cfn->c_at_head = cfn->c_at_tail = NULL;
1221 AttributeType *at, *prev = NULL;
1224 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1229 if ( cfn->c_at_tail == at ) {
1230 cfn->c_at_tail = prev;
1232 if ( cfn->c_at_head == at ) {
1234 cfn->c_at_head = at;
1240 /* FIXME: there is no limits_free function */
1242 /* FIXME: there is no ad_option_free function */
1244 /* FIXME: there is no way to remove attributes added by
1258 if(!(c->bi = backend_info(c->argv[1]))) {
1259 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1260 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1261 c->log, c->msg, c->argv[1] );
1268 /* NOTE: config is always the first backend!
1270 if ( !strcasecmp( c->argv[1], "config" )) {
1271 c->be = LDAP_STAILQ_FIRST(&backendDB);
1272 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1275 c->be = backend_db_init(c->argv[1], NULL, c->valx);
1277 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1278 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1279 c->log, c->msg, c->argv[1] );
1286 ldap_pvt_thread_set_concurrency(c->value_int);
1290 if ( c->value_int < 2 ) {
1291 snprintf( c->msg, sizeof( c->msg ),
1292 "threads=%d smaller than minimum value 2",
1294 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1295 c->log, c->msg, 0 );
1298 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1299 snprintf( c->msg, sizeof( c->msg ),
1300 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1301 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1302 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1303 c->log, c->msg, 0 );
1305 if ( slapMode & SLAP_SERVER_MODE )
1306 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1307 connection_pool_max = c->value_int; /* save for reference */
1311 if ( slapMode & SLAP_TOOL_MODE )
1312 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1313 slap_tool_thread_max = c->value_int; /* save for reference */
1317 if ( passwd_salt ) ch_free( passwd_salt );
1318 passwd_salt = c->value_string;
1319 lutil_salt_format(passwd_salt);
1323 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1329 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1331 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1335 ch_free(c->value_string);
1336 if (slap_sasl_setpolicy( c->argv[1] )) {
1337 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1338 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1339 c->log, c->msg, c->argv[1] );
1345 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1349 #ifdef HAVE_CYRUS_SASL
1352 char *txt = slap_sasl_secprops( c->argv[1] );
1354 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1356 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1364 c->be->be_max_deref_depth = c->value_int;
1370 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1372 if(parse_oidm(c, 1, &om))
1374 if (!cfn->c_om_head) cfn->c_om_head = om;
1375 cfn->c_om_tail = om;
1380 ObjectClass *oc, *prev;
1382 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1384 if ( c->valx < 0 ) {
1385 prev = cfn->c_oc_tail;
1388 /* If adding anything after the first, prev is easy */
1391 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1396 /* If adding the first, and head exists, find its prev */
1397 if (cfn->c_oc_head) {
1398 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1403 /* else prev is NULL, append to end of global list */
1405 if(parse_oc(c, &oc, prev)) return(1);
1406 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1407 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1412 AttributeType *at, *prev;
1414 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1416 if ( c->valx < 0 ) {
1417 prev = cfn->c_at_tail;
1420 /* If adding anything after the first, prev is easy */
1423 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1428 /* If adding the first, and head exists, find its prev */
1429 if (cfn->c_at_head) {
1430 for ( at_start( &at ); at != cfn->c_at_head; ) {
1435 /* else prev is NULL, append to end of global list */
1437 if(parse_at(c, &at, prev)) return(1);
1438 if (!cfn->c_at_head) cfn->c_at_head = at;
1439 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1446 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1448 if(parse_cr(c, &cr)) return(1);
1449 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1450 cfn->c_cr_tail = cr;
1455 ad_define_option(NULL, NULL, 0);
1456 for(i = 1; i < c->argc; i++)
1457 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1462 /* Don't append to the global ACL if we're on a specific DB */
1464 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1467 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1471 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1476 case CFG_REPLICA_ARGSFILE:
1477 if(SLAP_MONITOR(c->be)) {
1478 Debug(LDAP_DEBUG_ANY, "%s: "
1479 "\"replica-argsfile\" should not be used "
1480 "inside monitor database\n",
1482 /* FIXME: should this be an error? */
1486 if ( c->be->be_replica_argsfile != NULL ) {
1488 Debug(LDAP_DEBUG_ANY, "%s: "
1489 "\"replica-argsfile\" already provided; "
1490 "replacing \"%s\" with \"%s\".\n",
1491 c->log, c->be->be_replica_argsfile, c->value_string );
1492 ch_free( c->be->be_replica_argsfile );
1495 c->be->be_replica_argsfile = c->value_string;
1498 case CFG_REPLICA_PIDFILE:
1499 if(SLAP_MONITOR(c->be)) {
1500 Debug(LDAP_DEBUG_ANY, "%s: "
1501 "\"replica-pidfile\" should not be used "
1502 "inside monitor database\n",
1504 /* FIXME: should this be an error? */
1508 if ( c->be->be_replica_pidfile != NULL ) {
1510 Debug(LDAP_DEBUG_ANY, "%s: "
1511 "\"replica-pidfile\" already provided; "
1512 "replacing \"%s\" with \"%s\".\n",
1513 c->log, c->be->be_replica_pidfile, c->value_string );
1514 ch_free( c->be->be_replica_pidfile );
1517 c->be->be_replica_pidfile = c->value_string;
1520 case CFG_REPLICATIONINTERVAL:
1521 if(SLAP_MONITOR(c->be)) {
1522 Debug(LDAP_DEBUG_ANY, "%s: "
1523 "\"replicationinterval\" should not be used "
1524 "inside monitor database\n",
1526 /* FIXME: should this be an error? */
1530 c->be->be_replicationinterval = c->value_int;
1534 if(SLAP_MONITOR(c->be)) {
1535 Debug(LDAP_DEBUG_ANY, "%s: "
1536 "\"replogfile\" should not be used "
1537 "inside monitor database\n",
1539 /* FIXME: should this be an error? */
1543 if ( c->be->be_replogfile != NULL ) {
1545 Debug(LDAP_DEBUG_ANY, "%s: "
1546 "\"replogfile\" already provided; "
1547 "replacing \"%s\" with \"%s\".\n",
1548 c->log, c->be->be_replogfile, c->value_string );
1549 ch_free( c->be->be_replogfile );
1552 c->be->be_replogfile = c->value_string;
1556 if(root_dse_read_file(c->argv[1])) {
1557 snprintf( c->msg, sizeof( c->msg ), "<%s> could not read file", c->argv[0] );
1558 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1559 c->log, c->msg, c->argv[1] );
1564 ber_str2bv( c->argv[1], 0, 1, &bv );
1565 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1567 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1573 ServerID *si, **sip;
1575 int num = atoi( c->argv[1] );
1576 if ( num < 0 || num > SLAP_SYNC_SID_MAX ) {
1577 snprintf( c->msg, sizeof( c->msg ),
1578 "<%s> illegal server ID", c->argv[0] );
1579 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1580 c->log, c->msg, c->argv[1] );
1583 /* only one value allowed if no URL is given */
1584 if ( c->argc > 2 ) {
1587 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1588 snprintf( c->msg, sizeof( c->msg ),
1589 "<%s> only one server ID allowed now", c->argv[0] );
1590 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1591 c->log, c->msg, c->argv[1] );
1595 if ( ldap_url_parse( c->argv[2], &lud )) {
1596 snprintf( c->msg, sizeof( c->msg ),
1597 "<%s> invalid URL", c->argv[0] );
1598 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1599 c->log, c->msg, c->argv[2] );
1602 len = strlen( c->argv[2] );
1603 si = ch_malloc( sizeof(ServerID) + len + 1 );
1604 si->si_url.bv_val = (char *)(si+1);
1605 si->si_url.bv_len = len;
1606 strcpy( si->si_url.bv_val, c->argv[2] );
1609 snprintf( c->msg, sizeof( c->msg ),
1610 "<%s> unqualified server ID not allowed now", c->argv[0] );
1611 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1612 c->log, c->msg, c->argv[1] );
1615 si = ch_malloc( sizeof(ServerID) );
1616 slap_serverID = num;
1620 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1623 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1624 /* If hostname is empty, or is localhost, or matches
1625 * our hostname, this serverID refers to this host.
1626 * Compare it against listeners and ports.
1628 if ( !lud->lud_host || !lud->lud_host[0] ||
1629 !strncasecmp("localhost", lud->lud_host,
1630 STRLENOF("localhost")) ||
1631 !strcasecmp( global_host, lud->lud_host )) {
1632 Listener **l = slapd_get_listeners();
1635 for ( i=0; l[i]; i++ ) {
1638 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1640 if ( strcasecmp( lud->lud_scheme,
1643 if ( lud->lud_port != lu2->lud_port )
1645 /* Listener on ANY address */
1646 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1650 /* URL on ANY address */
1651 if ( !lud->lud_host || !lud->lud_host[0] ) {
1655 /* Listener has specific host, must
1658 if ( !strcasecmp( lud->lud_host,
1664 ldap_free_urldesc( lu2 );
1666 slap_serverID = si->si_num;
1673 ldap_free_urldesc( lud );
1678 if ( logfileName ) ch_free( logfileName );
1679 logfileName = c->value_string;
1680 logfile = fopen(logfileName, "w");
1681 if(logfile) lutil_debug_file(logfile);
1685 if(SLAP_NOLASTMODCMD(c->be)) {
1686 snprintf( c->msg, sizeof( c->msg ), "<%s> not available for %s database",
1687 c->argv[0], c->be->bd_info->bi_type );
1688 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1689 c->log, c->msg, 0 );
1693 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1695 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1698 case CFG_MIRRORMODE:
1699 if(!SLAP_SHADOW(c->be)) {
1700 snprintf( c->msg, sizeof( c->msg ), "<%s> database is not a shadow",
1702 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1703 c->log, c->msg, 0 );
1707 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1709 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1712 case CFG_MONITORING:
1714 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1716 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1721 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1723 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1726 case CFG_SSTR_IF_MAX:
1727 if (c->value_int < index_substr_if_minlen) {
1728 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1729 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1730 c->log, c->msg, c->value_int );
1733 index_substr_if_maxlen = c->value_int;
1736 case CFG_SSTR_IF_MIN:
1737 if (c->value_int > index_substr_if_maxlen) {
1738 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1739 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1740 c->log, c->msg, c->value_int );
1743 index_substr_if_minlen = c->value_int;
1746 #ifdef SLAPD_MODULES
1748 /* If we're just adding a module on an existing modpath,
1749 * make sure we've selected the current path.
1751 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1752 modcur = c->private;
1753 /* This should never fail */
1754 if ( module_path( modcur->mp_path.bv_val )) {
1755 snprintf( c->msg, sizeof( c->msg ), "<%s> module path no longer valid",
1757 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1758 c->log, c->msg, modcur->mp_path.bv_val );
1762 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1764 /* Record this load on the current path */
1768 if ( c->op == SLAP_CONFIG_ADD ) {
1769 ptr = c->line + STRLENOF("moduleload");
1770 while (!isspace((unsigned char) *ptr)) ptr++;
1771 while (isspace((unsigned char) *ptr)) ptr++;
1775 ber_str2bv(ptr, 0, 1, &bv);
1776 ber_bvarray_add( &modcur->mp_loads, &bv );
1778 /* Check for any new hardcoded schema */
1779 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1780 config_check_schema( NULL, &cfBackInfo );
1785 if(module_path(c->argv[1])) return(1);
1786 /* Record which path was used with each module */
1790 if (!modpaths.mp_loads) {
1793 mp = ch_malloc( sizeof( ModPaths ));
1794 modlast->mp_next = mp;
1796 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1798 mp->mp_loads = NULL;
1809 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1811 slapi_plugins_used++;
1815 #ifdef SLAP_AUTH_REWRITE
1820 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1823 if ( c->argc > 1 ) {
1826 /* quote all args but the first */
1827 line = ldap_charray2str( c->argv, "\" \"" );
1828 ber_str2bv( line, 0, 0, &bv );
1829 s = ber_bvchr( &bv, '"' );
1830 assert( s != NULL );
1831 /* move the trailing quote of argv[0] to the end */
1832 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1833 bv.bv_val[ bv.bv_len - 1 ] = '"';
1836 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1839 ber_bvarray_add( &authz_rewrites, &bv );
1846 Debug( LDAP_DEBUG_ANY,
1847 "%s: unknown CFG_TYPE %d.\n",
1848 c->log, c->type, 0 );
1857 config_fname(ConfigArgs *c) {
1858 if(c->op == SLAP_CONFIG_EMIT) {
1860 ConfigFile *cf = c->private;
1861 value_add_one( &c->rvalue_vals, &cf->c_file );
1870 config_cfdir(ConfigArgs *c) {
1871 if(c->op == SLAP_CONFIG_EMIT) {
1872 if ( !BER_BVISEMPTY( &cfdir )) {
1873 value_add_one( &c->rvalue_vals, &cfdir );
1882 config_search_base(ConfigArgs *c) {
1883 if(c->op == SLAP_CONFIG_EMIT) {
1885 if (!BER_BVISEMPTY(&default_search_base)) {
1886 value_add_one(&c->rvalue_vals, &default_search_base);
1887 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1891 } else if( c->op == LDAP_MOD_DELETE ) {
1892 ch_free( default_search_base.bv_val );
1893 ch_free( default_search_nbase.bv_val );
1894 BER_BVZERO( &default_search_base );
1895 BER_BVZERO( &default_search_nbase );
1899 if(c->bi || c->be != frontendDB) {
1900 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1901 "prior to any backend or database definition\n",
1906 if(default_search_nbase.bv_len) {
1907 free(default_search_base.bv_val);
1908 free(default_search_nbase.bv_val);
1911 default_search_base = c->value_dn;
1912 default_search_nbase = c->value_ndn;
1917 config_passwd_hash(ConfigArgs *c) {
1919 if (c->op == SLAP_CONFIG_EMIT) {
1921 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1922 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1923 value_add_one(&c->rvalue_vals, &bv);
1926 } else if ( c->op == LDAP_MOD_DELETE ) {
1927 if ( c->valx < 0 ) {
1928 ldap_charray_free( default_passwd_hash );
1929 default_passwd_hash = NULL;
1932 ch_free( default_passwd_hash[i] );
1933 for (; default_passwd_hash[i]; i++ )
1934 default_passwd_hash[i] = default_passwd_hash[i+1];
1938 if(default_passwd_hash) {
1939 Debug(LDAP_DEBUG_ANY, "%s: "
1940 "already set default password_hash\n",
1944 for(i = 1; i < c->argc; i++) {
1945 if(!lutil_passwd_scheme(c->argv[i])) {
1946 snprintf( c->msg, sizeof( c->msg ), "<%s> scheme not available", c->argv[0] );
1947 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1948 c->log, c->msg, c->argv[i]);
1950 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1952 if(!default_passwd_hash) {
1953 snprintf( c->msg, sizeof( c->msg ), "<%s> no valid hashes found", c->argv[0] );
1954 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1955 c->log, c->msg, 0 );
1963 config_schema_dn(ConfigArgs *c) {
1964 if ( c->op == SLAP_CONFIG_EMIT ) {
1966 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1967 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1968 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1972 } else if ( c->op == LDAP_MOD_DELETE ) {
1973 ch_free( c->be->be_schemadn.bv_val );
1974 ch_free( c->be->be_schemandn.bv_val );
1975 BER_BVZERO( &c->be->be_schemadn );
1976 BER_BVZERO( &c->be->be_schemandn );
1979 ch_free( c->be->be_schemadn.bv_val );
1980 ch_free( c->be->be_schemandn.bv_val );
1981 c->be->be_schemadn = c->value_dn;
1982 c->be->be_schemandn = c->value_ndn;
1987 config_sizelimit(ConfigArgs *c) {
1989 struct slap_limits_set *lim = &c->be->be_def_limit;
1990 if (c->op == SLAP_CONFIG_EMIT) {
1995 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
1996 if ( !BER_BVISEMPTY( &bv ))
1997 value_add_one( &c->rvalue_vals, &bv );
2001 } else if ( c->op == LDAP_MOD_DELETE ) {
2002 /* Reset to defaults */
2003 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2004 lim->lms_s_hard = 0;
2005 lim->lms_s_unchecked = -1;
2007 lim->lms_s_pr_hide = 0;
2008 lim->lms_s_pr_total = 0;
2011 for(i = 1; i < c->argc; i++) {
2012 if(!strncasecmp(c->argv[i], "size", 4)) {
2013 rc = limits_parse_one(c->argv[i], lim);
2015 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
2016 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2017 c->log, c->msg, c->argv[i]);
2021 if(!strcasecmp(c->argv[i], "unlimited")) {
2022 lim->lms_s_soft = -1;
2024 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2025 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
2026 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2027 c->log, c->msg, c->argv[i]);
2031 lim->lms_s_hard = 0;
2038 config_timelimit(ConfigArgs *c) {
2040 struct slap_limits_set *lim = &c->be->be_def_limit;
2041 if (c->op == SLAP_CONFIG_EMIT) {
2046 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2047 if ( !BER_BVISEMPTY( &bv ))
2048 value_add_one( &c->rvalue_vals, &bv );
2052 } else if ( c->op == LDAP_MOD_DELETE ) {
2053 /* Reset to defaults */
2054 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2055 lim->lms_t_hard = 0;
2058 for(i = 1; i < c->argc; i++) {
2059 if(!strncasecmp(c->argv[i], "time", 4)) {
2060 rc = limits_parse_one(c->argv[i], lim);
2062 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
2063 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2064 c->log, c->msg, c->argv[i]);
2068 if(!strcasecmp(c->argv[i], "unlimited")) {
2069 lim->lms_t_soft = -1;
2071 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2072 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
2073 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2074 c->log, c->msg, c->argv[i]);
2078 lim->lms_t_hard = 0;
2085 config_overlay(ConfigArgs *c) {
2086 if (c->op == SLAP_CONFIG_EMIT) {
2088 } else if ( c->op == LDAP_MOD_DELETE ) {
2091 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2094 Debug( LDAP_DEBUG_ANY,
2095 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2096 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2098 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
2105 config_subordinate(ConfigArgs *c)
2111 case SLAP_CONFIG_EMIT:
2112 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2115 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2116 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2119 value_add_one( &c->rvalue_vals, &bv );
2123 case LDAP_MOD_DELETE:
2124 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2125 glue_sub_del( c->be );
2127 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2132 case SLAP_CONFIG_ADD:
2133 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2134 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2141 config_suffix(ConfigArgs *c)
2144 struct berval pdn, ndn;
2145 char *notallowed = NULL;
2147 if ( c->be == frontendDB ) {
2148 notallowed = "frontend";
2150 } else if ( SLAP_MONITOR(c->be) ) {
2151 notallowed = "monitor";
2153 } else if ( SLAP_CONFIG(c->be) ) {
2154 notallowed = "config";
2157 if ( notallowed != NULL ) {
2158 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2162 case LDAP_MOD_DELETE:
2163 case LDAP_MOD_REPLACE:
2164 case LDAP_MOD_INCREMENT:
2165 case SLAP_CONFIG_ADD:
2166 if ( !BER_BVISNULL( &c->value_dn ) ) {
2167 snprintf( buf, sizeof( buf ), "<%s> ",
2168 c->value_dn.bv_val );
2171 Debug(LDAP_DEBUG_ANY,
2172 "%s: suffix %snot allowed in %s database.\n",
2173 c->log, buf, notallowed );
2176 case SLAP_CONFIG_EMIT:
2177 /* don't complain when emitting... */
2181 /* FIXME: don't know what values may be valid;
2182 * please remove assertion, or add legal values
2183 * to either block */
2191 if (c->op == SLAP_CONFIG_EMIT) {
2192 if ( c->be->be_suffix == NULL
2193 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2197 value_add( &c->rvalue_vals, c->be->be_suffix );
2198 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2201 } else if ( c->op == LDAP_MOD_DELETE ) {
2202 if ( c->valx < 0 ) {
2203 ber_bvarray_free( c->be->be_suffix );
2204 ber_bvarray_free( c->be->be_nsuffix );
2205 c->be->be_suffix = NULL;
2206 c->be->be_nsuffix = NULL;
2209 ch_free( c->be->be_suffix[i].bv_val );
2210 ch_free( c->be->be_nsuffix[i].bv_val );
2212 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2213 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2215 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2220 #ifdef SLAPD_MONITOR_DN
2221 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2222 snprintf( c->msg, sizeof( c->msg ), "<%s> DN is reserved for monitoring slapd",
2224 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2225 c->log, c->msg, SLAPD_MONITOR_DN);
2232 if (SLAP_DBHIDDEN( c->be ))
2235 tbe = select_backend(&ndn, 0, 0);
2237 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2243 BackendDB *b2 = tbe;
2245 /* Does tbe precede be? */
2246 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2249 char *type = tbe->bd_info->bi_type;
2251 if ( overlay_is_over( tbe ) ) {
2252 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2253 type = oi->oi_orig->bi_type;
2256 snprintf( c->msg, sizeof( c->msg ), "<%s> namingContext \"%s\" "
2257 "already served by a preceding %s database",
2258 c->argv[0], pdn.bv_val, type );
2259 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2260 c->log, c->msg, tbe->be_suffix[0].bv_val);
2266 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2267 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2268 "base provided \"%s\" (assuming okay)\n",
2269 c->log, default_search_base.bv_val, 0);
2271 ber_bvarray_add(&c->be->be_suffix, &pdn);
2272 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2277 config_rootdn(ConfigArgs *c) {
2278 if (c->op == SLAP_CONFIG_EMIT) {
2279 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2280 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2281 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2286 } else if ( c->op == LDAP_MOD_DELETE ) {
2287 ch_free( c->be->be_rootdn.bv_val );
2288 ch_free( c->be->be_rootndn.bv_val );
2289 BER_BVZERO( &c->be->be_rootdn );
2290 BER_BVZERO( &c->be->be_rootndn );
2293 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2294 ch_free( c->be->be_rootdn.bv_val );
2295 ch_free( c->be->be_rootndn.bv_val );
2297 c->be->be_rootdn = c->value_dn;
2298 c->be->be_rootndn = c->value_ndn;
2303 config_rootpw(ConfigArgs *c) {
2306 if (c->op == SLAP_CONFIG_EMIT) {
2307 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2308 /* don't copy, because "rootpw" is marked
2310 c->value_bv = c->be->be_rootpw;
2314 } else if ( c->op == LDAP_MOD_DELETE ) {
2315 ch_free( c->be->be_rootpw.bv_val );
2316 BER_BVZERO( &c->be->be_rootpw );
2320 tbe = select_backend(&c->be->be_rootndn, 0, 0);
2322 snprintf( c->msg, sizeof( c->msg ), "<%s> can only be set when rootdn is under suffix",
2324 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2328 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2329 ch_free( c->be->be_rootpw.bv_val );
2330 c->be->be_rootpw = c->value_bv;
2335 config_restrict(ConfigArgs *c) {
2336 slap_mask_t restrictops = 0;
2338 slap_verbmasks restrictable_ops[] = {
2339 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2340 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2341 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2342 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2343 { BER_BVC("modrdn"), 0 },
2344 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2345 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2346 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2347 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2348 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2349 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2350 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2351 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2352 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2353 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2354 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2358 if (c->op == SLAP_CONFIG_EMIT) {
2359 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2361 } else if ( c->op == LDAP_MOD_DELETE ) {
2363 c->be->be_restrictops = 0;
2365 restrictops = verb_to_mask( c->line, restrictable_ops );
2366 c->be->be_restrictops ^= restrictops;
2370 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2372 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown operation", c->argv[0] );
2373 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2374 c->log, c->msg, c->argv[i]);
2377 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2378 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2379 c->be->be_restrictops |= restrictops;
2384 config_allows(ConfigArgs *c) {
2385 slap_mask_t allows = 0;
2387 slap_verbmasks allowable_ops[] = {
2388 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2389 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2390 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2391 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2392 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2395 if (c->op == SLAP_CONFIG_EMIT) {
2396 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2397 } else if ( c->op == LDAP_MOD_DELETE ) {
2401 allows = verb_to_mask( c->line, allowable_ops );
2402 global_allows ^= allows;
2406 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2408 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2409 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2410 c->log, c->msg, c->argv[i]);
2413 global_allows |= allows;
2418 config_disallows(ConfigArgs *c) {
2419 slap_mask_t disallows = 0;
2421 slap_verbmasks disallowable_ops[] = {
2422 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2423 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2424 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2425 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2428 if (c->op == SLAP_CONFIG_EMIT) {
2429 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2430 } else if ( c->op == LDAP_MOD_DELETE ) {
2432 global_disallows = 0;
2434 disallows = verb_to_mask( c->line, disallowable_ops );
2435 global_disallows ^= disallows;
2439 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2441 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2442 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2443 c->log, c->msg, c->argv[i]);
2446 global_disallows |= disallows;
2451 config_requires(ConfigArgs *c) {
2452 slap_mask_t requires = frontendDB->be_requires;
2453 int i, argc = c->argc;
2454 char **argv = c->argv;
2456 slap_verbmasks requires_ops[] = {
2457 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2458 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2459 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2460 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2461 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2464 if (c->op == SLAP_CONFIG_EMIT) {
2465 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2466 } else if ( c->op == LDAP_MOD_DELETE ) {
2468 c->be->be_requires = 0;
2470 requires = verb_to_mask( c->line, requires_ops );
2471 c->be->be_requires ^= requires;
2475 /* "none" can only be first, to wipe out default/global values */
2476 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2481 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2483 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2484 snprintf( c->msg, sizeof( c->msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2485 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2488 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2489 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2490 c->log, c->msg, c->argv[i]);
2494 c->be->be_requires = requires;
2498 static slap_verbmasks *loglevel_ops;
2501 loglevel_init( void )
2503 slap_verbmasks lo[] = {
2504 { BER_BVC("Any"), -1 },
2505 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2506 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2507 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2508 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2509 { BER_BVC("BER"), LDAP_DEBUG_BER },
2510 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2511 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2512 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2513 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2514 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2515 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2516 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2517 #if 0 /* no longer used (nor supported) */
2518 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2519 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2521 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2522 { BER_BVC("None"), LDAP_DEBUG_NONE },
2526 return slap_verbmasks_init( &loglevel_ops, lo );
2530 loglevel_destroy( void )
2532 if ( loglevel_ops ) {
2533 (void)slap_verbmasks_destroy( loglevel_ops );
2535 loglevel_ops = NULL;
2538 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2541 slap_loglevel_register( slap_mask_t m, struct berval *s )
2545 if ( loglevel_ops == NULL ) {
2549 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2552 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2560 slap_loglevel_get( struct berval *s, int *l )
2566 if ( loglevel_ops == NULL ) {
2570 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2571 m |= loglevel_ops[ i ].mask;
2576 for ( i = 1; i <= ( 1 << ( sizeof( int ) * 8 - 1 ) ) && !( m & i ); i <<= 1 )
2583 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2586 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2597 str2loglevel( const char *s, int *l )
2601 if ( loglevel_ops == NULL ) {
2605 i = verb_to_mask( s, loglevel_ops );
2607 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2611 *l = loglevel_ops[ i ].mask;
2617 loglevel2str( int l )
2619 struct berval bv = BER_BVNULL;
2621 loglevel2bv( l, &bv );
2627 loglevel2bv( int l, struct berval *bv )
2629 if ( loglevel_ops == NULL ) {
2635 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2639 loglevel2bvarray( int l, BerVarray *bva )
2641 if ( loglevel_ops == NULL ) {
2645 return mask_to_verbs( loglevel_ops, l, bva );
2649 loglevel_print( FILE *out )
2653 if ( loglevel_ops == NULL ) {
2657 fprintf( out, "Installed log subsystems:\n\n" );
2658 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2659 fprintf( out, "\t%-30s (%lu)\n",
2660 loglevel_ops[ i ].word.bv_val,
2661 loglevel_ops[ i ].mask );
2664 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2665 "by specific code\n\n" );
2670 static int config_syslog;
2673 config_loglevel(ConfigArgs *c) {
2676 if ( loglevel_ops == NULL ) {
2680 if (c->op == SLAP_CONFIG_EMIT) {
2681 /* Get default or commandline slapd setting */
2682 if ( ldap_syslog && !config_syslog )
2683 config_syslog = ldap_syslog;
2684 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2686 } else if ( c->op == LDAP_MOD_DELETE ) {
2690 int level = verb_to_mask( c->line, loglevel_ops );
2691 config_syslog ^= level;
2693 if ( slapMode & SLAP_SERVER_MODE ) {
2694 ldap_syslog = config_syslog;
2701 for( i=1; i < c->argc; i++ ) {
2704 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2705 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2706 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse level", c->argv[0] );
2707 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2708 c->log, c->msg, c->argv[i]);
2712 if ( str2loglevel( c->argv[i], &level ) ) {
2713 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown level", c->argv[0] );
2714 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2715 c->log, c->msg, c->argv[i]);
2719 config_syslog |= level;
2721 if ( slapMode & SLAP_SERVER_MODE ) {
2722 ldap_syslog = config_syslog;
2728 config_referral(ConfigArgs *c) {
2730 if (c->op == SLAP_CONFIG_EMIT) {
2731 if ( default_referral ) {
2732 value_add( &c->rvalue_vals, default_referral );
2737 } else if ( c->op == LDAP_MOD_DELETE ) {
2738 if ( c->valx < 0 ) {
2739 ber_bvarray_free( default_referral );
2740 default_referral = NULL;
2743 ch_free( default_referral[i].bv_val );
2744 for (; default_referral[i].bv_val; i++ )
2745 default_referral[i] = default_referral[i+1];
2749 if(validate_global_referral(c->argv[1])) {
2750 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
2751 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2752 c->log, c->msg, c->argv[1]);
2756 ber_str2bv(c->argv[1], 0, 0, &val);
2757 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2765 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2766 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2767 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2768 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2769 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2770 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2771 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2772 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2773 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2778 config_security(ConfigArgs *c) {
2779 slap_ssf_set_t *set = &c->be->be_ssf_set;
2782 if (c->op == SLAP_CONFIG_EMIT) {
2788 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2789 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2792 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2793 if ( bv.bv_len >= sizeof( numbuf ) ) {
2794 ber_bvarray_free_x( c->rvalue_vals, NULL );
2795 c->rvalue_vals = NULL;
2799 bv.bv_len += sec_keys[i].key.bv_len;
2800 bv.bv_val = ch_malloc( bv.bv_len + 1);
2801 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2802 strcpy( next, numbuf );
2803 ber_bvarray_add( &c->rvalue_vals, &bv );
2808 for(i = 1; i < c->argc; i++) {
2809 slap_ssf_t *tgt = NULL;
2811 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2812 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2813 sec_keys[j].key.bv_len)) {
2814 src = c->argv[i] + sec_keys[j].key.bv_len;
2815 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2820 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown factor", c->argv[0] );
2821 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2822 c->log, c->msg, c->argv[i]);
2826 if ( lutil_atou( tgt, src ) != 0 ) {
2827 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse factor", c->argv[0] );
2828 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2829 c->log, c->msg, c->argv[i]);
2837 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2841 for (; !BER_BVISNULL( &an->an_name ); an++) {
2842 /* if buflen == 0, assume the buffer size has been
2843 * already checked otherwise */
2844 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2845 if ( comma ) *ptr++ = ',';
2846 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2853 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2857 struct berval bc = BER_BVNULL;
2860 assert( !BER_BVISNULL( &ri->ri_bindconf.sb_uri ) );
2864 len = snprintf(numbuf, sizeof( numbuf ), SLAP_X_ORDERED_FMT, i );
2865 if ( len >= sizeof( numbuf ) ) {
2866 /* FIXME: how can indicate error? */
2870 if ( ri->ri_nsuffix ) {
2871 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2872 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2875 if ( ri->ri_attrs ) {
2876 len += STRLENOF(" attrs");
2877 if ( ri->ri_exclude ) len++;
2878 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2879 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2882 bindconf_unparse( &ri->ri_bindconf, &bc );
2885 bv->bv_val = ch_malloc(len + 1);
2888 ptr = lutil_strcopy( bv->bv_val, numbuf );
2890 /* start with URI from bindconf */
2891 assert( !BER_BVISNULL( &bc ) );
2893 strcpy( ptr, bc.bv_val );
2894 ch_free( bc.bv_val );
2897 if ( ri->ri_nsuffix ) {
2898 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2899 ptr = lutil_strcopy( ptr, " suffix=\"" );
2900 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2904 if ( ri->ri_attrs ) {
2905 ptr = lutil_strcopy( ptr, " attrs" );
2906 if ( ri->ri_exclude ) *ptr++ = '!';
2908 ptr = anlist_unparse( ri->ri_attrs, ptr, 0 );
2913 config_replica(ConfigArgs *c) {
2915 char *replicahost = NULL, *replicauri = NULL;
2918 if (c->op == SLAP_CONFIG_EMIT) {
2919 if (c->be->be_replica) {
2921 for (i=0;c->be->be_replica[i]; i++) {
2922 replica_unparse( c->be->be_replica[i], i, &bv );
2923 ber_bvarray_add( &c->rvalue_vals, &bv );
2928 } else if ( c->op == LDAP_MOD_DELETE ) {
2929 /* FIXME: there is no replica_free function */
2930 if ( c->valx < 0 ) {
2934 if(SLAP_MONITOR(c->be)) {
2935 Debug(LDAP_DEBUG_ANY, "%s: "
2936 "\"replica\" should not be used inside monitor database\n",
2938 return(0); /* FIXME: should this be an error? */
2941 for(i = 1; i < c->argc; i++) {
2942 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2946 snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] );
2947 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2951 replicahost = c->argv[i] + STRLENOF("host=");
2952 len = strlen( replicahost ) + STRLENOF("ldap://");
2953 replicauri = ch_malloc( len + 1 );
2954 snprintf( replicauri, len + 1, "ldap://%s", replicahost );
2955 replicahost = replicauri + STRLENOF( "ldap://");
2956 nr = add_replica_info(c->be, replicauri, replicahost);
2958 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2962 snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] );
2963 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2967 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2968 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid uri", c->argv[0] );
2969 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2972 if(!ludp->lud_host) {
2973 ldap_free_urldesc(ludp);
2974 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid uri - missing hostname",
2976 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2980 len = strlen(ludp->lud_scheme) + strlen(ludp->lud_host) +
2981 STRLENOF("://") + 1;
2982 if (ludp->lud_port != LDAP_PORT) {
2983 if (ludp->lud_port < 1 || ludp->lud_port > 65535) {
2984 ldap_free_urldesc(ludp);
2985 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid port",
2987 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2990 len += STRLENOF(":65535");
2992 replicauri = ch_malloc( len );
2993 replicahost = lutil_strcopy( replicauri, ludp->lud_scheme );
2994 replicahost = lutil_strcopy( replicahost, "://" );
2995 if (ludp->lud_port == LDAP_PORT) {
2996 strcpy( replicahost, ludp->lud_host );
2998 sprintf( replicahost, "%s:%d",ludp->lud_host,ludp->lud_port );
3000 ldap_free_urldesc(ludp);
3001 nr = add_replica_info(c->be, replicauri, replicahost);
3006 snprintf( c->msg, sizeof( c->msg ), "<%s> missing host or uri", c->argv[0] );
3007 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
3009 } else if(nr == -1) {
3010 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to add replica", c->argv[0] );
3011 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg,
3012 replicauri ? replicauri : "" );
3015 for(i = 1; i < c->argc; i++) {
3016 if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
3017 /* dealt with separately; don't let it get to bindconf */
3020 } else if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
3021 /* dealt with separately; don't let it get to bindconf */
3024 } else if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
3025 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
3027 Debug( LDAP_DEBUG_ANY, "%s: "
3028 "suffix \"%s\" in \"replica\" line is not valid for backend.\n",
3029 c->log, c->argv[i] + STRLENOF("suffix="), 0);
3033 Debug( LDAP_DEBUG_ANY, "%s: "
3034 "unable to normalize suffix in \"replica\" line.\n",
3040 } else if (!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))
3041 || !strncasecmp(c->argv[i], "attrs", STRLENOF("attrs")))
3044 char *arg = c->argv[i] + STRLENOF("attr");
3045 if (arg[0] == 's') {
3048 Debug( LDAP_DEBUG_ANY,
3050 "is deprecated (and undocumented); "
3051 "use \"attrs\" instead.\n",
3061 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
3062 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown attribute", c->argv[0] );
3063 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3064 c->log, c->msg, arg + 1);
3067 } else if ( bindconf_parse( c->argv[i],
3068 &c->be->be_replica[nr]->ri_bindconf ) ) {
3077 config_updatedn(ConfigArgs *c) {
3078 if (c->op == SLAP_CONFIG_EMIT) {
3079 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3080 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3081 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3085 } else if ( c->op == LDAP_MOD_DELETE ) {
3086 ch_free( c->be->be_update_ndn.bv_val );
3087 BER_BVZERO( &c->be->be_update_ndn );
3088 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3091 if(SLAP_SHADOW(c->be)) {
3092 snprintf( c->msg, sizeof( c->msg ), "<%s> database already shadowed", c->argv[0] );
3093 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3098 ber_memfree_x( c->value_dn.bv_val, NULL );
3099 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3100 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3102 c->be->be_update_ndn = c->value_ndn;
3103 BER_BVZERO( &c->value_dn );
3104 BER_BVZERO( &c->value_ndn );
3106 return config_slurp_shadow( c );
3110 config_shadow( ConfigArgs *c, int flag )
3112 char *notallowed = NULL;
3114 if ( c->be == frontendDB ) {
3115 notallowed = "frontend";
3117 } else if ( SLAP_MONITOR(c->be) ) {
3118 notallowed = "monitor";
3121 if ( notallowed != NULL ) {
3122 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3126 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3132 config_updateref(ConfigArgs *c) {
3134 if (c->op == SLAP_CONFIG_EMIT) {
3135 if ( c->be->be_update_refs ) {
3136 value_add( &c->rvalue_vals, c->be->be_update_refs );
3141 } else if ( c->op == LDAP_MOD_DELETE ) {
3142 if ( c->valx < 0 ) {
3143 ber_bvarray_free( c->be->be_update_refs );
3144 c->be->be_update_refs = NULL;
3147 ch_free( c->be->be_update_refs[i].bv_val );
3148 for (; c->be->be_update_refs[i].bv_val; i++)
3149 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3153 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3154 snprintf( c->msg, sizeof( c->msg ), "<%s> must appear after syncrepl or updatedn",
3156 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3161 if(validate_global_referral(c->argv[1])) {
3162 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
3163 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3164 c->log, c->msg, c->argv[1]);
3167 ber_str2bv(c->argv[1], 0, 0, &val);
3168 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3173 config_include(ConfigArgs *c) {
3174 int savelineno = c->lineno;
3177 ConfigFile *cfsave = cfn;
3178 ConfigFile *cf2 = NULL;
3180 /* No dynamic config for include files */
3181 cf = ch_calloc( 1, sizeof(ConfigFile));
3182 if ( cfn->c_kids ) {
3183 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3189 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3190 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3191 c->lineno = savelineno - 1;
3194 if ( cf2 ) cf2->c_sibs = NULL;
3195 else cfn->c_kids = NULL;
3196 ch_free( cf->c_file.bv_val );
3206 config_tls_option(ConfigArgs *c) {
3208 LDAP *ld = slap_tls_ld;
3210 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3211 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3212 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3213 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3214 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3215 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3216 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3217 default: Debug(LDAP_DEBUG_ANY, "%s: "
3218 "unknown tls_option <0x%x>\n",
3219 c->log, c->type, 0);
3222 if (c->op == SLAP_CONFIG_EMIT) {
3223 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3224 } else if ( c->op == LDAP_MOD_DELETE ) {
3225 return ldap_pvt_tls_set_option( ld, flag, NULL );
3227 ch_free(c->value_string);
3228 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3231 /* FIXME: this ought to be provided by libldap */
3233 config_tls_config(ConfigArgs *c) {
3236 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3237 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3239 Debug(LDAP_DEBUG_ANY, "%s: "
3240 "unknown tls_option <0x%x>\n",
3241 c->log, c->type, 0);
3244 if (c->op == SLAP_CONFIG_EMIT) {
3245 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3246 } else if ( c->op == LDAP_MOD_DELETE ) {
3248 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3250 ch_free( c->value_string );
3251 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3252 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3253 Debug(LDAP_DEBUG_ANY, "%s: "
3254 "unable to parse %s \"%s\"\n",
3255 c->log, c->argv[0], c->argv[1] );
3258 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3260 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3265 static CfEntryInfo *
3266 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3276 if ( dn_match( &root->ce_entry->e_nname, dn ))
3279 c = dn->bv_val+dn->bv_len;
3280 for (;*c != ',';c--);
3284 for (--c;c>dn->bv_val && *c != ',';c--);
3288 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3290 root = root->ce_kids;
3292 for (;root;root=root->ce_sibs) {
3293 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3294 if ( cdn.bv_val == dn->bv_val ) {
3304 typedef struct setup_cookie {
3314 config_ldif_resp( Operation *op, SlapReply *rs )
3316 if ( rs->sr_type == REP_SEARCH ) {
3317 setup_cookie *sc = op->o_callback->sc_private;
3319 sc->cfb->cb_got_ldif = 1;
3320 /* Does the frontend exist? */
3321 if ( !sc->got_frontend ) {
3322 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3323 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3324 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3325 STRLENOF( "olcDatabase" ), "={-1}frontend",
3326 STRLENOF( "={-1}frontend" ))) {
3329 sc->ca->be = frontendDB;
3330 sc->ca->bi = frontendDB->bd_info;
3331 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3332 rdn.bv_val = sc->ca->log;
3333 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3334 "%s=" SLAP_X_ORDERED_FMT "%s",
3335 cfAd_database->ad_cname.bv_val, -1,
3336 sc->ca->bi->bi_type);
3338 sc->frontend = config_build_entry( op, rs,
3339 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3340 sc->ca->be->be_cf_ocs );
3349 /* Does the configDB exist? */
3350 if ( sc->got_frontend && !sc->got_config &&
3351 !strncmp( rs->sr_entry->e_nname.bv_val,
3352 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3353 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3354 STRLENOF( "olcDatabase" ), "={0}config",
3355 STRLENOF( "={0}config" ))) {
3358 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3359 sc->ca->bi = sc->ca->be->bd_info;
3360 rdn.bv_val = sc->ca->log;
3361 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3362 "%s=" SLAP_X_ORDERED_FMT "%s",
3363 cfAd_database->ad_cname.bv_val, 0,
3364 sc->ca->bi->bi_type);
3366 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3367 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3374 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3375 if ( rs->sr_err != LDAP_SUCCESS ) {
3376 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3377 rs->sr_entry->e_name.bv_val, sc->ca->msg, 0 );
3383 /* Configure and read the underlying back-ldif store */
3385 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3386 CfBackInfo *cfb = be->be_private;
3392 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3393 Connection conn = {0};
3394 OperationBuffer opbuf;
3396 SlapReply rs = {REP_RESULT};
3397 Filter filter = { LDAP_FILTER_PRESENT };
3398 struct berval filterstr = BER_BVC("(objectclass=*)");
3401 /* Is the config directory available? */
3402 if ( stat( dir, &st ) < 0 ) {
3403 /* No, so don't bother using the backing store.
3404 * All changes will be in-memory only.
3409 cfb->cb_db.bd_info = backend_info( "ldif" );
3410 if ( !cfb->cb_db.bd_info )
3411 return 0; /* FIXME: eventually this will be a fatal error */
3413 if ( backend_db_init( "ldif", &cfb->cb_db, -1 ) == NULL )
3416 cfb->cb_db.be_suffix = be->be_suffix;
3417 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3419 /* The suffix is always "cn=config". The underlying DB's rootdn
3420 * is always the same as the suffix.
3422 cfb->cb_db.be_rootdn = be->be_suffix[0];
3423 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3425 ber_str2bv( dir, 0, 1, &cfdir );
3430 argv[0] = "directory";
3431 argv[1] = (char *)dir;
3435 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3439 if ( config_add_vals( ct, &c ))
3442 if ( backend_startup_one( &cfb->cb_db ))
3446 void *thrctx = ldap_pvt_thread_pool_context();
3449 op = (Operation *) &opbuf;
3450 connection_fake_init( &conn, op, thrctx );
3452 filter.f_desc = slap_schema.si_ad_objectClass;
3454 op->o_tag = LDAP_REQ_SEARCH;
3456 op->ors_filter = &filter;
3457 op->ors_filterstr = filterstr;
3458 op->ors_scope = LDAP_SCOPE_SUBTREE;
3460 op->o_dn = c.be->be_rootdn;
3461 op->o_ndn = c.be->be_rootndn;
3463 op->o_req_dn = be->be_suffix[0];
3464 op->o_req_ndn = be->be_nsuffix[0];
3466 op->ors_tlimit = SLAP_NO_LIMIT;
3467 op->ors_slimit = SLAP_NO_LIMIT;
3469 op->ors_attrs = slap_anlist_all_attributes;
3470 op->ors_attrsonly = 0;
3472 op->o_callback = &cb;
3475 cb.sc_private = ≻
3476 sc.got_frontend = 0;
3481 op->o_bd = &cfb->cb_db;
3483 /* Allow unknown attrs in DNs */
3484 prev_DN_strict = slap_DN_strict;
3487 rc = op->o_bd->be_search( op, &rs );
3489 /* Restore normal DN validation */
3490 slap_DN_strict = prev_DN_strict;
3492 op->o_tag = LDAP_REQ_ADD;
3493 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3494 op->ora_e = sc.frontend;
3495 rc = op->o_bd->be_add( op, &rs );
3497 if ( rc == LDAP_SUCCESS && sc.config ) {
3498 op->ora_e = sc.config;
3499 rc = op->o_bd->be_add( op, &rs );
3501 ldap_pvt_thread_pool_context_reset( thrctx );
3504 /* ITS#4194 - only use if it's present, or we're converting. */
3505 if ( !readit || rc == LDAP_SUCCESS )
3506 cfb->cb_use_ldif = 1;
3512 CfOc_cmp( const void *c1, const void *c2 ) {
3513 const ConfigOCs *co1 = c1;
3514 const ConfigOCs *co2 = c2;
3516 return ber_bvcmp( co1->co_name, co2->co_name );
3520 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3523 i = init_config_attrs( ct );
3526 /* set up the objectclasses */
3527 i = init_config_ocs( ocs );
3530 for (i=0; ocs[i].co_def; i++) {
3531 if ( ocs[i].co_oc ) {
3532 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3533 if ( !ocs[i].co_table )
3534 ocs[i].co_table = ct;
3535 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3542 read_config(const char *fname, const char *dir) {
3545 const char *cfdir, *cfname;
3548 /* Setup the config backend */
3549 be = backend_db_init( "config", NULL, 0 );
3553 cfb = be->be_private;
3554 be->be_dfltaccess = ACL_NONE;
3556 /* If no .conf, or a dir was specified, setup the dir */
3557 if ( !fname || dir ) {
3559 /* If explicitly given, check for existence */
3562 if ( stat( dir, &st ) < 0 ) {
3563 Debug( LDAP_DEBUG_ANY,
3564 "invalid config directory %s, error %d\n",
3570 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3572 /* if fname is defaulted, try reading .d */
3573 rc = config_setup_ldif( be, cfdir, !fname );
3576 /* It may be OK if the base object doesn't exist yet. */
3577 if ( rc != LDAP_NO_SUCH_OBJECT )
3579 /* ITS#4194: But if dir was specified and no fname,
3580 * then we were supposed to read the dir. Unless we're
3581 * trying to slapadd the dir...
3583 if ( dir && !fname ) {
3584 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3586 /* Assume it's slapadd with a config dir, let it continue */
3588 cfb->cb_got_ldif = 1;
3589 cfb->cb_use_ldif = 1;
3594 /* If we read the config from back-ldif, nothing to do here */
3595 if ( cfb->cb_got_ldif ) {
3604 cfname = SLAPD_DEFAULT_CONFIGFILE;
3606 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3609 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3612 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3613 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3614 &frontendDB->be_schemadn );
3615 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3616 if ( rc != LDAP_SUCCESS ) {
3617 Debug(LDAP_DEBUG_ANY, "read_config: "
3618 "unable to normalize default schema DN \"%s\"\n",
3619 frontendDB->be_schemadn.bv_val, 0, 0 );
3620 /* must not happen */
3628 config_back_bind( Operation *op, SlapReply *rs )
3630 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
3631 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3632 /* frontend sends result */
3633 return LDAP_SUCCESS;
3636 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3637 send_ldap_result( op, rs );
3643 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3647 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3649 rs->sr_attrs = op->ors_attrs;
3650 rs->sr_entry = ce->ce_entry;
3652 rc = send_search_entry( op, rs );
3654 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3655 if ( ce->ce_kids ) {
3656 rc = config_send( op, rs, ce->ce_kids, 1 );
3657 if ( rc ) return rc;
3660 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3661 rc = config_send( op, rs, ce, 0 );
3669 static ConfigTable *
3670 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
3674 for (j=0; j<nocs; j++) {
3675 for (i=0; colst[j]->co_table[i].name; i++)
3676 if ( colst[j]->co_table[i].ad == ad )
3677 return &colst[j]->co_table[i];
3682 /* Sort the attributes of the entry according to the order defined
3683 * in the objectclass, with required attributes occurring before
3684 * allowed attributes. For any attributes with sequencing dependencies
3685 * (e.g., rootDN must be defined after suffix) the objectclass must
3686 * list the attributes in the desired sequence.
3689 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3691 Attribute *a, *head = NULL, *tail = NULL, **prev;
3694 for (i=0; i<nocs; i++) {
3695 if ( colst[i]->co_oc->soc_required ) {
3696 AttributeType **at = colst[i]->co_oc->soc_required;
3697 for (j=0; at[j]; j++) {
3698 for (a=e->e_attrs, prev=&e->e_attrs; a;
3699 prev = &(*prev)->a_next, a=a->a_next) {
3700 if ( a->a_desc == at[j]->sat_ad ) {
3714 if ( colst[i]->co_oc->soc_allowed ) {
3715 AttributeType **at = colst[i]->co_oc->soc_allowed;
3716 for (j=0; at[j]; j++) {
3717 for (a=e->e_attrs, prev=&e->e_attrs; a;
3718 prev = &(*prev)->a_next, a=a->a_next) {
3719 if ( a->a_desc == at[j]->sat_ad ) {
3735 tail->a_next = e->e_attrs;
3741 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3743 Attribute *a = NULL;
3744 AttributeDescription *ad;
3754 Modifications *ml = ptr;
3756 vals = ml->sml_values;
3759 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3760 rc = ordered_value_sort( a, 1 );
3762 snprintf(ca->msg, sizeof( ca->msg ), "ordered_value_sort failed on attr %s\n",
3763 ad->ad_cname.bv_val );
3767 for ( i=0; vals[i].bv_val; i++ ) {
3768 ca->line = vals[i].bv_val;
3769 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3770 ca->line[0] == '{' ) {
3771 char *idx = strchr( ca->line, '}' );
3772 if ( idx ) ca->line = idx+1;
3774 rc = config_parse_vals( ct, ca, i );
3783 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3786 struct berval rtype, rval;
3788 AttributeDescription *ad = NULL;
3790 dnRdn( &e->e_name, rdn );
3791 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3792 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3793 rtype.bv_val = rdn->bv_val;
3794 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3797 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3798 a = attr_find( e->e_attrs, ad );
3799 if (!a ) return LDAP_NAMING_VIOLATION;
3806 config_rename_kids( CfEntryInfo *ce )
3809 struct berval rdn, nrdn;
3811 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3812 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3813 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3814 free( ce2->ce_entry->e_name.bv_val );
3815 free( ce2->ce_entry->e_nname.bv_val );
3816 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3818 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3820 config_rename_kids( ce2 );
3825 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3826 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3827 struct berval *nnewrdn, int use_ldif )
3831 struct berval odn, ondn;
3835 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3836 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3839 free( a->a_vals[0].bv_val );
3840 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3841 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3842 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3843 strcpy( a->a_vals[0].bv_val, ptr1 );
3845 if ( a->a_nvals != a->a_vals ) {
3846 free( a->a_nvals[0].bv_val );
3847 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3848 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3849 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3850 strcpy( a->a_nvals[0].bv_val, ptr1 );
3853 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3854 BackendDB *be = op->o_bd;
3855 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3856 struct berval dn, ndn, xdn, xndn;
3858 op->o_bd = &cfb->cb_db;
3860 /* Save current rootdn; use the underlying DB's rootdn */
3864 xndn = op->o_req_ndn;
3865 op->o_dn = op->o_bd->be_rootdn;
3866 op->o_ndn = op->o_bd->be_rootndn;
3868 op->o_req_ndn = ondn;
3870 scp = op->o_callback;
3871 op->o_callback = ≻
3872 op->orr_newrdn = *newrdn;
3873 op->orr_nnewrdn = *nnewrdn;
3874 op->orr_deleteoldrdn = 1;
3875 op->orr_modlist = NULL;
3876 slap_modrdn2mods( op, rs );
3877 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3878 rc = op->o_bd->be_modrdn( op, rs );
3879 slap_mods_free( op->orr_modlist, 1 );
3882 op->o_callback = scp;
3886 op->o_req_ndn = xndn;
3889 free( ondn.bv_val );
3891 config_rename_kids( e->e_private );
3896 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3897 Entry *e, int idx, int tailindex, int use_ldif )
3899 struct berval ival, newrdn, nnewrdn;
3902 char ibuf[32], *ptr1, *ptr2 = NULL;
3905 rc = config_rename_attr( rs, e, &rdn, &a );
3906 if ( rc ) return rc;
3909 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3910 if ( ival.bv_len >= sizeof( ibuf ) ) {
3911 return LDAP_NAMING_VIOLATION;
3914 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3915 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3918 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3919 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3922 ptr2 = ber_bvchr( &rdn, '}' );
3926 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3928 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3929 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3930 a->a_desc->ad_cname.bv_len );
3932 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3933 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3937 /* Do the equivalent of ModRDN */
3938 /* Replace DN / NDN */
3939 newrdn.bv_len = ptr1 - newrdn.bv_val;
3940 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3941 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3943 free( nnewrdn.bv_val );
3944 free( newrdn.bv_val );
3949 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3950 SlapReply *rs, int *renum, int *ibase )
3953 int index = -1, gotindex = 0, nsibs, rc = 0;
3954 int renumber = 0, tailindex = 0, isfrontend = 0;
3955 char *ptr1, *ptr2 = NULL;
3958 if ( renum ) *renum = 0;
3960 /* These entries don't get indexed/renumbered */
3961 if ( ce_type == Cft_Global ) return 0;
3962 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3964 if ( ce_type == Cft_Module )
3967 /* See if the rdn has an index already */
3968 dnRdn( &e->e_name, &rdn );
3969 if ( ce_type == Cft_Database && !strncmp( rdn.bv_val + rdn.bv_len -
3970 STRLENOF("frontend"), "frontend", STRLENOF("frontend") ))
3972 ptr1 = ber_bvchr( &e->e_name, '{' );
3973 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3975 ptr2 = strchr( ptr1, '}' );
3976 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3977 return LDAP_NAMING_VIOLATION;
3978 if ( ptr2-ptr1 == 1)
3979 return LDAP_NAMING_VIOLATION;
3981 index = strtol( ptr1 + 1, &next, 10 );
3982 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3983 return LDAP_NAMING_VIOLATION;
3986 /* Special case, we allow -1 for the frontendDB */
3987 if ( index != -1 || !isfrontend )
3988 return LDAP_NAMING_VIOLATION;
3992 /* count related kids */
3993 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3994 if ( ce->ce_type == ce_type ) nsibs++;
3997 if ( index != nsibs ) {
3999 if ( index < nsibs ) {
4000 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4001 /* Siblings need to be renumbered */
4002 if ( index != -1 || !isfrontend )
4006 if ( !isfrontend && index == -1 )
4009 /* just make index = nsibs */
4011 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4014 if ( ibase ) *ibase = index;
4015 if ( renum ) *renum = renumber;
4020 count_ocs( Attribute *oc_at, int *nocs )
4023 ConfigOCs co, *coptr, **colst;
4025 /* count the objectclasses */
4026 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
4028 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
4030 for ( i=0, j=0; i<n; i++) {
4031 co.co_name = &oc_at->a_nvals[i];
4032 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4034 /* ignore non-config objectclasses. probably should be
4035 * an error, general data doesn't belong here.
4037 if ( !coptr ) continue;
4039 /* Ignore the root objectclass, it has no implementation.
4041 if ( coptr->co_type == Cft_Abstract ) continue;
4049 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4053 /* This entry is hardcoded, don't re-parse it */
4054 if ( p->ce_type == Cft_Global ) {
4055 cfn = p->ce_private;
4057 return LDAP_COMPARE_TRUE;
4059 if ( p->ce_type != Cft_Schema )
4060 return LDAP_CONSTRAINT_VIOLATION;
4062 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4064 cfo = p->ce_private;
4065 cfn->c_sibs = cfo->c_kids;
4067 return LDAP_SUCCESS;
4071 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4073 if ( p->ce_type != Cft_Global )
4074 return LDAP_CONSTRAINT_VIOLATION;
4075 ca->be = frontendDB; /* just to get past check_vals */
4076 return LDAP_SUCCESS;
4080 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4082 if ( p->ce_type != Cft_Global )
4083 return LDAP_CONSTRAINT_VIOLATION;
4084 return LDAP_SUCCESS;
4088 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4090 if ( p->ce_type != Cft_Global )
4091 return LDAP_CONSTRAINT_VIOLATION;
4092 return LDAP_SUCCESS;
4096 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4098 if ( p->ce_type != Cft_Database )
4099 return LDAP_CONSTRAINT_VIOLATION;
4101 return LDAP_SUCCESS;
4104 /* Parse an LDAP entry into config directives */
4106 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4107 int *renum, Operation *op )
4109 CfEntryInfo *ce, *last;
4111 Attribute *a, *oc_at;
4112 int i, ibase = -1, nocs, rc = 0;
4117 memset( ca, 0, sizeof(ConfigArgs));
4119 /* Make sure parent exists and entry does not. But allow
4120 * Databases and Overlays to be inserted. Don't do any
4121 * auto-renumbering if manageDSAit control is present.
4123 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4125 if (( op && op->o_managedsait ) ||
4126 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4127 ce->ce_type != Cft_Module ))
4128 return LDAP_ALREADY_EXISTS;
4131 dnParent( &e->e_nname, &pdn );
4133 /* If last is NULL, the new entry is the root/suffix entry,
4134 * otherwise last should be the parent.
4136 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
4138 rs->sr_matched = last->ce_entry->e_name.bv_val;
4139 return LDAP_NO_SUCH_OBJECT;
4143 /* No parent, must be root. This will never happen... */
4144 if ( !last && !be_isroot( op ) && !be_shadow_update( op ))
4145 return LDAP_NO_SUCH_OBJECT;
4146 if ( last && !access_allowed( op, last->ce_entry,
4147 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ))
4148 return LDAP_INSUFFICIENT_ACCESS;
4151 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4152 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4154 /* Fake the coordinates based on whether we're part of an
4155 * LDAP Add or if reading the config dir
4158 ca->fname = "slapd";
4161 ca->fname = cfdir.bv_val;
4166 colst = count_ocs( oc_at, &nocs );
4168 /* Only the root can be Cft_Global, everything else must
4169 * have a parent. Only limited nesting arrangements are allowed.
4171 rc = LDAP_CONSTRAINT_VIOLATION;
4172 if ( colst[0]->co_type == Cft_Global && !last ) {
4173 cfn = cfb->cb_config;
4175 ca->be = frontendDB; /* just to get past check_vals */
4179 /* Check whether the Add is allowed by its parent, and do
4180 * any necessary arg setup
4183 for ( i=0; i<nocs; i++ ) {
4184 if ( colst[i]->co_ldadd &&
4185 ( rc = colst[i]->co_ldadd( last, e, ca ))
4186 != LDAP_CONSTRAINT_VIOLATION ) {
4192 /* Add the entry but don't parse it, we already have its contents */
4193 if ( rc == LDAP_COMPARE_TRUE ) {
4198 if ( rc != LDAP_SUCCESS )
4201 /* Parse all the values and check for simple syntax errors before
4202 * performing any set actions.
4204 * If doing an LDAPadd, check for indexed names and any necessary
4205 * renaming/renumbering. Entries that don't need indexed names are
4206 * ignored. Entries that need an indexed name and arrive without one
4207 * are assigned to the end. Entries that arrive with an index may
4208 * cause the following entries to be renumbered/bumped down.
4210 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4211 * don't allow Adding an entry with an index that's already in use.
4212 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4214 * These entries can have auto-assigned indexes (appended to the end)
4215 * but only the other types support auto-renumbering of siblings.
4218 rc = check_name_index( last, colst[0]->co_type, e, rs, renum,
4223 if ( renum && *renum && colst[0]->co_type != Cft_Database &&
4224 colst[0]->co_type != Cft_Overlay ) {
4225 snprintf( ca->msg, sizeof( ca->msg ),
4226 "operation requires sibling renumbering" );
4227 rc = LDAP_UNWILLING_TO_PERFORM;
4232 init_config_argv( ca );
4234 /* Make sure we process attrs in the required order */
4235 sort_attrs( e, colst, nocs );
4237 for ( a=e->e_attrs; a; a=a->a_next ) {
4238 if ( a == oc_at ) continue;
4239 ct = config_find_table( colst, nocs, a->a_desc );
4240 if ( !ct ) continue; /* user data? */
4241 rc = check_vals( ct, ca, a, 1 );
4242 if ( rc ) goto done;
4245 /* Basic syntax checks are OK. Do the actual settings. */
4246 for ( a=e->e_attrs; a; a=a->a_next ) {
4247 if ( a == oc_at ) continue;
4248 ct = config_find_table( colst, nocs, a->a_desc );
4249 if ( !ct ) continue; /* user data? */
4250 for (i=0; a->a_vals[i].bv_val; i++) {
4252 ca->line = a->a_vals[i].bv_val;
4253 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4254 ptr = strchr( ca->line, '}' );
4256 iptr = strchr( ca->line, '{' );
4260 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4262 ca->valx = strtol( iptr+1, NULL, 0 );
4269 rc = config_parse_add( ct, ca, i );
4277 /* Newly added databases and overlays need to be started up */
4278 if ( CONFIG_ONLINE_ADD( ca )) {
4279 if ( colst[0]->co_type == Cft_Database ) {
4280 rc = backend_startup_one( ca->be );
4282 } else if ( colst[0]->co_type == Cft_Overlay ) {
4283 if ( ca->bi->bi_db_open ) {
4284 BackendInfo *bi_orig = ca->be->bd_info;
4285 ca->be->bd_info = ca->bi;
4286 rc = ca->bi->bi_db_open( ca->be );
4287 ca->be->bd_info = bi_orig;
4291 snprintf( ca->msg, sizeof( ca->msg ), "<%s> failed startup", ca->argv[0] );
4292 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4293 ca->log, ca->msg, ca->argv[1] );
4300 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4301 ce->ce_parent = last;
4302 ce->ce_entry = entry_dup( e );
4303 ce->ce_entry->e_private = ce;
4304 ce->ce_type = colst[0]->co_type;
4307 ce->ce_private = ca->private;
4308 ca->ca_entry = ce->ce_entry;
4311 } else if ( last->ce_kids ) {
4312 CfEntryInfo *c2, **cprev;
4314 /* Advance to first of this type */
4315 cprev = &last->ce_kids;
4316 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4317 cprev = &c2->ce_sibs;
4320 /* Account for the (-1) frontendDB entry */
4321 if ( ce->ce_type == Cft_Database ) {
4322 if ( ca->be == frontendDB )
4324 else if ( ibase != -1 )
4329 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4330 cprev = &c2->ce_sibs;
4336 for ( i=0; i<ibase; i++ ) {
4338 cprev = &c2->ce_sibs;
4341 ce->ce_sibs = *cprev;
4349 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4350 if ( ca->be != frontendDB )
4351 backend_destroy_one( ca->be, 1 );
4352 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4353 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4357 ch_free( ca->argv );
4358 if ( colst ) ch_free( colst );
4362 #define BIGTMP 10000
4364 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4365 int base, int rebase, int max, int use_ldif )
4367 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4368 ConfigType etype = ce->ce_type;
4369 int count = 0, rc = 0;
4371 /* Reverse ce list */
4372 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4373 if (ce2->ce_type != etype) {
4378 ce2->ce_sibs = cetmp;
4381 if ( max && count >= max ) {
4387 /* Move original to a temp name until increments are done */
4389 ce->ce_entry->e_private = NULL;
4390 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4391 base+BIGTMP, 0, use_ldif );
4392 ce->ce_entry->e_private = ce;
4394 /* start incrementing */
4395 for (ce2=cetmp; ce2; ce2=ce3) {
4397 ce2->ce_sibs = cerem;
4400 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4401 count+base, 0, use_ldif );
4405 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4406 base, 0, use_ldif );
4411 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4412 CfEntryInfo *ce2, int old, int use_ldif )
4416 /* Renumber original to a temp value */
4417 ce->ce_entry->e_private = NULL;
4418 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4419 old+BIGTMP, 0, use_ldif );
4420 ce->ce_entry->e_private = ce;
4422 /* start decrementing */
4423 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4424 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4425 count+old, 0, use_ldif );
4428 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4429 count+old, 0, use_ldif );
4432 /* Parse an LDAP entry into config directives, then store in underlying
4436 config_back_add( Operation *op, SlapReply *rs )
4442 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4443 NULL, ACL_WADD, NULL )) {
4444 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4448 cfb = (CfBackInfo *)op->o_bd->be_private;
4450 /* add opattrs for syncprov */
4452 char textbuf[SLAP_TEXT_BUFLEN];
4453 size_t textlen = sizeof textbuf;
4454 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4455 &rs->sr_text, textbuf, sizeof( textbuf ) );
4456 if ( rs->sr_err != LDAP_SUCCESS )
4458 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4459 if ( rs->sr_err != LDAP_SUCCESS ) {
4460 Debug( LDAP_DEBUG_TRACE,
4461 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4462 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4467 ldap_pvt_thread_pool_pause( &connection_pool );
4470 * 1) check for existence of entry
4471 * 2) check for sibling renumbering
4472 * 3) perform internal add
4473 * 4) perform any necessary renumbering
4474 * 5) store entry in underlying database
4476 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4477 if ( rs->sr_err != LDAP_SUCCESS ) {
4478 rs->sr_text = ca.msg;
4483 CfEntryInfo *ce = ca.ca_entry->e_private;
4484 req_add_s addr = op->oq_add;
4485 op->o_tag = LDAP_REQ_MODRDN;
4486 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4487 op->o_tag = LDAP_REQ_ADD;
4489 if ( rs->sr_err != LDAP_SUCCESS ) {
4494 if ( cfb->cb_use_ldif ) {
4495 BackendDB *be = op->o_bd;
4496 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4497 struct berval dn, ndn;
4499 op->o_bd = &cfb->cb_db;
4501 /* Save current rootdn; use the underlying DB's rootdn */
4504 op->o_dn = op->o_bd->be_rootdn;
4505 op->o_ndn = op->o_bd->be_rootndn;
4507 scp = op->o_callback;
4508 op->o_callback = ≻
4509 op->o_bd->be_add( op, rs );
4511 op->o_callback = scp;
4517 ldap_pvt_thread_pool_resume( &connection_pool );
4520 send_ldap_result( op, rs );
4521 slap_graduate_commit_csn( op );
4525 typedef struct delrec {
4526 struct delrec *next;
4532 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4535 int rc = LDAP_UNWILLING_TO_PERFORM;
4537 Entry *e = ce->ce_entry;
4538 Attribute *save_attrs = e->e_attrs, *oc_at;
4543 delrec *dels = NULL, *deltail = NULL;
4545 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4546 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4548 colst = count_ocs( oc_at, &nocs );
4550 e->e_attrs = attrs_dup( e->e_attrs );
4552 init_config_argv( ca );
4555 ca->private = ce->ce_private;
4557 ca->fname = "slapd";
4559 strcpy( ca->log, "back-config" );
4561 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4562 ct = config_find_table( colst, nocs, ml->sml_desc );
4563 switch (ml->sml_op) {
4564 case LDAP_MOD_DELETE:
4565 case LDAP_MOD_REPLACE: {
4566 BerVarray vals = NULL, nvals = NULL;
4568 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4570 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
4571 ml->sml_desc->ad_cname.bv_val );
4574 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4575 vals = ml->sml_values;
4576 nvals = ml->sml_nvalues;
4577 ml->sml_values = NULL;
4578 ml->sml_nvalues = NULL;
4580 /* If we're deleting by values, remember the indexes of the
4581 * values we deleted.
4583 if ( ct && ml->sml_values ) {
4585 for (i=0; ml->sml_values[i].bv_val; i++);
4586 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4597 rc = modify_delete_vindex(e, &ml->sml_mod,
4598 get_permissiveModify(op),
4599 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
4600 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4601 ml->sml_values = vals;
4602 ml->sml_nvalues = nvals;
4607 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4610 case SLAP_MOD_SOFTADD: {
4611 int mop = ml->sml_op;
4613 ml->sml_op = LDAP_MOD_ADD;
4615 if ( ct->arg_type & ARG_NO_INSERT ) {
4616 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4618 for (i = 0; a->a_vals[i].bv_val; i++ );
4622 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4623 if ( ml->sml_values[i].bv_val[0] == '{' &&
4626 char *next, *val = ml->sml_values[i].bv_val + 1;
4629 j = strtol( val, &next, 0 );
4630 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4632 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
4633 ml->sml_desc->ad_cname.bv_val );
4637 rc = check_vals( ct, ca, ml, 0 );
4641 rc = modify_add_values(e, &ml->sml_mod,
4642 get_permissiveModify(op),
4643 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4645 /* If value already exists, show success here
4646 * and ignore this operation down below.
4648 if ( mop == SLAP_MOD_SOFTADD ) {
4649 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4659 case LDAP_MOD_INCREMENT: /* FIXME */
4664 if(rc != LDAP_SUCCESS) break;
4667 if(rc == LDAP_SUCCESS) {
4668 /* check that the entry still obeys the schema */
4669 rc = entry_schema_check(op, e, NULL, 0, 0,
4670 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4672 if ( rc == LDAP_SUCCESS ) {
4673 /* Basic syntax checks are OK. Do the actual settings. */
4674 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4675 ct = config_find_table( colst, nocs, ml->sml_desc );
4676 if ( !ct ) continue;
4678 switch (ml->sml_op) {
4679 case LDAP_MOD_DELETE:
4680 case LDAP_MOD_REPLACE: {
4681 BerVarray vals = NULL, nvals = NULL;
4685 a = attr_find( e->e_attrs, ml->sml_desc );
4687 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4688 vals = ml->sml_values;
4689 nvals = ml->sml_nvalues;
4690 ml->sml_values = NULL;
4691 ml->sml_nvalues = NULL;
4694 if ( ml->sml_values )
4697 /* If we didn't delete the whole attribute */
4698 if ( ml->sml_values && a ) {
4699 struct berval *mvals;
4702 if ( ml->sml_nvalues )
4703 mvals = ml->sml_nvalues;
4705 mvals = ml->sml_values;
4707 /* use the indexes we saved up above */
4708 for (i=0; i < d->nidx; i++) {
4709 struct berval bv = *mvals++;
4710 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4711 bv.bv_val[0] == '{' ) {
4712 ptr = strchr( bv.bv_val, '}' ) + 1;
4713 bv.bv_len -= ptr - bv.bv_val;
4716 ca->line = bv.bv_val;
4717 ca->valx = d->idx[i];
4718 rc = config_del_vals( ct, ca );
4719 if ( rc != LDAP_SUCCESS ) break;
4720 for (j=i+1; j < d->nidx; j++)
4721 if ( d->idx[j] >d->idx[i] )
4727 rc = config_del_vals( ct, ca );
4728 if ( rc ) rc = LDAP_OTHER;
4730 if ( ml->sml_values ) {
4735 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4736 ml->sml_values = vals;
4737 ml->sml_nvalues = nvals;
4739 if ( !vals || rc != LDAP_SUCCESS )
4742 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4745 for (i=0; ml->sml_values[i].bv_val; i++) {
4746 ca->line = ml->sml_values[i].bv_val;
4748 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4749 ca->line[0] == '{' )
4751 ptr = strchr( ca->line + 1, '}' );
4755 ca->valx = strtol( ca->line + 1, &next, 0 );
4756 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4763 rc = config_parse_add( ct, ca, i );
4778 if ( rc == LDAP_SUCCESS ) {
4779 attrs_free( save_attrs );
4781 attrs_free( e->e_attrs );
4782 e->e_attrs = save_attrs;
4784 ch_free( ca->argv );
4785 if ( colst ) ch_free( colst );
4787 deltail = dels->next;
4796 config_back_modify( Operation *op, SlapReply *rs )
4799 CfEntryInfo *ce, *last;
4801 ConfigArgs ca = {0};
4804 AttributeDescription *rad = NULL;
4806 cfb = (CfBackInfo *)op->o_bd->be_private;
4808 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4811 rs->sr_matched = last->ce_entry->e_name.bv_val;
4812 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4816 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4817 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4821 /* Get type of RDN */
4822 rdn = ce->ce_entry->e_nname;
4823 ptr = strchr( rdn.bv_val, '=' );
4824 rdn.bv_len = ptr - rdn.bv_val;
4825 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4827 /* Some basic validation... */
4828 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4829 /* Don't allow Modify of RDN; must use ModRdn for that. */
4830 if ( ml->sml_desc == rad ) {
4831 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4832 rs->sr_text = "Use modrdn to change the entry name";
4837 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4839 if ( !slapd_shutdown )
4840 ldap_pvt_thread_pool_pause( &connection_pool );
4843 * 1) perform the Modify on the cached Entry.
4844 * 2) verify that the Entry still satisfies the schema.
4845 * 3) perform the individual config operations.
4846 * 4) store Modified entry in underlying LDIF backend.
4848 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4850 rs->sr_text = ca.msg;
4851 } else if ( cfb->cb_use_ldif ) {
4852 BackendDB *be = op->o_bd;
4853 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4854 struct berval dn, ndn;
4856 op->o_bd = &cfb->cb_db;
4860 op->o_dn = op->o_bd->be_rootdn;
4861 op->o_ndn = op->o_bd->be_rootndn;
4863 scp = op->o_callback;
4864 op->o_callback = ≻
4865 op->o_bd->be_modify( op, rs );
4867 op->o_callback = scp;
4872 if ( !slapd_shutdown )
4873 ldap_pvt_thread_pool_resume( &connection_pool );
4875 send_ldap_result( op, rs );
4876 slap_graduate_commit_csn( op );
4881 config_back_modrdn( Operation *op, SlapReply *rs )
4884 CfEntryInfo *ce, *last;
4888 cfb = (CfBackInfo *)op->o_bd->be_private;
4890 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4893 rs->sr_matched = last->ce_entry->e_name.bv_val;
4894 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4897 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4898 NULL, ACL_WRITE, NULL )) {
4899 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4903 if ( ce->ce_parent )
4904 parent = ce->ce_parent->ce_entry;
4906 parent = (Entry *)&slap_entry_root;
4907 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
4908 NULL, ACL_WRITE, NULL )) {
4909 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4914 /* We don't allow moving objects to new parents.
4915 * Generally we only allow reordering a set of ordered entries.
4917 if ( op->orr_newSup ) {
4918 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4922 /* If newRDN == oldRDN, quietly succeed */
4923 dnRdn( &op->o_req_ndn, &rdn );
4924 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
4925 rs->sr_err = LDAP_SUCCESS;
4929 /* Current behavior, subject to change as needed:
4931 * For backends and overlays, we only allow renumbering.
4932 * For schema, we allow renaming with the same number.
4933 * Otherwise, the op is not allowed.
4936 if ( ce->ce_type == Cft_Schema ) {
4940 /* Can't alter the main cn=schema entry */
4941 if ( ce->ce_parent->ce_type == Cft_Global ) {
4942 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4943 rs->sr_text = "renaming not allowed for this entry";
4947 /* We could support this later if desired */
4948 ptr1 = ber_bvchr( &rdn, '}' );
4949 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4950 len = ptr1 - rdn.bv_val;
4951 if ( len != ptr2 - op->orr_newrdn.bv_val ||
4952 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
4953 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4954 rs->sr_text = "schema reordering not supported";
4957 } else if ( ce->ce_type == Cft_Database ||
4958 ce->ce_type == Cft_Overlay ) {
4959 char *ptr1, *ptr2, *iptr1, *iptr2;
4962 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
4963 if ( *iptr2 != '{' ) {
4964 rs->sr_err = LDAP_NAMING_VIOLATION;
4965 rs->sr_text = "new ordering index is required";
4969 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
4970 ptr1 = ber_bvchr( &rdn, '}' );
4971 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4973 rs->sr_err = LDAP_NAMING_VIOLATION;
4974 rs->sr_text = "new ordering index is required";
4978 len1 = ptr1 - rdn.bv_val;
4979 len2 = ptr2 - op->orr_newrdn.bv_val;
4981 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
4982 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
4983 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4984 rs->sr_text = "changing database/overlay type not allowed";
4987 ixold = strtol( iptr1, NULL, 0 );
4988 ixnew = strtol( iptr2, &ptr1, 0 );
4989 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
4990 rs->sr_err = LDAP_NAMING_VIOLATION;
4993 /* config DB is always 0, cannot be changed */
4994 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
4995 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
4999 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5000 rs->sr_text = "renaming not supported for this entry";
5004 ldap_pvt_thread_pool_pause( &connection_pool );
5006 if ( ce->ce_type == Cft_Schema ) {
5007 req_modrdn_s modr = op->oq_modrdn;
5010 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5011 if ( rs->sr_err == LDAP_SUCCESS ) {
5012 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5013 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5016 op->oq_modrdn = modr;
5018 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5019 req_modrdn_s modr = op->oq_modrdn;
5022 /* Advance to first of this type */
5023 cprev = &ce->ce_parent->ce_kids;
5024 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5025 cprev = &ce2->ce_sibs;
5028 /* Skip the -1 entry */
5029 if ( ce->ce_type == Cft_Database ) {
5030 cprev = &ce2->ce_sibs;
5036 /* Remove from old slot */
5037 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5038 cprev = &ce2->ce_sibs;
5039 *cprev = ce->ce_sibs;
5040 ceold = ce->ce_sibs;
5042 /* Insert into new slot */
5044 for ( i=0; i<ixnew; i++ ) {
5048 cprev = &ce2->ce_sibs;
5050 ce->ce_sibs = *cprev;
5055 /* NOTE: These should be encoded in the OC tables, not inline here */
5056 if ( ce->ce_type == Cft_Database )
5057 backend_db_move( ce->ce_be, ixnew );
5058 else if ( ce->ce_type == Cft_Overlay )
5059 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5061 if ( ixold < ixnew ) {
5062 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5065 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5066 ixold - ixnew, cfb->cb_use_ldif );
5068 op->oq_modrdn = modr;
5071 ldap_pvt_thread_pool_resume( &connection_pool );
5073 send_ldap_result( op, rs );
5078 config_back_delete( Operation *op, SlapReply *rs )
5080 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5085 config_back_search( Operation *op, SlapReply *rs )
5088 CfEntryInfo *ce, *last;
5091 cfb = (CfBackInfo *)op->o_bd->be_private;
5093 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5096 rs->sr_matched = last->ce_entry->e_name.bv_val;
5097 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5100 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5101 ACL_SEARCH, NULL, &mask ))
5103 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5104 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5106 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5110 switch ( op->ors_scope ) {
5111 case LDAP_SCOPE_BASE:
5112 case LDAP_SCOPE_SUBTREE:
5113 config_send( op, rs, ce, 0 );
5116 case LDAP_SCOPE_ONELEVEL:
5117 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5118 config_send( op, rs, ce, 1 );
5123 rs->sr_err = LDAP_SUCCESS;
5125 send_ldap_result( op, rs );
5129 /* no-op, we never free entries */
5130 int config_entry_release(
5135 return LDAP_SUCCESS;
5138 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5140 int config_back_entry_get(
5144 AttributeDescription *at,
5149 CfEntryInfo *ce, *last;
5151 cfb = (CfBackInfo *)op->o_bd->be_private;
5153 ce = config_find_base( cfb->cb_root, ndn, &last );
5155 *ent = ce->ce_entry;
5156 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5161 return ( *ent == NULL ? 1 : 0 );
5165 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5166 ConfigTable *ct, ConfigArgs *c )
5170 for (; at && *at; at++) {
5171 /* Skip the naming attr */
5172 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5174 for (i=0;ct[i].name;i++) {
5175 if (ct[i].ad == (*at)->sat_ad) {
5176 rc = config_get_vals(&ct[i], c);
5177 /* NOTE: tolerate that config_get_vals()
5178 * returns success with no values */
5179 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5180 if ( c->rvalue_nvals )
5181 attr_merge(e, ct[i].ad, c->rvalue_vals,
5184 attr_merge_normalize(e, ct[i].ad,
5185 c->rvalue_vals, NULL);
5186 ber_bvarray_free( c->rvalue_nvals );
5187 ber_bvarray_free( c->rvalue_vals );
5196 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5197 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5199 Entry *e = entry_alloc();
5200 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5202 struct berval ad_name;
5203 AttributeDescription *ad = NULL;
5210 CfEntryInfo *ceprev = NULL;
5212 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5215 ce->ce_type = main->co_type;
5216 ce->ce_parent = parent;
5218 pdn = parent->ce_entry->e_nname;
5219 if ( parent->ce_kids && parent->ce_kids->ce_type < ce->ce_type )
5220 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5221 ceprev->ce_type < ce->ce_type;
5222 ceprev = ceprev->ce_sibs );
5227 ce->ce_private = c->private;
5231 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5232 ber_dupbv( &e->e_nname, &e->e_name );
5234 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5235 main->co_name, NULL );
5237 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5238 extra->co_name, NULL );
5239 ptr = strchr(rdn->bv_val, '=');
5240 ad_name.bv_val = rdn->bv_val;
5241 ad_name.bv_len = ptr - rdn->bv_val;
5242 rc = slap_bv2ad( &ad_name, &ad, &text );
5247 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5248 attr_merge_normalize_one(e, ad, &val, NULL );
5251 if ( oc->soc_required )
5252 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5254 if ( oc->soc_allowed )
5255 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5259 if ( oc->soc_required )
5260 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5262 if ( oc->soc_allowed )
5263 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5266 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5267 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->msg,
5268 sizeof(c->msg), op ? op->o_tmpmemctx : NULL );
5269 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5270 if ( op && !op->o_noop ) {
5272 op->ora_modlist = NULL;
5273 op->o_bd->be_add( op, rs );
5274 if ( ( rs->sr_err != LDAP_SUCCESS )
5275 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5280 ce->ce_sibs = ceprev->ce_sibs;
5281 ceprev->ce_sibs = ce;
5282 } else if ( parent ) {
5283 ce->ce_sibs = parent->ce_kids;
5284 parent->ce_kids = ce;
5291 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5292 Operation *op, SlapReply *rs )
5295 ConfigFile *cf = c->private;
5299 for (; cf; cf=cf->c_sibs, c->depth++) {
5300 c->value_dn.bv_val = c->log;
5301 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5306 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5308 ptr = strchr( bv.bv_val, '.' );
5310 bv.bv_len = ptr - bv.bv_val;
5311 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5312 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5313 /* FIXME: how can indicate error? */
5316 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5318 c->value_dn.bv_len += bv.bv_len;
5319 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5322 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5323 &CFOC_SCHEMA, NULL );
5326 } else if ( e && cf->c_kids ) {
5327 c->private = cf->c_kids;
5328 config_build_schema_inc( c, e->e_private, op, rs );
5334 #ifdef SLAPD_MODULES
5337 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5338 Operation *op, SlapReply *rs )
5343 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5344 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5346 c->value_dn.bv_val = c->log;
5347 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5348 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5349 /* FIXME: how can indicate error? */
5353 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5362 config_check_schema(Operation *op, CfBackInfo *cfb)
5364 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5366 CfEntryInfo *ce, *last;
5369 /* If there's no root entry, we must be in the midst of converting */
5370 if ( !cfb->cb_root )
5373 /* Make sure the main schema entry exists */
5374 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5381 /* Make sure it's up to date */
5382 if ( cf_om_tail != om_sys_tail ) {
5383 a = attr_find( e->e_attrs, cfAd_om );
5385 if ( a->a_nvals != a->a_vals )
5386 ber_bvarray_free( a->a_nvals );
5387 ber_bvarray_free( a->a_vals );
5391 oidm_unparse( &bv, NULL, NULL, 1 );
5392 attr_merge_normalize( e, cfAd_om, bv, NULL );
5393 ber_bvarray_free( bv );
5394 cf_om_tail = om_sys_tail;
5396 if ( cf_at_tail != at_sys_tail ) {
5397 a = attr_find( e->e_attrs, cfAd_attr );
5399 if ( a->a_nvals != a->a_vals )
5400 ber_bvarray_free( a->a_nvals );
5401 ber_bvarray_free( a->a_vals );
5405 at_unparse( &bv, NULL, NULL, 1 );
5406 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5407 ber_bvarray_free( bv );
5408 cf_at_tail = at_sys_tail;
5410 if ( cf_oc_tail != oc_sys_tail ) {
5411 a = attr_find( e->e_attrs, cfAd_oc );
5413 if ( a->a_nvals != a->a_vals )
5414 ber_bvarray_free( a->a_nvals );
5415 ber_bvarray_free( a->a_vals );
5419 oc_unparse( &bv, NULL, NULL, 1 );
5420 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5421 ber_bvarray_free( bv );
5422 cf_oc_tail = oc_sys_tail;
5425 SlapReply rs = {REP_RESULT};
5427 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5428 &CFOC_SCHEMA, NULL );
5433 ce->ce_private = cfb->cb_config;
5434 cf_at_tail = at_sys_tail;
5435 cf_oc_tail = oc_sys_tail;
5436 cf_om_tail = om_sys_tail;
5441 static const char *defacl[] = {
5442 NULL, "to", "*", "by", "*", "none", NULL
5446 config_back_db_open( BackendDB *be )
5448 CfBackInfo *cfb = be->be_private;
5451 CfEntryInfo *ce, *ceparent;
5455 Connection conn = {0};
5456 OperationBuffer opbuf;
5458 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5459 SlapReply rs = {REP_RESULT};
5460 void *thrctx = NULL;
5462 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5464 /* If we have no explicitly configured ACLs, don't just use
5465 * the global ACLs. Explicitly deny access to everything.
5467 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5468 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5471 thrctx = ldap_pvt_thread_pool_context();
5472 op = (Operation *) &opbuf;
5473 connection_fake_init( &conn, op, thrctx );
5475 op->o_tag = LDAP_REQ_ADD;
5476 op->o_callback = &cb;
5477 op->o_bd = &cfb->cb_db;
5478 op->o_dn = op->o_bd->be_rootdn;
5479 op->o_ndn = op->o_bd->be_rootndn;
5481 if ( !cfb->cb_use_ldif ) {
5485 /* If we read the config from back-ldif, do some quick sanity checks */
5486 if ( cfb->cb_got_ldif ) {
5487 return config_check_schema( op, cfb );
5490 /* create root of tree */
5492 c.private = cfb->cb_config;
5494 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5504 #ifdef SLAPD_MODULES
5505 /* Create Module nodes... */
5506 if ( modpaths.mp_loads ) {
5507 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5513 /* Create schema nodes... cn=schema will contain the hardcoded core
5514 * schema, read-only. Child objects will contain runtime loaded schema
5519 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5524 ce->ce_private = cfb->cb_config;
5525 cf_at_tail = at_sys_tail;
5526 cf_oc_tail = oc_sys_tail;
5527 cf_om_tail = om_sys_tail;
5529 /* Create schema nodes for included schema... */
5530 if ( cfb->cb_config->c_kids ) {
5532 c.private = cfb->cb_config->c_kids;
5533 if (config_build_schema_inc( &c, ce, op, &rs )) {
5538 /* Create backend nodes. Skip if they don't provide a cf_table.
5539 * There usually aren't any of these.
5543 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5544 if (!bi->bi_cf_ocs) {
5545 /* If it only supports the old config mech, complain. */
5546 if ( bi->bi_config ) {
5547 Debug( LDAP_DEBUG_ANY,
5548 "WARNING: No dynamic config support for backend %s.\n",
5549 bi->bi_type, 0, 0 );
5554 if (!bi->bi_private) continue;
5557 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5558 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5559 if ( rdn.bv_len >= sizeof( c.log ) ) {
5560 /* FIXME: holler ... */ ;
5563 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5570 /* Create database nodes... */
5571 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5572 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5573 for ( i = -1, be = frontendDB ; be;
5574 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5575 slap_overinfo *oi = NULL;
5577 if ( overlay_is_over( be )) {
5578 oi = be->bd_info->bi_private;
5584 /* If this backend supports the old config mechanism, but not
5585 * the new mech, complain.
5587 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5588 Debug( LDAP_DEBUG_ANY,
5589 "WARNING: No dynamic config support for database %s.\n",
5590 bi->bi_type, 0, 0 );
5594 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5595 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5597 if ( rdn.bv_len >= sizeof( c.log ) ) {
5598 /* FIXME: holler ... */ ;
5602 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5608 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5609 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5610 /* Iterate through overlays */
5616 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5617 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5618 Debug( LDAP_DEBUG_ANY,
5619 "WARNING: No dynamic config support for overlay %s.\n",
5620 on->on_bi.bi_type, 0, 0 );
5624 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5625 "%s=" SLAP_X_ORDERED_FMT "%s",
5626 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5627 if ( rdn.bv_len >= sizeof( c.log ) ) {
5628 /* FIXME: holler ... */ ;
5632 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5633 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5637 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5638 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5643 ldap_pvt_thread_pool_context_reset( thrctx );
5645 if ( unsupp && cfb->cb_use_ldif ) {
5646 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5647 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5654 cfb_free_cffile( ConfigFile *cf )
5658 for (; cf; cf=next) {
5661 cfb_free_cffile( cf->c_kids );
5662 ch_free( cf->c_file.bv_val );
5663 ber_bvarray_free( cf->c_dseFiles );
5669 cfb_free_entries( CfEntryInfo *ce )
5673 for (; ce; ce=next) {
5676 cfb_free_entries( ce->ce_kids );
5677 ce->ce_entry->e_private = NULL;
5678 entry_free( ce->ce_entry );
5684 config_back_db_close( BackendDB *be )
5686 CfBackInfo *cfb = be->be_private;
5688 cfb_free_entries( cfb->cb_root );
5689 cfb->cb_root = NULL;
5691 if ( cfb->cb_db.bd_info ) {
5692 backend_shutdown( &cfb->cb_db );
5699 config_back_db_destroy( BackendDB *be )
5701 CfBackInfo *cfb = be->be_private;
5703 cfb_free_cffile( cfb->cb_config );
5705 ch_free( cfdir.bv_val );
5707 avl_free( CfOcTree, NULL );
5709 if ( cfb->cb_db.bd_info ) {
5710 cfb->cb_db.be_suffix = NULL;
5711 cfb->cb_db.be_nsuffix = NULL;
5712 BER_BVZERO( &cfb->cb_db.be_rootdn );
5713 BER_BVZERO( &cfb->cb_db.be_rootndn );
5715 backend_destroy_one( &cfb->cb_db, 0 );
5724 config_back_db_init( BackendDB *be )
5730 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5731 cfn = cfb->cb_config;
5732 be->be_private = cfb;
5734 ber_dupbv( &be->be_rootdn, &config_rdn );
5735 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5736 ber_dupbv( &dn, &be->be_rootdn );
5737 ber_bvarray_add( &be->be_suffix, &dn );
5738 ber_dupbv( &dn, &be->be_rootdn );
5739 ber_bvarray_add( &be->be_nsuffix, &dn );
5741 /* Hide from namingContexts */
5742 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5748 config_back_destroy( BackendInfo *bi )
5750 ldif_must_b64_encode_release();
5755 config_tool_entry_open( BackendDB *be, int mode )
5757 CfBackInfo *cfb = be->be_private;
5758 BackendInfo *bi = cfb->cb_db.bd_info;
5760 if ( bi && bi->bi_tool_entry_open )
5761 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5768 config_tool_entry_close( BackendDB *be )
5770 CfBackInfo *cfb = be->be_private;
5771 BackendInfo *bi = cfb->cb_db.bd_info;
5773 if ( bi && bi->bi_tool_entry_close )
5774 return bi->bi_tool_entry_close( &cfb->cb_db );
5780 config_tool_entry_first( BackendDB *be )
5782 CfBackInfo *cfb = be->be_private;
5783 BackendInfo *bi = cfb->cb_db.bd_info;
5785 if ( bi && bi->bi_tool_entry_first )
5786 return bi->bi_tool_entry_first( &cfb->cb_db );
5792 config_tool_entry_next( BackendDB *be )
5794 CfBackInfo *cfb = be->be_private;
5795 BackendInfo *bi = cfb->cb_db.bd_info;
5797 if ( bi && bi->bi_tool_entry_next )
5798 return bi->bi_tool_entry_next( &cfb->cb_db );
5804 config_tool_entry_get( BackendDB *be, ID id )
5806 CfBackInfo *cfb = be->be_private;
5807 BackendInfo *bi = cfb->cb_db.bd_info;
5809 if ( bi && bi->bi_tool_entry_get )
5810 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5816 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5818 CfBackInfo *cfb = be->be_private;
5819 BackendInfo *bi = cfb->cb_db.bd_info;
5822 if ( bi && bi->bi_tool_entry_put &&
5823 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
5824 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
5831 AttributeDescription **desc;
5833 { "attribute", &cfAd_attr },
5834 { "backend", &cfAd_backend },
5835 { "database", &cfAd_database },
5836 { "include", &cfAd_include },
5837 { "objectclass", &cfAd_oc },
5838 { "objectidentifier", &cfAd_om },
5839 { "overlay", &cfAd_overlay },
5844 * add / delete: all types that may be added or deleted must use an
5845 * X-ORDERED attributeType for their RDN. Adding and deleting entries
5846 * should automatically renumber the index of any siblings as needed,
5847 * so that no gaps in the numbering sequence exist after the add/delete
5849 * What can be added:
5851 * backend objects for backend-specific config directives
5855 * delete: probably no support this time around.
5857 * modrdn: generally not done. Will be invoked automatically by add/
5858 * delete to update numbering sequence. Perform as an explicit operation
5859 * so that the renumbering effect may be replicated. Subtree rename must
5860 * be supported, since renumbering a database will affect all its child
5863 * modify: must be fully supported.
5867 config_back_initialize( BackendInfo *bi )
5869 ConfigTable *ct = config_back_cf_table;
5873 AttributeDescription *ad = NULL;
5875 static char *controls[] = {
5876 LDAP_CONTROL_MANAGEDSAIT,
5880 /* Make sure we don't exceed the bits reserved for userland */
5881 config_check_userland( CFG_LAST );
5883 bi->bi_controls = controls;
5888 bi->bi_destroy = config_back_destroy;
5890 bi->bi_db_init = config_back_db_init;
5891 bi->bi_db_config = 0;
5892 bi->bi_db_open = config_back_db_open;
5893 bi->bi_db_close = config_back_db_close;
5894 bi->bi_db_destroy = config_back_db_destroy;
5896 bi->bi_op_bind = config_back_bind;
5897 bi->bi_op_unbind = 0;
5898 bi->bi_op_search = config_back_search;
5899 bi->bi_op_compare = 0;
5900 bi->bi_op_modify = config_back_modify;
5901 bi->bi_op_modrdn = config_back_modrdn;
5902 bi->bi_op_add = config_back_add;
5903 bi->bi_op_delete = config_back_delete;
5904 bi->bi_op_abandon = 0;
5906 bi->bi_extended = 0;
5908 bi->bi_chk_referrals = 0;
5910 bi->bi_access_allowed = slap_access_allowed;
5912 bi->bi_connection_init = 0;
5913 bi->bi_connection_destroy = 0;
5915 bi->bi_entry_release_rw = config_entry_release;
5916 bi->bi_entry_get_rw = config_back_entry_get;
5918 bi->bi_tool_entry_open = config_tool_entry_open;
5919 bi->bi_tool_entry_close = config_tool_entry_close;
5920 bi->bi_tool_entry_first = config_tool_entry_first;
5921 bi->bi_tool_entry_next = config_tool_entry_next;
5922 bi->bi_tool_entry_get = config_tool_entry_get;
5923 bi->bi_tool_entry_put = config_tool_entry_put;
5926 argv[ 0 ] = "slapd";
5932 for (i=0; OidMacros[i].name; i++ ) {
5933 argv[1] = OidMacros[i].name;
5934 argv[2] = OidMacros[i].oid;
5935 parse_oidm( &ca, 0, NULL );
5938 bi->bi_cf_ocs = cf_ocs;
5940 i = config_register_schema( ct, cf_ocs );
5943 /* setup olcRootPW to be base64-encoded when written in LDIF form;
5944 * basically, we don't care if it fails */
5945 i = slap_str2ad( "olcRootPW", &ad, &text );
5947 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
5948 "warning, unable to get \"olcRootPW\" "
5949 "attribute description: %d: %s\n",
5952 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
5953 ad->ad_type->sat_oid );
5956 /* set up the notable AttributeDescriptions */
5958 for (;ct->name;ct++) {
5959 if (strcmp(ct->name, ads[i].name)) continue;
5960 *ads[i].desc = ct->ad;
5962 if (!ads[i].name) break;