1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 static struct berval config_rdn = BER_BVC("cn=config");
41 static struct berval schema_rdn = BER_BVC("cn=schema");
46 typedef struct modpath_s {
47 struct modpath_s *mp_next;
48 struct berval mp_path;
52 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
55 typedef struct ConfigFile {
56 struct ConfigFile *c_sibs;
57 struct ConfigFile *c_kids;
59 AttributeType *c_at_head, *c_at_tail;
60 ContentRule *c_cr_head, *c_cr_tail;
61 ObjectClass *c_oc_head, *c_oc_tail;
62 OidMacro *c_om_head, *c_om_tail;
67 ConfigFile *cb_config;
69 BackendDB cb_db; /* underlying database */
74 /* These do nothing in slapd, they're kept only to make them
77 static char *replica_pidFile, *replica_argsFile;
78 static int replicationInterval;
80 static char *passwd_salt;
81 static char *logfileName;
82 static BerVarray authz_rewrites;
84 static struct berval cfdir;
87 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
90 static ConfigFile cf_prv, *cfn = &cf_prv;
92 static Avlnode *CfOcTree;
94 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
95 SlapReply *rs, int *renumber );
97 static ConfigDriver config_fname;
98 static ConfigDriver config_cfdir;
99 static ConfigDriver config_generic;
100 static ConfigDriver config_search_base;
101 static ConfigDriver config_passwd_hash;
102 static ConfigDriver config_schema_dn;
103 static ConfigDriver config_sizelimit;
104 static ConfigDriver config_timelimit;
105 static ConfigDriver config_overlay;
106 static ConfigDriver config_suffix;
107 static ConfigDriver config_deref_depth;
108 static ConfigDriver config_rootdn;
109 static ConfigDriver config_rootpw;
110 static ConfigDriver config_restrict;
111 static ConfigDriver config_allows;
112 static ConfigDriver config_disallows;
113 static ConfigDriver config_requires;
114 static ConfigDriver config_security;
115 static ConfigDriver config_referral;
116 static ConfigDriver config_loglevel;
117 static ConfigDriver config_replica;
118 static ConfigDriver config_updatedn;
119 static ConfigDriver config_updateref;
120 static ConfigDriver config_include;
122 static ConfigDriver config_tls_option;
123 static ConfigDriver config_tls_config;
125 extern ConfigDriver syncrepl_config;
171 static OidRec OidMacros[] = {
172 /* OpenLDAProot:666.11.1 */
173 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
174 { "OLcfgAt", "OLcfg:3" },
175 { "OLcfgGlAt", "OLcfgAt:0" },
176 { "OLcfgBkAt", "OLcfgAt:1" },
177 { "OLcfgDbAt", "OLcfgAt:2" },
178 { "OLcfgOvAt", "OLcfgAt:3" },
179 { "OLcfgOc", "OLcfg:4" },
180 { "OLcfgGlOc", "OLcfgOc:0" },
181 { "OLcfgBkOc", "OLcfgOc:1" },
182 { "OLcfgDbOc", "OLcfgOc:2" },
183 { "OLcfgOvOc", "OLcfgOc:3" },
184 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
185 { "OMsInteger", "OMsyn:27" },
186 { "OMsBoolean", "OMsyn:7" },
187 { "OMsDN", "OMsyn:12" },
188 { "OMsDirectoryString", "OMsyn:15" },
189 { "OMsOctetString", "OMsyn:40" },
194 * OLcfg{Bk|Db}{Oc|At}:0 -> common
195 * OLcfg{Bk|Db}{Oc|At}:1 -> bdb
196 * OLcfg{Bk|Db}{Oc|At}:2 -> ldif
197 * OLcfg{Bk|Db}{Oc|At}:3 -> ldap?
200 /* alphabetical ordering */
202 static ConfigTable config_back_cf_table[] = {
203 /* This attr is read-only */
204 { "", "", 0, 0, 0, ARG_MAGIC,
205 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
206 "DESC 'File for slapd configuration directives' "
207 "EQUALITY caseIgnoreMatch "
208 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
209 { "", "", 0, 0, 0, ARG_MAGIC,
210 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
211 "DESC 'Directory for slapd configuration backend' "
212 "EQUALITY caseIgnoreMatch "
213 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
214 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
215 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
216 "DESC 'Access Control List' "
217 "EQUALITY caseIgnoreMatch "
218 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
219 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
220 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
221 "DESC 'Allowed set of deprecated features' "
222 "EQUALITY caseIgnoreMatch "
223 "SYNTAX OMsDirectoryString )", NULL, NULL },
224 { "argsfile", "file", 2, 2, 0, ARG_STRING,
225 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
226 "DESC 'File for slapd command line options' "
227 "EQUALITY caseIgnoreMatch "
228 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
229 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
230 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
231 "EQUALITY caseIgnoreMatch "
232 "SYNTAX OMsDirectoryString )", NULL, NULL },
233 { "attribute", "attribute", 2, 0, 9,
234 ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT,
235 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
236 "DESC 'OpenLDAP attributeTypes' "
237 "EQUALITY caseIgnoreMatch "
238 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
240 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
241 #ifdef SLAP_AUTH_REWRITE
242 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
246 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
247 "EQUALITY caseIgnoreMatch "
248 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
249 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
250 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
251 "EQUALITY caseIgnoreMatch "
252 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
253 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
254 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
255 "EQUALITY caseIgnoreMatch "
256 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
257 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
258 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
259 "DESC 'A type of backend' "
260 "EQUALITY caseIgnoreMatch "
261 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
263 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
264 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
265 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
266 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
267 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
268 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
269 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
270 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
271 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
272 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
273 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
274 "DESC 'The backend type for a database instance' "
275 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
276 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
277 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
278 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
279 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
280 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString )", NULL, NULL },
283 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
284 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
285 "DESC 'OpenLDAP DIT content rules' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
289 { "gentlehup", "on|off", 2, 2, 0,
291 ARG_ON_OFF, &global_gentlehup,
295 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
296 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
297 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
298 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
299 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
300 { "include", "file", 2, 2, 0, ARG_MAGIC,
301 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
302 "SUP labeledURI )", NULL, NULL },
303 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
304 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
305 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
306 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
307 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
308 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
309 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
310 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
311 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
312 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
313 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
314 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
315 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
316 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
317 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
318 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
319 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
320 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
321 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
322 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
323 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
324 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
325 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
326 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
327 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
328 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
329 "SYNTAX OMsDirectoryString )", NULL, NULL },
330 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
331 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
332 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
333 { "moduleload", "file", 2, 0, 0,
335 ARG_MAGIC|CFG_MODLOAD, &config_generic,
339 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
340 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
341 { "modulepath", "path", 2, 2, 0,
343 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
347 "( OLcfgGlAt:31 NAME 'olcModulePath' "
348 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
349 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT,
350 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
351 "DESC 'OpenLDAP object classes' "
352 "EQUALITY caseIgnoreMatch "
353 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
355 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
356 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
357 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
358 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
359 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
360 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
361 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
362 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
363 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
364 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
365 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
366 "SYNTAX OMsDirectoryString )", NULL, NULL },
367 { "pidfile", "file", 2, 2, 0, ARG_STRING,
368 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
369 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
370 { "plugin", NULL, 0, 0, 0,
372 ARG_MAGIC|CFG_PLUGIN, &config_generic,
376 "( OLcfgGlAt:38 NAME 'olcPlugin' "
377 "SYNTAX OMsDirectoryString )", NULL, NULL },
378 { "pluginlog", "filename", 2, 2, 0,
380 ARG_STRING, &slapi_log_file,
384 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
385 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
386 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
387 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
388 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
389 { "referral", "url", 2, 2, 0, ARG_MAGIC,
390 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
391 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
392 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
393 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
394 "SUP labeledURI )", NULL, NULL },
395 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
396 &replica_argsFile, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
397 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
398 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
399 &replica_pidFile, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
400 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
401 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
402 &replicationInterval, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
403 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
404 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
405 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
406 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
407 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
408 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
409 "SYNTAX OMsDirectoryString )", NULL, NULL },
410 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
411 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
412 "SYNTAX OMsDirectoryString )", NULL, NULL },
413 { "reverse-lookup", "on|off", 2, 2, 0,
414 #ifdef SLAPD_RLOOKUPS
415 ARG_ON_OFF, &use_reverse_lookup,
419 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
420 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
421 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
422 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
423 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
424 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
425 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
426 "SYNTAX OMsDirectoryString )", NULL, NULL },
427 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
428 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
429 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
430 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
431 &config_generic, NULL, NULL, NULL },
432 { "sasl-host", "host", 2, 2, 0,
433 #ifdef HAVE_CYRUS_SASL
434 ARG_STRING|ARG_UNIQUE, &global_host,
438 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
439 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
440 { "sasl-realm", "realm", 2, 2, 0,
441 #ifdef HAVE_CYRUS_SASL
442 ARG_STRING|ARG_UNIQUE, &global_realm,
446 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
447 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
448 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
449 &config_generic, NULL, NULL, NULL },
450 { "sasl-secprops", "properties", 2, 2, 0,
451 #ifdef HAVE_CYRUS_SASL
452 ARG_MAGIC|CFG_SASLSECP, &config_generic,
456 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
457 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
458 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
459 &config_generic, NULL, NULL, NULL },
460 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
461 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
462 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
463 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
464 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
465 "SYNTAX OMsDirectoryString )", NULL, NULL },
466 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
467 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
468 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
469 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
470 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
471 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
472 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
473 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
474 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
475 { "srvtab", "file", 2, 2, 0,
476 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
477 ARG_STRING, &ldap_srvtab,
481 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
482 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
483 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
484 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
485 "SYNTAX OMsDN )", NULL, NULL },
486 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
487 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
488 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
489 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
490 &config_generic, "( OLcfgGlAt:66 NAME 'olcThreads' "
491 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
492 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
493 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
494 "SYNTAX OMsDirectoryString )", NULL, NULL },
495 { "TLSCACertificateFile", NULL, 0, 0, 0,
497 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
501 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
502 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
503 { "TLSCACertificatePath", NULL, 0, 0, 0,
505 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
509 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
510 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
511 { "TLSCertificateFile", NULL, 0, 0, 0,
513 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
517 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
518 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
519 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
521 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
525 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
526 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
527 { "TLSCipherSuite", NULL, 0, 0, 0,
529 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
533 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
534 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
535 { "TLSCRLCheck", NULL, 0, 0, 0,
536 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
537 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
541 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
542 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
543 { "TLSRandFile", NULL, 0, 0, 0,
545 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
549 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
550 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
551 { "TLSVerifyClient", NULL, 0, 0, 0,
553 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
557 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
558 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
559 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
560 NULL, NULL, NULL, NULL },
561 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
562 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
563 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
564 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
565 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
566 "SUP labeledURI )", NULL, NULL },
567 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
568 NULL, NULL, NULL, NULL }
571 /* Routines to check if a child can be added to this type */
572 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
573 cfAddBackend, cfAddModule, cfAddOverlay;
575 #define CFOC_GLOBAL cf_ocs[1]
576 #define CFOC_SCHEMA cf_ocs[2]
577 #define CFOC_BACKEND cf_ocs[3]
578 #define CFOC_DATABASE cf_ocs[4]
579 #define CFOC_OVERLAY cf_ocs[5]
580 #define CFOC_INCLUDE cf_ocs[6]
581 #define CFOC_MODULE cf_ocs[7]
583 static ConfigOCs cf_ocs[] = {
586 "DESC 'OpenLDAP configuration object' "
587 "ABSTRACT SUP top )", Cft_Abstract, NULL },
590 "DESC 'OpenLDAP Global configuration options' "
591 "SUP olcConfig STRUCTURAL "
592 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
593 "olcAttributeOptions $ olcAuthIDRewrite $ "
594 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
595 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
596 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
597 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
598 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
600 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
601 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
602 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
603 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
604 "olcRootDSE $ olcRootPW $ "
605 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
606 "olcSecurity $ olcSizeLimit $ "
607 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
608 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
609 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
610 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
611 "olcTLSRandFile $ olcTLSVerifyClient $ "
612 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
613 "olcDitContentRules ) )", Cft_Global },
615 "NAME 'olcSchemaConfig' "
616 "DESC 'OpenLDAP schema object' "
617 "SUP olcConfig STRUCTURAL "
618 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
619 "olcObjectClasses $ olcDitContentRules ) )",
620 Cft_Schema, NULL, cfAddSchema },
622 "NAME 'olcBackendConfig' "
623 "DESC 'OpenLDAP Backend-specific options' "
624 "SUP olcConfig STRUCTURAL "
625 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
627 "NAME 'olcDatabaseConfig' "
628 "DESC 'OpenLDAP Database-specific options' "
629 "SUP olcConfig STRUCTURAL "
631 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
632 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
633 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
634 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
635 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
636 Cft_Database, NULL, cfAddDatabase },
638 "NAME 'olcOverlayConfig' "
639 "DESC 'OpenLDAP Overlay-specific options' "
640 "SUP olcConfig STRUCTURAL "
641 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
643 "NAME 'olcIncludeFile' "
644 "DESC 'OpenLDAP configuration include file' "
645 "SUP olcConfig STRUCTURAL "
647 "MAY ( cn $ olcRootDSE ) )",
648 Cft_Include, NULL, cfAddInclude },
651 "NAME 'olcModuleList' "
652 "DESC 'OpenLDAP dynamic module info' "
653 "SUP olcConfig STRUCTURAL "
654 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
655 Cft_Module, NULL, cfAddModule },
661 config_generic(ConfigArgs *c) {
665 if ( c->op == SLAP_CONFIG_EMIT ) {
669 c->value_int = ldap_pvt_thread_get_concurrency();
672 c->value_int = connection_pool_max;
676 c->value_string = ch_strdup( passwd_salt );
681 if ( c->be->be_limits ) {
686 for ( i=0; c->be->be_limits[i]; i++ ) {
687 bv.bv_len = sprintf( buf, IFMT, i );
688 bv.bv_val = buf+bv.bv_len;
689 limits_unparse( c->be->be_limits[i], &bv );
690 bv.bv_len += bv.bv_val - buf;
692 value_add_one( &c->rvalue_vals, &bv );
695 if ( !c->rvalue_vals ) rc = 1;
698 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
699 SLAP_RESTRICT_OP_WRITES;
702 c->value_string = ch_strdup( slap_sasl_getpolicy());
705 slap_sasl_regexp_unparse( &c->rvalue_vals );
706 if ( !c->rvalue_vals ) rc = 1;
708 #ifdef HAVE_CYRUS_SASL
710 struct berval bv = BER_BVNULL;
711 slap_sasl_secprops_unparse( &bv );
712 if ( !BER_BVISNULL( &bv )) {
713 ber_bvarray_add( &c->rvalue_vals, &bv );
721 c->value_int = c->be->be_max_deref_depth;
724 ConfigFile *cf = c->private;
726 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
727 else if ( cf->c_om_head )
728 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
730 if ( !c->rvalue_vals )
735 ConfigFile *cf = c->private;
737 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
738 else if ( cf->c_oc_head )
739 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
741 if ( !c->rvalue_vals )
746 ConfigFile *cf = c->private;
748 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
749 else if ( cf->c_at_head )
750 at_unparse( &c->rvalue_vals, cf->c_at_head,
752 if ( !c->rvalue_vals )
757 ConfigFile *cf = c->private;
759 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
760 else if ( cf->c_cr_head )
761 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
763 if ( !c->rvalue_vals )
770 char *src, *dst, ibuf[11];
771 struct berval bv, abv;
772 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
773 abv.bv_len = sprintf( ibuf, IFMT, i );
774 acl_unparse( a, &bv );
775 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
776 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
777 /* Turn TAB / EOL into plain space */
778 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
779 if (isspace(*src)) *dst++ = ' ';
783 if (dst[-1] == ' ') {
787 abv.bv_len = dst - abv.bv_val;
788 ber_bvarray_add( &c->rvalue_vals, &abv );
794 if ( c->be->be_replogfile )
795 c->value_string = ch_strdup( c->be->be_replogfile );
798 ConfigFile *cf = c->private;
799 if ( cf->c_dseFiles ) {
800 value_add( &c->rvalue_vals, cf->c_dseFiles );
808 c->value_string = ch_strdup( logfileName );
813 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
815 case CFG_SSTR_IF_MAX:
816 c->value_int = index_substr_if_maxlen;
818 case CFG_SSTR_IF_MIN:
819 c->value_int = index_substr_if_minlen;
823 ModPaths *mp = c->private;
826 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
829 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
830 mp->mp_loads[i].bv_val );
831 value_add_one( &c->rvalue_vals, &bv );
835 rc = c->rvalue_vals ? 0 : 1;
839 ModPaths *mp = c->private;
840 if ( !BER_BVISNULL( &mp->mp_path ))
841 value_add_one( &c->rvalue_vals, &mp->mp_path );
843 rc = c->rvalue_vals ? 0 : 1;
849 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
850 if ( !c->rvalue_vals ) rc = 1;
853 #ifdef SLAP_AUTH_REWRITE
855 if ( authz_rewrites ) {
856 struct berval bv, idx;
861 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
862 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
863 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
864 bv.bv_val = ch_malloc( bv.bv_len + 1 );
865 strcpy( bv.bv_val, idx.bv_val );
866 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
867 ber_bvarray_add( &c->rvalue_vals, &bv );
870 if ( !c->rvalue_vals ) rc = 1;
877 } else if ( c->op == LDAP_MOD_DELETE ) {
880 /* single-valued attrs, no-ops */
888 case CFG_SSTR_IF_MAX:
889 case CFG_SSTR_IF_MIN:
892 /* no-ops, requires slapd restart */
897 sprintf(c->log, "change requires slapd restart");
901 ch_free( passwd_salt );
906 ch_free( c->be->be_replogfile );
907 c->be->be_replogfile = NULL;
911 ch_free( logfileName );
918 if ( c->be == frontendDB )
921 end = frontendDB->be_acl;
922 acl_destroy( c->be->be_acl, end );
924 AccessControl **prev, *a;
926 for (i=0, prev = &c->be->be_acl; i < c->valx;
938 /* FIXME: there is no limits_free function */
940 /* FIXME: there is no ad_option_free function */
942 /* FIXME: there is no way to remove attributes added by
956 p = strchr(c->line,'(' /*')'*/);
960 if(!(c->bi = backend_info(c->argv[1]))) {
961 sprintf( c->msg, "<%s> failed init", c->argv[0] );
962 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
963 c->log, c->msg, c->argv[1] );
970 /* NOTE: config is always the first backend!
972 if ( !strcasecmp( c->argv[1], "config" )) {
973 c->be = LDAP_STAILQ_FIRST(&backendDB);
974 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
977 c->be = backend_db_init(c->argv[1]);
979 sprintf( c->msg, "<%s> failed init", c->argv[0] );
980 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
981 c->log, c->msg, c->argv[1] );
988 ldap_pvt_thread_set_concurrency(c->value_int);
992 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
993 connection_pool_max = c->value_int; /* save for reference */
997 if ( passwd_salt ) ch_free( passwd_salt );
998 passwd_salt = c->value_string;
999 lutil_salt_format(passwd_salt);
1003 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1009 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1011 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1015 ch_free(c->value_string);
1016 if (slap_sasl_setpolicy( c->argv[1] )) {
1017 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1018 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1019 c->log, c->msg, c->argv[1] );
1025 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1029 #ifdef HAVE_CYRUS_SASL
1032 char *txt = slap_sasl_secprops( c->argv[1] );
1034 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1036 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1044 c->be->be_max_deref_depth = c->value_int;
1050 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1052 if (!cfn->c_om_head) cfn->c_om_head = om;
1053 cfn->c_om_tail = om;
1060 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1061 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1062 cfn->c_oc_tail = oc;
1069 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1070 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1071 cfn->c_cr_tail = cr;
1078 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1079 if (!cfn->c_at_head) cfn->c_at_head = at;
1080 cfn->c_at_tail = at;
1085 ad_define_option(NULL, NULL, 0);
1086 for(i = 1; i < c->argc; i++)
1087 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1092 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1096 if(SLAP_MONITOR(c->be)) {
1097 Debug(LDAP_DEBUG_ANY, "%s: "
1098 "\"replogfile\" should not be used "
1099 "inside monitor database\n",
1101 return(0); /* FIXME: should this be an error? */
1104 c->be->be_replogfile = c->value_string;
1108 if(read_root_dse_file(c->argv[1])) {
1109 sprintf( c->msg, "<%s> could not read file", c->argv[0] );
1110 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1111 c->log, c->msg, c->argv[1] );
1116 ber_str2bv( c->argv[1], 0, 1, &bv );
1117 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1123 if ( logfileName ) ch_free( logfileName );
1124 logfileName = c->value_string;
1125 logfile = fopen(logfileName, "w");
1126 if(logfile) lutil_debug_file(logfile);
1130 if(SLAP_NOLASTMODCMD(c->be)) {
1131 sprintf( c->msg, "<%s> not available for %s database",
1132 c->argv[0], c->be->bd_info->bi_type );
1133 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1134 c->log, c->msg, 0 );
1138 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1140 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1143 case CFG_SSTR_IF_MAX:
1144 if (c->value_int < index_substr_if_minlen) {
1145 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1146 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1147 c->log, c->msg, c->value_int );
1150 index_substr_if_maxlen = c->value_int;
1153 case CFG_SSTR_IF_MIN:
1154 if (c->value_int > index_substr_if_maxlen) {
1155 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1156 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1157 c->log, c->msg, c->value_int );
1160 index_substr_if_minlen = c->value_int;
1163 #ifdef SLAPD_MODULES
1165 /* If we're just adding a module on an existing modpath,
1166 * make sure we've selected the current path.
1168 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1169 modcur = c->private;
1170 /* This should never fail */
1171 if ( module_path( modcur->mp_path.bv_val )) {
1172 sprintf( c->msg, "<%s> module path no longer valid",
1174 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1175 c->log, c->msg, modcur->mp_path.bv_val );
1179 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1181 /* Record this load on the current path */
1185 if ( c->op == SLAP_CONFIG_ADD ) {
1186 ptr = c->line + STRLENOF("moduleload");
1187 while (!isspace(*ptr)) ptr++;
1188 while (isspace(*ptr)) ptr++;
1192 ber_str2bv(ptr, 0, 1, &bv);
1193 ber_bvarray_add( &modcur->mp_loads, &bv );
1198 if(module_path(c->argv[1])) return(1);
1199 /* Record which path was used with each module */
1203 if (!modpaths.mp_loads) {
1206 mp = ch_malloc( sizeof( ModPaths ));
1207 modlast->mp_next = mp;
1209 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1211 mp->mp_loads = NULL;
1222 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1224 slapi_plugins_used++;
1228 #ifdef SLAP_AUTH_REWRITE
1233 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1236 if ( c->argc > 1 ) {
1239 /* quote all args but the first */
1240 line = ldap_charray2str( c->argv, "\" \"" );
1241 ber_str2bv( line, 0, 0, &bv );
1242 s = strchr( bv.bv_val, '"' );
1243 assert( s != NULL );
1244 /* move the trailing quote of argv[0] to the end */
1245 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1246 bv.bv_val[ bv.bv_len - 1 ] = '"';
1249 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1252 ber_bvarray_add( &authz_rewrites, &bv );
1259 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1260 "%s: unknown CFG_TYPE %d"
1261 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1262 c->log, c->type, 0 );
1263 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1265 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1273 config_fname(ConfigArgs *c) {
1274 if(c->op == SLAP_CONFIG_EMIT) {
1276 ConfigFile *cf = c->private;
1277 value_add_one( &c->rvalue_vals, &cf->c_file );
1286 config_cfdir(ConfigArgs *c) {
1287 if(c->op == SLAP_CONFIG_EMIT) {
1288 if ( !BER_BVISEMPTY( &cfdir )) {
1289 value_add_one( &c->rvalue_vals, &cfdir );
1298 config_search_base(ConfigArgs *c) {
1301 if(c->op == SLAP_CONFIG_EMIT) {
1303 if (!BER_BVISEMPTY(&default_search_base)) {
1304 value_add_one(&c->rvalue_vals, &default_search_base);
1305 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1309 } else if( c->op == LDAP_MOD_DELETE ) {
1310 ch_free( default_search_base.bv_val );
1311 ch_free( default_search_nbase.bv_val );
1312 BER_BVZERO( &default_search_base );
1313 BER_BVZERO( &default_search_nbase );
1317 if(c->bi || c->be != frontendDB) {
1318 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1319 "prior to any backend or database definition\n",
1324 if(default_search_nbase.bv_len) {
1325 free(default_search_base.bv_val);
1326 free(default_search_nbase.bv_val);
1329 default_search_base = c->value_dn;
1330 default_search_nbase = c->value_ndn;
1335 config_passwd_hash(ConfigArgs *c) {
1337 if (c->op == SLAP_CONFIG_EMIT) {
1339 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1340 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1341 value_add_one(&c->rvalue_vals, &bv);
1344 } else if ( c->op == LDAP_MOD_DELETE ) {
1345 if ( c->valx < 0 ) {
1346 ldap_charray_free( default_passwd_hash );
1347 default_passwd_hash = NULL;
1350 ch_free( default_passwd_hash[i] );
1351 for (; default_passwd_hash[i]; i++ )
1352 default_passwd_hash[i] = default_passwd_hash[i+1];
1356 if(default_passwd_hash) {
1357 Debug(LDAP_DEBUG_ANY, "%s: "
1358 "already set default password_hash\n",
1362 for(i = 1; i < c->argc; i++) {
1363 if(!lutil_passwd_scheme(c->argv[i])) {
1364 sprintf( c->msg, "<%s> schema not available", c->argv[0] );
1365 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1366 c->log, c->msg, c->argv[i]);
1368 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1370 if(!default_passwd_hash) {
1371 sprintf( c->msg, "<%s> no valid hashes found", c->argv[0] );
1372 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1373 c->log, c->msg, 0 );
1381 config_schema_dn(ConfigArgs *c) {
1382 if ( c->op == SLAP_CONFIG_EMIT ) {
1384 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1385 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1386 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1390 } else if ( c->op == LDAP_MOD_DELETE ) {
1391 ch_free( c->be->be_schemadn.bv_val );
1392 ch_free( c->be->be_schemandn.bv_val );
1393 BER_BVZERO( &c->be->be_schemadn );
1394 BER_BVZERO( &c->be->be_schemandn );
1397 ch_free( c->be->be_schemadn.bv_val );
1398 ch_free( c->be->be_schemandn.bv_val );
1399 c->be->be_schemadn = c->value_dn;
1400 c->be->be_schemandn = c->value_ndn;
1405 config_sizelimit(ConfigArgs *c) {
1408 struct slap_limits_set *lim = &c->be->be_def_limit;
1409 if (c->op == SLAP_CONFIG_EMIT) {
1414 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1415 if ( !BER_BVISEMPTY( &bv ))
1416 value_add_one( &c->rvalue_vals, &bv );
1420 } else if ( c->op == LDAP_MOD_DELETE ) {
1421 /* Reset to defaults */
1422 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1423 lim->lms_s_hard = 0;
1424 lim->lms_s_unchecked = -1;
1426 lim->lms_s_pr_hide = 0;
1427 lim->lms_s_pr_total = 0;
1430 for(i = 1; i < c->argc; i++) {
1431 if(!strncasecmp(c->argv[i], "size", 4)) {
1432 rc = limits_parse_one(c->argv[i], lim);
1434 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1435 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1436 c->log, c->msg, c->argv[i]);
1440 if(!strcasecmp(c->argv[i], "unlimited")) {
1441 lim->lms_s_soft = -1;
1443 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1444 if(next == c->argv[i]) {
1445 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1446 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1447 c->log, c->msg, c->argv[i]);
1449 } else if(next[0] != '\0') {
1450 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1451 "trailing chars \"%s\" in \"sizelimit <limit>\" line"
1452 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1454 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1456 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1459 lim->lms_s_hard = 0;
1466 config_timelimit(ConfigArgs *c) {
1469 struct slap_limits_set *lim = &c->be->be_def_limit;
1470 if (c->op == SLAP_CONFIG_EMIT) {
1475 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1476 if ( !BER_BVISEMPTY( &bv ))
1477 value_add_one( &c->rvalue_vals, &bv );
1481 } else if ( c->op == LDAP_MOD_DELETE ) {
1482 /* Reset to defaults */
1483 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1484 lim->lms_t_hard = 0;
1487 for(i = 1; i < c->argc; i++) {
1488 if(!strncasecmp(c->argv[i], "time", 4)) {
1489 rc = limits_parse_one(c->argv[i], lim);
1491 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1492 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1493 c->log, c->msg, c->argv[i]);
1497 if(!strcasecmp(c->argv[i], "unlimited")) {
1498 lim->lms_t_soft = -1;
1500 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1501 if(next == c->argv[i]) {
1502 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1503 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1504 c->log, c->msg, c->argv[i]);
1506 } else if(next[0] != '\0') {
1507 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1508 "trailing chars \"%s\" in \"timelimit <limit>\" line"
1509 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1511 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1513 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1516 lim->lms_t_hard = 0;
1523 config_overlay(ConfigArgs *c) {
1525 if (c->op == SLAP_CONFIG_EMIT) {
1527 } else if ( c->op == LDAP_MOD_DELETE ) {
1530 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1532 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: (optional) %s overlay \"%s\" configuration failed"
1533 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1534 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1535 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1537 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1538 } else if(overlay_config(c->be, c->argv[1])) {
1541 /* Setup context for subsequent config directives.
1542 * The newly added overlay is at the head of the list.
1544 oi = (slap_overinfo *)c->be->bd_info;
1545 c->bi = &oi->oi_list->on_bi;
1550 config_suffix(ConfigArgs *c)
1553 struct berval pdn, ndn;
1555 char *notallowed = NULL;
1557 if ( c->be == frontendDB ) {
1558 notallowed = "frontend";
1560 } else if ( SLAP_MONITOR(c->be) ) {
1561 notallowed = "monitor";
1563 } else if ( SLAP_CONFIG(c->be) ) {
1564 notallowed = "config";
1567 if ( notallowed != NULL ) {
1568 Debug(LDAP_DEBUG_ANY,
1569 "%s: suffix <%s> not allowed in %s database.\n",
1570 c->log, c->value_dn.bv_val, notallowed );
1574 if (c->op == SLAP_CONFIG_EMIT) {
1575 if ( c->be->be_suffix == NULL
1576 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1580 value_add( &c->rvalue_vals, c->be->be_suffix );
1581 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1584 } else if ( c->op == LDAP_MOD_DELETE ) {
1585 if ( c->valx < 0 ) {
1586 ber_bvarray_free( c->be->be_suffix );
1587 ber_bvarray_free( c->be->be_nsuffix );
1588 c->be->be_suffix = NULL;
1589 c->be->be_nsuffix = NULL;
1592 ch_free( c->be->be_suffix[i].bv_val );
1593 ch_free( c->be->be_nsuffix[i].bv_val );
1594 for (; c->be->be_suffix[i].bv_val; i++) {
1595 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1596 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1602 #ifdef SLAPD_MONITOR_DN
1603 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1604 sprintf( c->msg, "<%s> DN is reserved for monitoring slapd",
1606 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1607 c->log, c->msg, SLAPD_MONITOR_DN);
1614 tbe = select_backend(&ndn, 0, 0);
1616 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1617 "%s: suffix already served by this backend!"
1618 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1620 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1622 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1626 sprintf( c->msg, "<%s> suffix already served by a preceding backend",
1628 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1629 c->log, c->msg, tbe->be_suffix[0].bv_val);
1633 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1634 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1635 "base provided \"%s\" (assuming okay)\n",
1636 c->log, default_search_base.bv_val, 0);
1638 ber_bvarray_add(&c->be->be_suffix, &pdn);
1639 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1644 config_rootdn(ConfigArgs *c) {
1645 if (c->op == SLAP_CONFIG_EMIT) {
1646 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1647 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1648 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1653 } else if ( c->op == LDAP_MOD_DELETE ) {
1654 ch_free( c->be->be_rootdn.bv_val );
1655 ch_free( c->be->be_rootndn.bv_val );
1656 BER_BVZERO( &c->be->be_rootdn );
1657 BER_BVZERO( &c->be->be_rootndn );
1660 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1661 ch_free( c->be->be_rootdn.bv_val );
1662 ch_free( c->be->be_rootndn.bv_val );
1664 c->be->be_rootdn = c->value_dn;
1665 c->be->be_rootndn = c->value_ndn;
1670 config_rootpw(ConfigArgs *c) {
1672 /* config_add_internal sets c->be = frontendDB. While the cn=config
1673 * rootpw is technically inside a backend, we expose it in the
1674 * global entry, and need to point to it properly here.
1676 if (c->be == frontendDB)
1677 c->be = LDAP_STAILQ_FIRST(&backendDB);
1679 if (c->op == SLAP_CONFIG_EMIT) {
1680 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1681 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1685 } else if ( c->op == LDAP_MOD_DELETE ) {
1686 ch_free( c->be->be_rootpw.bv_val );
1687 BER_BVZERO( &c->be->be_rootpw );
1691 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1693 sprintf( c->msg, "<%s> can only be set when rootdn is under suffix",
1695 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1699 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1700 ch_free( c->be->be_rootpw.bv_val );
1701 c->be->be_rootpw = c->value_bv;
1706 config_restrict(ConfigArgs *c) {
1707 slap_mask_t restrictops = 0;
1709 slap_verbmasks restrictable_ops[] = {
1710 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1711 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1712 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1713 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1714 { BER_BVC("modrdn"), 0 },
1715 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1716 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1717 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1718 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1719 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1720 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1721 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1722 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1723 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1724 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1728 if (c->op == SLAP_CONFIG_EMIT) {
1729 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1731 } else if ( c->op == LDAP_MOD_DELETE ) {
1733 c->be->be_restrictops = 0;
1735 restrictops = verb_to_mask( c->line, restrictable_ops );
1736 c->be->be_restrictops ^= restrictops;
1740 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1742 sprintf( c->msg, "<%s> unknown operation", c->argv[0] );
1743 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1744 c->log, c->msg, c->argv[i]);
1747 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1748 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1749 c->be->be_restrictops |= restrictops;
1754 config_allows(ConfigArgs *c) {
1755 slap_mask_t allows = 0;
1757 slap_verbmasks allowable_ops[] = {
1758 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1759 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1760 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1761 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1764 if (c->op == SLAP_CONFIG_EMIT) {
1765 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1766 } else if ( c->op == LDAP_MOD_DELETE ) {
1770 allows = verb_to_mask( c->line, allowable_ops );
1771 global_allows ^= allows;
1775 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1777 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1778 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1779 c->log, c->msg, c->argv[i]);
1782 global_allows |= allows;
1787 config_disallows(ConfigArgs *c) {
1788 slap_mask_t disallows = 0;
1790 slap_verbmasks disallowable_ops[] = {
1791 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1792 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1793 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1794 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1795 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1798 if (c->op == SLAP_CONFIG_EMIT) {
1799 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1800 } else if ( c->op == LDAP_MOD_DELETE ) {
1802 global_disallows = 0;
1804 disallows = verb_to_mask( c->line, disallowable_ops );
1805 global_disallows ^= disallows;
1809 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1811 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1812 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1813 c->log, c->msg, c->argv[i]);
1816 global_disallows |= disallows;
1821 config_requires(ConfigArgs *c) {
1822 slap_mask_t requires = 0;
1824 slap_verbmasks requires_ops[] = {
1825 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1826 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1827 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1828 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1829 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1832 if (c->op == SLAP_CONFIG_EMIT) {
1833 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1834 } else if ( c->op == LDAP_MOD_DELETE ) {
1836 c->be->be_requires = 0;
1838 requires = verb_to_mask( c->line, requires_ops );
1839 c->be->be_requires ^= requires;
1843 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1845 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1846 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1847 c->log, c->msg, c->argv[i]);
1850 c->be->be_requires = requires;
1855 config_loglevel(ConfigArgs *c) {
1858 slap_verbmasks loglevel_ops[] = {
1859 { BER_BVC("Any"), -1 },
1860 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1861 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1862 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1863 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1864 { BER_BVC("BER"), LDAP_DEBUG_BER },
1865 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1866 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1867 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1868 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1869 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1870 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1871 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1872 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1873 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1874 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
1878 if (c->op == SLAP_CONFIG_EMIT) {
1879 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1880 } else if ( c->op == LDAP_MOD_DELETE ) {
1884 int level = verb_to_mask( c->line, loglevel_ops );
1885 ldap_syslog ^= level;
1892 for( i=1; i < c->argc; i++ ) {
1895 if ( isdigit( c->argv[i][0] ) || c->argv[i][0] == '-' ) {
1896 level = strtol( c->argv[i], &next, 10 );
1897 if ( next == NULL || next[0] != '\0' ) {
1898 sprintf( c->msg, "<%s> unable to parse level", c->argv[0] );
1899 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1900 c->log, c->msg, c->argv[i]);
1904 int j = verb_to_mask(c->argv[i], loglevel_ops);
1905 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1906 sprintf( c->msg, "<%s> unknown level", c->argv[0] );
1907 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1908 c->log, c->msg, c->argv[i]);
1911 level = loglevel_ops[j].mask;
1913 ldap_syslog |= level;
1919 config_referral(ConfigArgs *c) {
1921 if (c->op == SLAP_CONFIG_EMIT) {
1922 if ( default_referral ) {
1923 value_add( &c->rvalue_vals, default_referral );
1928 } else if ( c->op == LDAP_MOD_DELETE ) {
1929 if ( c->valx < 0 ) {
1930 ber_bvarray_free( default_referral );
1931 default_referral = NULL;
1934 ch_free( default_referral[i].bv_val );
1935 for (; default_referral[i].bv_val; i++ )
1936 default_referral[i] = default_referral[i+1];
1940 if(validate_global_referral(c->argv[1])) {
1941 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
1942 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1943 c->log, c->msg, c->argv[1]);
1947 ber_str2bv(c->argv[1], 0, 0, &val);
1948 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
1956 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1957 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1958 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1959 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1960 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1961 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1962 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1963 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1964 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1969 config_security(ConfigArgs *c) {
1970 slap_ssf_set_t *set = &c->be->be_ssf_set;
1973 if (c->op == SLAP_CONFIG_EMIT) {
1979 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1980 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1983 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1984 bv.bv_len += sec_keys[i].key.bv_len;
1985 bv.bv_val = ch_malloc( bv.bv_len + 1);
1986 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1987 strcpy( next, numbuf );
1988 ber_bvarray_add( &c->rvalue_vals, &bv );
1993 for(i = 1; i < c->argc; i++) {
1994 slap_ssf_t *tgt = NULL;
1996 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1997 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1998 sec_keys[j].key.bv_len)) {
1999 src = c->argv[i] + sec_keys[j].key.bv_len;
2000 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2005 sprintf( c->msg, "<%s> unknown factor", c->argv[0] );
2006 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2007 c->log, c->msg, c->argv[i]);
2011 *tgt = strtol(src, &next, 10);
2012 if(next == NULL || next[0] != '\0' ) {
2013 sprintf( c->msg, "<%s> unable to parse factor", c->argv[0] );
2014 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2015 c->log, c->msg, c->argv[i]);
2023 anlist_unparse( AttributeName *an, char *ptr ) {
2026 for (; !BER_BVISNULL( &an->an_name ); an++) {
2027 if ( comma ) *ptr++ = ',';
2028 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2035 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2039 struct berval bc = {0};
2042 len = sprintf(numbuf, IFMT, i );
2044 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2045 if ( ri->ri_nsuffix ) {
2046 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2047 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2050 if ( ri->ri_attrs ) {
2051 len += STRLENOF("attr");
2052 if ( ri->ri_exclude ) len++;
2053 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2054 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2057 bindconf_unparse( &ri->ri_bindconf, &bc );
2060 bv->bv_val = ch_malloc(len + 1);
2063 ptr = lutil_strcopy( bv->bv_val, numbuf );
2064 ptr = lutil_strcopy( ptr, "uri=" );
2065 ptr = lutil_strcopy( ptr, ri->ri_uri );
2067 if ( ri->ri_nsuffix ) {
2068 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2069 ptr = lutil_strcopy( ptr, " suffix=\"" );
2070 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2074 if ( ri->ri_attrs ) {
2075 ptr = lutil_strcopy( ptr, "attr" );
2076 if ( ri->ri_exclude ) *ptr++ = '!';
2078 ptr = anlist_unparse( ri->ri_attrs, ptr );
2081 strcpy( ptr, bc.bv_val );
2082 ch_free( bc.bv_val );
2087 config_replica(ConfigArgs *c) {
2088 int i, nr = -1, len;
2089 char *replicahost, *replicauri;
2092 if (c->op == SLAP_CONFIG_EMIT) {
2093 if (c->be->be_replica) {
2095 for (i=0;c->be->be_replica[i]; i++) {
2096 replica_unparse( c->be->be_replica[i], i, &bv );
2097 ber_bvarray_add( &c->rvalue_vals, &bv );
2102 } else if ( c->op == LDAP_MOD_DELETE ) {
2103 /* FIXME: there is no replica_free function */
2104 if ( c->valx < 0 ) {
2108 if(SLAP_MONITOR(c->be)) {
2109 Debug(LDAP_DEBUG_ANY, "%s: "
2110 "\"replica\" should not be used inside monitor database\n",
2112 return(0); /* FIXME: should this be an error? */
2115 for(i = 1; i < c->argc; i++) {
2116 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2117 replicahost = c->argv[i] + STRLENOF("host=");
2118 len = strlen( replicahost );
2119 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2120 sprintf( replicauri, "ldap://%s", replicahost );
2121 replicahost = replicauri + STRLENOF( "ldap://");
2122 nr = add_replica_info(c->be, replicauri, replicahost);
2124 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2125 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2126 sprintf( c->msg, "<%s> invalid uri", c->argv[0] );
2127 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2130 if(!ludp->lud_host) {
2131 sprintf( c->msg, "<%s> invalid uri - missing hostname",
2133 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2136 ldap_free_urldesc(ludp);
2137 replicauri = c->argv[i] + STRLENOF("uri=");
2138 replicauri = ch_strdup( replicauri );
2139 replicahost = strchr( replicauri, '/' );
2141 nr = add_replica_info(c->be, replicauri, replicahost);
2146 sprintf( c->msg, "<%s> missing host or uri", c->argv[0] );
2147 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2149 } else if(nr == -1) {
2150 sprintf( c->msg, "<%s> unable to add replica", c->argv[0] );
2151 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2154 for(i = 1; i < c->argc; i++) {
2155 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2156 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2158 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2159 "suffix \"%s\" in \"replica\" line is not valid for backend"
2160 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2161 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2162 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2164 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2167 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2168 "unable to normalize suffix in \"replica\" line"
2169 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2171 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2173 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2177 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2179 char *arg = c->argv[i] + STRLENOF("attr");
2187 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2188 sprintf( c->msg, "<%s> unknown attribute", c->argv[0] );
2189 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2190 c->log, c->msg, arg + 1);
2193 } else if ( bindconf_parse( c->argv[i],
2194 &c->be->be_replica[nr]->ri_bindconf ) ) {
2203 config_updatedn(ConfigArgs *c) {
2206 if (c->op == SLAP_CONFIG_EMIT) {
2207 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2208 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2209 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2213 } else if ( c->op == LDAP_MOD_DELETE ) {
2214 ch_free( c->be->be_update_ndn.bv_val );
2215 c->be->be_update_ndn.bv_val = NULL;
2216 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2219 if(SLAP_SHADOW(c->be)) {
2220 sprintf( c->msg, "<%s> database already shadowed", c->argv[0] );
2221 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2226 ber_str2bv(c->argv[1], 0, 0, &dn);
2228 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2230 if(rc != LDAP_SUCCESS) {
2231 sprintf( c->msg, "<%s> invalid DN %d (%s)", c->argv[0],
2232 rc, ldap_err2string(rc));
2233 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2234 c->log, c->msg, 0 );
2238 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2243 config_updateref(ConfigArgs *c) {
2245 if (c->op == SLAP_CONFIG_EMIT) {
2246 if ( c->be->be_update_refs ) {
2247 value_add( &c->rvalue_vals, c->be->be_update_refs );
2252 } else if ( c->op == LDAP_MOD_DELETE ) {
2253 if ( c->valx < 0 ) {
2254 ber_bvarray_free( c->be->be_update_refs );
2255 c->be->be_update_refs = NULL;
2258 ch_free( c->be->be_update_refs[i].bv_val );
2259 for (; c->be->be_update_refs[i].bv_val; i++)
2260 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2264 if(!SLAP_SHADOW(c->be)) {
2265 sprintf( c->msg, "<%s> must appear after syncrepl or updatedn",
2267 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2272 if(validate_global_referral(c->argv[1])) {
2273 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2274 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2275 c->log, c->msg, c->argv[1]);
2278 ber_str2bv(c->argv[1], 0, 0, &val);
2279 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2284 config_include(ConfigArgs *c) {
2285 unsigned long savelineno = c->lineno;
2288 ConfigFile *cfsave = cfn;
2289 ConfigFile *cf2 = NULL;
2290 if (c->op == SLAP_CONFIG_EMIT) {
2292 ConfigFile *cf = c->private;
2293 value_add_one( &c->rvalue_vals, &cf->c_file );
2297 } else if ( c->op == LDAP_MOD_DELETE ) {
2299 cf = ch_calloc( 1, sizeof(ConfigFile));
2300 if ( cfn->c_kids ) {
2301 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2307 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2308 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2309 c->lineno = savelineno - 1;
2312 if ( cf2 ) cf2->c_sibs = NULL;
2313 else cfn->c_kids = NULL;
2314 ch_free( cf->c_file.bv_val );
2324 config_tls_option(ConfigArgs *c) {
2327 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2328 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2329 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2330 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2331 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2332 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2333 default: Debug(LDAP_DEBUG_ANY, "%s: "
2334 "unknown tls_option <0x%x>\n",
2335 c->log, c->type, 0);
2337 if (c->op == SLAP_CONFIG_EMIT) {
2338 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2339 } else if ( c->op == LDAP_MOD_DELETE ) {
2340 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2342 ch_free(c->value_string);
2343 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2346 /* FIXME: this ought to be provided by libldap */
2348 config_tls_config(ConfigArgs *c) {
2350 slap_verbmasks crlkeys[] = {
2351 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2352 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2353 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2356 slap_verbmasks vfykeys[] = {
2357 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2358 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2359 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2360 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2364 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2365 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2367 Debug(LDAP_DEBUG_ANY, "%s: "
2368 "unknown tls_option <0x%x>\n",
2369 c->log, c->type, 0);
2371 if (c->op == SLAP_CONFIG_EMIT) {
2372 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2373 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2374 if (keys[i].mask == c->value_int) {
2375 c->value_string = ch_strdup( keys[i].word.bv_val );
2380 } else if ( c->op == LDAP_MOD_DELETE ) {
2382 return ldap_pvt_tls_set_option( NULL, flag, &i );
2384 ch_free( c->value_string );
2385 if(isdigit((unsigned char)c->argv[1][0])) {
2386 i = atoi(c->argv[1]);
2387 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2389 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2394 static CfEntryInfo *
2395 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2405 if ( dn_match( &root->ce_entry->e_nname, dn ))
2408 c = dn->bv_val+dn->bv_len;
2409 for (;*c != ',';c--);
2413 for (--c;c>dn->bv_val && *c != ',';c--);
2417 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2419 root = root->ce_kids;
2421 for (;root;root=root->ce_sibs) {
2422 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2423 if ( cdn.bv_val == dn->bv_val ) {
2433 typedef struct setup_cookie {
2439 config_ldif_resp( Operation *op, SlapReply *rs )
2441 if ( rs->sr_type == REP_SEARCH ) {
2442 setup_cookie *sc = op->o_callback->sc_private;
2444 sc->cfb->cb_got_ldif = 1;
2445 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL );
2450 /* Configure and read the underlying back-ldif store */
2452 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
2453 CfBackInfo *cfb = be->be_private;
2459 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2460 Connection conn = {0};
2461 char opbuf[OPERATION_BUFFER_SIZE];
2463 SlapReply rs = {REP_RESULT};
2464 Filter filter = { LDAP_FILTER_PRESENT };
2465 struct berval filterstr = BER_BVC("(objectclass=*)");
2468 /* Is the config directory available? */
2469 if ( stat( dir, &st ) < 0 ) {
2470 /* No, so don't bother using the backing store.
2471 * All changes will be in-memory only.
2476 cfb->cb_db.bd_info = backend_info( "ldif" );
2477 if ( !cfb->cb_db.bd_info )
2478 return 0; /* FIXME: eventually this will be a fatal error */
2480 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2482 /* Mark that back-ldif type is in use */
2483 cfb->cb_db.bd_info->bi_nDB++;
2485 cfb->cb_db.be_suffix = be->be_suffix;
2486 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2487 cfb->cb_db.be_rootdn = be->be_rootdn;
2488 cfb->cb_db.be_rootndn = be->be_rootndn;
2490 ber_str2bv( dir, 0, 1, &cfdir );
2495 argv[0] = "directory";
2496 argv[1] = (char *)dir;
2500 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
2504 if ( config_add_vals( ct, &c ))
2507 if ( backend_startup_one( &cfb->cb_db ))
2511 op = (Operation *)opbuf;
2512 connection_fake_init( &conn, op, cfb );
2514 filter.f_desc = slap_schema.si_ad_objectClass;
2516 op->o_tag = LDAP_REQ_SEARCH;
2518 op->ors_filter = &filter;
2519 op->ors_filterstr = filterstr;
2520 op->ors_scope = LDAP_SCOPE_SUBTREE;
2522 op->o_dn = be->be_rootdn;
2523 op->o_ndn = be->be_rootndn;
2525 op->o_req_dn = be->be_suffix[0];
2526 op->o_req_ndn = be->be_nsuffix[0];
2528 op->ors_tlimit = SLAP_NO_LIMIT;
2529 op->ors_slimit = SLAP_NO_LIMIT;
2531 op->ors_attrs = slap_anlist_all_attributes;
2532 op->ors_attrsonly = 0;
2534 op->o_callback = &cb;
2537 cb.sc_private = ≻
2539 op->o_bd = &cfb->cb_db;
2540 rc = op->o_bd->be_search( op, &rs );
2543 cfb->cb_use_ldif = 1;
2549 CfOc_cmp( const void *c1, const void *c2 ) {
2550 const ConfigOCs *co1 = c1;
2551 const ConfigOCs *co2 = c2;
2553 return ber_bvcmp( co1->co_name, co2->co_name );
2557 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2560 i = init_config_attrs( ct );
2563 /* set up the objectclasses */
2564 i = init_config_ocs( ocs );
2567 for (i=0; ocs[i].co_def; i++) {
2568 if ( ocs[i].co_oc ) {
2569 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
2570 if ( !ocs[i].co_table )
2571 ocs[i].co_table = ct;
2572 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
2579 read_config(const char *fname, const char *dir) {
2582 const char *cfdir, *cfname;
2585 /* Setup the config backend */
2586 be = backend_db_init( "config" );
2590 cfb = be->be_private;
2592 /* If no .conf, or a dir was specified, setup the dir */
2593 if ( !fname || dir ) {
2595 /* If explicitly given, check for existence */
2598 if ( stat( dir, &st ) < 0 ) {
2599 Debug( LDAP_DEBUG_ANY,
2600 "invalid config directory %s, error %d\n",
2606 cfdir = SLAPD_DEFAULT_CONFIGDIR;
2608 /* if fname is defaulted, try reading .d */
2609 rc = config_setup_ldif( be, cfdir, !fname );
2611 /* It's OK if the base object doesn't exist yet */
2612 if ( rc && rc != LDAP_NO_SUCH_OBJECT )
2615 /* If we read the config from back-ldif, nothing to do here */
2616 if ( cfb->cb_got_ldif ) {
2625 cfname = SLAPD_DEFAULT_CONFIGFILE;
2627 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
2630 ber_str2bv( cfname, 0, 1, &cf_prv.c_file );
2632 /* If we got this far and failed, it may be a serious problem. In server
2633 * mode, we should never come to this. However, it may be alright if we're
2634 * using slapadd to create the conf dir.
2637 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
2639 /* If a config file was explicitly given, fail */
2643 /* Seems to be slapadd with a config dir, let it continue */
2644 if ( cfb->cb_use_ldif ) {
2646 cfb->cb_got_ldif = 1;
2652 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2653 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
2654 &frontendDB->be_schemadn );
2655 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2656 if ( rc != LDAP_SUCCESS ) {
2657 Debug(LDAP_DEBUG_ANY, "read_config: "
2658 "unable to normalize default schema DN \"%s\"\n",
2659 frontendDB->be_schemadn.bv_val, 0, 0 );
2660 /* must not happen */
2668 config_back_bind( Operation *op, SlapReply *rs )
2670 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2671 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2672 /* frontend sends result */
2673 return LDAP_SUCCESS;
2676 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2677 send_ldap_result( op, rs );
2683 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2687 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2689 rs->sr_attrs = op->ors_attrs;
2690 rs->sr_entry = ce->ce_entry;
2691 rc = send_search_entry( op, rs );
2693 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2694 if ( ce->ce_kids ) {
2695 rc = config_send( op, rs, ce->ce_kids, 1 );
2696 if ( rc ) return rc;
2699 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2700 rc = config_send( op, rs, ce, 0 );
2708 static ConfigTable *
2709 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
2713 for (j=0; j<nocs; j++) {
2714 for (i=0; colst[j]->co_table[i].name; i++)
2715 if ( colst[j]->co_table[i].ad == ad )
2716 return &colst[j]->co_table[i];
2721 /* Sort the attributes of the entry according to the order defined
2722 * in the objectclass, with required attributes occurring before
2723 * allowed attributes. For any attributes with sequencing dependencies
2724 * (e.g., rootDN must be defined after suffix) the objectclass must
2725 * list the attributes in the desired sequence.
2728 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
2730 Attribute *a, *head = NULL, *tail = NULL, **prev;
2733 for (i=0; i<nocs; i++) {
2734 if ( colst[i]->co_oc->soc_required ) {
2735 AttributeType **at = colst[i]->co_oc->soc_required;
2736 for (j=0; at[j]; j++) {
2737 for (a=e->e_attrs, prev=&e->e_attrs; a;
2738 prev = &(*prev)->a_next, a=a->a_next) {
2739 if ( a->a_desc == at[j]->sat_ad ) {
2753 if ( colst[i]->co_oc->soc_allowed ) {
2754 AttributeType **at = colst[i]->co_oc->soc_allowed;
2755 for (j=0; at[j]; j++) {
2756 for (a=e->e_attrs, prev=&e->e_attrs; a;
2757 prev = &(*prev)->a_next, a=a->a_next) {
2758 if ( a->a_desc == at[j]->sat_ad ) {
2774 tail->a_next = e->e_attrs;
2780 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2782 Attribute *a = NULL;
2783 AttributeDescription *ad;
2786 int i, rc = 0, sort = 0;
2793 Modifications *ml = ptr;
2795 vals = ml->sml_values;
2798 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2800 rc = ordered_value_sort( a, 1 );
2804 for ( i=0; vals[i].bv_val; i++ ) {
2805 ca->line = vals[i].bv_val;
2807 char *idx = strchr( ca->line, '}' );
2808 if ( idx ) ca->line = idx+1;
2810 rc = config_parse_vals( ct, ca, i );
2819 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2820 SlapReply *rs, int *renum )
2823 int index = -1, gotindex = 0, nsibs;
2824 int renumber = 0, tailindex = 0;
2828 if ( renum ) *renum = 0;
2830 /* These entries don't get indexed/renumbered */
2831 if ( ce_type == Cft_Global ) return 0;
2832 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2834 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2837 /* See if the rdn has an index already */
2838 dnRdn( &e->e_name, &rdn );
2839 ptr1 = strchr( e->e_name.bv_val, '{' );
2840 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2841 ptr2 = strchr( ptr1, '}' );
2842 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2843 return LDAP_NAMING_VIOLATION;
2844 if ( ptr2-ptr1 == 1)
2845 return LDAP_NAMING_VIOLATION;
2847 index = atoi(ptr1+1);
2849 return LDAP_NAMING_VIOLATION;
2852 /* count related kids */
2853 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2854 if ( ce->ce_type == ce_type ) nsibs++;
2857 if ( index != nsibs ) {
2859 if ( index < nsibs ) {
2860 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2861 /* Siblings need to be renumbered */
2866 struct berval ival, newrdn, nnewrdn;
2867 struct berval rtype, rval;
2869 AttributeDescription *ad = NULL;
2873 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2874 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2875 rtype.bv_val = rdn.bv_val;
2876 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2879 slap_bv2ad( &rtype, &ad, &text );
2880 a = attr_find( e->e_attrs, ad );
2881 if (!a ) return LDAP_NAMING_VIOLATION;
2884 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2886 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2887 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2890 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2891 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2898 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
2900 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
2903 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2904 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
2908 /* Do the equivalent of ModRDN */
2909 /* Replace DN / NDN */
2910 newrdn.bv_len = ptr1 - newrdn.bv_val;
2911 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
2912 free( e->e_name.bv_val );
2913 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
2915 free( e->e_nname.bv_val );
2916 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
2920 free( a->a_vals[0].bv_val );
2921 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
2922 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
2923 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
2924 strcpy( a->a_vals[0].bv_val, ptr1 );
2926 if ( a->a_nvals != a->a_vals ) {
2927 free( a->a_nvals[0].bv_val );
2928 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
2929 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
2930 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
2931 strcpy( a->a_nvals[0].bv_val, ptr1 );
2933 free( nnewrdn.bv_val );
2934 free( newrdn.bv_val );
2937 if ( renum ) *renum = renumber;
2942 count_ocs( Attribute *oc_at, int *nocs )
2945 ConfigOCs co, *coptr, **colst;
2947 /* count the objectclasses */
2948 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2950 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
2952 for ( i=0, j=0; i<n; i++) {
2953 co.co_name = &oc_at->a_nvals[i];
2954 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
2956 /* ignore non-config objectclasses. probably should be
2957 * an error, general data doesn't belong here.
2959 if ( !coptr ) continue;
2961 /* Ignore the root objectclass, it has no implementation.
2963 if ( coptr->co_type == Cft_Abstract ) continue;
2971 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2973 if ( p->ce_type != Cft_Global && p->ce_type != Cft_Include )
2974 return LDAP_CONSTRAINT_VIOLATION;
2976 /* If we're reading from a configdir, don't parse this entry */
2978 return LDAP_COMPARE_TRUE;
2980 if ( p->ce_type == Cft_Global )
2983 cfn = p->ce_private;
2985 return LDAP_SUCCESS;
2989 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2993 /* This entry is hardcoded, don't re-parse it */
2994 if ( p->ce_type == Cft_Global ) {
2997 return LDAP_COMPARE_TRUE;
2999 if ( p->ce_type != Cft_Schema )
3000 return LDAP_CONSTRAINT_VIOLATION;
3002 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3004 cfo = p->ce_private;
3005 cfn->c_sibs = cfo->c_kids;
3007 return LDAP_SUCCESS;
3011 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3013 if ( p->ce_type != Cft_Global )
3014 return LDAP_CONSTRAINT_VIOLATION;
3015 ca->be = frontendDB; /* just to get past check_vals */
3016 return LDAP_SUCCESS;
3020 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3022 if ( p->ce_type != Cft_Global )
3023 return LDAP_CONSTRAINT_VIOLATION;
3024 return LDAP_SUCCESS;
3028 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3030 if ( p->ce_type != Cft_Global )
3031 return LDAP_CONSTRAINT_VIOLATION;
3032 return LDAP_SUCCESS;
3036 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3038 if ( p->ce_type != Cft_Database )
3039 return LDAP_CONSTRAINT_VIOLATION;
3041 return LDAP_SUCCESS;
3044 /* Parse an LDAP entry into config directives */
3046 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs, int *renum )
3048 CfEntryInfo *ce, *last;
3050 Attribute *a, *oc_at;
3051 int i, j, nocs, rc = 0;
3056 /* Make sure parent exists and entry does not */
3057 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3059 return LDAP_ALREADY_EXISTS;
3061 dnParent( &e->e_nname, &pdn );
3063 /* If last is NULL, the new entry is the root/suffix entry,
3064 * otherwise last should be the parent.
3066 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3068 rs->sr_matched = last->ce_entry->e_name.bv_val;
3069 return LDAP_NO_SUCH_OBJECT;
3072 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3073 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3075 memset( ca, 0, sizeof(ConfigArgs));
3077 /* Fake the coordinates based on whether we're part of an
3078 * LDAP Add or if reading the config dir
3081 ca->fname = "slapd";
3084 ca->fname = cfdir.bv_val;
3088 colst = count_ocs( oc_at, &nocs );
3090 /* Only the root can be Cft_Global, everything else must
3091 * have a parent. Only limited nesting arrangements are allowed.
3093 rc = LDAP_CONSTRAINT_VIOLATION;
3094 if ( colst[0]->co_type == Cft_Global && !last ) {
3097 ca->be = frontendDB; /* just to get past check_vals */
3101 /* Check whether the Add is allowed by its parent, and do
3102 * any necessary arg setup
3105 for ( i=0; i<nocs; i++ ) {
3106 if ( colst[i]->co_ldadd &&
3107 ( rc = colst[i]->co_ldadd( last, e, ca ))
3108 != LDAP_CONSTRAINT_VIOLATION ) {
3114 /* Add the entry but don't parse it, we already have its contents */
3115 if ( rc == LDAP_COMPARE_TRUE ) {
3120 if ( rc != LDAP_SUCCESS )
3123 /* Parse all the values and check for simple syntax errors before
3124 * performing any set actions.
3126 * If doing an LDAPadd, check for indexed names and any necessary
3127 * renaming/renumbering. Entries that don't need indexed names are
3128 * ignored. Entries that need an indexed name and arrive without one
3129 * are assigned to the end. Entries that arrive with an index may
3130 * cause the following entries to be renumbered/bumped down.
3132 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3133 * don't allow Adding an entry with an index that's already in use.
3134 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3136 * These entries can have auto-assigned indexes (appended to the end)
3137 * but only the other types support auto-renumbering of siblings.
3139 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3143 init_config_argv( ca );
3145 /* Make sure we process attrs in the required order */
3146 sort_attrs( e, colst, nocs );
3148 for ( a=e->e_attrs; a; a=a->a_next ) {
3149 if ( a == oc_at ) continue;
3150 ct = config_find_table( colst, nocs, a->a_desc );
3151 if ( !ct ) continue; /* user data? */
3152 rc = check_vals( ct, ca, a, 1 );
3153 if ( rc ) goto leave;
3156 /* Basic syntax checks are OK. Do the actual settings. */
3157 for ( a=e->e_attrs; a; a=a->a_next ) {
3158 if ( a == oc_at ) continue;
3159 ct = config_find_table( colst, nocs, a->a_desc );
3160 if ( !ct ) continue; /* user data? */
3161 for (i=0; a->a_vals[i].bv_val; i++) {
3162 ca->line = a->a_vals[i].bv_val;
3163 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3164 ptr = strchr( ca->line, '}' );
3165 if ( ptr ) ca->line = ptr+1;
3168 rc = config_parse_add( ct, ca );
3176 /* Newly added databases and overlays need to be started up */
3177 if ( CONFIG_ONLINE_ADD( ca )) {
3178 if ( colst[0]->co_type == Cft_Database ) {
3179 rc = backend_startup_one( ca->be );
3181 } else if ( colst[0]->co_type == Cft_Overlay ) {
3182 if ( ca->bi->bi_db_open ) {
3183 BackendInfo *bi_orig = ca->be->bd_info;
3184 ca->be->bd_info = ca->bi;
3185 rc = ca->bi->bi_db_open( ca->be );
3186 ca->be->bd_info = bi_orig;
3190 sprintf( ca->msg, "<%s> failed startup", ca->argv[0] );
3191 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
3192 ca->log, ca->msg, ca->argv[1] );
3198 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3199 ce->ce_parent = last;
3200 ce->ce_entry = entry_dup( e );
3201 ce->ce_entry->e_private = ce;
3202 ce->ce_type = colst[0]->co_type;
3205 ce->ce_private = ca->private;
3208 } else if ( last->ce_kids ) {
3211 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3220 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
3221 backend_destroy_one( ca->be );
3222 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
3223 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
3227 ch_free( ca->argv );
3228 if ( colst ) ch_free( colst );
3232 /* Parse an LDAP entry into config directives, then store in underlying
3236 config_back_add( Operation *op, SlapReply *rs )
3239 CfEntryInfo *ce, *last;
3243 if ( !be_isroot( op ) ) {
3244 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3248 cfb = (CfBackInfo *)op->o_bd->be_private;
3250 ldap_pvt_thread_pool_pause( &connection_pool );
3253 * 1) check for existence of entry
3254 * 2) check for sibling renumbering
3255 * 3) perform internal add
3256 * 4) store entry in underlying database
3257 * 5) perform any necessary renumbering
3259 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber );
3260 if ( rs->sr_err != LDAP_SUCCESS ) {
3261 rs->sr_text = ca.msg;
3262 } else if ( cfb->cb_use_ldif ) {
3263 BackendDB *be = op->o_bd;
3264 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3265 op->o_bd = &cfb->cb_db;
3266 sc.sc_next = op->o_callback;
3267 op->o_callback = ≻
3268 op->o_bd->be_add( op, rs );
3270 op->o_callback = sc.sc_next;
3275 ldap_pvt_thread_pool_resume( &connection_pool );
3278 send_ldap_result( op, rs );
3282 typedef struct delrec {
3283 struct delrec *next;
3289 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3292 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3293 int rc = LDAP_UNWILLING_TO_PERFORM;
3295 Entry *e = ce->ce_entry;
3296 Attribute *save_attrs = e->e_attrs, *oc_at;
3301 delrec *dels = NULL, *deltail = NULL;
3303 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3304 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3306 colst = count_ocs( oc_at, &nocs );
3308 e->e_attrs = attrs_dup( e->e_attrs );
3310 init_config_argv( ca );
3313 ca->private = ce->ce_private;
3315 strcpy( ca->log, "back-config" );
3317 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3318 ct = config_find_table( colst, nocs, ml->sml_desc );
3319 switch (ml->sml_op) {
3320 case LDAP_MOD_DELETE:
3321 case LDAP_MOD_REPLACE: {
3322 BerVarray vals = NULL, nvals;
3324 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3326 snprintf( ca->msg, sizeof(ca->msg),
3327 "<%s> cannot be deleted" );
3328 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3329 ml->sml_desc->ad_cname.bv_val );
3332 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3333 vals = ml->sml_values;
3334 nvals = ml->sml_nvalues;
3335 ml->sml_values = NULL;
3336 ml->sml_nvalues = NULL;
3338 /* If we're deleting by values, remember the indexes of the
3339 * values we deleted.
3341 if ( ct && ml->sml_values ) {
3343 for (i=0; ml->sml_values[i].bv_val; i++);
3344 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
3355 rc = modify_delete_vindex(e, &ml->sml_mod,
3356 get_permissiveModify(op),
3357 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3358 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3359 ml->sml_values = vals;
3360 ml->sml_nvalues = nvals;
3365 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3368 case SLAP_MOD_SOFTADD: {
3369 int mop = ml->sml_op;
3371 ml->sml_op = LDAP_MOD_ADD;
3373 if ( ct->arg_type & ARG_NO_INSERT ) {
3374 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3376 for (i = 0; a->a_vals[i].bv_val; i++ );
3380 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3381 if ( ml->sml_values[i].bv_val[0] == '{' &&
3383 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3386 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3387 ml->sml_desc->ad_cname.bv_val );
3391 rc = check_vals( ct, ca, ml, 0 );
3395 rc = modify_add_values(e, &ml->sml_mod,
3396 get_permissiveModify(op),
3397 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3399 /* If value already exists, show success here
3400 * and ignore this operation down below.
3402 if ( mop == SLAP_MOD_SOFTADD ) {
3403 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3413 case LDAP_MOD_INCREMENT: /* FIXME */
3418 if(rc != LDAP_SUCCESS) break;
3421 if(rc == LDAP_SUCCESS) {
3422 /* check that the entry still obeys the schema */
3423 rc = entry_schema_check(op->o_bd, e, NULL, 0,
3424 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3426 if ( rc == LDAP_SUCCESS ) {
3427 /* Basic syntax checks are OK. Do the actual settings. */
3428 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3429 ct = config_find_table( colst, nocs, ml->sml_desc );
3430 if ( !ct ) continue;
3432 switch (ml->sml_op) {
3433 case LDAP_MOD_DELETE:
3434 case LDAP_MOD_REPLACE: {
3435 BerVarray vals = NULL, nvals;
3439 a = attr_find( e->e_attrs, ml->sml_desc );
3441 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3442 vals = ml->sml_values;
3443 nvals = ml->sml_nvalues;
3444 ml->sml_values = NULL;
3445 ml->sml_nvalues = NULL;
3448 if ( ml->sml_values )
3451 /* If we didn't delete the whole attribute */
3452 if ( ml->sml_values && a ) {
3453 struct berval *mvals;
3456 if ( ml->sml_nvalues )
3457 mvals = ml->sml_nvalues;
3459 mvals = ml->sml_values;
3461 /* use the indexes we saved up above */
3462 for (i=0; i < d->nidx; i++) {
3463 struct berval bv = *mvals++;
3464 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3465 bv.bv_val[0] == '{' ) {
3466 ptr = strchr( bv.bv_val, '}' ) + 1;
3467 bv.bv_len -= ptr - bv.bv_val;
3470 ca->line = bv.bv_val;
3471 ca->valx = d->idx[i];
3472 rc = config_del_vals( ct, ca );
3473 if ( rc != LDAP_SUCCESS ) break;
3474 for (j=i+1; j < d->nidx; j++)
3475 if ( d->idx[j] >d->idx[i] )
3481 rc = config_del_vals( ct, ca );
3482 if ( rc ) rc = LDAP_OTHER;
3484 if ( ml->sml_values ) {
3488 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3489 ml->sml_values = vals;
3490 ml->sml_nvalues = nvals;
3492 if ( !vals || rc != LDAP_SUCCESS )
3495 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3498 for (i=0; ml->sml_values[i].bv_val; i++) {
3499 ca->line = ml->sml_values[i].bv_val;
3501 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3502 ca->line[0] == '{' ) {
3503 ptr = strchr( ca->line, '}' );
3505 ca->valx = strtol( ca->line+1, NULL, 0 );
3509 rc = config_parse_add( ct, ca );
3524 if ( rc == LDAP_SUCCESS ) {
3525 attrs_free( save_attrs );
3527 attrs_free( e->e_attrs );
3528 e->e_attrs = save_attrs;
3530 ch_free( ca->argv );
3531 if ( colst ) ch_free( colst );
3537 config_back_modify( Operation *op, SlapReply *rs )
3540 CfEntryInfo *ce, *last;
3542 ConfigArgs ca = {0};
3545 AttributeDescription *rad = NULL;
3547 if ( !be_isroot( op ) ) {
3548 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3552 cfb = (CfBackInfo *)op->o_bd->be_private;
3554 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3557 rs->sr_matched = last->ce_entry->e_name.bv_val;
3558 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3562 /* Get type of RDN */
3563 rdn = ce->ce_entry->e_nname;
3564 ptr = strchr( rdn.bv_val, '=' );
3565 rdn.bv_len = ptr - rdn.bv_val;
3566 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3568 /* Some basic validation... */
3569 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3570 /* Don't allow Modify of RDN; must use ModRdn for that. */
3571 if ( ml->sml_desc == rad ) {
3572 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3573 rs->sr_text = "Use modrdn to change the entry name";
3578 ldap_pvt_thread_pool_pause( &connection_pool );
3581 * 1) perform the Modify on the cached Entry.
3582 * 2) verify that the Entry still satisfies the schema.
3583 * 3) perform the individual config operations.
3584 * 4) store Modified entry in underlying LDIF backend.
3586 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3588 rs->sr_text = ca.msg;
3589 } else if ( cfb->cb_use_ldif ) {
3590 BackendDB *be = op->o_bd;
3591 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3592 op->o_bd = &cfb->cb_db;
3593 sc.sc_next = op->o_callback;
3594 op->o_callback = ≻
3595 op->o_bd->be_modify( op, rs );
3597 op->o_callback = sc.sc_next;
3600 ldap_pvt_thread_pool_resume( &connection_pool );
3602 send_ldap_result( op, rs );
3607 config_back_modrdn( Operation *op, SlapReply *rs )
3610 CfEntryInfo *ce, *last;
3612 if ( !be_isroot( op ) ) {
3613 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3617 cfb = (CfBackInfo *)op->o_bd->be_private;
3619 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3622 rs->sr_matched = last->ce_entry->e_name.bv_val;
3623 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3627 /* We don't allow moving objects to new parents.
3628 * Generally we only allow reordering a set of ordered entries.
3630 if ( op->orr_newSup ) {
3631 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3634 ldap_pvt_thread_pool_pause( &connection_pool );
3636 ldap_pvt_thread_pool_resume( &connection_pool );
3638 send_ldap_result( op, rs );
3643 config_back_search( Operation *op, SlapReply *rs )
3646 CfEntryInfo *ce, *last;
3649 if ( !be_isroot( op ) ) {
3650 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3654 cfb = (CfBackInfo *)op->o_bd->be_private;
3656 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3659 rs->sr_matched = last->ce_entry->e_name.bv_val;
3660 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3663 switch ( op->ors_scope ) {
3664 case LDAP_SCOPE_BASE:
3665 case LDAP_SCOPE_SUBTREE:
3666 config_send( op, rs, ce, 0 );
3669 case LDAP_SCOPE_ONELEVEL:
3670 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3671 config_send( op, rs, ce, 1 );
3676 rs->sr_err = LDAP_SUCCESS;
3678 send_ldap_result( op, rs );
3683 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
3684 ConfigTable *ct, ConfigArgs *c )
3688 for (; at && *at; at++) {
3689 /* Skip the naming attr */
3690 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3692 for (i=0;ct[i].name;i++) {
3693 if (ct[i].ad == (*at)->sat_ad) {
3694 rc = config_get_vals(&ct[i], c);
3695 if (rc == LDAP_SUCCESS) {
3696 if ( c->rvalue_nvals )
3697 attr_merge(e, ct[i].ad, c->rvalue_vals,
3700 attr_merge_normalize(e, ct[i].ad,
3701 c->rvalue_vals, NULL);
3702 ber_bvarray_free( c->rvalue_nvals );
3703 ber_bvarray_free( c->rvalue_vals );
3712 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3713 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
3715 Entry *e = ch_calloc( 1, sizeof(Entry) );
3716 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3718 struct berval ad_name;
3719 AttributeDescription *ad = NULL;
3726 CfEntryInfo *ceprev = NULL;
3730 ce->ce_parent = parent;
3732 pdn = parent->ce_entry->e_nname;
3733 if ( parent->ce_kids )
3734 for ( ceprev = parent->ce_kids; ceprev->ce_sibs;
3735 ceprev = ceprev->ce_sibs );
3740 ce->ce_type = main->co_type;
3741 ce->ce_private = c->private;
3745 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3746 ber_dupbv( &e->e_nname, &e->e_name );
3748 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3749 main->co_name, NULL );
3751 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3752 extra->co_name, NULL );
3753 ptr = strchr(rdn->bv_val, '=');
3754 ad_name.bv_val = rdn->bv_val;
3755 ad_name.bv_len = ptr - rdn->bv_val;
3756 rc = slap_bv2ad( &ad_name, &ad, &text );
3761 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3762 attr_merge_normalize_one(e, ad, &val, NULL );
3765 if ( oc->soc_required )
3766 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
3768 if ( oc->soc_allowed )
3769 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
3773 if ( oc->soc_required )
3774 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
3776 if ( oc->soc_allowed )
3777 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
3780 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3781 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3783 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3786 op->o_bd->be_add( op, rs );
3789 ceprev->ce_sibs = ce;
3790 } else if ( parent ) {
3791 parent->ce_kids = ce;
3798 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3799 Operation *op, SlapReply *rs )
3802 ConfigFile *cf = c->private;
3806 for (; cf; cf=cf->c_sibs, c->depth++) {
3807 c->value_dn.bv_val = c->log;
3808 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3813 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3815 ptr = strchr( bv.bv_val, '.' );
3817 bv.bv_len = ptr - bv.bv_val;
3818 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3819 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3821 c->value_dn.bv_len += bv.bv_len;
3822 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3825 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3826 &CFOC_SCHEMA, NULL );
3827 if ( e && cf->c_kids ) {
3828 c->private = cf->c_kids;
3829 config_build_schema_inc( c, e->e_private, op, rs );
3835 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3836 Operation *op, SlapReply *rs )
3840 ConfigFile *cf = c->private;
3842 for (i=0; cf; cf=cf->c_sibs, i++) {
3843 c->value_dn.bv_val = c->log;
3844 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3846 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3847 &CFOC_INCLUDE, NULL );
3848 if ( e && cf->c_kids ) {
3849 c->private = cf->c_kids;
3850 config_build_includes( c, e->e_private, op, rs );
3855 #ifdef SLAPD_MODULES
3858 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3859 Operation *op, SlapReply *rs )
3864 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3865 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3867 c->value_dn.bv_val = c->log;
3868 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3870 config_build_entry( op, rs, ceparent, c, &c->value_dn,
3871 &CFOC_MODULE, NULL );
3877 config_back_db_open( BackendDB *be )
3879 CfBackInfo *cfb = be->be_private;
3882 CfEntryInfo *ce, *ceparent, *ceprev;
3888 Connection conn = {0};
3889 char opbuf[OPERATION_BUFFER_SIZE];
3891 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3892 SlapReply rs = {REP_RESULT};
3894 /* If we read the config from back-ldif, nothing to do here */
3895 if ( cfb->cb_got_ldif )
3898 if ( cfb->cb_use_ldif ) {
3899 op = (Operation *)opbuf;
3900 connection_fake_init( &conn, op, cfb );
3902 op->o_dn = be->be_rootdn;
3903 op->o_ndn = be->be_rootndn;
3905 op->o_tag = LDAP_REQ_ADD;
3906 op->o_callback = &cb;
3907 op->o_bd = &cfb->cb_db;
3912 /* create root of tree */
3914 c.private = cfb->cb_config;
3916 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
3923 /* Create includeFile nodes */
3924 if ( cfb->cb_config->c_kids ) {
3926 c.private = cfb->cb_config->c_kids;
3927 config_build_includes( &c, ceparent, op, &rs );
3930 #ifdef SLAPD_MODULES
3931 /* Create Module nodes... */
3932 if ( modpaths.mp_loads ) {
3933 config_build_modules( &c, ceparent, op, &rs );
3937 /* Create schema nodes... cn=schema will contain the hardcoded core
3938 * schema, read-only. Child objects will contain runtime loaded schema
3943 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
3946 /* Create schema nodes for included schema... */
3947 if ( cfb->cb_config->c_kids ) {
3949 c.private = cfb->cb_config->c_kids;
3950 config_build_schema_inc( &c, ce, op, &rs );
3953 /* Create backend nodes. Skip if they don't provide a cf_table.
3954 * There usually aren't any of these.
3958 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3959 if (!bi->bi_cf_ocs) continue;
3960 if (!bi->bi_private) continue;
3963 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3965 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
3969 /* Create database nodes... */
3971 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3972 slap_overinfo *oi = NULL;
3979 if ( overlay_is_over( bptr )) {
3980 oi = bptr->bd_info->bi_private;
3986 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3990 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
3993 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
3994 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
3995 /* Iterate through overlays */
4001 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
4003 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
4004 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
4007 oe = config_build_entry( op, &rs, ce, &c, &rdn,
4008 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
4009 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
4010 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
4019 config_back_db_destroy( Backend *be )
4021 free( be->be_private );
4026 config_back_db_init( Backend *be )
4031 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4032 cfb->cb_config = &cf_prv;
4033 be->be_private = cfb;
4035 ber_dupbv( &be->be_rootdn, &config_rdn );
4036 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4037 ber_dupbv( &dn, &be->be_rootdn );
4038 ber_bvarray_add( &be->be_suffix, &dn );
4039 ber_dupbv( &dn, &be->be_rootdn );
4040 ber_bvarray_add( &be->be_nsuffix, &dn );
4042 /* Hide from namingContexts */
4043 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4049 config_back_destroy( BackendInfo *bi )
4051 ldif_must_b64_encode_release();
4056 config_tool_entry_open( BackendDB *be, int mode )
4058 CfBackInfo *cfb = be->be_private;
4059 BackendInfo *bi = cfb->cb_db.bd_info;
4061 if ( bi && bi->bi_tool_entry_open )
4062 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
4069 config_tool_entry_close( BackendDB *be )
4071 CfBackInfo *cfb = be->be_private;
4072 BackendInfo *bi = cfb->cb_db.bd_info;
4074 if ( bi && bi->bi_tool_entry_close )
4075 return bi->bi_tool_entry_close( &cfb->cb_db );
4081 config_tool_entry_first( BackendDB *be )
4083 CfBackInfo *cfb = be->be_private;
4084 BackendInfo *bi = cfb->cb_db.bd_info;
4086 if ( bi && bi->bi_tool_entry_first )
4087 return bi->bi_tool_entry_first( &cfb->cb_db );
4093 config_tool_entry_next( BackendDB *be )
4095 CfBackInfo *cfb = be->be_private;
4096 BackendInfo *bi = cfb->cb_db.bd_info;
4098 if ( bi && bi->bi_tool_entry_next )
4099 return bi->bi_tool_entry_next( &cfb->cb_db );
4105 config_tool_entry_get( BackendDB *be, ID id )
4107 CfBackInfo *cfb = be->be_private;
4108 BackendInfo *bi = cfb->cb_db.bd_info;
4110 if ( bi && bi->bi_tool_entry_get )
4111 return bi->bi_tool_entry_get( &cfb->cb_db, id );
4117 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
4119 CfBackInfo *cfb = be->be_private;
4120 BackendInfo *bi = cfb->cb_db.bd_info;
4123 if ( bi && bi->bi_tool_entry_put &&
4124 config_add_internal( cfb, e, &ca, NULL, NULL ) == 0 )
4125 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
4132 AttributeDescription **desc;
4134 { "backend", &cfAd_backend },
4135 { "database", &cfAd_database },
4136 { "include", &cfAd_include },
4137 { "overlay", &cfAd_overlay },
4142 * add / delete: all types that may be added or deleted must use an
4143 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4144 * should automatically renumber the index of any siblings as needed,
4145 * so that no gaps in the numbering sequence exist after the add/delete
4147 * What can be added:
4149 * backend objects for backend-specific config directives
4153 * delete: probably no support this time around.
4155 * modrdn: generally not done. Will be invoked automatically by add/
4156 * delete to update numbering sequence. Perform as an explicit operation
4157 * so that the renumbering effect may be replicated. Subtree rename must
4158 * be supported, since renumbering a database will affect all its child
4161 * modify: must be fully supported.
4165 config_back_initialize( BackendInfo *bi )
4167 ConfigTable *ct = config_back_cf_table;
4170 AttributeDescription *ad = NULL;
4172 static char *controls[] = {
4173 LDAP_CONTROL_MANAGEDSAIT,
4177 bi->bi_controls = controls;
4182 bi->bi_destroy = config_back_destroy;
4184 bi->bi_db_init = config_back_db_init;
4185 bi->bi_db_config = 0;
4186 bi->bi_db_open = config_back_db_open;
4187 bi->bi_db_close = 0;
4188 bi->bi_db_destroy = config_back_db_destroy;
4190 bi->bi_op_bind = config_back_bind;
4191 bi->bi_op_unbind = 0;
4192 bi->bi_op_search = config_back_search;
4193 bi->bi_op_compare = 0;
4194 bi->bi_op_modify = config_back_modify;
4195 bi->bi_op_modrdn = config_back_modrdn;
4196 bi->bi_op_add = config_back_add;
4197 bi->bi_op_delete = 0;
4198 bi->bi_op_abandon = 0;
4200 bi->bi_extended = 0;
4202 bi->bi_chk_referrals = 0;
4204 #ifdef SLAP_OVERLAY_ACCESS
4205 bi->bi_access_allowed = slap_access_always_allowed;
4206 #endif /* SLAP_OVERLAY_ACCESS */
4208 bi->bi_connection_init = 0;
4209 bi->bi_connection_destroy = 0;
4211 bi->bi_tool_entry_open = config_tool_entry_open;
4212 bi->bi_tool_entry_close = config_tool_entry_close;
4213 bi->bi_tool_entry_first = config_tool_entry_first;
4214 bi->bi_tool_entry_next = config_tool_entry_next;
4215 bi->bi_tool_entry_get = config_tool_entry_get;
4216 bi->bi_tool_entry_put = config_tool_entry_put;
4218 /* Make sure we don't exceed the bits reserved for userland */
4219 assert( ( ( CFG_LAST - 1 ) & ARGS_USERLAND ) == ( CFG_LAST - 1 ) );
4222 for (i=0; OidMacros[i].name; i++ ) {
4223 argv[1] = OidMacros[i].name;
4224 argv[2] = OidMacros[i].oid;
4225 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4228 bi->bi_cf_ocs = cf_ocs;
4230 i = config_register_schema( ct, cf_ocs );
4233 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4234 * basically, we don't care if it fails */
4235 i = slap_str2ad( "olcRootPW", &ad, &text );
4237 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4238 "warning, unable to get \"olcRootPW\" "
4239 "attribute description: %d: %s\n",
4242 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4243 ad->ad_type->sat_oid );
4246 /* set up the notable AttributeDescriptions */
4248 for (;ct->name;ct++) {
4249 if (strcmp(ct->name, ads[i].name)) continue;
4250 *ads[i].desc = ct->ad;
4252 if (!ads[i].name) break;