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, SlapReply *rs,
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 "MUST ( olcModulePath $ olcModuleLoad ) "
652 "MAY cn )", 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 value_add_one( &c->rvalue_vals, &mp->mp_path );
838 rc = c->rvalue_vals ? 0 : 1;
844 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
845 if ( !c->rvalue_vals ) rc = 1;
848 #ifdef SLAP_AUTH_REWRITE
850 if ( authz_rewrites ) {
851 struct berval bv, idx;
856 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
857 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
858 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
859 bv.bv_val = ch_malloc( bv.bv_len + 1 );
860 strcpy( bv.bv_val, idx.bv_val );
861 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
862 ber_bvarray_add( &c->rvalue_vals, &bv );
865 if ( !c->rvalue_vals ) rc = 1;
872 } else if ( c->op == LDAP_MOD_DELETE ) {
875 /* single-valued attrs, no-ops */
883 case CFG_SSTR_IF_MAX:
884 case CFG_SSTR_IF_MIN:
887 /* no-ops, requires slapd restart */
892 sprintf(c->log, "change requires slapd restart");
896 ch_free( passwd_salt );
901 ch_free( c->be->be_replogfile );
902 c->be->be_replogfile = NULL;
906 ch_free( logfileName );
913 if ( c->be == frontendDB )
916 end = frontendDB->be_acl;
917 acl_destroy( c->be->be_acl, end );
919 AccessControl **prev, *a;
921 for (i=0, prev = &c->be->be_acl; i < c->valx;
933 /* FIXME: there is no limits_free function */
935 /* FIXME: there is no ad_option_free function */
937 /* FIXME: there is no way to remove attributes added by
951 p = strchr(c->line,'(' /*')'*/);
955 if(!(c->bi = backend_info(c->argv[1]))) {
956 sprintf( c->msg, "<%s> failed init", c->argv[0] );
957 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
958 c->log, c->msg, c->argv[1] );
965 /* NOTE: config is always the first backend!
967 if ( !strcasecmp( c->argv[1], "config" )) {
968 c->be = LDAP_STAILQ_FIRST(&backendDB);
969 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
971 } else if(!(c->be = backend_db_init(c->argv[1]))) {
972 sprintf( c->msg, "<%s> failed init", c->argv[0] );
973 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
974 c->log, c->msg, c->argv[1] );
980 ldap_pvt_thread_set_concurrency(c->value_int);
984 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
985 connection_pool_max = c->value_int; /* save for reference */
989 if ( passwd_salt ) ch_free( passwd_salt );
990 passwd_salt = c->value_string;
991 lutil_salt_format(passwd_salt);
995 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1001 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1003 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1007 ch_free(c->value_string);
1008 if (slap_sasl_setpolicy( c->argv[1] )) {
1009 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1010 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1011 c->log, c->msg, c->argv[1] );
1017 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1021 #ifdef HAVE_CYRUS_SASL
1024 char *txt = slap_sasl_secprops( c->argv[1] );
1026 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1028 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1036 c->be->be_max_deref_depth = c->value_int;
1042 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1044 if (!cfn->c_om_head) cfn->c_om_head = om;
1045 cfn->c_om_tail = om;
1052 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1053 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1054 cfn->c_oc_tail = oc;
1061 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1062 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1063 cfn->c_cr_tail = cr;
1070 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1071 if (!cfn->c_at_head) cfn->c_at_head = at;
1072 cfn->c_at_tail = at;
1077 ad_define_option(NULL, NULL, 0);
1078 for(i = 1; i < c->argc; i++)
1079 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1084 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1088 if(SLAP_MONITOR(c->be)) {
1089 Debug(LDAP_DEBUG_ANY, "%s: "
1090 "\"replogfile\" should not be used "
1091 "inside monitor database\n",
1093 return(0); /* FIXME: should this be an error? */
1096 c->be->be_replogfile = c->value_string;
1100 if(read_root_dse_file(c->argv[1])) {
1101 sprintf( c->msg, "<%s> could not read file", c->argv[0] );
1102 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1103 c->log, c->msg, c->argv[1] );
1108 ber_str2bv( c->argv[1], 0, 1, &bv );
1109 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1115 if ( logfileName ) ch_free( logfileName );
1116 logfileName = c->value_string;
1117 logfile = fopen(logfileName, "w");
1118 if(logfile) lutil_debug_file(logfile);
1122 if(SLAP_NOLASTMODCMD(c->be)) {
1123 sprintf( c->msg, "<%s> not available for %s database",
1124 c->argv[0], c->be->bd_info->bi_type );
1125 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1126 c->log, c->msg, 0 );
1130 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1132 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1135 case CFG_SSTR_IF_MAX:
1136 if (c->value_int < index_substr_if_minlen) {
1137 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1138 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1139 c->log, c->msg, c->value_int );
1142 index_substr_if_maxlen = c->value_int;
1145 case CFG_SSTR_IF_MIN:
1146 if (c->value_int > index_substr_if_maxlen) {
1147 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1148 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1149 c->log, c->msg, c->value_int );
1152 index_substr_if_minlen = c->value_int;
1155 #ifdef SLAPD_MODULES
1157 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1159 /* Record this load on the current path */
1163 char *ptr = c->line + STRLENOF("moduleload");
1164 while (!isspace(*ptr)) ptr++;
1165 while (isspace(*ptr)) ptr++;
1166 ber_str2bv(ptr, 0, 1, &bv);
1167 if ( c->op == SLAP_CONFIG_ADD )
1171 ber_bvarray_add( &mp->mp_loads, &bv );
1176 if(module_path(c->argv[1])) return(1);
1177 /* Record which path was used with each module */
1181 if (!modpaths.mp_loads) {
1184 mp = ch_malloc( sizeof( ModPaths ));
1185 modlast->mp_next = mp;
1187 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1189 mp->mp_loads = NULL;
1192 if ( c->op == SLAP_CONFIG_ADD )
1201 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1203 slapi_plugins_used++;
1207 #ifdef SLAP_AUTH_REWRITE
1212 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1215 if ( c->argc > 1 ) {
1218 /* quote all args but the first */
1219 line = ldap_charray2str( c->argv, "\" \"" );
1220 ber_str2bv( line, 0, 0, &bv );
1221 s = strchr( bv.bv_val, '"' );
1222 assert( s != NULL );
1223 /* move the trailing quote of argv[0] to the end */
1224 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1225 bv.bv_val[ bv.bv_len - 1 ] = '"';
1228 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1231 ber_bvarray_add( &authz_rewrites, &bv );
1238 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1239 "%s: unknown CFG_TYPE %d"
1240 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1241 c->log, c->type, 0 );
1242 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1244 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1252 config_fname(ConfigArgs *c) {
1253 if(c->op == SLAP_CONFIG_EMIT) {
1255 ConfigFile *cf = c->private;
1256 value_add_one( &c->rvalue_vals, &cf->c_file );
1265 config_cfdir(ConfigArgs *c) {
1266 if(c->op == SLAP_CONFIG_EMIT) {
1267 if ( !BER_BVISEMPTY( &cfdir )) {
1268 value_add_one( &c->rvalue_vals, &cfdir );
1277 config_search_base(ConfigArgs *c) {
1280 if(c->op == SLAP_CONFIG_EMIT) {
1282 if (!BER_BVISEMPTY(&default_search_base)) {
1283 value_add_one(&c->rvalue_vals, &default_search_base);
1284 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1288 } else if( c->op == LDAP_MOD_DELETE ) {
1289 ch_free( default_search_base.bv_val );
1290 ch_free( default_search_nbase.bv_val );
1291 BER_BVZERO( &default_search_base );
1292 BER_BVZERO( &default_search_nbase );
1296 if(c->bi || c->be != frontendDB) {
1297 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1298 "prior to any backend or database definition\n",
1303 if(default_search_nbase.bv_len) {
1304 free(default_search_base.bv_val);
1305 free(default_search_nbase.bv_val);
1308 default_search_base = c->value_dn;
1309 default_search_nbase = c->value_ndn;
1314 config_passwd_hash(ConfigArgs *c) {
1316 if (c->op == SLAP_CONFIG_EMIT) {
1318 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1319 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1320 value_add_one(&c->rvalue_vals, &bv);
1323 } else if ( c->op == LDAP_MOD_DELETE ) {
1324 if ( c->valx < 0 ) {
1325 ldap_charray_free( default_passwd_hash );
1326 default_passwd_hash = NULL;
1329 ch_free( default_passwd_hash[i] );
1330 for (; default_passwd_hash[i]; i++ )
1331 default_passwd_hash[i] = default_passwd_hash[i+1];
1335 if(default_passwd_hash) {
1336 Debug(LDAP_DEBUG_ANY, "%s: "
1337 "already set default password_hash\n",
1341 for(i = 1; i < c->argc; i++) {
1342 if(!lutil_passwd_scheme(c->argv[i])) {
1343 sprintf( c->msg, "<%s> schema not available", c->argv[0] );
1344 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1345 c->log, c->msg, c->argv[i]);
1347 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1349 if(!default_passwd_hash) {
1350 sprintf( c->msg, "<%s> no valid hashes found", c->argv[0] );
1351 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1352 c->log, c->msg, 0 );
1360 config_schema_dn(ConfigArgs *c) {
1361 if ( c->op == SLAP_CONFIG_EMIT ) {
1363 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1364 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1365 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1369 } else if ( c->op == LDAP_MOD_DELETE ) {
1370 ch_free( c->be->be_schemadn.bv_val );
1371 ch_free( c->be->be_schemandn.bv_val );
1372 BER_BVZERO( &c->be->be_schemadn );
1373 BER_BVZERO( &c->be->be_schemandn );
1376 ch_free( c->be->be_schemadn.bv_val );
1377 ch_free( c->be->be_schemandn.bv_val );
1378 c->be->be_schemadn = c->value_dn;
1379 c->be->be_schemandn = c->value_ndn;
1384 config_sizelimit(ConfigArgs *c) {
1387 struct slap_limits_set *lim = &c->be->be_def_limit;
1388 if (c->op == SLAP_CONFIG_EMIT) {
1393 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1394 if ( !BER_BVISEMPTY( &bv ))
1395 value_add_one( &c->rvalue_vals, &bv );
1399 } else if ( c->op == LDAP_MOD_DELETE ) {
1400 /* Reset to defaults */
1401 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1402 lim->lms_s_hard = 0;
1403 lim->lms_s_unchecked = -1;
1405 lim->lms_s_pr_hide = 0;
1406 lim->lms_s_pr_total = 0;
1409 for(i = 1; i < c->argc; i++) {
1410 if(!strncasecmp(c->argv[i], "size", 4)) {
1411 rc = limits_parse_one(c->argv[i], lim);
1413 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1414 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1415 c->log, c->msg, c->argv[i]);
1419 if(!strcasecmp(c->argv[i], "unlimited")) {
1420 lim->lms_s_soft = -1;
1422 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1423 if(next == c->argv[i]) {
1424 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1425 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1426 c->log, c->msg, c->argv[i]);
1428 } else if(next[0] != '\0') {
1429 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1430 "trailing chars \"%s\" in \"sizelimit <limit>\" line"
1431 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1433 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1435 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1438 lim->lms_s_hard = 0;
1445 config_timelimit(ConfigArgs *c) {
1448 struct slap_limits_set *lim = &c->be->be_def_limit;
1449 if (c->op == SLAP_CONFIG_EMIT) {
1454 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1455 if ( !BER_BVISEMPTY( &bv ))
1456 value_add_one( &c->rvalue_vals, &bv );
1460 } else if ( c->op == LDAP_MOD_DELETE ) {
1461 /* Reset to defaults */
1462 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1463 lim->lms_t_hard = 0;
1466 for(i = 1; i < c->argc; i++) {
1467 if(!strncasecmp(c->argv[i], "time", 4)) {
1468 rc = limits_parse_one(c->argv[i], lim);
1470 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1471 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1472 c->log, c->msg, c->argv[i]);
1476 if(!strcasecmp(c->argv[i], "unlimited")) {
1477 lim->lms_t_soft = -1;
1479 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1480 if(next == c->argv[i]) {
1481 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1482 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1483 c->log, c->msg, c->argv[i]);
1485 } else if(next[0] != '\0') {
1486 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1487 "trailing chars \"%s\" in \"timelimit <limit>\" line"
1488 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1490 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1492 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1495 lim->lms_t_hard = 0;
1502 config_overlay(ConfigArgs *c) {
1504 if (c->op == SLAP_CONFIG_EMIT) {
1506 } else if ( c->op == LDAP_MOD_DELETE ) {
1509 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1511 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: (optional) %s overlay \"%s\" configuration failed"
1512 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1513 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1514 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1516 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1517 } else if(overlay_config(c->be, c->argv[1])) {
1520 /* Setup context for subsequent config directives.
1521 * The newly added overlay is at the head of the list.
1523 oi = (slap_overinfo *)c->be->bd_info;
1524 c->bi = &oi->oi_list->on_bi;
1529 config_suffix(ConfigArgs *c) {
1531 struct berval pdn, ndn;
1534 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1535 SLAP_CONFIG(c->be)) return 1;
1537 if (c->op == SLAP_CONFIG_EMIT) {
1538 if ( c->be->be_suffix == NULL
1539 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1543 value_add( &c->rvalue_vals, c->be->be_suffix );
1544 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1547 } else if ( c->op == LDAP_MOD_DELETE ) {
1548 if ( c->valx < 0 ) {
1549 ber_bvarray_free( c->be->be_suffix );
1550 ber_bvarray_free( c->be->be_nsuffix );
1551 c->be->be_suffix = NULL;
1552 c->be->be_nsuffix = NULL;
1555 ch_free( c->be->be_suffix[i].bv_val );
1556 ch_free( c->be->be_nsuffix[i].bv_val );
1557 for (; c->be->be_suffix[i].bv_val; i++) {
1558 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1559 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1564 #ifdef SLAPD_MONITOR_DN
1565 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1566 sprintf( c->msg, "<%s> DN is reserved for monitoring slapd",
1568 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1569 c->log, c->msg, SLAPD_MONITOR_DN);
1576 tbe = select_backend(&ndn, 0, 0);
1578 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1579 "%s: suffix already served by this backend!"
1580 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1582 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1584 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1588 sprintf( c->msg, "<%s> suffix already served by a preceding backend",
1590 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1591 c->log, c->msg, tbe->be_suffix[0].bv_val);
1595 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1596 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1597 "base provided \"%s\" (assuming okay)\n",
1598 c->log, default_search_base.bv_val, 0);
1600 ber_bvarray_add(&c->be->be_suffix, &pdn);
1601 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1606 config_rootdn(ConfigArgs *c) {
1607 if (c->op == SLAP_CONFIG_EMIT) {
1608 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1609 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1610 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1615 } else if ( c->op == LDAP_MOD_DELETE ) {
1616 ch_free( c->be->be_rootdn.bv_val );
1617 ch_free( c->be->be_rootndn.bv_val );
1618 BER_BVZERO( &c->be->be_rootdn );
1619 BER_BVZERO( &c->be->be_rootndn );
1622 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1623 ch_free( c->be->be_rootdn.bv_val );
1624 ch_free( c->be->be_rootndn.bv_val );
1626 c->be->be_rootdn = c->value_dn;
1627 c->be->be_rootndn = c->value_ndn;
1632 config_rootpw(ConfigArgs *c) {
1634 /* config_add_internal sets c->be = frontendDB. While the cn=config
1635 * rootpw is technically inside a backend, we expose it in the
1636 * global entry, and need to point to it properly here.
1638 if (c->be == frontendDB)
1639 c->be = LDAP_STAILQ_FIRST(&backendDB);
1641 if (c->op == SLAP_CONFIG_EMIT) {
1642 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1643 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1647 } else if ( c->op == LDAP_MOD_DELETE ) {
1648 ch_free( c->be->be_rootpw.bv_val );
1649 BER_BVZERO( &c->be->be_rootpw );
1653 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1655 sprintf( c->msg, "<%s> can only be set when rootdn is under suffix",
1657 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1661 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1662 ch_free( c->be->be_rootpw.bv_val );
1663 c->be->be_rootpw = c->value_bv;
1668 config_restrict(ConfigArgs *c) {
1669 slap_mask_t restrictops = 0;
1671 slap_verbmasks restrictable_ops[] = {
1672 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1673 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1674 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1675 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1676 { BER_BVC("modrdn"), 0 },
1677 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1678 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1679 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1680 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1681 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1682 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1683 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1684 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1685 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1686 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1690 if (c->op == SLAP_CONFIG_EMIT) {
1691 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1693 } else if ( c->op == LDAP_MOD_DELETE ) {
1695 c->be->be_restrictops = 0;
1697 restrictops = verb_to_mask( c->line, restrictable_ops );
1698 c->be->be_restrictops ^= restrictops;
1702 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1704 sprintf( c->msg, "<%s> unknown operation", c->argv[0] );
1705 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1706 c->log, c->msg, c->argv[i]);
1709 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1710 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1711 c->be->be_restrictops |= restrictops;
1716 config_allows(ConfigArgs *c) {
1717 slap_mask_t allows = 0;
1719 slap_verbmasks allowable_ops[] = {
1720 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1721 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1722 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1723 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1726 if (c->op == SLAP_CONFIG_EMIT) {
1727 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1728 } else if ( c->op == LDAP_MOD_DELETE ) {
1732 allows = verb_to_mask( c->line, allowable_ops );
1733 global_allows ^= allows;
1737 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1739 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1740 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1741 c->log, c->msg, c->argv[i]);
1744 global_allows |= allows;
1749 config_disallows(ConfigArgs *c) {
1750 slap_mask_t disallows = 0;
1752 slap_verbmasks disallowable_ops[] = {
1753 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1754 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1755 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1756 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1757 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1760 if (c->op == SLAP_CONFIG_EMIT) {
1761 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1762 } else if ( c->op == LDAP_MOD_DELETE ) {
1764 global_disallows = 0;
1766 disallows = verb_to_mask( c->line, disallowable_ops );
1767 global_disallows ^= disallows;
1771 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1773 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1774 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1775 c->log, c->msg, c->argv[i]);
1778 global_disallows |= disallows;
1783 config_requires(ConfigArgs *c) {
1784 slap_mask_t requires = 0;
1786 slap_verbmasks requires_ops[] = {
1787 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1788 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1789 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1790 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1791 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1794 if (c->op == SLAP_CONFIG_EMIT) {
1795 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1796 } else if ( c->op == LDAP_MOD_DELETE ) {
1798 c->be->be_requires = 0;
1800 requires = verb_to_mask( c->line, requires_ops );
1801 c->be->be_requires ^= requires;
1805 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1807 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1808 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1809 c->log, c->msg, c->argv[i]);
1812 c->be->be_requires = requires;
1817 config_loglevel(ConfigArgs *c) {
1820 slap_verbmasks loglevel_ops[] = {
1821 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1822 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1823 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1824 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1825 { BER_BVC("BER"), LDAP_DEBUG_BER },
1826 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1827 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1828 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1829 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1830 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1831 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1832 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1833 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1834 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1835 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
1836 { BER_BVC("Any"), -1 },
1840 if (c->op == SLAP_CONFIG_EMIT) {
1841 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1842 } else if ( c->op == LDAP_MOD_DELETE ) {
1846 int level = verb_to_mask( c->line, loglevel_ops );
1847 ldap_syslog ^= level;
1854 for( i=1; i < c->argc; i++ ) {
1857 if ( isdigit( c->argv[i][0] ) ) {
1858 level = strtol( c->argv[i], &next, 10 );
1859 if ( next == NULL || next[0] != '\0' ) {
1860 sprintf( c->msg, "<%s> unable to parse level", c->argv[0] );
1861 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1862 c->log, c->msg, c->argv[i]);
1866 int j = verb_to_mask(c->argv[i], loglevel_ops);
1867 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1868 sprintf( c->msg, "<%s> unknown level", c->argv[0] );
1869 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1870 c->log, c->msg, c->argv[i]);
1873 level = loglevel_ops[j].mask;
1875 ldap_syslog |= level;
1881 config_referral(ConfigArgs *c) {
1883 if (c->op == SLAP_CONFIG_EMIT) {
1884 if ( default_referral ) {
1885 value_add( &c->rvalue_vals, default_referral );
1890 } else if ( c->op == LDAP_MOD_DELETE ) {
1891 if ( c->valx < 0 ) {
1892 ber_bvarray_free( default_referral );
1893 default_referral = NULL;
1896 ch_free( default_referral[i].bv_val );
1897 for (; default_referral[i].bv_val; i++ )
1898 default_referral[i] = default_referral[i+1];
1902 if(validate_global_referral(c->argv[1])) {
1903 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
1904 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1905 c->log, c->msg, c->argv[1]);
1909 ber_str2bv(c->argv[1], 0, 0, &val);
1910 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
1918 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1919 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1920 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1921 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1922 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1923 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1924 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1925 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1926 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1931 config_security(ConfigArgs *c) {
1932 slap_ssf_set_t *set = &c->be->be_ssf_set;
1935 if (c->op == SLAP_CONFIG_EMIT) {
1941 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1942 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1945 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1946 bv.bv_len += sec_keys[i].key.bv_len;
1947 bv.bv_val = ch_malloc( bv.bv_len + 1);
1948 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1949 strcpy( next, numbuf );
1950 ber_bvarray_add( &c->rvalue_vals, &bv );
1955 for(i = 1; i < c->argc; i++) {
1956 slap_ssf_t *tgt = NULL;
1958 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1959 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1960 sec_keys[j].key.bv_len)) {
1961 src = c->argv[i] + sec_keys[j].key.bv_len;
1962 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1967 sprintf( c->msg, "<%s> unknown factor", c->argv[0] );
1968 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1969 c->log, c->msg, c->argv[i]);
1973 *tgt = strtol(src, &next, 10);
1974 if(next == NULL || next[0] != '\0' ) {
1975 sprintf( c->msg, "<%s> unable to parse factor", c->argv[0] );
1976 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1977 c->log, c->msg, c->argv[i]);
1985 anlist_unparse( AttributeName *an, char *ptr ) {
1988 for (; !BER_BVISNULL( &an->an_name ); an++) {
1989 if ( comma ) *ptr++ = ',';
1990 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1997 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2001 struct berval bc = {0};
2004 len = sprintf(numbuf, IFMT, i );
2006 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2007 if ( ri->ri_nsuffix ) {
2008 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2009 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2012 if ( ri->ri_attrs ) {
2013 len += STRLENOF("attr");
2014 if ( ri->ri_exclude ) len++;
2015 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2016 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2019 bindconf_unparse( &ri->ri_bindconf, &bc );
2022 bv->bv_val = ch_malloc(len + 1);
2025 ptr = lutil_strcopy( bv->bv_val, numbuf );
2026 ptr = lutil_strcopy( ptr, "uri=" );
2027 ptr = lutil_strcopy( ptr, ri->ri_uri );
2029 if ( ri->ri_nsuffix ) {
2030 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2031 ptr = lutil_strcopy( ptr, " suffix=\"" );
2032 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2036 if ( ri->ri_attrs ) {
2037 ptr = lutil_strcopy( ptr, "attr" );
2038 if ( ri->ri_exclude ) *ptr++ = '!';
2040 ptr = anlist_unparse( ri->ri_attrs, ptr );
2043 strcpy( ptr, bc.bv_val );
2044 ch_free( bc.bv_val );
2049 config_replica(ConfigArgs *c) {
2050 int i, nr = -1, len;
2051 char *replicahost, *replicauri;
2054 if (c->op == SLAP_CONFIG_EMIT) {
2055 if (c->be->be_replica) {
2057 for (i=0;c->be->be_replica[i]; i++) {
2058 replica_unparse( c->be->be_replica[i], i, &bv );
2059 ber_bvarray_add( &c->rvalue_vals, &bv );
2064 } else if ( c->op == LDAP_MOD_DELETE ) {
2065 /* FIXME: there is no replica_free function */
2066 if ( c->valx < 0 ) {
2070 if(SLAP_MONITOR(c->be)) {
2071 Debug(LDAP_DEBUG_ANY, "%s: "
2072 "\"replica\" should not be used inside monitor database\n",
2074 return(0); /* FIXME: should this be an error? */
2077 for(i = 1; i < c->argc; i++) {
2078 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2079 replicahost = c->argv[i] + STRLENOF("host=");
2080 len = strlen( replicahost );
2081 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2082 sprintf( replicauri, "ldap://%s", replicahost );
2083 replicahost = replicauri + STRLENOF( "ldap://");
2084 nr = add_replica_info(c->be, replicauri, replicahost);
2086 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2087 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2088 sprintf( c->msg, "<%s> invalid uri", c->argv[0] );
2089 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2092 if(!ludp->lud_host) {
2093 sprintf( c->msg, "<%s> invalid uri - missing hostname",
2095 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2098 ldap_free_urldesc(ludp);
2099 replicauri = c->argv[i] + STRLENOF("uri=");
2100 replicauri = ch_strdup( replicauri );
2101 replicahost = strchr( replicauri, '/' );
2103 nr = add_replica_info(c->be, replicauri, replicahost);
2108 sprintf( c->msg, "<%s> missing host or uri", c->argv[0] );
2109 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2111 } else if(nr == -1) {
2112 sprintf( c->msg, "<%s> unable to add replica", c->argv[0] );
2113 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2116 for(i = 1; i < c->argc; i++) {
2117 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2118 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2120 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2121 "suffix \"%s\" in \"replica\" line is not valid for backend"
2122 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2123 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2124 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2126 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2129 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2130 "unable to normalize suffix in \"replica\" line"
2131 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2133 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2135 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2139 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2141 char *arg = c->argv[i] + STRLENOF("attr");
2149 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2150 sprintf( c->msg, "<%s> unknown attribute", c->argv[0] );
2151 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2152 c->log, c->msg, arg + 1);
2155 } else if ( bindconf_parse( c->argv[i],
2156 &c->be->be_replica[nr]->ri_bindconf ) ) {
2165 config_updatedn(ConfigArgs *c) {
2168 if (c->op == SLAP_CONFIG_EMIT) {
2169 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2170 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2171 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2175 } else if ( c->op == LDAP_MOD_DELETE ) {
2176 ch_free( c->be->be_update_ndn.bv_val );
2177 c->be->be_update_ndn.bv_val = NULL;
2178 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2181 if(SLAP_SHADOW(c->be)) {
2182 sprintf( c->msg, "<%s> database already shadowed", c->argv[0] );
2183 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2188 ber_str2bv(c->argv[1], 0, 0, &dn);
2190 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2192 if(rc != LDAP_SUCCESS) {
2193 sprintf( c->msg, "<%s> invalid DN %d (%s)", c->argv[0],
2194 rc, ldap_err2string(rc));
2195 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2196 c->log, c->msg, 0 );
2200 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2205 config_updateref(ConfigArgs *c) {
2207 if (c->op == SLAP_CONFIG_EMIT) {
2208 if ( c->be->be_update_refs ) {
2209 value_add( &c->rvalue_vals, c->be->be_update_refs );
2214 } else if ( c->op == LDAP_MOD_DELETE ) {
2215 if ( c->valx < 0 ) {
2216 ber_bvarray_free( c->be->be_update_refs );
2217 c->be->be_update_refs = NULL;
2220 ch_free( c->be->be_update_refs[i].bv_val );
2221 for (; c->be->be_update_refs[i].bv_val; i++)
2222 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2226 if(!SLAP_SHADOW(c->be)) {
2227 sprintf( c->msg, "<%s> must appear after syncrepl or updatedn",
2229 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2234 if(validate_global_referral(c->argv[1])) {
2235 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2236 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2237 c->log, c->msg, c->argv[1]);
2240 ber_str2bv(c->argv[1], 0, 0, &val);
2241 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2246 config_include(ConfigArgs *c) {
2247 unsigned long savelineno = c->lineno;
2250 ConfigFile *cfsave = cfn;
2251 ConfigFile *cf2 = NULL;
2252 if (c->op == SLAP_CONFIG_EMIT) {
2254 ConfigFile *cf = c->private;
2255 value_add_one( &c->rvalue_vals, &cf->c_file );
2259 } else if ( c->op == LDAP_MOD_DELETE ) {
2261 cf = ch_calloc( 1, sizeof(ConfigFile));
2262 if ( cfn->c_kids ) {
2263 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2269 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2270 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2271 c->lineno = savelineno - 1;
2274 if ( cf2 ) cf2->c_sibs = NULL;
2275 else cfn->c_kids = NULL;
2276 ch_free( cf->c_file.bv_val );
2286 config_tls_option(ConfigArgs *c) {
2289 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2290 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2291 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2292 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2293 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2294 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2295 default: Debug(LDAP_DEBUG_ANY, "%s: "
2296 "unknown tls_option <0x%x>\n",
2297 c->log, c->type, 0);
2299 if (c->op == SLAP_CONFIG_EMIT) {
2300 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2301 } else if ( c->op == LDAP_MOD_DELETE ) {
2302 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2304 ch_free(c->value_string);
2305 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2308 /* FIXME: this ought to be provided by libldap */
2310 config_tls_config(ConfigArgs *c) {
2312 slap_verbmasks crlkeys[] = {
2313 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2314 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2315 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2318 slap_verbmasks vfykeys[] = {
2319 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2320 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2321 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2322 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2326 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2327 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2329 Debug(LDAP_DEBUG_ANY, "%s: "
2330 "unknown tls_option <0x%x>\n",
2331 c->log, c->type, 0);
2333 if (c->op == SLAP_CONFIG_EMIT) {
2334 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2335 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2336 if (keys[i].mask == c->value_int) {
2337 c->value_string = ch_strdup( keys[i].word.bv_val );
2342 } else if ( c->op == LDAP_MOD_DELETE ) {
2344 return ldap_pvt_tls_set_option( NULL, flag, &i );
2346 ch_free( c->value_string );
2347 if(isdigit((unsigned char)c->argv[1][0])) {
2348 i = atoi(c->argv[1]);
2349 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2351 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2356 static CfEntryInfo *
2357 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2367 if ( dn_match( &root->ce_entry->e_nname, dn ))
2370 c = dn->bv_val+dn->bv_len;
2371 for (;*c != ',';c--);
2375 for (--c;c>dn->bv_val && *c != ',';c--);
2379 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2381 root = root->ce_kids;
2383 for (;root;root=root->ce_sibs) {
2384 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2385 if ( cdn.bv_val == dn->bv_val ) {
2396 config_ldif_resp( Operation *op, SlapReply *rs )
2398 if ( rs->sr_type == REP_SEARCH ) {
2399 CfBackInfo *cfb = op->o_callback->sc_private;
2401 cfb->cb_got_ldif = 1;
2402 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL );
2407 /* Configure and read the underlying back-ldif store */
2409 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
2410 CfBackInfo *cfb = be->be_private;
2415 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2416 Connection conn = {0};
2417 char opbuf[OPERATION_BUFFER_SIZE];
2419 SlapReply rs = {REP_RESULT};
2420 Filter filter = { LDAP_FILTER_PRESENT };
2421 struct berval filterstr = BER_BVC("(objectclass=*)");
2424 /* Is the config directory available? */
2425 if ( stat( dir, &st ) < 0 ) {
2426 /* No, so don't bother using the backing store.
2427 * All changes will be in-memory only.
2432 cfb->cb_db.bd_info = backend_info( "ldif" );
2433 if ( !cfb->cb_db.bd_info )
2434 return 0; /* FIXME: eventually this will be a fatal error */
2436 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2438 /* Mark that back-ldif type is in use */
2439 cfb->cb_db.bd_info->bi_nDB++;
2441 cfb->cb_db.be_suffix = be->be_suffix;
2442 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2443 cfb->cb_db.be_rootdn = be->be_rootdn;
2444 cfb->cb_db.be_rootndn = be->be_rootndn;
2446 ber_str2bv( dir, 0, 1, &cfdir );
2451 argv[0] = "directory";
2452 argv[1] = (char *)dir;
2456 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
2460 if ( config_add_vals( ct, &c ))
2463 if ( backend_startup_one( &cfb->cb_db ))
2467 op = (Operation *)opbuf;
2468 connection_fake_init( &conn, op, cfb );
2470 filter.f_desc = slap_schema.si_ad_objectClass;
2472 op->o_tag = LDAP_REQ_SEARCH;
2474 op->ors_filter = &filter;
2475 op->ors_filterstr = filterstr;
2476 op->ors_scope = LDAP_SCOPE_SUBTREE;
2478 op->o_dn = be->be_rootdn;
2479 op->o_ndn = be->be_rootndn;
2481 op->o_req_dn = be->be_suffix[0];
2482 op->o_req_ndn = be->be_nsuffix[0];
2484 op->ors_tlimit = SLAP_NO_LIMIT;
2485 op->ors_slimit = SLAP_NO_LIMIT;
2487 op->ors_attrs = slap_anlist_all_attributes;
2488 op->ors_attrsonly = 0;
2490 op->o_callback = &cb;
2491 cb.sc_private = cfb;
2493 op->o_bd = &cfb->cb_db;
2494 rc = op->o_bd->be_search( op, &rs );
2497 cfb->cb_use_ldif = 1;
2503 CfOc_cmp( const void *c1, const void *c2 ) {
2504 const ConfigOCs *co1 = c1;
2505 const ConfigOCs *co2 = c2;
2507 return ber_bvcmp( co1->co_name, co2->co_name );
2511 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2514 i = init_config_attrs( ct );
2517 /* set up the objectclasses */
2518 i = init_config_ocs( ocs );
2521 for (i=0; ocs[i].co_def; i++) {
2522 if ( ocs[i].co_oc ) {
2523 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
2524 if ( !ocs[i].co_table )
2525 ocs[i].co_table = ct;
2526 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
2533 read_config(const char *fname, const char *dir) {
2536 const char *cfdir, *cfname;
2539 /* Setup the config backend */
2540 be = backend_db_init( "config" );
2544 cfb = be->be_private;
2546 /* If no .conf, or a dir was specified, setup the dir */
2547 if ( !fname || dir ) {
2549 /* If explicitly given, check for existence */
2552 if ( stat( dir, &st ) < 0 ) {
2553 Debug( LDAP_DEBUG_ANY,
2554 "invalid config directory %s, error %d\n",
2560 cfdir = SLAPD_DEFAULT_CONFIGDIR;
2562 /* if fname is defaulted, try reading .d */
2563 rc = config_setup_ldif( be, cfdir, !fname );
2565 /* It's OK if the base object doesn't exist yet */
2566 if ( rc && rc != LDAP_NO_SUCH_OBJECT )
2569 /* If we read the config from back-ldif, nothing to do here */
2570 if ( cfb->cb_got_ldif ) {
2579 cfname = SLAPD_DEFAULT_CONFIGFILE;
2581 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
2584 ber_str2bv( cfname, 0, 1, &cf_prv.c_file );
2586 /* If we got this far and failed, it may be a serious problem. In server
2587 * mode, we should never come to this. However, it may be alright if we're
2588 * using slapadd to create the conf dir.
2591 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
2593 /* If a config file was explicitly given, fail */
2597 /* Seems to be slapadd with a config dir, let it continue */
2598 if ( cfb->cb_use_ldif ) {
2600 cfb->cb_got_ldif = 1;
2606 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2607 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
2608 &frontendDB->be_schemadn );
2609 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2610 if ( rc != LDAP_SUCCESS ) {
2611 Debug(LDAP_DEBUG_ANY, "read_config: "
2612 "unable to normalize default schema DN \"%s\"\n",
2613 frontendDB->be_schemadn.bv_val, 0, 0 );
2614 /* must not happen */
2622 config_back_bind( Operation *op, SlapReply *rs )
2624 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2625 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2626 /* frontend sends result */
2627 return LDAP_SUCCESS;
2630 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2631 send_ldap_result( op, rs );
2637 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2641 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2643 rs->sr_attrs = op->ors_attrs;
2644 rs->sr_entry = ce->ce_entry;
2645 rc = send_search_entry( op, rs );
2647 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2648 if ( ce->ce_kids ) {
2649 rc = config_send( op, rs, ce->ce_kids, 1 );
2650 if ( rc ) return rc;
2653 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2654 rc = config_send( op, rs, ce, 0 );
2662 static ConfigTable *
2663 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
2667 for (j=0; j<nocs; j++) {
2668 for (i=0; colst[j]->co_table[i].name; i++)
2669 if ( colst[j]->co_table[i].ad == ad )
2670 return &colst[j]->co_table[i];
2675 /* Sort the attributes of the entry according to the order defined
2676 * in the objectclass, with required attributes occurring before
2677 * allowed attributes. For any attributes with sequencing dependencies
2678 * (e.g., rootDN must be defined after suffix) the objectclass must
2679 * list the attributes in the desired sequence.
2682 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
2684 Attribute *a, *head = NULL, *tail = NULL, **prev;
2687 for (i=0; i<nocs; i++) {
2688 if ( colst[i]->co_oc->soc_required ) {
2689 AttributeType **at = colst[i]->co_oc->soc_required;
2690 for (j=0; at[j]; j++) {
2691 for (a=e->e_attrs, prev=&e->e_attrs; a;
2692 prev = &(*prev)->a_next, a=a->a_next) {
2693 if ( a->a_desc == at[j]->sat_ad ) {
2707 if ( colst[i]->co_oc->soc_allowed ) {
2708 AttributeType **at = colst[i]->co_oc->soc_allowed;
2709 for (j=0; at[j]; j++) {
2710 for (a=e->e_attrs, prev=&e->e_attrs; a;
2711 prev = &(*prev)->a_next, a=a->a_next) {
2712 if ( a->a_desc == at[j]->sat_ad ) {
2728 tail->a_next = e->e_attrs;
2734 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2736 Attribute *a = NULL;
2737 AttributeDescription *ad;
2740 int i, rc = 0, sort = 0;
2747 Modifications *ml = ptr;
2749 vals = ml->sml_values;
2752 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2754 rc = ordered_value_sort( a, 1 );
2758 for ( i=0; vals[i].bv_val; i++ ) {
2759 ca->line = vals[i].bv_val;
2761 char *idx = strchr( ca->line, '}' );
2762 if ( idx ) ca->line = idx+1;
2764 rc = config_parse_vals( ct, ca, i );
2772 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2773 SlapReply *rs, int *renum )
2776 int index = -1, gotindex = 0, nsibs;
2777 int renumber = 0, tailindex = 0;
2781 if ( renum ) *renum = 0;
2783 /* These entries don't get indexed/renumbered */
2784 if ( ce_type == Cft_Global ) return 0;
2785 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2787 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2790 /* See if the rdn has an index already */
2791 dnRdn( &e->e_name, &rdn );
2792 ptr1 = strchr( e->e_name.bv_val, '{' );
2793 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2794 ptr2 = strchr( ptr1, '}' );
2795 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2796 return LDAP_NAMING_VIOLATION;
2797 if ( ptr2-ptr1 == 1)
2798 return LDAP_NAMING_VIOLATION;
2800 index = atoi(ptr1+1);
2802 return LDAP_NAMING_VIOLATION;
2805 /* count related kids */
2806 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2807 if ( ce->ce_type == ce_type ) nsibs++;
2810 if ( index != nsibs ) {
2812 if ( index < nsibs ) {
2813 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2814 /* Siblings need to be renumbered */
2819 struct berval ival, newrdn, nnewrdn;
2820 struct berval rtype, rval;
2822 AttributeDescription *ad = NULL;
2826 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2827 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2828 rtype.bv_val = rdn.bv_val;
2829 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2832 slap_bv2ad( &rtype, &ad, &text );
2833 a = attr_find( e->e_attrs, ad );
2834 if (!a ) return LDAP_NAMING_VIOLATION;
2837 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2839 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2840 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2843 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2844 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2851 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
2853 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
2856 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2857 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
2861 /* Do the equivalent of ModRDN */
2862 /* Replace DN / NDN */
2863 newrdn.bv_len = ptr1 - newrdn.bv_val;
2864 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
2865 free( e->e_name.bv_val );
2866 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
2868 free( e->e_nname.bv_val );
2869 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
2873 free( a->a_vals[0].bv_val );
2874 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
2875 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
2876 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
2877 strcpy( a->a_vals[0].bv_val, ptr1 );
2879 if ( a->a_nvals != a->a_vals ) {
2880 free( a->a_nvals[0].bv_val );
2881 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
2882 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
2883 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
2884 strcpy( a->a_nvals[0].bv_val, ptr1 );
2886 free( nnewrdn.bv_val );
2887 free( newrdn.bv_val );
2890 if ( renum ) *renum = renumber;
2895 count_ocs( Attribute *oc_at, int *nocs )
2898 ConfigOCs co, *coptr, **colst;
2900 /* count the objectclasses */
2901 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2903 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
2905 for ( i=0, j=0; i<n; i++) {
2906 co.co_name = &oc_at->a_nvals[i];
2907 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
2909 /* ignore non-config objectclasses. probably should be
2910 * an error, general data doesn't belong here.
2912 if ( !coptr ) continue;
2914 /* Ignore the root objectclass, it has no implementation.
2916 if ( coptr->co_type == Cft_Abstract ) continue;
2924 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2926 if ( p->ce_type != Cft_Global && p->ce_type != Cft_Include )
2927 return LDAP_CONSTRAINT_VIOLATION;
2929 /* If we're reading from a configdir, don't parse this entry */
2931 return LDAP_COMPARE_TRUE;
2933 if ( p->ce_type == Cft_Global )
2936 cfn = p->ce_private;
2938 return LDAP_SUCCESS;
2942 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
2946 /* This entry is hardcoded, don't re-parse it */
2947 if ( p->ce_type == Cft_Global ) {
2950 return LDAP_COMPARE_TRUE;
2952 if ( p->ce_type != Cft_Schema )
2953 return LDAP_CONSTRAINT_VIOLATION;
2955 cfn = ch_calloc( 1, sizeof(ConfigFile) );
2957 cfo = p->ce_private;
2958 cfn->c_sibs = cfo->c_kids;
2960 return LDAP_SUCCESS;
2964 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
2966 if ( p->ce_type != Cft_Global )
2967 return LDAP_CONSTRAINT_VIOLATION;
2968 ca->be = frontendDB; /* just to get past check_vals */
2969 return LDAP_SUCCESS;
2973 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
2975 if ( p->ce_type != Cft_Global )
2976 return LDAP_CONSTRAINT_VIOLATION;
2977 return LDAP_SUCCESS;
2981 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
2983 if ( p->ce_type != Cft_Global )
2984 return LDAP_CONSTRAINT_VIOLATION;
2985 return LDAP_SUCCESS;
2989 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
2991 if ( p->ce_type != Cft_Database )
2992 return LDAP_CONSTRAINT_VIOLATION;
2994 return LDAP_SUCCESS;
2997 /* Parse an LDAP entry into config directives */
2999 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
3001 CfEntryInfo *ce, *last;
3003 Attribute *a, *oc_at;
3004 int i, j, nocs, rc = 0;
3005 ConfigArgs ca = {0};
3010 /* Make sure parent exists and entry does not */
3011 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3013 return LDAP_ALREADY_EXISTS;
3015 dnParent( &e->e_nname, &pdn );
3017 /* If last is NULL, the new entry is the root/suffix entry,
3018 * otherwise last should be the parent.
3020 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3022 rs->sr_matched = last->ce_entry->e_name.bv_val;
3023 return LDAP_NO_SUCH_OBJECT;
3026 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3027 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3029 /* Fake the coordinates based on whether we're part of an
3030 * LDAP Add or if reading the config dir
3036 ca.fname = cfdir.bv_val;
3040 colst = count_ocs( oc_at, &nocs );
3042 /* Only the root can be Cft_Global, everything else must
3043 * have a parent. Only limited nesting arrangements are allowed.
3045 rc = LDAP_CONSTRAINT_VIOLATION;
3046 if ( colst[0]->co_type == Cft_Global && !last ) {
3049 ca.be = frontendDB; /* just to get past check_vals */
3053 /* Check whether the Add is allowed by its parent, and do
3054 * any necessary arg setup
3057 for ( i=0; i<nocs; i++ ) {
3058 if ( colst[i]->co_ldadd &&
3059 ( rc = colst[i]->co_ldadd( last, e, &ca ))
3060 != LDAP_CONSTRAINT_VIOLATION ) {
3066 /* Add the entry but don't parse it, we already have its contents */
3067 if ( rc == LDAP_COMPARE_TRUE ) {
3072 if ( rc != LDAP_SUCCESS )
3075 /* Parse all the values and check for simple syntax errors before
3076 * performing any set actions.
3078 * If doing an LDAPadd, check for indexed names and any necessary
3079 * renaming/renumbering. Entries that don't need indexed names are
3080 * ignored. Entries that need an indexed name and arrive without one
3081 * are assigned to the end. Entries that arrive with an index may
3082 * cause the following entries to be renumbered/bumped down.
3084 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3085 * don't allow Adding an entry with an index that's already in use.
3086 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3088 * These entries can have auto-assigned indexes (appended to the end)
3089 * but only the other types support auto-renumbering of siblings.
3091 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3095 init_config_argv( &ca );
3097 /* Make sure we process attrs in the required order */
3098 sort_attrs( e, colst, nocs );
3100 for ( a=e->e_attrs; a; a=a->a_next ) {
3101 if ( a == oc_at ) continue;
3102 ct = config_find_table( colst, nocs, a->a_desc );
3103 if ( !ct ) continue; /* user data? */
3104 rc = check_vals( ct, &ca, a, 1 );
3105 if ( rc ) goto leave;
3108 /* Basic syntax checks are OK. Do the actual settings. */
3109 for ( a=e->e_attrs; a; a=a->a_next ) {
3110 if ( a == oc_at ) continue;
3111 ct = config_find_table( colst, nocs, a->a_desc );
3112 if ( !ct ) continue; /* user data? */
3113 for (i=0; a->a_vals[i].bv_val; i++) {
3114 ca.line = a->a_vals[i].bv_val;
3115 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3116 ptr = strchr( ca.line, '}' );
3117 if ( ptr ) ca.line = ptr+1;
3120 rc = config_parse_add( ct, &ca );
3128 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3129 ce->ce_parent = last;
3130 ce->ce_entry = entry_dup( e );
3131 ce->ce_entry->e_private = ce;
3132 ce->ce_type = colst[0]->co_type;
3135 ce->ce_private = ca.private;
3138 } else if ( last->ce_kids ) {
3141 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3150 if ( colst ) ch_free( colst );
3154 /* Parse an LDAP entry into config directives, then store in underlying
3158 config_back_add( Operation *op, SlapReply *rs )
3161 CfEntryInfo *ce, *last;
3164 if ( !be_isroot( op ) ) {
3165 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3169 cfb = (CfBackInfo *)op->o_bd->be_private;
3171 ldap_pvt_thread_pool_pause( &connection_pool );
3174 * 1) check for existence of entry
3175 * 2) check for sibling renumbering
3176 * 3) perform internal add
3177 * 4) store entry in underlying database
3178 * 5) perform any necessary renumbering
3180 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3181 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3182 BackendDB *be = op->o_bd;
3183 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3184 op->o_bd = &cfb->cb_db;
3185 sc.sc_next = op->o_callback;
3186 op->o_callback = ≻
3187 op->o_bd->be_add( op, rs );
3189 op->o_callback = sc.sc_next;
3194 ldap_pvt_thread_pool_resume( &connection_pool );
3197 send_ldap_result( op, rs );
3201 typedef struct delrec {
3202 struct delrec *next;
3208 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3211 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3212 int rc = LDAP_UNWILLING_TO_PERFORM;
3214 Entry *e = ce->ce_entry;
3215 Attribute *save_attrs = e->e_attrs, *oc_at;
3220 delrec *dels = NULL, *deltail = NULL;
3222 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3223 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3225 colst = count_ocs( oc_at, &nocs );
3227 e->e_attrs = attrs_dup( e->e_attrs );
3229 init_config_argv( ca );
3232 ca->private = ce->ce_private;
3234 strcpy( ca->log, "back-config" );
3236 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3237 ct = config_find_table( colst, nocs, ml->sml_desc );
3238 switch (ml->sml_op) {
3239 case LDAP_MOD_DELETE:
3240 case LDAP_MOD_REPLACE: {
3241 BerVarray vals = NULL, nvals;
3243 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3245 snprintf( ca->msg, sizeof(ca->msg),
3246 "<%s> cannot be deleted" );
3247 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3248 ml->sml_desc->ad_cname.bv_val );
3251 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3252 vals = ml->sml_values;
3253 nvals = ml->sml_nvalues;
3254 ml->sml_values = NULL;
3255 ml->sml_nvalues = NULL;
3257 /* If we're deleting by values, remember the indexes of the
3258 * values we deleted.
3260 if ( ct && ml->sml_values ) {
3262 for (i=0; ml->sml_values[i].bv_val; i++);
3263 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
3274 rc = modify_delete_vindex(e, &ml->sml_mod,
3275 get_permissiveModify(op),
3276 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3277 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3278 ml->sml_values = vals;
3279 ml->sml_nvalues = nvals;
3284 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3287 case SLAP_MOD_SOFTADD: {
3288 int mop = ml->sml_op;
3290 ml->sml_op = LDAP_MOD_ADD;
3292 if ( ct->arg_type & ARG_NO_INSERT ) {
3293 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3295 for (i = 0; a->a_vals[i].bv_val; i++ );
3299 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3300 if ( ml->sml_values[i].bv_val[0] == '{' &&
3302 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3305 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3306 ml->sml_desc->ad_cname.bv_val );
3310 rc = check_vals( ct, ca, ml, 0 );
3314 rc = modify_add_values(e, &ml->sml_mod,
3315 get_permissiveModify(op),
3316 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3318 /* If value already exists, show success here
3319 * and ignore this operation down below.
3321 if ( mop == SLAP_MOD_SOFTADD ) {
3322 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3332 case LDAP_MOD_INCREMENT: /* FIXME */
3337 if(rc != LDAP_SUCCESS) break;
3340 if(rc == LDAP_SUCCESS) {
3341 /* check that the entry still obeys the schema */
3342 rc = entry_schema_check(op->o_bd, e, NULL, 0,
3343 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3345 if ( rc == LDAP_SUCCESS ) {
3346 /* Basic syntax checks are OK. Do the actual settings. */
3347 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3348 ct = config_find_table( colst, nocs, ml->sml_desc );
3349 if ( !ct ) continue;
3351 switch (ml->sml_op) {
3352 case LDAP_MOD_DELETE:
3353 case LDAP_MOD_REPLACE: {
3354 BerVarray vals = NULL, nvals;
3358 a = attr_find( e->e_attrs, ml->sml_desc );
3360 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3361 vals = ml->sml_values;
3362 nvals = ml->sml_nvalues;
3363 ml->sml_values = NULL;
3364 ml->sml_nvalues = NULL;
3367 if ( ml->sml_values )
3370 /* If we didn't delete the whole attribute */
3371 if ( ml->sml_values && a ) {
3372 struct berval *mvals;
3375 if ( ml->sml_nvalues )
3376 mvals = ml->sml_nvalues;
3378 mvals = ml->sml_values;
3380 /* use the indexes we saved up above */
3381 for (i=0; i < d->nidx; i++) {
3382 struct berval bv = *mvals++;
3383 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3384 bv.bv_val[0] == '{' ) {
3385 ptr = strchr( bv.bv_val, '}' ) + 1;
3386 bv.bv_len -= ptr - bv.bv_val;
3389 ca->line = bv.bv_val;
3390 ca->valx = d->idx[i];
3391 rc = config_del_vals( ct, ca );
3392 if ( rc != LDAP_SUCCESS ) break;
3393 for (j=i+1; j < d->nidx; j++)
3394 if ( d->idx[j] >d->idx[i] )
3400 rc = config_del_vals( ct, ca );
3401 if ( rc ) rc = LDAP_OTHER;
3403 if ( ml->sml_values ) {
3407 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3408 ml->sml_values = vals;
3409 ml->sml_nvalues = nvals;
3411 if ( !vals || rc != LDAP_SUCCESS )
3414 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3417 for (i=0; ml->sml_values[i].bv_val; i++) {
3418 ca->line = ml->sml_values[i].bv_val;
3420 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3421 ca->line[0] == '{' ) {
3422 ptr = strchr( ca->line, '}' );
3424 ca->valx = strtol( ca->line+1, NULL, 0 );
3428 rc = config_parse_add( ct, ca );
3443 if ( rc == LDAP_SUCCESS ) {
3444 attrs_free( save_attrs );
3446 attrs_free( e->e_attrs );
3447 e->e_attrs = save_attrs;
3449 ch_free( ca->argv );
3450 if ( colst ) ch_free( colst );
3456 config_back_modify( Operation *op, SlapReply *rs )
3459 CfEntryInfo *ce, *last;
3461 ConfigArgs ca = {0};
3464 AttributeDescription *rad = NULL;
3466 if ( !be_isroot( op ) ) {
3467 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3471 cfb = (CfBackInfo *)op->o_bd->be_private;
3473 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3476 rs->sr_matched = last->ce_entry->e_name.bv_val;
3477 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3481 /* Get type of RDN */
3482 rdn = ce->ce_entry->e_nname;
3483 ptr = strchr( rdn.bv_val, '=' );
3484 rdn.bv_len = ptr - rdn.bv_val;
3485 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3487 /* Some basic validation... */
3488 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3489 /* Don't allow Modify of RDN; must use ModRdn for that. */
3490 if ( ml->sml_desc == rad ) {
3491 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3492 rs->sr_text = "Use modrdn to change the entry name";
3497 ldap_pvt_thread_pool_pause( &connection_pool );
3500 * 1) perform the Modify on the cached Entry.
3501 * 2) verify that the Entry still satisfies the schema.
3502 * 3) perform the individual config operations.
3503 * 4) store Modified entry in underlying LDIF backend.
3505 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3507 rs->sr_text = ca.msg;
3508 } else if ( cfb->cb_use_ldif ) {
3509 BackendDB *be = op->o_bd;
3510 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3511 op->o_bd = &cfb->cb_db;
3512 sc.sc_next = op->o_callback;
3513 op->o_callback = ≻
3514 op->o_bd->be_modify( op, rs );
3516 op->o_callback = sc.sc_next;
3519 ldap_pvt_thread_pool_resume( &connection_pool );
3521 send_ldap_result( op, rs );
3526 config_back_modrdn( Operation *op, SlapReply *rs )
3529 CfEntryInfo *ce, *last;
3531 if ( !be_isroot( op ) ) {
3532 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3536 cfb = (CfBackInfo *)op->o_bd->be_private;
3538 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3541 rs->sr_matched = last->ce_entry->e_name.bv_val;
3542 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3546 /* We don't allow moving objects to new parents.
3547 * Generally we only allow reordering a set of ordered entries.
3549 if ( op->orr_newSup ) {
3550 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3553 ldap_pvt_thread_pool_pause( &connection_pool );
3555 ldap_pvt_thread_pool_resume( &connection_pool );
3557 send_ldap_result( op, rs );
3562 config_back_search( Operation *op, SlapReply *rs )
3565 CfEntryInfo *ce, *last;
3568 if ( !be_isroot( op ) ) {
3569 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3573 cfb = (CfBackInfo *)op->o_bd->be_private;
3575 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3578 rs->sr_matched = last->ce_entry->e_name.bv_val;
3579 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3582 switch ( op->ors_scope ) {
3583 case LDAP_SCOPE_BASE:
3584 case LDAP_SCOPE_SUBTREE:
3585 config_send( op, rs, ce, 0 );
3588 case LDAP_SCOPE_ONELEVEL:
3589 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3590 config_send( op, rs, ce, 1 );
3595 rs->sr_err = LDAP_SUCCESS;
3597 send_ldap_result( op, rs );
3602 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
3603 ConfigTable *ct, ConfigArgs *c )
3607 for (; at && *at; at++) {
3608 /* Skip the naming attr */
3609 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3611 for (i=0;ct[i].name;i++) {
3612 if (ct[i].ad == (*at)->sat_ad) {
3613 rc = config_get_vals(&ct[i], c);
3614 if (rc == LDAP_SUCCESS) {
3615 if ( c->rvalue_nvals )
3616 attr_merge(e, ct[i].ad, c->rvalue_vals,
3619 attr_merge_normalize(e, ct[i].ad,
3620 c->rvalue_vals, NULL);
3621 ber_bvarray_free( c->rvalue_nvals );
3622 ber_bvarray_free( c->rvalue_vals );
3631 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3632 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
3634 Entry *e = ch_calloc( 1, sizeof(Entry) );
3635 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3637 struct berval ad_name;
3638 AttributeDescription *ad = NULL;
3645 CfEntryInfo *ceprev = NULL;
3649 ce->ce_parent = parent;
3651 pdn = parent->ce_entry->e_nname;
3652 if ( parent->ce_kids )
3653 for ( ceprev = parent->ce_kids; ceprev->ce_sibs;
3654 ceprev = ceprev->ce_sibs );
3659 ce->ce_type = main->co_type;
3660 ce->ce_private = c->private;
3664 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3665 ber_dupbv( &e->e_nname, &e->e_name );
3667 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3668 main->co_name, NULL );
3670 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3671 extra->co_name, NULL );
3672 ptr = strchr(rdn->bv_val, '=');
3673 ad_name.bv_val = rdn->bv_val;
3674 ad_name.bv_len = ptr - rdn->bv_val;
3675 rc = slap_bv2ad( &ad_name, &ad, &text );
3680 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3681 attr_merge_normalize_one(e, ad, &val, NULL );
3684 if ( oc->soc_required )
3685 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
3687 if ( oc->soc_allowed )
3688 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
3692 if ( oc->soc_required )
3693 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
3695 if ( oc->soc_allowed )
3696 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
3699 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3700 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3702 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3705 op->o_bd->be_add( op, rs );
3708 ceprev->ce_sibs = ce;
3709 } else if ( parent ) {
3710 parent->ce_kids = ce;
3717 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3718 Operation *op, SlapReply *rs )
3721 ConfigFile *cf = c->private;
3725 for (; cf; cf=cf->c_sibs, c->depth++) {
3726 c->value_dn.bv_val = c->log;
3727 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3732 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3734 ptr = strchr( bv.bv_val, '.' );
3736 bv.bv_len = ptr - bv.bv_val;
3737 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3738 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3740 c->value_dn.bv_len += bv.bv_len;
3741 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3744 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3745 &CFOC_SCHEMA, NULL );
3746 if ( e && cf->c_kids ) {
3747 c->private = cf->c_kids;
3748 config_build_schema_inc( c, e->e_private, op, rs );
3754 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3755 Operation *op, SlapReply *rs )
3759 ConfigFile *cf = c->private;
3761 for (i=0; cf; cf=cf->c_sibs, i++) {
3762 c->value_dn.bv_val = c->log;
3763 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3765 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3766 &CFOC_INCLUDE, NULL );
3767 if ( e && cf->c_kids ) {
3768 c->private = cf->c_kids;
3769 config_build_includes( c, e->e_private, op, rs );
3774 #ifdef SLAPD_MODULES
3777 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3778 Operation *op, SlapReply *rs )
3783 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3784 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3786 c->value_dn.bv_val = c->log;
3787 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3789 config_build_entry( op, rs, ceparent, c, &c->value_dn,
3790 &CFOC_MODULE, NULL );
3796 config_back_db_open( BackendDB *be )
3798 CfBackInfo *cfb = be->be_private;
3801 CfEntryInfo *ce, *ceparent, *ceprev;
3807 Connection conn = {0};
3808 char opbuf[OPERATION_BUFFER_SIZE];
3810 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3811 SlapReply rs = {REP_RESULT};
3813 /* If we read the config from back-ldif, nothing to do here */
3814 if ( cfb->cb_got_ldif )
3817 if ( cfb->cb_use_ldif ) {
3818 op = (Operation *)opbuf;
3819 connection_fake_init( &conn, op, cfb );
3821 op->o_dn = be->be_rootdn;
3822 op->o_ndn = be->be_rootndn;
3824 op->o_tag = LDAP_REQ_ADD;
3825 op->o_callback = &cb;
3826 op->o_bd = &cfb->cb_db;
3831 /* create root of tree */
3833 c.private = cfb->cb_config;
3835 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
3842 /* Create includeFile nodes */
3843 if ( cfb->cb_config->c_kids ) {
3845 c.private = cfb->cb_config->c_kids;
3846 config_build_includes( &c, ceparent, op, &rs );
3849 #ifdef SLAPD_MODULES
3850 /* Create Module nodes... */
3851 if ( modpaths.mp_loads ) {
3852 config_build_modules( &c, ceparent, op, &rs );
3856 /* Create schema nodes... cn=schema will contain the hardcoded core
3857 * schema, read-only. Child objects will contain runtime loaded schema
3862 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
3865 /* Create schema nodes for included schema... */
3866 if ( cfb->cb_config->c_kids ) {
3868 c.private = cfb->cb_config->c_kids;
3869 config_build_schema_inc( &c, ce, op, &rs );
3872 /* Create backend nodes. Skip if they don't provide a cf_table.
3873 * There usually aren't any of these.
3877 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3878 if (!bi->bi_cf_ocs) continue;
3879 if (!bi->bi_private) continue;
3882 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3884 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
3888 /* Create database nodes... */
3890 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3891 slap_overinfo *oi = NULL;
3898 if ( overlay_is_over( bptr )) {
3899 oi = bptr->bd_info->bi_private;
3905 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3909 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
3912 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
3913 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
3914 /* Iterate through overlays */
3920 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3922 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
3923 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3926 oe = config_build_entry( op, &rs, ce, &c, &rdn,
3927 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
3928 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
3929 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
3938 config_back_db_destroy( Backend *be )
3940 free( be->be_private );
3945 config_back_db_init( Backend *be )
3950 cfb = ch_calloc( 1, sizeof(CfBackInfo));
3951 cfb->cb_config = &cf_prv;
3952 be->be_private = cfb;
3954 ber_dupbv( &be->be_rootdn, &config_rdn );
3955 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
3956 ber_dupbv( &dn, &be->be_rootdn );
3957 ber_bvarray_add( &be->be_suffix, &dn );
3958 ber_dupbv( &dn, &be->be_rootdn );
3959 ber_bvarray_add( &be->be_nsuffix, &dn );
3961 /* Hide from namingContexts */
3962 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
3968 config_back_destroy( BackendInfo *bi )
3970 ldif_must_b64_encode_release();
3975 config_tool_entry_open( BackendDB *be, int mode )
3977 CfBackInfo *cfb = be->be_private;
3978 BackendInfo *bi = cfb->cb_db.bd_info;
3980 if ( bi && bi->bi_tool_entry_open )
3981 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
3988 config_tool_entry_close( BackendDB *be )
3990 CfBackInfo *cfb = be->be_private;
3991 BackendInfo *bi = cfb->cb_db.bd_info;
3993 if ( bi && bi->bi_tool_entry_close )
3994 return bi->bi_tool_entry_close( &cfb->cb_db );
4000 config_tool_entry_first( BackendDB *be )
4002 CfBackInfo *cfb = be->be_private;
4003 BackendInfo *bi = cfb->cb_db.bd_info;
4005 if ( bi && bi->bi_tool_entry_first )
4006 return bi->bi_tool_entry_first( &cfb->cb_db );
4012 config_tool_entry_next( BackendDB *be )
4014 CfBackInfo *cfb = be->be_private;
4015 BackendInfo *bi = cfb->cb_db.bd_info;
4017 if ( bi && bi->bi_tool_entry_next )
4018 return bi->bi_tool_entry_next( &cfb->cb_db );
4024 config_tool_entry_get( BackendDB *be, ID id )
4026 CfBackInfo *cfb = be->be_private;
4027 BackendInfo *bi = cfb->cb_db.bd_info;
4029 if ( bi && bi->bi_tool_entry_get )
4030 return bi->bi_tool_entry_get( &cfb->cb_db, id );
4036 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
4038 CfBackInfo *cfb = be->be_private;
4039 BackendInfo *bi = cfb->cb_db.bd_info;
4041 if ( bi && bi->bi_tool_entry_put &&
4042 config_add_internal( cfb, e, NULL, NULL ) == 0 )
4043 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
4050 AttributeDescription **desc;
4052 { "backend", &cfAd_backend },
4053 { "database", &cfAd_database },
4054 { "include", &cfAd_include },
4055 { "overlay", &cfAd_overlay },
4060 * add / delete: all types that may be added or deleted must use an
4061 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4062 * should automatically renumber the index of any siblings as needed,
4063 * so that no gaps in the numbering sequence exist after the add/delete
4065 * What can be added:
4067 * backend objects for backend-specific config directives
4071 * delete: probably no support this time around.
4073 * modrdn: generally not done. Will be invoked automatically by add/
4074 * delete to update numbering sequence. Perform as an explicit operation
4075 * so that the renumbering effect may be replicated. Subtree rename must
4076 * be supported, since renumbering a database will affect all its child
4079 * modify: must be fully supported.
4083 config_back_initialize( BackendInfo *bi )
4085 ConfigTable *ct = config_back_cf_table;
4088 AttributeDescription *ad = NULL;
4090 static char *controls[] = {
4091 LDAP_CONTROL_MANAGEDSAIT,
4095 bi->bi_controls = controls;
4100 bi->bi_destroy = config_back_destroy;
4102 bi->bi_db_init = config_back_db_init;
4103 bi->bi_db_config = 0;
4104 bi->bi_db_open = config_back_db_open;
4105 bi->bi_db_close = 0;
4106 bi->bi_db_destroy = config_back_db_destroy;
4108 bi->bi_op_bind = config_back_bind;
4109 bi->bi_op_unbind = 0;
4110 bi->bi_op_search = config_back_search;
4111 bi->bi_op_compare = 0;
4112 bi->bi_op_modify = config_back_modify;
4113 bi->bi_op_modrdn = config_back_modrdn;
4114 bi->bi_op_add = config_back_add;
4115 bi->bi_op_delete = 0;
4116 bi->bi_op_abandon = 0;
4118 bi->bi_extended = 0;
4120 bi->bi_chk_referrals = 0;
4122 #ifdef SLAP_OVERLAY_ACCESS
4123 bi->bi_access_allowed = slap_access_always_allowed;
4124 #endif /* SLAP_OVERLAY_ACCESS */
4126 bi->bi_connection_init = 0;
4127 bi->bi_connection_destroy = 0;
4129 bi->bi_tool_entry_open = config_tool_entry_open;
4130 bi->bi_tool_entry_close = config_tool_entry_close;
4131 bi->bi_tool_entry_first = config_tool_entry_first;
4132 bi->bi_tool_entry_next = config_tool_entry_next;
4133 bi->bi_tool_entry_get = config_tool_entry_get;
4134 bi->bi_tool_entry_put = config_tool_entry_put;
4137 for (i=0; OidMacros[i].name; i++ ) {
4138 argv[1] = OidMacros[i].name;
4139 argv[2] = OidMacros[i].oid;
4140 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4143 bi->bi_cf_ocs = cf_ocs;
4145 i = config_register_schema( ct, cf_ocs );
4148 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4149 * basically, we don't care if it fails */
4150 i = slap_str2ad( "olcRootPW", &ad, &text );
4152 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4153 "warning, unable to get \"olcRootPW\" "
4154 "attribute description: %d: %s\n",
4157 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4158 ad->ad_type->sat_oid );
4161 /* set up the notable AttributeDescriptions */
4163 for (;ct->name;ct++) {
4164 if (strcmp(ct->name, ads[i].name)) continue;
4165 *ads[i].desc = ct->ad;
4167 if (!ads[i].name) break;