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"
39 static struct berval config_rdn = BER_BVC("cn=config");
40 static struct berval schema_rdn = BER_BVC("cn=schema");
45 typedef struct modpath_s {
46 struct modpath_s *mp_next;
47 struct berval mp_path;
51 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
54 typedef struct ConfigFile {
55 struct ConfigFile *c_sibs;
56 struct ConfigFile *c_kids;
58 AttributeType *c_at_head, *c_at_tail;
59 ContentRule *c_cr_head, *c_cr_tail;
60 ObjectClass *c_oc_head, *c_oc_tail;
61 OidMacro *c_om_head, *c_om_tail;
66 ConfigFile *cb_config;
68 BackendDB cb_db; /* underlying database */
73 /* These do nothing in slapd, they're kept only to make them
76 static char *replica_pidFile, *replica_argsFile;
77 static int replicationInterval;
79 static char *passwd_salt;
80 static char *logfileName;
81 static BerVarray authz_rewrites;
83 static struct berval cfdir;
86 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
89 static ConfigFile cf_prv, *cfn = &cf_prv;
91 static Avlnode *CfOcTree;
93 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
94 SlapReply *rs, int *renumber );
96 static ConfigDriver config_fname;
97 static ConfigDriver config_cfdir;
98 static ConfigDriver config_generic;
99 static ConfigDriver config_search_base;
100 static ConfigDriver config_passwd_hash;
101 static ConfigDriver config_schema_dn;
102 static ConfigDriver config_sizelimit;
103 static ConfigDriver config_timelimit;
104 static ConfigDriver config_overlay;
105 static ConfigDriver config_suffix;
106 static ConfigDriver config_deref_depth;
107 static ConfigDriver config_rootdn;
108 static ConfigDriver config_rootpw;
109 static ConfigDriver config_restrict;
110 static ConfigDriver config_allows;
111 static ConfigDriver config_disallows;
112 static ConfigDriver config_requires;
113 static ConfigDriver config_security;
114 static ConfigDriver config_referral;
115 static ConfigDriver config_loglevel;
116 static ConfigDriver config_replica;
117 static ConfigDriver config_updatedn;
118 static ConfigDriver config_updateref;
119 static ConfigDriver config_include;
121 static ConfigDriver config_tls_option;
122 static ConfigDriver config_tls_config;
124 extern ConfigDriver syncrepl_config;
168 static OidRec OidMacros[] = {
169 /* OpenLDAProot:666.11.1 */
170 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
171 { "OLcfgAt", "OLcfg:3" },
172 { "OLcfgGlAt", "OLcfgAt:0" },
173 { "OLcfgBkAt", "OLcfgAt:1" },
174 { "OLcfgDbAt", "OLcfgAt:2" },
175 { "OLcfgOvAt", "OLcfgAt:3" },
176 { "OLcfgOc", "OLcfg:4" },
177 { "OLcfgGlOc", "OLcfgOc:0" },
178 { "OLcfgBkOc", "OLcfgOc:1" },
179 { "OLcfgDbOc", "OLcfgOc:2" },
180 { "OLcfgOvOc", "OLcfgOc:3" },
181 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
182 { "OMsInteger", "OMsyn:27" },
183 { "OMsBoolean", "OMsyn:7" },
184 { "OMsDN", "OMsyn:12" },
185 { "OMsDirectoryString", "OMsyn:15" },
186 { "OMsOctetString", "OMsyn:40" },
191 * OLcfg{Bk|Db}{Oc|At}:0 -> common
192 * OLcfg{Bk|Db}{Oc|At}:1 -> bdb
193 * OLcfg{Bk|Db}{Oc|At}:2 -> ldif
194 * OLcfg{Bk|Db}{Oc|At}:3 -> ldap?
197 /* alphabetical ordering */
199 static ConfigTable config_back_cf_table[] = {
200 /* This attr is read-only */
201 { "", "", 0, 0, 0, ARG_MAGIC,
202 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
203 "DESC 'File for slapd configuration directives' "
204 "EQUALITY caseIgnoreMatch "
205 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
206 { "", "", 0, 0, 0, ARG_MAGIC,
207 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
208 "DESC 'Directory for slapd configuration backend' "
209 "EQUALITY caseIgnoreMatch "
210 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
211 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
212 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
213 "DESC 'Access Control List' "
214 "EQUALITY caseIgnoreMatch "
215 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
216 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
217 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
218 "DESC 'Allowed set of deprecated features' "
219 "EQUALITY caseIgnoreMatch "
220 "SYNTAX OMsDirectoryString )", NULL, NULL },
221 { "argsfile", "file", 2, 2, 0, ARG_STRING,
222 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
223 "DESC 'File for slapd command line options' "
224 "EQUALITY caseIgnoreMatch "
225 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
226 { "attribute", "attribute", 2, 0, 9,
227 ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT,
228 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
229 "DESC 'OpenLDAP attributeTypes' "
230 "EQUALITY caseIgnoreMatch "
231 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
233 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
234 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
235 "EQUALITY caseIgnoreMatch "
236 "SYNTAX OMsDirectoryString )", NULL, NULL },
237 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
238 #ifdef SLAP_AUTH_REWRITE
239 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
243 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
244 "EQUALITY caseIgnoreMatch "
245 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
246 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
247 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
248 "EQUALITY caseIgnoreMatch "
249 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
250 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
251 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
252 "EQUALITY caseIgnoreMatch "
253 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
254 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
255 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
256 "DESC 'A type of backend' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
260 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
261 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
262 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
263 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
264 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
265 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
266 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
267 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
268 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
269 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
270 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
271 "DESC 'The backend type for a database instance' "
272 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
273 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
274 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
275 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
276 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
277 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
278 "EQUALITY caseIgnoreMatch "
279 "SYNTAX OMsDirectoryString )", NULL, NULL },
280 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
281 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
282 "DESC 'OpenLDAP DIT content rules' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
286 { "gentlehup", "on|off", 2, 2, 0,
288 ARG_ON_OFF, &global_gentlehup,
292 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
293 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
294 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
295 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
296 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
297 { "include", "file", 2, 2, 0, ARG_MAGIC,
298 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
299 "SUP labeledURI )", NULL, NULL },
300 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
301 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
302 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
303 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
304 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
305 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
306 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
307 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
308 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
309 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
310 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
311 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
312 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
313 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
314 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
315 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
316 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
317 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
318 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
319 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
320 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
321 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
322 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
323 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
324 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
325 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
326 "SYNTAX OMsDirectoryString )", NULL, NULL },
327 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
328 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
329 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
330 { "moduleload", "file", 2, 0, 0,
332 ARG_MAGIC|CFG_MODLOAD, &config_generic,
336 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
337 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
338 { "modulepath", "path", 2, 2, 0,
340 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
344 "( OLcfgGlAt:31 NAME 'olcModulePath' "
345 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
346 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT,
347 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
348 "DESC 'OpenLDAP object classes' "
349 "EQUALITY caseIgnoreMatch "
350 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
352 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
353 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
354 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
355 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
356 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
357 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
358 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
359 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
360 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
361 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
362 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
363 "SYNTAX OMsDirectoryString )", NULL, NULL },
364 { "pidfile", "file", 2, 2, 0, ARG_STRING,
365 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
366 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
367 { "plugin", NULL, 0, 0, 0,
369 ARG_MAGIC|CFG_PLUGIN, &config_generic,
373 "( OLcfgGlAt:38 NAME 'olcPlugin' "
374 "SYNTAX OMsDirectoryString )", NULL, NULL },
375 { "pluginlog", "filename", 2, 2, 0,
377 ARG_STRING, &slapi_log_file,
381 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
382 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
383 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
384 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
385 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
386 { "referral", "url", 2, 2, 0, ARG_MAGIC,
387 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
388 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
389 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
390 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
391 "SUP labeledURI )", NULL, NULL },
392 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
393 &replica_argsFile, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
394 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
395 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
396 &replica_pidFile, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
397 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
398 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
399 &replicationInterval, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
402 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
403 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
404 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
405 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
406 "SYNTAX OMsDirectoryString )", NULL, NULL },
407 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
408 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
409 "SYNTAX OMsDirectoryString )", NULL, NULL },
410 { "reverse-lookup", "on|off", 2, 2, 0,
411 #ifdef SLAPD_RLOOKUPS
412 ARG_ON_OFF, &use_reverse_lookup,
416 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
417 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
418 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
419 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
420 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
421 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
422 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
423 "SYNTAX OMsDirectoryString )", NULL, NULL },
424 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
425 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
426 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
427 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
428 &config_generic, NULL, NULL, NULL },
429 { "sasl-host", "host", 2, 2, 0,
430 #ifdef HAVE_CYRUS_SASL
431 ARG_STRING|ARG_UNIQUE, &global_host,
435 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
436 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
437 { "sasl-realm", "realm", 2, 2, 0,
438 #ifdef HAVE_CYRUS_SASL
439 ARG_STRING|ARG_UNIQUE, &global_realm,
443 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
444 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
445 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
446 &config_generic, NULL, NULL, NULL },
447 { "sasl-secprops", "properties", 2, 2, 0,
448 #ifdef HAVE_CYRUS_SASL
449 ARG_MAGIC|CFG_SASLSECP, &config_generic,
453 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
454 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
455 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
456 &config_generic, NULL, NULL, NULL },
457 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
458 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
459 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
460 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
461 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
462 "SYNTAX OMsDirectoryString )", NULL, NULL },
463 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
464 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
465 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
466 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
467 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
468 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
469 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
470 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
471 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
472 { "srvtab", "file", 2, 2, 0,
473 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
474 ARG_STRING, &ldap_srvtab,
478 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
479 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
480 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
481 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
482 "SYNTAX OMsDN )", NULL, NULL },
483 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
484 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
485 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
486 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
487 &config_generic, "( OLcfgGlAt:66 NAME 'olcThreads' "
488 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
489 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
490 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
491 "SYNTAX OMsDirectoryString )", NULL, NULL },
492 { "TLSCACertificateFile", NULL, 0, 0, 0,
494 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
498 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
499 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
500 { "TLSCACertificatePath", NULL, 0, 0, 0,
502 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
506 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
507 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
508 { "TLSCertificateFile", NULL, 0, 0, 0,
510 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
514 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
515 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
516 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
518 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
522 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
523 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
524 { "TLSCipherSuite", NULL, 0, 0, 0,
526 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
530 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
531 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
532 { "TLSCRLCheck", NULL, 0, 0, 0,
533 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
534 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
538 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
539 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
540 { "TLSRandFile", NULL, 0, 0, 0,
542 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
546 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
547 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
548 { "TLSVerifyClient", NULL, 0, 0, 0,
550 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
554 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
555 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
556 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
557 NULL, NULL, NULL, NULL },
558 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
559 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
560 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
561 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
562 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
563 "SUP labeledURI )", NULL, NULL },
564 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
565 NULL, NULL, NULL, NULL }
568 /* Routines to check if a child can be added to this type */
569 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
570 cfAddBackend, cfAddModule, cfAddOverlay;
572 #define CFOC_GLOBAL cf_ocs[1]
573 #define CFOC_SCHEMA cf_ocs[2]
574 #define CFOC_BACKEND cf_ocs[3]
575 #define CFOC_DATABASE cf_ocs[4]
576 #define CFOC_OVERLAY cf_ocs[5]
577 #define CFOC_INCLUDE cf_ocs[6]
578 #define CFOC_MODULE cf_ocs[7]
580 static ConfigOCs cf_ocs[] = {
583 "DESC 'OpenLDAP configuration object' "
584 "ABSTRACT SUP top )", Cft_Abstract, NULL },
587 "DESC 'OpenLDAP Global configuration options' "
588 "SUP olcConfig STRUCTURAL "
589 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
590 "olcAttributeOptions $ olcAuthIDRewrite $ "
591 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
592 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
593 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
594 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
595 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
597 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
598 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
599 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
600 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
601 "olcRootDSE $ olcRootPW $ "
602 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
603 "olcSecurity $ olcSizeLimit $ "
604 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
605 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
606 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
607 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
608 "olcTLSRandFile $ olcTLSVerifyClient $ "
609 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
610 "olcDitContentRules ) )", Cft_Global },
612 "NAME 'olcSchemaConfig' "
613 "DESC 'OpenLDAP schema object' "
614 "SUP olcConfig STRUCTURAL "
615 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
616 "olcObjectClasses $ olcDitContentRules ) )",
617 Cft_Schema, NULL, cfAddSchema },
619 "NAME 'olcBackendConfig' "
620 "DESC 'OpenLDAP Backend-specific options' "
621 "SUP olcConfig STRUCTURAL "
622 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
624 "NAME 'olcDatabaseConfig' "
625 "DESC 'OpenLDAP Database-specific options' "
626 "SUP olcConfig STRUCTURAL "
628 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
629 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
630 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
631 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
632 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
633 Cft_Database, NULL, cfAddDatabase },
635 "NAME 'olcOverlayConfig' "
636 "DESC 'OpenLDAP Overlay-specific options' "
637 "SUP olcConfig STRUCTURAL "
638 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
640 "NAME 'olcIncludeFile' "
641 "DESC 'OpenLDAP configuration include file' "
642 "SUP olcConfig STRUCTURAL "
644 "MAY ( cn $ olcRootDSE ) )",
645 Cft_Include, NULL, cfAddInclude },
648 "NAME 'olcModuleList' "
649 "DESC 'OpenLDAP dynamic module info' "
650 "SUP olcConfig STRUCTURAL "
651 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
652 Cft_Module, NULL, cfAddModule },
658 config_generic(ConfigArgs *c) {
662 if ( c->op == SLAP_CONFIG_EMIT ) {
666 c->value_int = ldap_pvt_thread_get_concurrency();
669 c->value_int = connection_pool_max;
673 c->value_string = ch_strdup( passwd_salt );
678 if ( c->be->be_limits ) {
683 for ( i=0; c->be->be_limits[i]; i++ ) {
684 bv.bv_len = sprintf( buf, IFMT, i );
685 bv.bv_val = buf+bv.bv_len;
686 limits_unparse( c->be->be_limits[i], &bv );
687 bv.bv_len += bv.bv_val - buf;
689 value_add_one( &c->rvalue_vals, &bv );
692 if ( !c->rvalue_vals ) rc = 1;
695 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
698 c->value_string = ch_strdup( slap_sasl_getpolicy());
701 slap_sasl_regexp_unparse( &c->rvalue_vals );
702 if ( !c->rvalue_vals ) rc = 1;
704 #ifdef HAVE_CYRUS_SASL
706 struct berval bv = BER_BVNULL;
707 slap_sasl_secprops_unparse( &bv );
708 if ( !BER_BVISNULL( &bv )) {
709 ber_bvarray_add( &c->rvalue_vals, &bv );
717 c->value_int = c->be->be_max_deref_depth;
720 ConfigFile *cf = c->private;
722 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
723 else if ( cf->c_om_head )
724 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
726 if ( !c->rvalue_vals )
731 ConfigFile *cf = c->private;
733 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
734 else if ( cf->c_oc_head )
735 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
737 if ( !c->rvalue_vals )
742 ConfigFile *cf = c->private;
744 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
745 else if ( cf->c_at_head )
746 at_unparse( &c->rvalue_vals, cf->c_at_head,
748 if ( !c->rvalue_vals )
753 ConfigFile *cf = c->private;
755 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
756 else if ( cf->c_cr_head )
757 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
759 if ( !c->rvalue_vals )
766 char *src, *dst, ibuf[11];
767 struct berval bv, abv;
768 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
769 abv.bv_len = sprintf( ibuf, IFMT, i );
770 acl_unparse( a, &bv );
771 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
772 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
773 /* Turn TAB / EOL into plain space */
774 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
775 if (isspace(*src)) *dst++ = ' ';
779 if (dst[-1] == ' ') {
783 abv.bv_len = dst - abv.bv_val;
784 ber_bvarray_add( &c->rvalue_vals, &abv );
790 if ( c->be->be_replogfile )
791 c->value_string = ch_strdup( c->be->be_replogfile );
794 ConfigFile *cf = c->private;
795 if ( cf->c_dseFiles ) {
796 value_add( &c->rvalue_vals, cf->c_dseFiles );
804 c->value_string = ch_strdup( logfileName );
809 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
811 case CFG_SSTR_IF_MAX:
812 c->value_int = index_substr_if_maxlen;
814 case CFG_SSTR_IF_MIN:
815 c->value_int = index_substr_if_minlen;
819 ModPaths *mp = c->private;
822 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
825 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
826 mp->mp_loads[i].bv_val );
827 value_add_one( &c->rvalue_vals, &bv );
831 rc = c->rvalue_vals ? 0 : 1;
835 ModPaths *mp = c->private;
836 if ( !BER_BVISNULL( &mp->mp_path ))
837 value_add_one( &c->rvalue_vals, &mp->mp_path );
839 rc = c->rvalue_vals ? 0 : 1;
845 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
846 if ( !c->rvalue_vals ) rc = 1;
849 #ifdef SLAP_AUTH_REWRITE
851 if ( authz_rewrites ) {
852 struct berval bv, idx;
857 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
858 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
859 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
860 bv.bv_val = ch_malloc( bv.bv_len + 1 );
861 strcpy( bv.bv_val, idx.bv_val );
862 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
863 ber_bvarray_add( &c->rvalue_vals, &bv );
866 if ( !c->rvalue_vals ) rc = 1;
873 } else if ( c->op == LDAP_MOD_DELETE ) {
876 /* single-valued attrs, no-ops */
884 case CFG_SSTR_IF_MAX:
885 case CFG_SSTR_IF_MIN:
888 /* no-ops, requires slapd restart */
893 sprintf(c->log, "change requires slapd restart");
897 ch_free( passwd_salt );
902 ch_free( c->be->be_replogfile );
903 c->be->be_replogfile = NULL;
907 ch_free( logfileName );
914 if ( c->be == frontendDB )
917 end = frontendDB->be_acl;
918 acl_destroy( c->be->be_acl, end );
920 AccessControl **prev, *a;
922 for (i=0, prev = &c->be->be_acl; i < c->valx;
934 /* FIXME: there is no limits_free function */
936 /* FIXME: there is no ad_option_free function */
938 /* FIXME: there is no way to remove attributes added by
952 p = strchr(c->line,'(' /*')'*/);
956 if(!(c->bi = backend_info(c->argv[1]))) {
957 sprintf( c->msg, "<%s> failed init", c->argv[0] );
958 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
959 c->log, c->msg, c->argv[1] );
966 /* NOTE: config is always the first backend!
968 if ( !strcasecmp( c->argv[1], "config" )) {
969 c->be = LDAP_STAILQ_FIRST(&backendDB);
970 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
973 c->be = backend_db_init(c->argv[1]);
975 sprintf( c->msg, "<%s> failed init", c->argv[0] );
976 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
977 c->log, c->msg, c->argv[1] );
984 ldap_pvt_thread_set_concurrency(c->value_int);
988 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
989 connection_pool_max = c->value_int; /* save for reference */
993 if ( passwd_salt ) ch_free( passwd_salt );
994 passwd_salt = c->value_string;
995 lutil_salt_format(passwd_salt);
999 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1005 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1007 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1011 ch_free(c->value_string);
1012 if (slap_sasl_setpolicy( c->argv[1] )) {
1013 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1014 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1015 c->log, c->msg, c->argv[1] );
1021 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1025 #ifdef HAVE_CYRUS_SASL
1028 char *txt = slap_sasl_secprops( c->argv[1] );
1030 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1032 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1040 c->be->be_max_deref_depth = c->value_int;
1046 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1048 if (!cfn->c_om_head) cfn->c_om_head = om;
1049 cfn->c_om_tail = om;
1056 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1057 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1058 cfn->c_oc_tail = oc;
1065 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1066 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1067 cfn->c_cr_tail = cr;
1074 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1075 if (!cfn->c_at_head) cfn->c_at_head = at;
1076 cfn->c_at_tail = at;
1081 ad_define_option(NULL, NULL, 0);
1082 for(i = 1; i < c->argc; i++)
1083 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1088 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1092 if(SLAP_MONITOR(c->be)) {
1093 Debug(LDAP_DEBUG_ANY, "%s: "
1094 "\"replogfile\" should not be used "
1095 "inside monitor database\n",
1097 return(0); /* FIXME: should this be an error? */
1100 c->be->be_replogfile = c->value_string;
1104 if(read_root_dse_file(c->argv[1])) {
1105 sprintf( c->msg, "<%s> could not read file", c->argv[0] );
1106 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1107 c->log, c->msg, c->argv[1] );
1112 ber_str2bv( c->argv[1], 0, 1, &bv );
1113 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1119 if ( logfileName ) ch_free( logfileName );
1120 logfileName = c->value_string;
1121 logfile = fopen(logfileName, "w");
1122 if(logfile) lutil_debug_file(logfile);
1126 if(SLAP_NOLASTMODCMD(c->be)) {
1127 sprintf( c->msg, "<%s> not available for %s database",
1128 c->argv[0], c->be->bd_info->bi_type );
1129 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1130 c->log, c->msg, 0 );
1134 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1136 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1139 case CFG_SSTR_IF_MAX:
1140 if (c->value_int < index_substr_if_minlen) {
1141 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1142 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1143 c->log, c->msg, c->value_int );
1146 index_substr_if_maxlen = c->value_int;
1149 case CFG_SSTR_IF_MIN:
1150 if (c->value_int > index_substr_if_maxlen) {
1151 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1152 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1153 c->log, c->msg, c->value_int );
1156 index_substr_if_minlen = c->value_int;
1159 #ifdef SLAPD_MODULES
1161 /* If we're just adding a module on an existing modpath,
1162 * make sure we've selected the current path.
1164 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1165 modcur = c->private;
1166 /* This should never fail */
1167 if ( module_path( modcur->mp_path.bv_val )) {
1168 sprintf( c->msg, "<%s> module path no longer valid",
1170 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1171 c->log, c->msg, modcur->mp_path.bv_val );
1175 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1177 /* Record this load on the current path */
1181 if ( c->op == SLAP_CONFIG_ADD ) {
1182 ptr = c->line + STRLENOF("moduleload");
1183 while (!isspace(*ptr)) ptr++;
1184 while (isspace(*ptr)) ptr++;
1188 ber_str2bv(ptr, 0, 1, &bv);
1189 ber_bvarray_add( &modcur->mp_loads, &bv );
1194 if(module_path(c->argv[1])) return(1);
1195 /* Record which path was used with each module */
1199 if (!modpaths.mp_loads) {
1202 mp = ch_malloc( sizeof( ModPaths ));
1203 modlast->mp_next = mp;
1205 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1207 mp->mp_loads = NULL;
1218 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1220 slapi_plugins_used++;
1224 #ifdef SLAP_AUTH_REWRITE
1229 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1232 if ( c->argc > 1 ) {
1235 /* quote all args but the first */
1236 line = ldap_charray2str( c->argv, "\" \"" );
1237 ber_str2bv( line, 0, 0, &bv );
1238 s = strchr( bv.bv_val, '"' );
1239 assert( s != NULL );
1240 /* move the trailing quote of argv[0] to the end */
1241 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1242 bv.bv_val[ bv.bv_len - 1 ] = '"';
1245 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1248 ber_bvarray_add( &authz_rewrites, &bv );
1255 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1256 "%s: unknown CFG_TYPE %d"
1257 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1258 c->log, c->type, 0 );
1259 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1261 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1269 config_fname(ConfigArgs *c) {
1270 if(c->op == SLAP_CONFIG_EMIT) {
1272 ConfigFile *cf = c->private;
1273 value_add_one( &c->rvalue_vals, &cf->c_file );
1282 config_cfdir(ConfigArgs *c) {
1283 if(c->op == SLAP_CONFIG_EMIT) {
1284 if ( !BER_BVISEMPTY( &cfdir )) {
1285 value_add_one( &c->rvalue_vals, &cfdir );
1294 config_search_base(ConfigArgs *c) {
1297 if(c->op == SLAP_CONFIG_EMIT) {
1299 if (!BER_BVISEMPTY(&default_search_base)) {
1300 value_add_one(&c->rvalue_vals, &default_search_base);
1301 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1305 } else if( c->op == LDAP_MOD_DELETE ) {
1306 ch_free( default_search_base.bv_val );
1307 ch_free( default_search_nbase.bv_val );
1308 BER_BVZERO( &default_search_base );
1309 BER_BVZERO( &default_search_nbase );
1313 if(c->bi || c->be != frontendDB) {
1314 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1315 "prior to any backend or database definition\n",
1320 if(default_search_nbase.bv_len) {
1321 free(default_search_base.bv_val);
1322 free(default_search_nbase.bv_val);
1325 default_search_base = c->value_dn;
1326 default_search_nbase = c->value_ndn;
1331 config_passwd_hash(ConfigArgs *c) {
1333 if (c->op == SLAP_CONFIG_EMIT) {
1335 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1336 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1337 value_add_one(&c->rvalue_vals, &bv);
1340 } else if ( c->op == LDAP_MOD_DELETE ) {
1341 if ( c->valx < 0 ) {
1342 ldap_charray_free( default_passwd_hash );
1343 default_passwd_hash = NULL;
1346 ch_free( default_passwd_hash[i] );
1347 for (; default_passwd_hash[i]; i++ )
1348 default_passwd_hash[i] = default_passwd_hash[i+1];
1352 if(default_passwd_hash) {
1353 Debug(LDAP_DEBUG_ANY, "%s: "
1354 "already set default password_hash\n",
1358 for(i = 1; i < c->argc; i++) {
1359 if(!lutil_passwd_scheme(c->argv[i])) {
1360 sprintf( c->msg, "<%s> schema not available", c->argv[0] );
1361 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1362 c->log, c->msg, c->argv[i]);
1364 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1366 if(!default_passwd_hash) {
1367 sprintf( c->msg, "<%s> no valid hashes found", c->argv[0] );
1368 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1369 c->log, c->msg, 0 );
1377 config_schema_dn(ConfigArgs *c) {
1378 if ( c->op == SLAP_CONFIG_EMIT ) {
1380 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1381 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1382 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1386 } else if ( c->op == LDAP_MOD_DELETE ) {
1387 ch_free( c->be->be_schemadn.bv_val );
1388 ch_free( c->be->be_schemandn.bv_val );
1389 BER_BVZERO( &c->be->be_schemadn );
1390 BER_BVZERO( &c->be->be_schemandn );
1393 ch_free( c->be->be_schemadn.bv_val );
1394 ch_free( c->be->be_schemandn.bv_val );
1395 c->be->be_schemadn = c->value_dn;
1396 c->be->be_schemandn = c->value_ndn;
1401 config_sizelimit(ConfigArgs *c) {
1404 struct slap_limits_set *lim = &c->be->be_def_limit;
1405 if (c->op == SLAP_CONFIG_EMIT) {
1410 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1411 if ( !BER_BVISEMPTY( &bv ))
1412 value_add_one( &c->rvalue_vals, &bv );
1416 } else if ( c->op == LDAP_MOD_DELETE ) {
1417 /* Reset to defaults */
1418 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1419 lim->lms_s_hard = 0;
1420 lim->lms_s_unchecked = -1;
1422 lim->lms_s_pr_hide = 0;
1423 lim->lms_s_pr_total = 0;
1426 for(i = 1; i < c->argc; i++) {
1427 if(!strncasecmp(c->argv[i], "size", 4)) {
1428 rc = limits_parse_one(c->argv[i], lim);
1430 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1431 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1432 c->log, c->msg, c->argv[i]);
1436 if(!strcasecmp(c->argv[i], "unlimited")) {
1437 lim->lms_s_soft = -1;
1439 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1440 if(next == c->argv[i]) {
1441 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1442 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1443 c->log, c->msg, c->argv[i]);
1445 } else if(next[0] != '\0') {
1446 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1447 "trailing chars \"%s\" in \"sizelimit <limit>\" line"
1448 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1450 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1452 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1455 lim->lms_s_hard = 0;
1462 config_timelimit(ConfigArgs *c) {
1465 struct slap_limits_set *lim = &c->be->be_def_limit;
1466 if (c->op == SLAP_CONFIG_EMIT) {
1471 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1472 if ( !BER_BVISEMPTY( &bv ))
1473 value_add_one( &c->rvalue_vals, &bv );
1477 } else if ( c->op == LDAP_MOD_DELETE ) {
1478 /* Reset to defaults */
1479 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1480 lim->lms_t_hard = 0;
1483 for(i = 1; i < c->argc; i++) {
1484 if(!strncasecmp(c->argv[i], "time", 4)) {
1485 rc = limits_parse_one(c->argv[i], lim);
1487 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1488 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1489 c->log, c->msg, c->argv[i]);
1493 if(!strcasecmp(c->argv[i], "unlimited")) {
1494 lim->lms_t_soft = -1;
1496 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1497 if(next == c->argv[i]) {
1498 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1499 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1500 c->log, c->msg, c->argv[i]);
1502 } else if(next[0] != '\0') {
1503 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1504 "trailing chars \"%s\" in \"timelimit <limit>\" line"
1505 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1507 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1509 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1512 lim->lms_t_hard = 0;
1519 config_overlay(ConfigArgs *c) {
1521 if (c->op == SLAP_CONFIG_EMIT) {
1523 } else if ( c->op == LDAP_MOD_DELETE ) {
1526 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1528 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: (optional) %s overlay \"%s\" configuration failed"
1529 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1530 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1531 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1533 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1534 } else if(overlay_config(c->be, c->argv[1])) {
1537 /* Setup context for subsequent config directives.
1538 * The newly added overlay is at the head of the list.
1540 oi = (slap_overinfo *)c->be->bd_info;
1541 c->bi = &oi->oi_list->on_bi;
1546 config_suffix(ConfigArgs *c) {
1548 struct berval pdn, ndn;
1551 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1552 SLAP_CONFIG(c->be)) return 1;
1554 if (c->op == SLAP_CONFIG_EMIT) {
1555 if ( c->be->be_suffix == NULL
1556 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1560 value_add( &c->rvalue_vals, c->be->be_suffix );
1561 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1564 } else if ( c->op == LDAP_MOD_DELETE ) {
1565 if ( c->valx < 0 ) {
1566 ber_bvarray_free( c->be->be_suffix );
1567 ber_bvarray_free( c->be->be_nsuffix );
1568 c->be->be_suffix = NULL;
1569 c->be->be_nsuffix = NULL;
1572 ch_free( c->be->be_suffix[i].bv_val );
1573 ch_free( c->be->be_nsuffix[i].bv_val );
1574 for (; c->be->be_suffix[i].bv_val; i++) {
1575 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1576 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1581 #ifdef SLAPD_MONITOR_DN
1582 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1583 sprintf( c->msg, "<%s> DN is reserved for monitoring slapd",
1585 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1586 c->log, c->msg, SLAPD_MONITOR_DN);
1593 tbe = select_backend(&ndn, 0, 0);
1595 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1596 "%s: suffix already served by this backend!"
1597 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1599 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1601 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1605 sprintf( c->msg, "<%s> suffix already served by a preceding backend",
1607 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1608 c->log, c->msg, tbe->be_suffix[0].bv_val);
1612 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1613 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1614 "base provided \"%s\" (assuming okay)\n",
1615 c->log, default_search_base.bv_val, 0);
1617 ber_bvarray_add(&c->be->be_suffix, &pdn);
1618 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1623 config_rootdn(ConfigArgs *c) {
1624 if (c->op == SLAP_CONFIG_EMIT) {
1625 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1626 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1627 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1632 } else if ( c->op == LDAP_MOD_DELETE ) {
1633 ch_free( c->be->be_rootdn.bv_val );
1634 ch_free( c->be->be_rootndn.bv_val );
1635 BER_BVZERO( &c->be->be_rootdn );
1636 BER_BVZERO( &c->be->be_rootndn );
1639 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1640 ch_free( c->be->be_rootdn.bv_val );
1641 ch_free( c->be->be_rootndn.bv_val );
1643 c->be->be_rootdn = c->value_dn;
1644 c->be->be_rootndn = c->value_ndn;
1649 config_rootpw(ConfigArgs *c) {
1651 /* config_add_internal sets c->be = frontendDB. While the cn=config
1652 * rootpw is technically inside a backend, we expose it in the
1653 * global entry, and need to point to it properly here.
1655 if (c->be == frontendDB)
1656 c->be = LDAP_STAILQ_FIRST(&backendDB);
1658 if (c->op == SLAP_CONFIG_EMIT) {
1659 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1660 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1664 } else if ( c->op == LDAP_MOD_DELETE ) {
1665 ch_free( c->be->be_rootpw.bv_val );
1666 BER_BVZERO( &c->be->be_rootpw );
1670 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1672 sprintf( c->msg, "<%s> can only be set when rootdn is under suffix",
1674 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1678 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1679 ch_free( c->be->be_rootpw.bv_val );
1680 c->be->be_rootpw = c->value_bv;
1685 config_restrict(ConfigArgs *c) {
1686 slap_mask_t restrictops = 0;
1688 slap_verbmasks restrictable_ops[] = {
1689 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1690 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1691 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1692 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1693 { BER_BVC("modrdn"), 0 },
1694 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1695 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1696 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1697 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1698 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1699 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1700 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1701 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1702 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1703 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1707 if (c->op == SLAP_CONFIG_EMIT) {
1708 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1710 } else if ( c->op == LDAP_MOD_DELETE ) {
1712 c->be->be_restrictops = 0;
1714 restrictops = verb_to_mask( c->line, restrictable_ops );
1715 c->be->be_restrictops ^= restrictops;
1719 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1721 sprintf( c->msg, "<%s> unknown operation", c->argv[0] );
1722 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1723 c->log, c->msg, c->argv[i]);
1726 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1727 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1728 c->be->be_restrictops |= restrictops;
1733 config_allows(ConfigArgs *c) {
1734 slap_mask_t allows = 0;
1736 slap_verbmasks allowable_ops[] = {
1737 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1738 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1739 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1740 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1743 if (c->op == SLAP_CONFIG_EMIT) {
1744 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1745 } else if ( c->op == LDAP_MOD_DELETE ) {
1749 allows = verb_to_mask( c->line, allowable_ops );
1750 global_allows ^= allows;
1754 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1756 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1757 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1758 c->log, c->msg, c->argv[i]);
1761 global_allows |= allows;
1766 config_disallows(ConfigArgs *c) {
1767 slap_mask_t disallows = 0;
1769 slap_verbmasks disallowable_ops[] = {
1770 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1771 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1772 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1773 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1774 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1777 if (c->op == SLAP_CONFIG_EMIT) {
1778 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1779 } else if ( c->op == LDAP_MOD_DELETE ) {
1781 global_disallows = 0;
1783 disallows = verb_to_mask( c->line, disallowable_ops );
1784 global_disallows ^= disallows;
1788 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1790 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1791 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1792 c->log, c->msg, c->argv[i]);
1795 global_disallows |= disallows;
1800 config_requires(ConfigArgs *c) {
1801 slap_mask_t requires = 0;
1803 slap_verbmasks requires_ops[] = {
1804 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1805 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1806 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1807 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1808 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1811 if (c->op == SLAP_CONFIG_EMIT) {
1812 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1813 } else if ( c->op == LDAP_MOD_DELETE ) {
1815 c->be->be_requires = 0;
1817 requires = verb_to_mask( c->line, requires_ops );
1818 c->be->be_requires ^= requires;
1822 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1824 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1825 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1826 c->log, c->msg, c->argv[i]);
1829 c->be->be_requires = requires;
1834 config_loglevel(ConfigArgs *c) {
1837 slap_verbmasks loglevel_ops[] = {
1838 { BER_BVC("Any"), -1 },
1839 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1840 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1841 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1842 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1843 { BER_BVC("BER"), LDAP_DEBUG_BER },
1844 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1845 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1846 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1847 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1848 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1849 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1850 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1851 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1852 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1853 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
1857 if (c->op == SLAP_CONFIG_EMIT) {
1858 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1859 } else if ( c->op == LDAP_MOD_DELETE ) {
1863 int level = verb_to_mask( c->line, loglevel_ops );
1864 ldap_syslog ^= level;
1871 for( i=1; i < c->argc; i++ ) {
1874 if ( isdigit( c->argv[i][0] ) ) {
1875 level = strtol( c->argv[i], &next, 10 );
1876 if ( next == NULL || next[0] != '\0' ) {
1877 sprintf( c->msg, "<%s> unable to parse level", c->argv[0] );
1878 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1879 c->log, c->msg, c->argv[i]);
1883 int j = verb_to_mask(c->argv[i], loglevel_ops);
1884 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1885 sprintf( c->msg, "<%s> unknown level", c->argv[0] );
1886 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1887 c->log, c->msg, c->argv[i]);
1890 level = loglevel_ops[j].mask;
1892 ldap_syslog |= level;
1898 config_referral(ConfigArgs *c) {
1900 if (c->op == SLAP_CONFIG_EMIT) {
1901 if ( default_referral ) {
1902 value_add( &c->rvalue_vals, default_referral );
1907 } else if ( c->op == LDAP_MOD_DELETE ) {
1908 if ( c->valx < 0 ) {
1909 ber_bvarray_free( default_referral );
1910 default_referral = NULL;
1913 ch_free( default_referral[i].bv_val );
1914 for (; default_referral[i].bv_val; i++ )
1915 default_referral[i] = default_referral[i+1];
1919 if(validate_global_referral(c->argv[1])) {
1920 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
1921 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1922 c->log, c->msg, c->argv[1]);
1926 ber_str2bv(c->argv[1], 0, 0, &val);
1927 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
1935 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1936 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1937 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1938 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1939 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1940 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1941 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1942 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1943 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1948 config_security(ConfigArgs *c) {
1949 slap_ssf_set_t *set = &c->be->be_ssf_set;
1952 if (c->op == SLAP_CONFIG_EMIT) {
1958 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1959 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1962 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1963 bv.bv_len += sec_keys[i].key.bv_len;
1964 bv.bv_val = ch_malloc( bv.bv_len + 1);
1965 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1966 strcpy( next, numbuf );
1967 ber_bvarray_add( &c->rvalue_vals, &bv );
1972 for(i = 1; i < c->argc; i++) {
1973 slap_ssf_t *tgt = NULL;
1975 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1976 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1977 sec_keys[j].key.bv_len)) {
1978 src = c->argv[i] + sec_keys[j].key.bv_len;
1979 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1984 sprintf( c->msg, "<%s> unknown factor", c->argv[0] );
1985 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1986 c->log, c->msg, c->argv[i]);
1990 *tgt = strtol(src, &next, 10);
1991 if(next == NULL || next[0] != '\0' ) {
1992 sprintf( c->msg, "<%s> unable to parse factor", c->argv[0] );
1993 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1994 c->log, c->msg, c->argv[i]);
2002 anlist_unparse( AttributeName *an, char *ptr ) {
2005 for (; !BER_BVISNULL( &an->an_name ); an++) {
2006 if ( comma ) *ptr++ = ',';
2007 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2014 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2018 struct berval bc = {0};
2021 len = sprintf(numbuf, IFMT, i );
2023 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2024 if ( ri->ri_nsuffix ) {
2025 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2026 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2029 if ( ri->ri_attrs ) {
2030 len += STRLENOF("attr");
2031 if ( ri->ri_exclude ) len++;
2032 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2033 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2036 bindconf_unparse( &ri->ri_bindconf, &bc );
2039 bv->bv_val = ch_malloc(len + 1);
2042 ptr = lutil_strcopy( bv->bv_val, numbuf );
2043 ptr = lutil_strcopy( ptr, "uri=" );
2044 ptr = lutil_strcopy( ptr, ri->ri_uri );
2046 if ( ri->ri_nsuffix ) {
2047 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2048 ptr = lutil_strcopy( ptr, " suffix=\"" );
2049 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2053 if ( ri->ri_attrs ) {
2054 ptr = lutil_strcopy( ptr, "attr" );
2055 if ( ri->ri_exclude ) *ptr++ = '!';
2057 ptr = anlist_unparse( ri->ri_attrs, ptr );
2060 strcpy( ptr, bc.bv_val );
2061 ch_free( bc.bv_val );
2066 config_replica(ConfigArgs *c) {
2067 int i, nr = -1, len;
2068 char *replicahost, *replicauri;
2071 if (c->op == SLAP_CONFIG_EMIT) {
2072 if (c->be->be_replica) {
2074 for (i=0;c->be->be_replica[i]; i++) {
2075 replica_unparse( c->be->be_replica[i], i, &bv );
2076 ber_bvarray_add( &c->rvalue_vals, &bv );
2081 } else if ( c->op == LDAP_MOD_DELETE ) {
2082 /* FIXME: there is no replica_free function */
2083 if ( c->valx < 0 ) {
2087 if(SLAP_MONITOR(c->be)) {
2088 Debug(LDAP_DEBUG_ANY, "%s: "
2089 "\"replica\" should not be used inside monitor database\n",
2091 return(0); /* FIXME: should this be an error? */
2094 for(i = 1; i < c->argc; i++) {
2095 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2096 replicahost = c->argv[i] + STRLENOF("host=");
2097 len = strlen( replicahost );
2098 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2099 sprintf( replicauri, "ldap://%s", replicahost );
2100 replicahost = replicauri + STRLENOF( "ldap://");
2101 nr = add_replica_info(c->be, replicauri, replicahost);
2103 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2104 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2105 sprintf( c->msg, "<%s> invalid uri", c->argv[0] );
2106 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2109 if(!ludp->lud_host) {
2110 sprintf( c->msg, "<%s> invalid uri - missing hostname",
2112 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2115 ldap_free_urldesc(ludp);
2116 replicauri = c->argv[i] + STRLENOF("uri=");
2117 replicauri = ch_strdup( replicauri );
2118 replicahost = strchr( replicauri, '/' );
2120 nr = add_replica_info(c->be, replicauri, replicahost);
2125 sprintf( c->msg, "<%s> missing host or uri", c->argv[0] );
2126 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2128 } else if(nr == -1) {
2129 sprintf( c->msg, "<%s> unable to add replica", c->argv[0] );
2130 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2133 for(i = 1; i < c->argc; i++) {
2134 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2135 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2137 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2138 "suffix \"%s\" in \"replica\" line is not valid for backend"
2139 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2140 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2141 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2143 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2146 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2147 "unable to normalize suffix in \"replica\" line"
2148 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2150 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2152 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2156 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2158 char *arg = c->argv[i] + STRLENOF("attr");
2166 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2167 sprintf( c->msg, "<%s> unknown attribute", c->argv[0] );
2168 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2169 c->log, c->msg, arg + 1);
2172 } else if ( bindconf_parse( c->argv[i],
2173 &c->be->be_replica[nr]->ri_bindconf ) ) {
2182 config_updatedn(ConfigArgs *c) {
2185 if (c->op == SLAP_CONFIG_EMIT) {
2186 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2187 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2188 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2192 } else if ( c->op == LDAP_MOD_DELETE ) {
2193 ch_free( c->be->be_update_ndn.bv_val );
2194 c->be->be_update_ndn.bv_val = NULL;
2195 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2198 if(SLAP_SHADOW(c->be)) {
2199 sprintf( c->msg, "<%s> database already shadowed", c->argv[0] );
2200 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2205 ber_str2bv(c->argv[1], 0, 0, &dn);
2207 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2209 if(rc != LDAP_SUCCESS) {
2210 sprintf( c->msg, "<%s> invalid DN %d (%s)", c->argv[0],
2211 rc, ldap_err2string(rc));
2212 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2213 c->log, c->msg, 0 );
2217 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2222 config_updateref(ConfigArgs *c) {
2224 if (c->op == SLAP_CONFIG_EMIT) {
2225 if ( c->be->be_update_refs ) {
2226 value_add( &c->rvalue_vals, c->be->be_update_refs );
2231 } else if ( c->op == LDAP_MOD_DELETE ) {
2232 if ( c->valx < 0 ) {
2233 ber_bvarray_free( c->be->be_update_refs );
2234 c->be->be_update_refs = NULL;
2237 ch_free( c->be->be_update_refs[i].bv_val );
2238 for (; c->be->be_update_refs[i].bv_val; i++)
2239 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2243 if(!SLAP_SHADOW(c->be)) {
2244 sprintf( c->msg, "<%s> must appear after syncrepl or updatedn",
2246 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2251 if(validate_global_referral(c->argv[1])) {
2252 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2253 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2254 c->log, c->msg, c->argv[1]);
2257 ber_str2bv(c->argv[1], 0, 0, &val);
2258 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2263 config_include(ConfigArgs *c) {
2264 unsigned long savelineno = c->lineno;
2267 ConfigFile *cfsave = cfn;
2268 ConfigFile *cf2 = NULL;
2269 if (c->op == SLAP_CONFIG_EMIT) {
2271 ConfigFile *cf = c->private;
2272 value_add_one( &c->rvalue_vals, &cf->c_file );
2276 } else if ( c->op == LDAP_MOD_DELETE ) {
2278 cf = ch_calloc( 1, sizeof(ConfigFile));
2279 if ( cfn->c_kids ) {
2280 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2286 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2287 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2288 c->lineno = savelineno - 1;
2291 if ( cf2 ) cf2->c_sibs = NULL;
2292 else cfn->c_kids = NULL;
2293 ch_free( cf->c_file.bv_val );
2303 config_tls_option(ConfigArgs *c) {
2306 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2307 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2308 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2309 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2310 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2311 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2312 default: Debug(LDAP_DEBUG_ANY, "%s: "
2313 "unknown tls_option <0x%x>\n",
2314 c->log, c->type, 0);
2316 if (c->op == SLAP_CONFIG_EMIT) {
2317 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2318 } else if ( c->op == LDAP_MOD_DELETE ) {
2319 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2321 ch_free(c->value_string);
2322 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2325 /* FIXME: this ought to be provided by libldap */
2327 config_tls_config(ConfigArgs *c) {
2329 slap_verbmasks crlkeys[] = {
2330 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2331 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2332 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2335 slap_verbmasks vfykeys[] = {
2336 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2337 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2338 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2339 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2343 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2344 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2346 Debug(LDAP_DEBUG_ANY, "%s: "
2347 "unknown tls_option <0x%x>\n",
2348 c->log, c->type, 0);
2350 if (c->op == SLAP_CONFIG_EMIT) {
2351 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2352 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2353 if (keys[i].mask == c->value_int) {
2354 c->value_string = ch_strdup( keys[i].word.bv_val );
2359 } else if ( c->op == LDAP_MOD_DELETE ) {
2361 return ldap_pvt_tls_set_option( NULL, flag, &i );
2363 ch_free( c->value_string );
2364 if(isdigit((unsigned char)c->argv[1][0])) {
2365 i = atoi(c->argv[1]);
2366 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2368 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2373 static CfEntryInfo *
2374 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2384 if ( dn_match( &root->ce_entry->e_nname, dn ))
2387 c = dn->bv_val+dn->bv_len;
2388 for (;*c != ',';c--);
2392 for (--c;c>dn->bv_val && *c != ',';c--);
2396 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2398 root = root->ce_kids;
2400 for (;root;root=root->ce_sibs) {
2401 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2402 if ( cdn.bv_val == dn->bv_val ) {
2412 typedef struct setup_cookie {
2418 config_ldif_resp( Operation *op, SlapReply *rs )
2420 if ( rs->sr_type == REP_SEARCH ) {
2421 setup_cookie *sc = op->o_callback->sc_private;
2423 sc->cfb->cb_got_ldif = 1;
2424 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL );
2429 /* Configure and read the underlying back-ldif store */
2431 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
2432 CfBackInfo *cfb = be->be_private;
2438 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2439 Connection conn = {0};
2440 char opbuf[OPERATION_BUFFER_SIZE];
2442 SlapReply rs = {REP_RESULT};
2443 Filter filter = { LDAP_FILTER_PRESENT };
2444 struct berval filterstr = BER_BVC("(objectclass=*)");
2447 /* Is the config directory available? */
2448 if ( stat( dir, &st ) < 0 ) {
2449 /* No, so don't bother using the backing store.
2450 * All changes will be in-memory only.
2455 cfb->cb_db.bd_info = backend_info( "ldif" );
2456 if ( !cfb->cb_db.bd_info )
2457 return 0; /* FIXME: eventually this will be a fatal error */
2459 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2461 /* Mark that back-ldif type is in use */
2462 cfb->cb_db.bd_info->bi_nDB++;
2464 cfb->cb_db.be_suffix = be->be_suffix;
2465 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2466 cfb->cb_db.be_rootdn = be->be_rootdn;
2467 cfb->cb_db.be_rootndn = be->be_rootndn;
2469 ber_str2bv( dir, 0, 1, &cfdir );
2474 argv[0] = "directory";
2475 argv[1] = (char *)dir;
2479 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
2483 if ( config_add_vals( ct, &c ))
2486 if ( backend_startup_one( &cfb->cb_db ))
2490 op = (Operation *)opbuf;
2491 connection_fake_init( &conn, op, cfb );
2493 filter.f_desc = slap_schema.si_ad_objectClass;
2495 op->o_tag = LDAP_REQ_SEARCH;
2497 op->ors_filter = &filter;
2498 op->ors_filterstr = filterstr;
2499 op->ors_scope = LDAP_SCOPE_SUBTREE;
2501 op->o_dn = be->be_rootdn;
2502 op->o_ndn = be->be_rootndn;
2504 op->o_req_dn = be->be_suffix[0];
2505 op->o_req_ndn = be->be_nsuffix[0];
2507 op->ors_tlimit = SLAP_NO_LIMIT;
2508 op->ors_slimit = SLAP_NO_LIMIT;
2510 op->ors_attrs = slap_anlist_all_attributes;
2511 op->ors_attrsonly = 0;
2513 op->o_callback = &cb;
2516 cb.sc_private = ≻
2518 op->o_bd = &cfb->cb_db;
2519 rc = op->o_bd->be_search( op, &rs );
2522 cfb->cb_use_ldif = 1;
2528 CfOc_cmp( const void *c1, const void *c2 ) {
2529 const ConfigOCs *co1 = c1;
2530 const ConfigOCs *co2 = c2;
2532 return ber_bvcmp( co1->co_name, co2->co_name );
2536 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2539 i = init_config_attrs( ct );
2542 /* set up the objectclasses */
2543 i = init_config_ocs( ocs );
2546 for (i=0; ocs[i].co_def; i++) {
2547 if ( ocs[i].co_oc ) {
2548 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
2549 if ( !ocs[i].co_table )
2550 ocs[i].co_table = ct;
2551 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
2558 read_config(const char *fname, const char *dir) {
2561 const char *cfdir, *cfname;
2564 /* Setup the config backend */
2565 be = backend_db_init( "config" );
2569 cfb = be->be_private;
2571 /* If no .conf, or a dir was specified, setup the dir */
2572 if ( !fname || dir ) {
2574 /* If explicitly given, check for existence */
2577 if ( stat( dir, &st ) < 0 ) {
2578 Debug( LDAP_DEBUG_ANY,
2579 "invalid config directory %s, error %d\n",
2585 cfdir = SLAPD_DEFAULT_CONFIGDIR;
2587 /* if fname is defaulted, try reading .d */
2588 rc = config_setup_ldif( be, cfdir, !fname );
2590 /* It's OK if the base object doesn't exist yet */
2591 if ( rc && rc != LDAP_NO_SUCH_OBJECT )
2594 /* If we read the config from back-ldif, nothing to do here */
2595 if ( cfb->cb_got_ldif ) {
2604 cfname = SLAPD_DEFAULT_CONFIGFILE;
2606 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
2609 ber_str2bv( cfname, 0, 1, &cf_prv.c_file );
2611 /* If we got this far and failed, it may be a serious problem. In server
2612 * mode, we should never come to this. However, it may be alright if we're
2613 * using slapadd to create the conf dir.
2616 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
2618 /* If a config file was explicitly given, fail */
2622 /* Seems to be slapadd with a config dir, let it continue */
2623 if ( cfb->cb_use_ldif ) {
2625 cfb->cb_got_ldif = 1;
2631 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2632 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
2633 &frontendDB->be_schemadn );
2634 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2635 if ( rc != LDAP_SUCCESS ) {
2636 Debug(LDAP_DEBUG_ANY, "read_config: "
2637 "unable to normalize default schema DN \"%s\"\n",
2638 frontendDB->be_schemadn.bv_val, 0, 0 );
2639 /* must not happen */
2647 config_back_bind( Operation *op, SlapReply *rs )
2649 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2650 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2651 /* frontend sends result */
2652 return LDAP_SUCCESS;
2655 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2656 send_ldap_result( op, rs );
2662 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2666 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2668 rs->sr_attrs = op->ors_attrs;
2669 rs->sr_entry = ce->ce_entry;
2670 rc = send_search_entry( op, rs );
2672 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2673 if ( ce->ce_kids ) {
2674 rc = config_send( op, rs, ce->ce_kids, 1 );
2675 if ( rc ) return rc;
2678 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2679 rc = config_send( op, rs, ce, 0 );
2687 static ConfigTable *
2688 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
2692 for (j=0; j<nocs; j++) {
2693 for (i=0; colst[j]->co_table[i].name; i++)
2694 if ( colst[j]->co_table[i].ad == ad )
2695 return &colst[j]->co_table[i];
2700 /* Sort the attributes of the entry according to the order defined
2701 * in the objectclass, with required attributes occurring before
2702 * allowed attributes. For any attributes with sequencing dependencies
2703 * (e.g., rootDN must be defined after suffix) the objectclass must
2704 * list the attributes in the desired sequence.
2707 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
2709 Attribute *a, *head = NULL, *tail = NULL, **prev;
2712 for (i=0; i<nocs; i++) {
2713 if ( colst[i]->co_oc->soc_required ) {
2714 AttributeType **at = colst[i]->co_oc->soc_required;
2715 for (j=0; at[j]; j++) {
2716 for (a=e->e_attrs, prev=&e->e_attrs; a;
2717 prev = &(*prev)->a_next, a=a->a_next) {
2718 if ( a->a_desc == at[j]->sat_ad ) {
2732 if ( colst[i]->co_oc->soc_allowed ) {
2733 AttributeType **at = colst[i]->co_oc->soc_allowed;
2734 for (j=0; at[j]; j++) {
2735 for (a=e->e_attrs, prev=&e->e_attrs; a;
2736 prev = &(*prev)->a_next, a=a->a_next) {
2737 if ( a->a_desc == at[j]->sat_ad ) {
2753 tail->a_next = e->e_attrs;
2759 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2761 Attribute *a = NULL;
2762 AttributeDescription *ad;
2765 int i, rc = 0, sort = 0;
2772 Modifications *ml = ptr;
2774 vals = ml->sml_values;
2777 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2779 rc = ordered_value_sort( a, 1 );
2783 for ( i=0; vals[i].bv_val; i++ ) {
2784 ca->line = vals[i].bv_val;
2786 char *idx = strchr( ca->line, '}' );
2787 if ( idx ) ca->line = idx+1;
2789 rc = config_parse_vals( ct, ca, i );
2797 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2798 SlapReply *rs, int *renum )
2801 int index = -1, gotindex = 0, nsibs;
2802 int renumber = 0, tailindex = 0;
2806 if ( renum ) *renum = 0;
2808 /* These entries don't get indexed/renumbered */
2809 if ( ce_type == Cft_Global ) return 0;
2810 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2812 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2815 /* See if the rdn has an index already */
2816 dnRdn( &e->e_name, &rdn );
2817 ptr1 = strchr( e->e_name.bv_val, '{' );
2818 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2819 ptr2 = strchr( ptr1, '}' );
2820 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2821 return LDAP_NAMING_VIOLATION;
2822 if ( ptr2-ptr1 == 1)
2823 return LDAP_NAMING_VIOLATION;
2825 index = atoi(ptr1+1);
2827 return LDAP_NAMING_VIOLATION;
2830 /* count related kids */
2831 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2832 if ( ce->ce_type == ce_type ) nsibs++;
2835 if ( index != nsibs ) {
2837 if ( index < nsibs ) {
2838 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2839 /* Siblings need to be renumbered */
2844 struct berval ival, newrdn, nnewrdn;
2845 struct berval rtype, rval;
2847 AttributeDescription *ad = NULL;
2851 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2852 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2853 rtype.bv_val = rdn.bv_val;
2854 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2857 slap_bv2ad( &rtype, &ad, &text );
2858 a = attr_find( e->e_attrs, ad );
2859 if (!a ) return LDAP_NAMING_VIOLATION;
2862 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2864 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2865 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2868 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2869 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2876 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
2878 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
2881 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2882 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
2886 /* Do the equivalent of ModRDN */
2887 /* Replace DN / NDN */
2888 newrdn.bv_len = ptr1 - newrdn.bv_val;
2889 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
2890 free( e->e_name.bv_val );
2891 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
2893 free( e->e_nname.bv_val );
2894 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
2898 free( a->a_vals[0].bv_val );
2899 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
2900 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
2901 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
2902 strcpy( a->a_vals[0].bv_val, ptr1 );
2904 if ( a->a_nvals != a->a_vals ) {
2905 free( a->a_nvals[0].bv_val );
2906 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
2907 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
2908 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
2909 strcpy( a->a_nvals[0].bv_val, ptr1 );
2911 free( nnewrdn.bv_val );
2912 free( newrdn.bv_val );
2915 if ( renum ) *renum = renumber;
2920 count_ocs( Attribute *oc_at, int *nocs )
2923 ConfigOCs co, *coptr, **colst;
2925 /* count the objectclasses */
2926 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2928 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
2930 for ( i=0, j=0; i<n; i++) {
2931 co.co_name = &oc_at->a_nvals[i];
2932 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
2934 /* ignore non-config objectclasses. probably should be
2935 * an error, general data doesn't belong here.
2937 if ( !coptr ) continue;
2939 /* Ignore the root objectclass, it has no implementation.
2941 if ( coptr->co_type == Cft_Abstract ) continue;
2949 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2951 if ( p->ce_type != Cft_Global && p->ce_type != Cft_Include )
2952 return LDAP_CONSTRAINT_VIOLATION;
2954 /* If we're reading from a configdir, don't parse this entry */
2956 return LDAP_COMPARE_TRUE;
2958 if ( p->ce_type == Cft_Global )
2961 cfn = p->ce_private;
2963 return LDAP_SUCCESS;
2967 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2971 /* This entry is hardcoded, don't re-parse it */
2972 if ( p->ce_type == Cft_Global ) {
2975 return LDAP_COMPARE_TRUE;
2977 if ( p->ce_type != Cft_Schema )
2978 return LDAP_CONSTRAINT_VIOLATION;
2980 cfn = ch_calloc( 1, sizeof(ConfigFile) );
2982 cfo = p->ce_private;
2983 cfn->c_sibs = cfo->c_kids;
2985 return LDAP_SUCCESS;
2989 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
2991 if ( p->ce_type != Cft_Global )
2992 return LDAP_CONSTRAINT_VIOLATION;
2993 ca->be = frontendDB; /* just to get past check_vals */
2994 return LDAP_SUCCESS;
2998 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3000 if ( p->ce_type != Cft_Global )
3001 return LDAP_CONSTRAINT_VIOLATION;
3002 return LDAP_SUCCESS;
3006 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3008 if ( p->ce_type != Cft_Global )
3009 return LDAP_CONSTRAINT_VIOLATION;
3010 return LDAP_SUCCESS;
3014 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3016 if ( p->ce_type != Cft_Database )
3017 return LDAP_CONSTRAINT_VIOLATION;
3019 return LDAP_SUCCESS;
3022 /* Parse an LDAP entry into config directives */
3024 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs, int *renum )
3026 CfEntryInfo *ce, *last;
3028 Attribute *a, *oc_at;
3029 int i, j, nocs, rc = 0;
3034 /* Make sure parent exists and entry does not */
3035 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3037 return LDAP_ALREADY_EXISTS;
3039 dnParent( &e->e_nname, &pdn );
3041 /* If last is NULL, the new entry is the root/suffix entry,
3042 * otherwise last should be the parent.
3044 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3046 rs->sr_matched = last->ce_entry->e_name.bv_val;
3047 return LDAP_NO_SUCH_OBJECT;
3050 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3051 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3053 memset( ca, 0, sizeof(ConfigArgs));
3055 /* Fake the coordinates based on whether we're part of an
3056 * LDAP Add or if reading the config dir
3059 ca->fname = "slapd";
3062 ca->fname = cfdir.bv_val;
3066 colst = count_ocs( oc_at, &nocs );
3068 /* Only the root can be Cft_Global, everything else must
3069 * have a parent. Only limited nesting arrangements are allowed.
3071 rc = LDAP_CONSTRAINT_VIOLATION;
3072 if ( colst[0]->co_type == Cft_Global && !last ) {
3075 ca->be = frontendDB; /* just to get past check_vals */
3079 /* Check whether the Add is allowed by its parent, and do
3080 * any necessary arg setup
3083 for ( i=0; i<nocs; i++ ) {
3084 if ( colst[i]->co_ldadd &&
3085 ( rc = colst[i]->co_ldadd( last, e, ca ))
3086 != LDAP_CONSTRAINT_VIOLATION ) {
3092 /* Add the entry but don't parse it, we already have its contents */
3093 if ( rc == LDAP_COMPARE_TRUE ) {
3098 if ( rc != LDAP_SUCCESS )
3101 /* Parse all the values and check for simple syntax errors before
3102 * performing any set actions.
3104 * If doing an LDAPadd, check for indexed names and any necessary
3105 * renaming/renumbering. Entries that don't need indexed names are
3106 * ignored. Entries that need an indexed name and arrive without one
3107 * are assigned to the end. Entries that arrive with an index may
3108 * cause the following entries to be renumbered/bumped down.
3110 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3111 * don't allow Adding an entry with an index that's already in use.
3112 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3114 * These entries can have auto-assigned indexes (appended to the end)
3115 * but only the other types support auto-renumbering of siblings.
3117 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3121 init_config_argv( ca );
3123 /* Make sure we process attrs in the required order */
3124 sort_attrs( e, colst, nocs );
3126 for ( a=e->e_attrs; a; a=a->a_next ) {
3127 if ( a == oc_at ) continue;
3128 ct = config_find_table( colst, nocs, a->a_desc );
3129 if ( !ct ) continue; /* user data? */
3130 rc = check_vals( ct, ca, a, 1 );
3131 if ( rc ) goto leave;
3134 /* Basic syntax checks are OK. Do the actual settings. */
3135 for ( a=e->e_attrs; a; a=a->a_next ) {
3136 if ( a == oc_at ) continue;
3137 ct = config_find_table( colst, nocs, a->a_desc );
3138 if ( !ct ) continue; /* user data? */
3139 for (i=0; a->a_vals[i].bv_val; i++) {
3140 ca->line = a->a_vals[i].bv_val;
3141 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3142 ptr = strchr( ca->line, '}' );
3143 if ( ptr ) ca->line = ptr+1;
3146 rc = config_parse_add( ct, ca );
3154 /* Newly added databases and overlays need to be started up */
3155 if ( CONFIG_ONLINE_ADD( ca )) {
3156 if ( colst[0]->co_type == Cft_Database ) {
3157 rc = backend_startup_one( ca->be );
3159 } else if ( colst[0]->co_type == Cft_Overlay ) {
3160 if ( ca->bi->bi_db_open ) {
3161 BackendInfo *bi_orig = ca->be->bd_info;
3162 ca->be->bd_info = ca->bi;
3163 rc = ca->bi->bi_db_open( ca->be );
3164 ca->be->bd_info = bi_orig;
3168 sprintf( ca->msg, "<%s> failed startup", ca->argv[0] );
3169 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
3170 ca->log, ca->msg, ca->argv[1] );
3176 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3177 ce->ce_parent = last;
3178 ce->ce_entry = entry_dup( e );
3179 ce->ce_entry->e_private = ce;
3180 ce->ce_type = colst[0]->co_type;
3183 ce->ce_private = ca->private;
3186 } else if ( last->ce_kids ) {
3189 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3197 ch_free( ca->argv );
3198 if ( colst ) ch_free( colst );
3202 /* Parse an LDAP entry into config directives, then store in underlying
3206 config_back_add( Operation *op, SlapReply *rs )
3209 CfEntryInfo *ce, *last;
3213 if ( !be_isroot( op ) ) {
3214 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3218 cfb = (CfBackInfo *)op->o_bd->be_private;
3220 ldap_pvt_thread_pool_pause( &connection_pool );
3223 * 1) check for existence of entry
3224 * 2) check for sibling renumbering
3225 * 3) perform internal add
3226 * 4) store entry in underlying database
3227 * 5) perform any necessary renumbering
3229 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber );
3230 if ( rs->sr_err != LDAP_SUCCESS ) {
3231 rs->sr_text = ca.msg;
3232 } else if ( cfb->cb_use_ldif ) {
3233 BackendDB *be = op->o_bd;
3234 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3235 op->o_bd = &cfb->cb_db;
3236 sc.sc_next = op->o_callback;
3237 op->o_callback = ≻
3238 op->o_bd->be_add( op, rs );
3240 op->o_callback = sc.sc_next;
3245 ldap_pvt_thread_pool_resume( &connection_pool );
3248 send_ldap_result( op, rs );
3252 typedef struct delrec {
3253 struct delrec *next;
3259 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3262 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3263 int rc = LDAP_UNWILLING_TO_PERFORM;
3265 Entry *e = ce->ce_entry;
3266 Attribute *save_attrs = e->e_attrs, *oc_at;
3271 delrec *dels = NULL, *deltail = NULL;
3273 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3274 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3276 colst = count_ocs( oc_at, &nocs );
3278 e->e_attrs = attrs_dup( e->e_attrs );
3280 init_config_argv( ca );
3283 ca->private = ce->ce_private;
3285 strcpy( ca->log, "back-config" );
3287 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3288 ct = config_find_table( colst, nocs, ml->sml_desc );
3289 switch (ml->sml_op) {
3290 case LDAP_MOD_DELETE:
3291 case LDAP_MOD_REPLACE: {
3292 BerVarray vals = NULL, nvals;
3294 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3296 snprintf( ca->msg, sizeof(ca->msg),
3297 "<%s> cannot be deleted" );
3298 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3299 ml->sml_desc->ad_cname.bv_val );
3302 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3303 vals = ml->sml_values;
3304 nvals = ml->sml_nvalues;
3305 ml->sml_values = NULL;
3306 ml->sml_nvalues = NULL;
3308 /* If we're deleting by values, remember the indexes of the
3309 * values we deleted.
3311 if ( ct && ml->sml_values ) {
3313 for (i=0; ml->sml_values[i].bv_val; i++);
3314 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
3325 rc = modify_delete_vindex(e, &ml->sml_mod,
3326 get_permissiveModify(op),
3327 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3328 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3329 ml->sml_values = vals;
3330 ml->sml_nvalues = nvals;
3335 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3338 case SLAP_MOD_SOFTADD: {
3339 int mop = ml->sml_op;
3341 ml->sml_op = LDAP_MOD_ADD;
3343 if ( ct->arg_type & ARG_NO_INSERT ) {
3344 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3346 for (i = 0; a->a_vals[i].bv_val; i++ );
3350 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3351 if ( ml->sml_values[i].bv_val[0] == '{' &&
3353 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3356 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3357 ml->sml_desc->ad_cname.bv_val );
3361 rc = check_vals( ct, ca, ml, 0 );
3365 rc = modify_add_values(e, &ml->sml_mod,
3366 get_permissiveModify(op),
3367 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3369 /* If value already exists, show success here
3370 * and ignore this operation down below.
3372 if ( mop == SLAP_MOD_SOFTADD ) {
3373 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3383 case LDAP_MOD_INCREMENT: /* FIXME */
3388 if(rc != LDAP_SUCCESS) break;
3391 if(rc == LDAP_SUCCESS) {
3392 /* check that the entry still obeys the schema */
3393 rc = entry_schema_check(op->o_bd, e, NULL, 0,
3394 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3396 if ( rc == LDAP_SUCCESS ) {
3397 /* Basic syntax checks are OK. Do the actual settings. */
3398 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3399 ct = config_find_table( colst, nocs, ml->sml_desc );
3400 if ( !ct ) continue;
3402 switch (ml->sml_op) {
3403 case LDAP_MOD_DELETE:
3404 case LDAP_MOD_REPLACE: {
3405 BerVarray vals = NULL, nvals;
3409 a = attr_find( e->e_attrs, ml->sml_desc );
3411 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3412 vals = ml->sml_values;
3413 nvals = ml->sml_nvalues;
3414 ml->sml_values = NULL;
3415 ml->sml_nvalues = NULL;
3418 if ( ml->sml_values )
3421 /* If we didn't delete the whole attribute */
3422 if ( ml->sml_values && a ) {
3423 struct berval *mvals;
3426 if ( ml->sml_nvalues )
3427 mvals = ml->sml_nvalues;
3429 mvals = ml->sml_values;
3431 /* use the indexes we saved up above */
3432 for (i=0; i < d->nidx; i++) {
3433 struct berval bv = *mvals++;
3434 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3435 bv.bv_val[0] == '{' ) {
3436 ptr = strchr( bv.bv_val, '}' ) + 1;
3437 bv.bv_len -= ptr - bv.bv_val;
3440 ca->line = bv.bv_val;
3441 ca->valx = d->idx[i];
3442 rc = config_del_vals( ct, ca );
3443 if ( rc != LDAP_SUCCESS ) break;
3444 for (j=i+1; j < d->nidx; j++)
3445 if ( d->idx[j] >d->idx[i] )
3451 rc = config_del_vals( ct, ca );
3452 if ( rc ) rc = LDAP_OTHER;
3454 if ( ml->sml_values ) {
3458 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3459 ml->sml_values = vals;
3460 ml->sml_nvalues = nvals;
3462 if ( !vals || rc != LDAP_SUCCESS )
3465 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3468 for (i=0; ml->sml_values[i].bv_val; i++) {
3469 ca->line = ml->sml_values[i].bv_val;
3471 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3472 ca->line[0] == '{' ) {
3473 ptr = strchr( ca->line, '}' );
3475 ca->valx = strtol( ca->line+1, NULL, 0 );
3479 rc = config_parse_add( ct, ca );
3494 if ( rc == LDAP_SUCCESS ) {
3495 attrs_free( save_attrs );
3497 attrs_free( e->e_attrs );
3498 e->e_attrs = save_attrs;
3500 ch_free( ca->argv );
3501 if ( colst ) ch_free( colst );
3507 config_back_modify( Operation *op, SlapReply *rs )
3510 CfEntryInfo *ce, *last;
3512 ConfigArgs ca = {0};
3515 AttributeDescription *rad = NULL;
3517 if ( !be_isroot( op ) ) {
3518 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3522 cfb = (CfBackInfo *)op->o_bd->be_private;
3524 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3527 rs->sr_matched = last->ce_entry->e_name.bv_val;
3528 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3532 /* Get type of RDN */
3533 rdn = ce->ce_entry->e_nname;
3534 ptr = strchr( rdn.bv_val, '=' );
3535 rdn.bv_len = ptr - rdn.bv_val;
3536 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3538 /* Some basic validation... */
3539 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3540 /* Don't allow Modify of RDN; must use ModRdn for that. */
3541 if ( ml->sml_desc == rad ) {
3542 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3543 rs->sr_text = "Use modrdn to change the entry name";
3548 ldap_pvt_thread_pool_pause( &connection_pool );
3551 * 1) perform the Modify on the cached Entry.
3552 * 2) verify that the Entry still satisfies the schema.
3553 * 3) perform the individual config operations.
3554 * 4) store Modified entry in underlying LDIF backend.
3556 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3558 rs->sr_text = ca.msg;
3559 } else if ( cfb->cb_use_ldif ) {
3560 BackendDB *be = op->o_bd;
3561 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3562 op->o_bd = &cfb->cb_db;
3563 sc.sc_next = op->o_callback;
3564 op->o_callback = ≻
3565 op->o_bd->be_modify( op, rs );
3567 op->o_callback = sc.sc_next;
3570 ldap_pvt_thread_pool_resume( &connection_pool );
3572 send_ldap_result( op, rs );
3577 config_back_modrdn( Operation *op, SlapReply *rs )
3580 CfEntryInfo *ce, *last;
3582 if ( !be_isroot( op ) ) {
3583 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3587 cfb = (CfBackInfo *)op->o_bd->be_private;
3589 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3592 rs->sr_matched = last->ce_entry->e_name.bv_val;
3593 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3597 /* We don't allow moving objects to new parents.
3598 * Generally we only allow reordering a set of ordered entries.
3600 if ( op->orr_newSup ) {
3601 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3604 ldap_pvt_thread_pool_pause( &connection_pool );
3606 ldap_pvt_thread_pool_resume( &connection_pool );
3608 send_ldap_result( op, rs );
3613 config_back_search( Operation *op, SlapReply *rs )
3616 CfEntryInfo *ce, *last;
3619 if ( !be_isroot( op ) ) {
3620 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3624 cfb = (CfBackInfo *)op->o_bd->be_private;
3626 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3629 rs->sr_matched = last->ce_entry->e_name.bv_val;
3630 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3633 switch ( op->ors_scope ) {
3634 case LDAP_SCOPE_BASE:
3635 case LDAP_SCOPE_SUBTREE:
3636 config_send( op, rs, ce, 0 );
3639 case LDAP_SCOPE_ONELEVEL:
3640 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3641 config_send( op, rs, ce, 1 );
3646 rs->sr_err = LDAP_SUCCESS;
3648 send_ldap_result( op, rs );
3653 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
3654 ConfigTable *ct, ConfigArgs *c )
3658 for (; at && *at; at++) {
3659 /* Skip the naming attr */
3660 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3662 for (i=0;ct[i].name;i++) {
3663 if (ct[i].ad == (*at)->sat_ad) {
3664 rc = config_get_vals(&ct[i], c);
3665 if (rc == LDAP_SUCCESS) {
3666 if ( c->rvalue_nvals )
3667 attr_merge(e, ct[i].ad, c->rvalue_vals,
3670 attr_merge_normalize(e, ct[i].ad,
3671 c->rvalue_vals, NULL);
3672 ber_bvarray_free( c->rvalue_nvals );
3673 ber_bvarray_free( c->rvalue_vals );
3682 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3683 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
3685 Entry *e = ch_calloc( 1, sizeof(Entry) );
3686 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3688 struct berval ad_name;
3689 AttributeDescription *ad = NULL;
3696 CfEntryInfo *ceprev = NULL;
3700 ce->ce_parent = parent;
3702 pdn = parent->ce_entry->e_nname;
3703 if ( parent->ce_kids )
3704 for ( ceprev = parent->ce_kids; ceprev->ce_sibs;
3705 ceprev = ceprev->ce_sibs );
3710 ce->ce_type = main->co_type;
3711 ce->ce_private = c->private;
3715 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3716 ber_dupbv( &e->e_nname, &e->e_name );
3718 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3719 main->co_name, NULL );
3721 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3722 extra->co_name, NULL );
3723 ptr = strchr(rdn->bv_val, '=');
3724 ad_name.bv_val = rdn->bv_val;
3725 ad_name.bv_len = ptr - rdn->bv_val;
3726 rc = slap_bv2ad( &ad_name, &ad, &text );
3731 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3732 attr_merge_normalize_one(e, ad, &val, NULL );
3735 if ( oc->soc_required )
3736 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
3738 if ( oc->soc_allowed )
3739 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
3743 if ( oc->soc_required )
3744 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
3746 if ( oc->soc_allowed )
3747 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
3750 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3751 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3753 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3756 op->o_bd->be_add( op, rs );
3759 ceprev->ce_sibs = ce;
3760 } else if ( parent ) {
3761 parent->ce_kids = ce;
3768 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3769 Operation *op, SlapReply *rs )
3772 ConfigFile *cf = c->private;
3776 for (; cf; cf=cf->c_sibs, c->depth++) {
3777 c->value_dn.bv_val = c->log;
3778 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3783 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3785 ptr = strchr( bv.bv_val, '.' );
3787 bv.bv_len = ptr - bv.bv_val;
3788 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3789 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3791 c->value_dn.bv_len += bv.bv_len;
3792 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3795 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3796 &CFOC_SCHEMA, NULL );
3797 if ( e && cf->c_kids ) {
3798 c->private = cf->c_kids;
3799 config_build_schema_inc( c, e->e_private, op, rs );
3805 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3806 Operation *op, SlapReply *rs )
3810 ConfigFile *cf = c->private;
3812 for (i=0; cf; cf=cf->c_sibs, i++) {
3813 c->value_dn.bv_val = c->log;
3814 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3816 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3817 &CFOC_INCLUDE, NULL );
3818 if ( e && cf->c_kids ) {
3819 c->private = cf->c_kids;
3820 config_build_includes( c, e->e_private, op, rs );
3825 #ifdef SLAPD_MODULES
3828 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3829 Operation *op, SlapReply *rs )
3834 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3835 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3837 c->value_dn.bv_val = c->log;
3838 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3840 config_build_entry( op, rs, ceparent, c, &c->value_dn,
3841 &CFOC_MODULE, NULL );
3847 config_back_db_open( BackendDB *be )
3849 CfBackInfo *cfb = be->be_private;
3852 CfEntryInfo *ce, *ceparent, *ceprev;
3858 Connection conn = {0};
3859 char opbuf[OPERATION_BUFFER_SIZE];
3861 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3862 SlapReply rs = {REP_RESULT};
3864 /* If we read the config from back-ldif, nothing to do here */
3865 if ( cfb->cb_got_ldif )
3868 if ( cfb->cb_use_ldif ) {
3869 op = (Operation *)opbuf;
3870 connection_fake_init( &conn, op, cfb );
3872 op->o_dn = be->be_rootdn;
3873 op->o_ndn = be->be_rootndn;
3875 op->o_tag = LDAP_REQ_ADD;
3876 op->o_callback = &cb;
3877 op->o_bd = &cfb->cb_db;
3882 /* create root of tree */
3884 c.private = cfb->cb_config;
3886 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
3893 /* Create includeFile nodes */
3894 if ( cfb->cb_config->c_kids ) {
3896 c.private = cfb->cb_config->c_kids;
3897 config_build_includes( &c, ceparent, op, &rs );
3900 #ifdef SLAPD_MODULES
3901 /* Create Module nodes... */
3902 if ( modpaths.mp_loads ) {
3903 config_build_modules( &c, ceparent, op, &rs );
3907 /* Create schema nodes... cn=schema will contain the hardcoded core
3908 * schema, read-only. Child objects will contain runtime loaded schema
3913 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
3916 /* Create schema nodes for included schema... */
3917 if ( cfb->cb_config->c_kids ) {
3919 c.private = cfb->cb_config->c_kids;
3920 config_build_schema_inc( &c, ce, op, &rs );
3923 /* Create backend nodes. Skip if they don't provide a cf_table.
3924 * There usually aren't any of these.
3928 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3929 if (!bi->bi_cf_ocs) continue;
3930 if (!bi->bi_private) continue;
3933 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3935 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
3939 /* Create database nodes... */
3941 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3942 slap_overinfo *oi = NULL;
3949 if ( overlay_is_over( bptr )) {
3950 oi = bptr->bd_info->bi_private;
3956 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3960 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
3963 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
3964 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
3965 /* Iterate through overlays */
3971 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3973 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
3974 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3977 oe = config_build_entry( op, &rs, ce, &c, &rdn,
3978 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
3979 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
3980 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
3989 config_back_db_destroy( Backend *be )
3991 free( be->be_private );
3996 config_back_db_init( Backend *be )
4001 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4002 cfb->cb_config = &cf_prv;
4003 be->be_private = cfb;
4005 ber_dupbv( &be->be_rootdn, &config_rdn );
4006 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4007 ber_dupbv( &dn, &be->be_rootdn );
4008 ber_bvarray_add( &be->be_suffix, &dn );
4009 ber_dupbv( &dn, &be->be_rootdn );
4010 ber_bvarray_add( &be->be_nsuffix, &dn );
4012 /* Hide from namingContexts */
4013 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4019 config_back_destroy( BackendInfo *bi )
4021 ldif_must_b64_encode_release();
4026 config_tool_entry_open( BackendDB *be, int mode )
4028 CfBackInfo *cfb = be->be_private;
4029 BackendInfo *bi = cfb->cb_db.bd_info;
4031 if ( bi && bi->bi_tool_entry_open )
4032 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
4039 config_tool_entry_close( BackendDB *be )
4041 CfBackInfo *cfb = be->be_private;
4042 BackendInfo *bi = cfb->cb_db.bd_info;
4044 if ( bi && bi->bi_tool_entry_close )
4045 return bi->bi_tool_entry_close( &cfb->cb_db );
4051 config_tool_entry_first( BackendDB *be )
4053 CfBackInfo *cfb = be->be_private;
4054 BackendInfo *bi = cfb->cb_db.bd_info;
4056 if ( bi && bi->bi_tool_entry_first )
4057 return bi->bi_tool_entry_first( &cfb->cb_db );
4063 config_tool_entry_next( BackendDB *be )
4065 CfBackInfo *cfb = be->be_private;
4066 BackendInfo *bi = cfb->cb_db.bd_info;
4068 if ( bi && bi->bi_tool_entry_next )
4069 return bi->bi_tool_entry_next( &cfb->cb_db );
4075 config_tool_entry_get( BackendDB *be, ID id )
4077 CfBackInfo *cfb = be->be_private;
4078 BackendInfo *bi = cfb->cb_db.bd_info;
4080 if ( bi && bi->bi_tool_entry_get )
4081 return bi->bi_tool_entry_get( &cfb->cb_db, id );
4087 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
4089 CfBackInfo *cfb = be->be_private;
4090 BackendInfo *bi = cfb->cb_db.bd_info;
4093 if ( bi && bi->bi_tool_entry_put &&
4094 config_add_internal( cfb, e, &ca, NULL, NULL ) == 0 )
4095 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
4102 AttributeDescription **desc;
4104 { "backend", &cfAd_backend },
4105 { "database", &cfAd_database },
4106 { "include", &cfAd_include },
4107 { "overlay", &cfAd_overlay },
4112 * add / delete: all types that may be added or deleted must use an
4113 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4114 * should automatically renumber the index of any siblings as needed,
4115 * so that no gaps in the numbering sequence exist after the add/delete
4117 * What can be added:
4119 * backend objects for backend-specific config directives
4123 * delete: probably no support this time around.
4125 * modrdn: generally not done. Will be invoked automatically by add/
4126 * delete to update numbering sequence. Perform as an explicit operation
4127 * so that the renumbering effect may be replicated. Subtree rename must
4128 * be supported, since renumbering a database will affect all its child
4131 * modify: must be fully supported.
4135 config_back_initialize( BackendInfo *bi )
4137 ConfigTable *ct = config_back_cf_table;
4140 AttributeDescription *ad = NULL;
4142 static char *controls[] = {
4143 LDAP_CONTROL_MANAGEDSAIT,
4147 bi->bi_controls = controls;
4152 bi->bi_destroy = config_back_destroy;
4154 bi->bi_db_init = config_back_db_init;
4155 bi->bi_db_config = 0;
4156 bi->bi_db_open = config_back_db_open;
4157 bi->bi_db_close = 0;
4158 bi->bi_db_destroy = config_back_db_destroy;
4160 bi->bi_op_bind = config_back_bind;
4161 bi->bi_op_unbind = 0;
4162 bi->bi_op_search = config_back_search;
4163 bi->bi_op_compare = 0;
4164 bi->bi_op_modify = config_back_modify;
4165 bi->bi_op_modrdn = config_back_modrdn;
4166 bi->bi_op_add = config_back_add;
4167 bi->bi_op_delete = 0;
4168 bi->bi_op_abandon = 0;
4170 bi->bi_extended = 0;
4172 bi->bi_chk_referrals = 0;
4174 #ifdef SLAP_OVERLAY_ACCESS
4175 bi->bi_access_allowed = slap_access_always_allowed;
4176 #endif /* SLAP_OVERLAY_ACCESS */
4178 bi->bi_connection_init = 0;
4179 bi->bi_connection_destroy = 0;
4181 bi->bi_tool_entry_open = config_tool_entry_open;
4182 bi->bi_tool_entry_close = config_tool_entry_close;
4183 bi->bi_tool_entry_first = config_tool_entry_first;
4184 bi->bi_tool_entry_next = config_tool_entry_next;
4185 bi->bi_tool_entry_get = config_tool_entry_get;
4186 bi->bi_tool_entry_put = config_tool_entry_put;
4189 for (i=0; OidMacros[i].name; i++ ) {
4190 argv[1] = OidMacros[i].name;
4191 argv[2] = OidMacros[i].oid;
4192 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4195 bi->bi_cf_ocs = cf_ocs;
4197 i = config_register_schema( ct, cf_ocs );
4200 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4201 * basically, we don't care if it fails */
4202 i = slap_str2ad( "olcRootPW", &ad, &text );
4204 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4205 "warning, unable to get \"olcRootPW\" "
4206 "attribute description: %d: %s\n",
4209 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4210 ad->ad_type->sat_oid );
4213 /* set up the notable AttributeDescriptions */
4215 for (;ct->name;ct++) {
4216 if (strcmp(ct->name, ads[i].name)) continue;
4217 *ads[i].desc = ct->ad;
4219 if (!ads[i].name) break;