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;
65 typedef struct CfOcInfo {
66 struct berval *co_name;
67 ConfigTable *co_table;
72 typedef struct CfEntryInfo {
73 struct CfEntryInfo *ce_parent;
74 struct CfEntryInfo *ce_sibs;
75 struct CfEntryInfo *ce_kids;
84 ConfigFile *cb_config;
86 BackendDB cb_db; /* underlying database */
91 /* These do nothing in slapd, they're kept only to make them
94 static char *replica_pidFile, *replica_argsFile;
95 static int replicationInterval;
97 static char *passwd_salt;
98 static char *logfileName;
99 static BerVarray authz_rewrites;
101 static struct berval cfdir;
104 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
107 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
108 *cfOc_include, *cfOc_overlay, *cfOc_module;
110 static ConfigFile cf_prv, *cfn = &cf_prv;
112 static Avlnode *CfOcTree;
114 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs,
117 static ConfigDriver config_fname;
118 static ConfigDriver config_cfdir;
119 static ConfigDriver config_generic;
120 static ConfigDriver config_search_base;
121 static ConfigDriver config_passwd_hash;
122 static ConfigDriver config_schema_dn;
123 static ConfigDriver config_sizelimit;
124 static ConfigDriver config_timelimit;
125 static ConfigDriver config_overlay;
126 static ConfigDriver config_suffix;
127 static ConfigDriver config_deref_depth;
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_replica;
138 static ConfigDriver config_updatedn;
139 static ConfigDriver config_updateref;
140 static ConfigDriver config_include;
142 static ConfigDriver config_tls_option;
143 static ConfigDriver config_tls_config;
145 extern ConfigDriver syncrepl_config;
190 static OidRec OidMacros[] = {
191 /* OpenLDAProot:666.11.1 */
192 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
193 { "OLcfgAt", "OLcfg:3" },
194 { "OLcfgGlAt", "OLcfgAt:0" },
195 { "OLcfgBkAt", "OLcfgAt:1" },
196 { "OLcfgDbAt", "OLcfgAt:2" },
197 { "OLcfgOvAt", "OLcfgAt:3" },
198 { "OLcfgOc", "OLcfg:4" },
199 { "OLcfgGlOc", "OLcfgOc:0" },
200 { "OLcfgBkOc", "OLcfgOc:1" },
201 { "OLcfgDbOc", "OLcfgOc:2" },
202 { "OLcfgOvOc", "OLcfgOc:3" },
203 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
204 { "OMsInteger", "OMsyn:27" },
205 { "OMsBoolean", "OMsyn:7" },
206 { "OMsDN", "OMsyn:12" },
207 { "OMsDirectoryString", "OMsyn:15" },
208 { "OMsOctetString", "OMsyn:40" },
213 * OLcfg{Bk|Db}{Oc|At}:0 -> common
214 * OLcfg{Bk|Db}{Oc|At}:1 -> bdb
215 * OLcfg{Bk|Db}{Oc|At}:2 -> ldif
216 * OLcfg{Bk|Db}{Oc|At}:3 -> ldap?
219 /* alphabetical ordering */
221 ConfigTable config_back_cf_table[] = {
222 /* This attr is read-only */
223 { "", "", 0, 0, 0, ARG_MAGIC,
224 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
225 "DESC 'File for slapd configuration directives' "
226 "EQUALITY caseIgnoreMatch "
227 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
228 { "", "", 0, 0, 0, ARG_MAGIC,
229 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
230 "DESC 'Directory for slapd configuration backend' "
231 "EQUALITY caseIgnoreMatch "
232 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
233 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
234 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
235 "DESC 'Access Control List' "
236 "EQUALITY caseIgnoreMatch "
237 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
238 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
239 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
240 "DESC 'Allowed set of deprecated features' "
241 "EQUALITY caseIgnoreMatch "
242 "SYNTAX OMsDirectoryString )", NULL, NULL },
243 { "argsfile", "file", 2, 2, 0, ARG_STRING,
244 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
245 "DESC 'File for slapd command line options' "
246 "EQUALITY caseIgnoreMatch "
247 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
248 { "attribute", "attribute", 2, 0, 9,
249 ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT,
250 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
251 "DESC 'OpenLDAP attributeTypes' "
252 "EQUALITY caseIgnoreMatch "
253 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
255 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
256 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString )", NULL, NULL },
259 { "authid-rewrite", NULL, 2, 0, 0,
260 #ifdef SLAP_AUTH_REWRITE
261 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
265 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
266 "EQUALITY caseIgnoreMatch "
267 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
268 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
269 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
270 "EQUALITY caseIgnoreMatch "
271 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
272 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
273 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
274 "EQUALITY caseIgnoreMatch "
275 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
276 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
277 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
278 "DESC 'A type of backend' "
279 "EQUALITY caseIgnoreMatch "
280 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
282 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
283 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
284 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
285 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
286 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
287 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
288 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
289 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
290 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
291 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
292 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
293 "DESC 'The backend type for a database instance' "
294 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
295 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
296 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
297 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
298 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
299 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
300 "EQUALITY caseIgnoreMatch "
301 "SYNTAX OMsDirectoryString )", NULL, NULL },
302 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
303 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
304 "DESC 'OpenLDAP DIT content rules' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
308 { "gentlehup", "on|off", 2, 2, 0,
310 ARG_ON_OFF, &global_gentlehup,
314 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
315 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
316 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
317 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
318 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
319 { "include", "file", 2, 2, 0, ARG_MAGIC,
320 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
321 "SUP labeledURI )", NULL, NULL },
322 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
323 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
324 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
325 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
326 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
327 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
328 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
329 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
330 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
331 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
332 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
333 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
334 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
335 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
336 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
337 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
338 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
339 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
340 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
341 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
342 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
343 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
344 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
345 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
346 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
347 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
348 "SYNTAX OMsDirectoryString )", NULL, NULL },
349 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
350 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
351 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
352 { "moduleload", "file", 2, 0, 0,
354 ARG_MAGIC|CFG_MODLOAD, &config_generic,
358 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
359 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
360 { "modulepath", "path", 2, 2, 0,
362 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
366 "( OLcfgGlAt:31 NAME 'olcModulePath' "
367 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
368 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT,
369 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
370 "DESC 'OpenLDAP object classes' "
371 "EQUALITY caseIgnoreMatch "
372 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
374 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
375 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
376 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
377 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
378 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
379 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
380 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
381 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
382 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
383 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
384 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
385 "SYNTAX OMsDirectoryString )", NULL, NULL },
386 { "pidfile", "file", 2, 2, 0, ARG_STRING,
387 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
388 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
389 { "plugin", NULL, 0, 0, 0,
391 ARG_MAGIC|CFG_PLUGIN, &config_generic,
395 "( OLcfgGlAt:38 NAME 'olcPlugin' "
396 "SYNTAX OMsDirectoryString )", NULL, NULL },
397 { "pluginlog", "filename", 2, 2, 0,
399 ARG_STRING, &slapi_log_file,
403 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
404 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
405 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
406 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
407 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
408 { "referral", "url", 2, 2, 0, ARG_MAGIC,
409 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
410 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
411 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
412 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
413 "SUP labeledURI )", NULL, NULL },
414 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
415 &replica_argsFile, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
416 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
417 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
418 &replica_pidFile, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
419 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
420 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
421 &replicationInterval, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
422 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
423 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
424 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
425 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
426 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
427 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
428 "SYNTAX OMsDirectoryString )", NULL, NULL },
429 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
430 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
431 "SYNTAX OMsDirectoryString )", NULL, NULL },
432 { "reverse-lookup", "on|off", 2, 2, 0,
433 #ifdef SLAPD_RLOOKUPS
434 ARG_ON_OFF, &use_reverse_lookup,
438 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
439 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
440 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
441 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
442 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
443 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
444 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
445 "SYNTAX OMsDirectoryString )", NULL, NULL },
446 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
447 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
448 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
449 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
450 &config_generic, NULL, NULL, NULL },
451 { "sasl-host", "host", 2, 2, 0,
452 #ifdef HAVE_CYRUS_SASL
453 ARG_STRING|ARG_UNIQUE, &global_host,
457 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
458 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
459 { "sasl-realm", "realm", 2, 2, 0,
460 #ifdef HAVE_CYRUS_SASL
461 ARG_STRING|ARG_UNIQUE, &global_realm,
465 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
466 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
467 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
468 &config_generic, NULL, NULL, NULL },
469 { "sasl-secprops", "properties", 2, 2, 0,
470 #ifdef HAVE_CYRUS_SASL
471 ARG_MAGIC|CFG_SASLSECP, &config_generic,
475 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
476 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
477 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
478 &config_generic, NULL, NULL, NULL },
479 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
480 &config_generic, "( OLcfgGlAt:57 NAME 'olcSchemaCheck' "
481 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
482 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
483 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
484 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
485 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
486 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
487 "SYNTAX OMsDirectoryString )", NULL, NULL },
488 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
489 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
490 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
491 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
492 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
493 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
494 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
495 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
496 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
497 { "srvtab", "file", 2, 2, 0,
498 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
499 ARG_STRING, &ldap_srvtab,
503 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
504 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
505 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
506 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
507 "SYNTAX OMsDN )", NULL, NULL },
508 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
509 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
510 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
511 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
512 &config_generic, "( OLcfgGlAt:66 NAME 'olcThreads' "
513 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
514 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
515 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
516 "SYNTAX OMsDirectoryString )", NULL, NULL },
517 { "TLSCACertificateFile", NULL, 0, 0, 0,
519 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
523 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "TLSCACertificatePath", NULL, 0, 0, 0,
527 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
531 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
532 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
533 { "TLSCertificateFile", NULL, 0, 0, 0,
535 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
539 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
543 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
547 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
548 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
549 { "TLSCipherSuite", NULL, 0, 0, 0,
551 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
555 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
556 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
557 { "TLSCRLCheck", NULL, 0, 0, 0,
558 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
559 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
563 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
564 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
565 { "TLSRandFile", NULL, 0, 0, 0,
567 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
571 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "TLSVerifyClient", NULL, 0, 0, 0,
575 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
579 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
580 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
581 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
582 NULL, NULL, NULL, NULL },
583 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
584 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
585 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
586 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
587 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
588 "SUP labeledURI )", NULL, NULL },
589 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
590 NULL, NULL, NULL, NULL }
593 static ConfigOCs cf_ocs[] = {
596 "DESC 'OpenLDAP configuration object' "
597 "ABSTRACT SUP top )", Cft_Abstract, NULL },
600 "DESC 'OpenLDAP Global configuration options' "
601 "SUP olcConfig STRUCTURAL "
602 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
603 "olcAttributeOptions $ olcAuthIDRewrite $ "
604 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
605 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
606 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
607 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
608 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
610 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
611 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
612 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
613 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
614 "olcRootDSE $ olcRootPW $ "
615 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
616 "olcSchemaCheck $ olcSecurity $ olcSizeLimit $ "
617 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
618 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
619 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
620 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
621 "olcTLSRandFile $ olcTLSVerifyClient $ "
622 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
623 "olcDitContentRules ) )", Cft_Global, &cfOc_global },
625 "NAME 'olcSchemaConfig' "
626 "DESC 'OpenLDAP schema object' "
627 "SUP olcConfig STRUCTURAL "
628 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
629 "olcObjectClasses $ olcDitContentRules ) )",
630 Cft_Schema, &cfOc_schema },
632 "NAME 'olcBackendConfig' "
633 "DESC 'OpenLDAP Backend-specific options' "
634 "SUP olcConfig STRUCTURAL "
635 "MUST olcBackend )", Cft_Backend, &cfOc_backend },
637 "NAME 'olcDatabaseConfig' "
638 "DESC 'OpenLDAP Database-specific options' "
639 "SUP olcConfig STRUCTURAL "
641 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
642 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
643 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
644 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
645 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
646 Cft_Database, &cfOc_database },
648 "NAME 'olcOverlayConfig' "
649 "DESC 'OpenLDAP Overlay-specific options' "
650 "SUP olcConfig STRUCTURAL "
651 "MUST olcOverlay )", Cft_Overlay, &cfOc_overlay },
653 "NAME 'olcIncludeFile' "
654 "DESC 'OpenLDAP configuration include file' "
655 "SUP olcConfig STRUCTURAL "
657 "MAY ( cn $ olcRootDSE ) )",
658 Cft_Include, &cfOc_include },
661 "NAME 'olcModuleList' "
662 "DESC 'OpenLDAP dynamic module info' "
663 "SUP olcConfig STRUCTURAL "
664 "MUST ( olcModulePath $ olcModuleLoad ) "
665 "MAY cn )", Cft_Module, &cfOc_module },
671 config_generic(ConfigArgs *c) {
675 if ( c->op == SLAP_CONFIG_EMIT ) {
679 c->value_int = ldap_pvt_thread_get_concurrency();
682 c->value_int = connection_pool_max;
686 c->value_string = ch_strdup( passwd_salt );
691 if ( c->be->be_limits ) {
696 for ( i=0; c->be->be_limits[i]; i++ ) {
697 bv.bv_len = sprintf( buf, IFMT, i );
698 bv.bv_val = buf+bv.bv_len;
699 limits_unparse( c->be->be_limits[i], &bv );
700 bv.bv_len += bv.bv_val - buf;
702 value_add_one( &c->rvalue_vals, &bv );
705 if ( !c->rvalue_vals ) rc = 1;
708 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
711 c->value_string = ch_strdup( slap_sasl_getpolicy());
714 slap_sasl_regexp_unparse( &c->rvalue_vals );
715 if ( !c->rvalue_vals ) rc = 1;
717 #ifdef HAVE_CYRUS_SASL
719 struct berval bv = BER_BVNULL;
720 slap_sasl_secprops_unparse( &bv );
721 if ( !BER_BVISNULL( &bv )) {
722 ber_bvarray_add( &c->rvalue_vals, &bv );
730 c->value_int = c->be->be_max_deref_depth;
733 ConfigFile *cf = c->private;
735 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
736 else if ( cf->c_om_head )
737 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
739 if ( !c->rvalue_vals )
744 ConfigFile *cf = c->private;
746 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
747 else if ( cf->c_oc_head )
748 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
750 if ( !c->rvalue_vals )
755 ConfigFile *cf = c->private;
757 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
758 else if ( cf->c_at_head )
759 at_unparse( &c->rvalue_vals, cf->c_at_head,
761 if ( !c->rvalue_vals )
766 ConfigFile *cf = c->private;
768 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
769 else if ( cf->c_cr_head )
770 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
772 if ( !c->rvalue_vals )
778 c->value_int = global_schemacheck;
782 char *src, *dst, ibuf[11];
783 struct berval bv, abv;
784 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
785 abv.bv_len = sprintf( ibuf, IFMT, i );
786 acl_unparse( a, &bv );
787 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
788 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
789 /* Turn TAB / EOL into plain space */
790 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
791 if (isspace(*src)) *dst++ = ' ';
795 if (dst[-1] == ' ') {
799 abv.bv_len = dst - abv.bv_val;
800 ber_bvarray_add( &c->rvalue_vals, &abv );
806 if ( c->be->be_replogfile )
807 c->value_string = ch_strdup( c->be->be_replogfile );
810 ConfigFile *cf = c->private;
811 if ( cf->c_dseFiles ) {
812 value_add( &c->rvalue_vals, cf->c_dseFiles );
820 c->value_string = ch_strdup( logfileName );
825 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
827 case CFG_SSTR_IF_MAX:
828 c->value_int = index_substr_if_maxlen;
830 case CFG_SSTR_IF_MIN:
831 c->value_int = index_substr_if_minlen;
835 ModPaths *mp = c->private;
838 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
841 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
842 mp->mp_loads[i].bv_val );
843 value_add_one( &c->rvalue_vals, &bv );
847 rc = c->rvalue_vals ? 0 : 1;
851 ModPaths *mp = c->private;
852 value_add_one( &c->rvalue_vals, &mp->mp_path );
854 rc = c->rvalue_vals ? 0 : 1;
860 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
861 if ( !c->rvalue_vals ) rc = 1;
864 #ifdef SLAP_AUTH_REWRITE
866 if ( authz_rewrites ) {
867 struct berval bv, idx;
872 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
873 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
874 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
875 bv.bv_val = ch_malloc( bv.bv_len + 1 );
876 strcpy( bv.bv_val, idx.bv_val );
877 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
878 ber_bvarray_add( &c->rvalue_vals, &bv );
881 if ( !c->rvalue_vals ) rc = 1;
888 } else if ( c->op == LDAP_MOD_DELETE ) {
891 /* single-valued attrs, no-ops */
900 case CFG_SSTR_IF_MAX:
901 case CFG_SSTR_IF_MIN:
904 /* no-ops, requires slapd restart */
909 sprintf(c->log, "change requires slapd restart");
913 ch_free( passwd_salt );
918 ch_free( c->be->be_replogfile );
919 c->be->be_replogfile = NULL;
923 ch_free( logfileName );
930 if ( c->be == frontendDB )
933 end = frontendDB->be_acl;
934 acl_destroy( c->be->be_acl, end );
936 AccessControl **prev, *a;
938 for (i=0, prev = &c->be->be_acl; i < c->valx;
950 /* FIXME: there is no limits_free function */
952 /* FIXME: there is no ad_option_free function */
954 /* FIXME: there is no way to remove attributes added by
968 p = strchr(c->line,'(' /*')'*/);
972 if(!(c->bi = backend_info(c->argv[1]))) {
973 sprintf( c->msg, "<%s> failed init", c->argv[0] );
974 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
975 c->log, c->msg, c->argv[1] );
982 /* NOTE: config is always the first backend!
984 if ( !strcasecmp( c->argv[1], "config" )) {
985 c->be = LDAP_STAILQ_FIRST(&backendDB);
986 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
988 } else if(!(c->be = backend_db_init(c->argv[1]))) {
989 sprintf( c->msg, "<%s> failed init", c->argv[0] );
990 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
991 c->log, c->msg, c->argv[1] );
997 ldap_pvt_thread_set_concurrency(c->value_int);
1001 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1002 connection_pool_max = c->value_int; /* save for reference */
1006 if ( passwd_salt ) ch_free( passwd_salt );
1007 passwd_salt = c->value_string;
1008 lutil_salt_format(passwd_salt);
1012 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1018 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1020 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1024 ch_free(c->value_string);
1025 if (slap_sasl_setpolicy( c->argv[1] )) {
1026 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1027 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1028 c->log, c->msg, c->argv[1] );
1034 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1038 #ifdef HAVE_CYRUS_SASL
1041 char *txt = slap_sasl_secprops( c->argv[1] );
1043 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1045 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1053 c->be->be_max_deref_depth = c->value_int;
1059 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1061 if (!cfn->c_om_head) cfn->c_om_head = om;
1062 cfn->c_om_tail = om;
1069 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1070 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1071 cfn->c_oc_tail = oc;
1078 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1079 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1080 cfn->c_cr_tail = cr;
1087 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1088 if (!cfn->c_at_head) cfn->c_at_head = at;
1089 cfn->c_at_tail = at;
1094 ad_define_option(NULL, NULL, 0);
1095 for(i = 1; i < c->argc; i++)
1096 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1101 global_schemacheck = c->value_int;
1102 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1103 "schema checking disabled! your mileage may vary!\n",
1108 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1112 if(SLAP_MONITOR(c->be)) {
1113 Debug(LDAP_DEBUG_ANY, "%s: "
1114 "\"replogfile\" should not be used "
1115 "inside monitor database\n",
1117 return(0); /* FIXME: should this be an error? */
1120 c->be->be_replogfile = c->value_string;
1124 if(read_root_dse_file(c->argv[1])) {
1125 sprintf( c->msg, "<%s> could not read file", c->argv[0] );
1126 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1127 c->log, c->msg, c->argv[1] );
1132 ber_str2bv( c->argv[1], 0, 1, &bv );
1133 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1139 if ( logfileName ) ch_free( logfileName );
1140 logfileName = c->value_string;
1141 logfile = fopen(logfileName, "w");
1142 if(logfile) lutil_debug_file(logfile);
1146 if(SLAP_NOLASTMODCMD(c->be)) {
1147 sprintf( c->msg, "<%s> not available for %s database",
1148 c->argv[0], c->be->bd_info->bi_type );
1149 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1150 c->log, c->msg, 0 );
1154 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1156 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1159 case CFG_SSTR_IF_MAX:
1160 if (c->value_int < index_substr_if_minlen) {
1161 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1162 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1163 c->log, c->msg, c->value_int );
1166 index_substr_if_maxlen = c->value_int;
1169 case CFG_SSTR_IF_MIN:
1170 if (c->value_int > index_substr_if_maxlen) {
1171 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1172 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1173 c->log, c->msg, c->value_int );
1176 index_substr_if_minlen = c->value_int;
1179 #ifdef SLAPD_MODULES
1181 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1183 /* Record this load on the current path */
1187 char *ptr = c->line + STRLENOF("moduleload");
1188 while (!isspace(*ptr)) ptr++;
1189 while (isspace(*ptr)) ptr++;
1190 ber_str2bv(ptr, 0, 1, &bv);
1191 if ( c->op == SLAP_CONFIG_ADD )
1195 ber_bvarray_add( &mp->mp_loads, &bv );
1200 if(module_path(c->argv[1])) return(1);
1201 /* Record which path was used with each module */
1205 if (!modpaths.mp_loads) {
1208 mp = ch_malloc( sizeof( ModPaths ));
1209 modlast->mp_next = mp;
1211 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1213 mp->mp_loads = NULL;
1216 if ( c->op == SLAP_CONFIG_ADD )
1225 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1227 slapi_plugins_used++;
1231 #ifdef SLAP_AUTH_REWRITE
1234 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1236 ber_str2bv( c->line, 0, 1, &bv );
1237 ber_bvarray_add( &authz_rewrites, &bv );
1244 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1245 "(ignored)\n", c->log, c->type, 0);
1253 config_fname(ConfigArgs *c) {
1254 if(c->op == SLAP_CONFIG_EMIT) {
1256 ConfigFile *cf = c->private;
1257 value_add_one( &c->rvalue_vals, &cf->c_file );
1266 config_cfdir(ConfigArgs *c) {
1267 if(c->op == SLAP_CONFIG_EMIT) {
1268 if ( !BER_BVISEMPTY( &cfdir )) {
1269 value_add_one( &c->rvalue_vals, &cfdir );
1278 config_search_base(ConfigArgs *c) {
1281 if(c->op == SLAP_CONFIG_EMIT) {
1283 if (!BER_BVISEMPTY(&default_search_base)) {
1284 value_add_one(&c->rvalue_vals, &default_search_base);
1285 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1289 } else if( c->op == LDAP_MOD_DELETE ) {
1290 ch_free( default_search_base.bv_val );
1291 ch_free( default_search_nbase.bv_val );
1292 BER_BVZERO( &default_search_base );
1293 BER_BVZERO( &default_search_nbase );
1297 if(c->bi || c->be != frontendDB) {
1298 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1299 "prior to any backend or database definition\n",
1304 if(default_search_nbase.bv_len) {
1305 free(default_search_base.bv_val);
1306 free(default_search_nbase.bv_val);
1309 default_search_base = c->value_dn;
1310 default_search_nbase = c->value_ndn;
1315 config_passwd_hash(ConfigArgs *c) {
1317 if (c->op == SLAP_CONFIG_EMIT) {
1319 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1320 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1321 value_add_one(&c->rvalue_vals, &bv);
1324 } else if ( c->op == LDAP_MOD_DELETE ) {
1325 if ( c->valx < 0 ) {
1326 ldap_charray_free( default_passwd_hash );
1327 default_passwd_hash = NULL;
1330 ch_free( default_passwd_hash[i] );
1331 for (; default_passwd_hash[i]; i++ )
1332 default_passwd_hash[i] = default_passwd_hash[i+1];
1336 if(default_passwd_hash) {
1337 Debug(LDAP_DEBUG_ANY, "%s: "
1338 "already set default password_hash\n",
1342 for(i = 1; i < c->argc; i++) {
1343 if(!lutil_passwd_scheme(c->argv[i])) {
1344 sprintf( c->msg, "<%s> schema not available", c->argv[0] );
1345 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1346 c->log, c->msg, c->argv[i]);
1348 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1350 if(!default_passwd_hash) {
1351 sprintf( c->msg, "<%s> no valid hashes found", c->argv[0] );
1352 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1353 c->log, c->msg, 0 );
1361 config_schema_dn(ConfigArgs *c) {
1362 if ( c->op == SLAP_CONFIG_EMIT ) {
1364 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1365 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1366 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1370 } else if ( c->op == LDAP_MOD_DELETE ) {
1371 ch_free( c->be->be_schemadn.bv_val );
1372 ch_free( c->be->be_schemandn.bv_val );
1373 BER_BVZERO( &c->be->be_schemadn );
1374 BER_BVZERO( &c->be->be_schemandn );
1377 ch_free( c->be->be_schemadn.bv_val );
1378 ch_free( c->be->be_schemandn.bv_val );
1379 c->be->be_schemadn = c->value_dn;
1380 c->be->be_schemandn = c->value_ndn;
1385 config_sizelimit(ConfigArgs *c) {
1388 struct slap_limits_set *lim = &c->be->be_def_limit;
1389 if (c->op == SLAP_CONFIG_EMIT) {
1394 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1395 if ( !BER_BVISEMPTY( &bv ))
1396 value_add_one( &c->rvalue_vals, &bv );
1400 } else if ( c->op == LDAP_MOD_DELETE ) {
1401 /* Reset to defaults */
1402 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1403 lim->lms_s_hard = 0;
1404 lim->lms_s_unchecked = -1;
1406 lim->lms_s_pr_hide = 0;
1407 lim->lms_s_pr_total = 0;
1410 for(i = 1; i < c->argc; i++) {
1411 if(!strncasecmp(c->argv[i], "size", 4)) {
1412 rc = limits_parse_one(c->argv[i], lim);
1414 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1415 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1416 c->log, c->msg, c->argv[i]);
1420 if(!strcasecmp(c->argv[i], "unlimited")) {
1421 lim->lms_s_soft = -1;
1423 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1424 if(next == c->argv[i]) {
1425 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1426 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1427 c->log, c->msg, c->argv[i]);
1429 } else if(next[0] != '\0') {
1430 Debug(LDAP_DEBUG_ANY, "%s: "
1431 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1435 lim->lms_s_hard = 0;
1442 config_timelimit(ConfigArgs *c) {
1445 struct slap_limits_set *lim = &c->be->be_def_limit;
1446 if (c->op == SLAP_CONFIG_EMIT) {
1451 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1452 if ( !BER_BVISEMPTY( &bv ))
1453 value_add_one( &c->rvalue_vals, &bv );
1457 } else if ( c->op == LDAP_MOD_DELETE ) {
1458 /* Reset to defaults */
1459 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1460 lim->lms_t_hard = 0;
1463 for(i = 1; i < c->argc; i++) {
1464 if(!strncasecmp(c->argv[i], "time", 4)) {
1465 rc = limits_parse_one(c->argv[i], lim);
1467 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1468 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1469 c->log, c->msg, c->argv[i]);
1473 if(!strcasecmp(c->argv[i], "unlimited")) {
1474 lim->lms_t_soft = -1;
1476 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1477 if(next == c->argv[i]) {
1478 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1479 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1480 c->log, c->msg, c->argv[i]);
1482 } else if(next[0] != '\0') {
1483 Debug(LDAP_DEBUG_ANY, "%s: "
1484 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1488 lim->lms_t_hard = 0;
1495 config_overlay(ConfigArgs *c) {
1496 if (c->op == SLAP_CONFIG_EMIT) {
1498 } else if ( c->op == LDAP_MOD_DELETE ) {
1501 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1503 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1504 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1505 } else if(overlay_config(c->be, c->argv[1])) {
1512 config_suffix(ConfigArgs *c) {
1514 struct berval pdn, ndn;
1517 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1518 SLAP_CONFIG(c->be)) return 1;
1520 if (c->op == SLAP_CONFIG_EMIT) {
1521 if ( c->be->be_suffix == NULL
1522 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1526 value_add( &c->rvalue_vals, c->be->be_suffix );
1527 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1530 } else if ( c->op == LDAP_MOD_DELETE ) {
1531 if ( c->valx < 0 ) {
1532 ber_bvarray_free( c->be->be_suffix );
1533 ber_bvarray_free( c->be->be_nsuffix );
1534 c->be->be_suffix = NULL;
1535 c->be->be_nsuffix = NULL;
1538 ch_free( c->be->be_suffix[i].bv_val );
1539 ch_free( c->be->be_nsuffix[i].bv_val );
1540 for (; c->be->be_suffix[i].bv_val; i++) {
1541 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1542 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1547 #ifdef SLAPD_MONITOR_DN
1548 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1549 sprintf( c->msg, "<%s> DN is reserved for monitoring slapd",
1551 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1552 c->log, c->msg, SLAPD_MONITOR_DN);
1559 tbe = select_backend(&ndn, 0, 0);
1561 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1566 sprintf( c->msg, "<%s> suffix already served by a preceding backend",
1568 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1569 c->log, c->msg, tbe->be_suffix[0].bv_val);
1573 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1574 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1575 "base provided \"%s\" (assuming okay)\n",
1576 c->log, default_search_base.bv_val, 0);
1578 ber_bvarray_add(&c->be->be_suffix, &pdn);
1579 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1584 config_rootdn(ConfigArgs *c) {
1585 if (c->op == SLAP_CONFIG_EMIT) {
1586 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1587 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1588 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1593 } else if ( c->op == LDAP_MOD_DELETE ) {
1594 ch_free( c->be->be_rootdn.bv_val );
1595 ch_free( c->be->be_rootndn.bv_val );
1596 BER_BVZERO( &c->be->be_rootdn );
1597 BER_BVZERO( &c->be->be_rootndn );
1600 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1601 ch_free( c->be->be_rootdn.bv_val );
1602 ch_free( c->be->be_rootndn.bv_val );
1604 c->be->be_rootdn = c->value_dn;
1605 c->be->be_rootndn = c->value_ndn;
1610 config_rootpw(ConfigArgs *c) {
1612 /* config_add_internal sets c->be = frontendDB. While the cn=config
1613 * rootpw is technically inside a backend, we expose it in the
1614 * global entry, and need to point to it properly here.
1616 if (c->be == frontendDB)
1617 c->be = LDAP_STAILQ_FIRST(&backendDB);
1619 if (c->op == SLAP_CONFIG_EMIT) {
1620 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1621 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1625 } else if ( c->op == LDAP_MOD_DELETE ) {
1626 ch_free( c->be->be_rootpw.bv_val );
1627 BER_BVZERO( &c->be->be_rootpw );
1631 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1633 sprintf( c->msg, "<%s> can only be set when rootdn is under suffix",
1635 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1639 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1640 ch_free( c->be->be_rootpw.bv_val );
1641 c->be->be_rootpw = c->value_bv;
1646 config_restrict(ConfigArgs *c) {
1647 slap_mask_t restrictops = 0;
1649 slap_verbmasks restrictable_ops[] = {
1650 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1651 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1652 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1653 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1654 { BER_BVC("modrdn"), 0 },
1655 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1656 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1657 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1658 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1659 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1660 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1661 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1662 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1663 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1664 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1668 if (c->op == SLAP_CONFIG_EMIT) {
1669 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1671 } else if ( c->op == LDAP_MOD_DELETE ) {
1673 c->be->be_restrictops = 0;
1675 restrictops = verb_to_mask( c->line, restrictable_ops );
1676 c->be->be_restrictops ^= restrictops;
1680 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1682 sprintf( c->msg, "<%s> unknown operation", c->argv[0] );
1683 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1684 c->log, c->msg, c->argv[i]);
1687 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1688 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1689 c->be->be_restrictops |= restrictops;
1694 config_allows(ConfigArgs *c) {
1695 slap_mask_t allows = 0;
1697 slap_verbmasks allowable_ops[] = {
1698 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1699 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1700 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1701 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1704 if (c->op == SLAP_CONFIG_EMIT) {
1705 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1706 } else if ( c->op == LDAP_MOD_DELETE ) {
1710 allows = verb_to_mask( c->line, allowable_ops );
1711 global_allows ^= allows;
1715 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1717 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1718 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1719 c->log, c->msg, c->argv[i]);
1722 global_allows |= allows;
1727 config_disallows(ConfigArgs *c) {
1728 slap_mask_t disallows = 0;
1730 slap_verbmasks disallowable_ops[] = {
1731 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1732 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1733 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1734 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1735 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1738 if (c->op == SLAP_CONFIG_EMIT) {
1739 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1740 } else if ( c->op == LDAP_MOD_DELETE ) {
1742 global_disallows = 0;
1744 disallows = verb_to_mask( c->line, disallowable_ops );
1745 global_disallows ^= disallows;
1749 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1751 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1752 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1753 c->log, c->msg, c->argv[i]);
1756 global_disallows |= disallows;
1761 config_requires(ConfigArgs *c) {
1762 slap_mask_t requires = 0;
1764 slap_verbmasks requires_ops[] = {
1765 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1766 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1767 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1768 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1769 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1772 if (c->op == SLAP_CONFIG_EMIT) {
1773 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1774 } else if ( c->op == LDAP_MOD_DELETE ) {
1776 c->be->be_requires = 0;
1778 requires = verb_to_mask( c->line, requires_ops );
1779 c->be->be_requires ^= requires;
1783 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1785 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1786 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1787 c->log, c->msg, c->argv[i]);
1790 c->be->be_requires = requires;
1795 config_loglevel(ConfigArgs *c) {
1798 slap_verbmasks loglevel_ops[] = {
1799 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1800 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1801 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1802 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1803 { BER_BVC("BER"), LDAP_DEBUG_BER },
1804 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1805 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1806 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1807 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1808 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1809 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1810 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1811 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1812 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1813 { BER_BVC("Any"), -1 },
1817 if (c->op == SLAP_CONFIG_EMIT) {
1818 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1819 } else if ( c->op == LDAP_MOD_DELETE ) {
1823 int level = verb_to_mask( c->line, loglevel_ops );
1824 ldap_syslog ^= level;
1831 for( i=1; i < c->argc; i++ ) {
1834 if ( isdigit( c->argv[i][0] ) ) {
1835 level = strtol( c->argv[i], &next, 10 );
1836 if ( next == NULL || next[0] != '\0' ) {
1837 sprintf( c->msg, "<%s> unable to parse level", c->argv[0] );
1838 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1839 c->log, c->msg, c->argv[i]);
1843 int j = verb_to_mask(c->argv[i], loglevel_ops);
1844 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1845 sprintf( c->msg, "<%s> unknown level", c->argv[0] );
1846 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1847 c->log, c->msg, c->argv[i]);
1850 level = loglevel_ops[j].mask;
1852 ldap_syslog |= level;
1858 config_referral(ConfigArgs *c) {
1860 if (c->op == SLAP_CONFIG_EMIT) {
1861 if ( default_referral ) {
1862 value_add( &c->rvalue_vals, default_referral );
1867 } else if ( c->op == LDAP_MOD_DELETE ) {
1868 if ( c->valx < 0 ) {
1869 ber_bvarray_free( default_referral );
1870 default_referral = NULL;
1873 ch_free( default_referral[i].bv_val );
1874 for (; default_referral[i].bv_val; i++ )
1875 default_referral[i] = default_referral[i+1];
1879 if(validate_global_referral(c->argv[1])) {
1880 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
1881 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1882 c->log, c->msg, c->argv[1]);
1886 ber_str2bv(c->argv[1], 0, 0, &val);
1887 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
1895 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1896 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1897 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1898 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1899 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1900 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1901 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1902 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1903 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1908 config_security(ConfigArgs *c) {
1909 slap_ssf_set_t *set = &c->be->be_ssf_set;
1912 if (c->op == SLAP_CONFIG_EMIT) {
1918 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1919 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1922 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1923 bv.bv_len += sec_keys[i].key.bv_len;
1924 bv.bv_val = ch_malloc( bv.bv_len + 1);
1925 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1926 strcpy( next, numbuf );
1927 ber_bvarray_add( &c->rvalue_vals, &bv );
1932 for(i = 1; i < c->argc; i++) {
1933 slap_ssf_t *tgt = NULL;
1935 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1936 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1937 sec_keys[j].key.bv_len)) {
1938 src = c->argv[i] + sec_keys[j].key.bv_len;
1939 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1944 sprintf( c->msg, "<%s> unknown factor", c->argv[0] );
1945 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1946 c->log, c->msg, c->argv[i]);
1950 *tgt = strtol(src, &next, 10);
1951 if(next == NULL || next[0] != '\0' ) {
1952 sprintf( c->msg, "<%s> unable to parse factor", c->argv[0] );
1953 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1954 c->log, c->msg, c->argv[i]);
1962 anlist_unparse( AttributeName *an, char *ptr ) {
1965 for (; !BER_BVISNULL( &an->an_name ); an++) {
1966 if ( comma ) *ptr++ = ',';
1967 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1974 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1978 struct berval bc = {0};
1981 len = sprintf(numbuf, IFMT, i );
1983 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1984 if ( ri->ri_nsuffix ) {
1985 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1986 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1989 if ( ri->ri_attrs ) {
1990 len += STRLENOF("attr");
1991 if ( ri->ri_exclude ) len++;
1992 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1993 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1996 bindconf_unparse( &ri->ri_bindconf, &bc );
1999 bv->bv_val = ch_malloc(len + 1);
2002 ptr = lutil_strcopy( bv->bv_val, numbuf );
2003 ptr = lutil_strcopy( ptr, "uri=" );
2004 ptr = lutil_strcopy( ptr, ri->ri_uri );
2006 if ( ri->ri_nsuffix ) {
2007 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2008 ptr = lutil_strcopy( ptr, " suffix=\"" );
2009 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2013 if ( ri->ri_attrs ) {
2014 ptr = lutil_strcopy( ptr, "attr" );
2015 if ( ri->ri_exclude ) *ptr++ = '!';
2017 ptr = anlist_unparse( ri->ri_attrs, ptr );
2020 strcpy( ptr, bc.bv_val );
2021 ch_free( bc.bv_val );
2026 config_replica(ConfigArgs *c) {
2027 int i, nr = -1, len;
2028 char *replicahost, *replicauri;
2031 if (c->op == SLAP_CONFIG_EMIT) {
2032 if (c->be->be_replica) {
2034 for (i=0;c->be->be_replica[i]; i++) {
2035 replica_unparse( c->be->be_replica[i], i, &bv );
2036 ber_bvarray_add( &c->rvalue_vals, &bv );
2041 } else if ( c->op == LDAP_MOD_DELETE ) {
2042 /* FIXME: there is no replica_free function */
2043 if ( c->valx < 0 ) {
2047 if(SLAP_MONITOR(c->be)) {
2048 Debug(LDAP_DEBUG_ANY, "%s: "
2049 "\"replica\" should not be used inside monitor database\n",
2051 return(0); /* FIXME: should this be an error? */
2054 for(i = 1; i < c->argc; i++) {
2055 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2056 replicahost = c->argv[i] + STRLENOF("host=");
2057 len = strlen( replicahost );
2058 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2059 sprintf( replicauri, "ldap://%s", replicahost );
2060 replicahost = replicauri + STRLENOF( "ldap://");
2061 nr = add_replica_info(c->be, replicauri, replicahost);
2063 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2064 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2065 sprintf( c->msg, "<%s> invalid uri", c->argv[0] );
2066 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2069 if(!ludp->lud_host) {
2070 sprintf( c->msg, "<%s> invalid uri - missing hostname",
2072 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2075 ldap_free_urldesc(ludp);
2076 replicauri = c->argv[i] + STRLENOF("uri=");
2077 replicauri = ch_strdup( replicauri );
2078 replicahost = strchr( replicauri, '/' );
2080 nr = add_replica_info(c->be, replicauri, replicahost);
2085 sprintf( c->msg, "<%s> missing host or uri", c->argv[0] );
2086 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2088 } else if(nr == -1) {
2089 sprintf( c->msg, "<%s> unable to add replica", c->argv[0] );
2090 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2093 for(i = 1; i < c->argc; i++) {
2094 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2095 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2097 Debug(LDAP_DEBUG_ANY, "%s: "
2098 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2099 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2102 Debug(LDAP_DEBUG_ANY, "%s: "
2103 "unable to normalize suffix in \"replica\" line (ignored)\n",
2108 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2110 char *arg = c->argv[i] + STRLENOF("attr");
2118 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2119 sprintf( c->msg, "<%s> unknown attribute", c->argv[0] );
2120 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2121 c->log, c->msg, arg + 1);
2124 } else if ( bindconf_parse( c->argv[i],
2125 &c->be->be_replica[nr]->ri_bindconf ) ) {
2134 config_updatedn(ConfigArgs *c) {
2137 if (c->op == SLAP_CONFIG_EMIT) {
2138 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2139 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2140 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2144 } else if ( c->op == LDAP_MOD_DELETE ) {
2145 ch_free( c->be->be_update_ndn.bv_val );
2146 c->be->be_update_ndn.bv_val = NULL;
2147 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2150 if(SLAP_SHADOW(c->be)) {
2151 sprintf( c->msg, "<%s> database already shadowed", c->argv[0] );
2152 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2157 ber_str2bv(c->argv[1], 0, 0, &dn);
2159 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2161 if(rc != LDAP_SUCCESS) {
2162 sprintf( c->msg, "<%s> invalid DN %d (%s)", c->argv[0],
2163 rc, ldap_err2string(rc));
2164 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2165 c->log, c->msg, 0 );
2169 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2174 config_updateref(ConfigArgs *c) {
2176 if (c->op == SLAP_CONFIG_EMIT) {
2177 if ( c->be->be_update_refs ) {
2178 value_add( &c->rvalue_vals, c->be->be_update_refs );
2183 } else if ( c->op == LDAP_MOD_DELETE ) {
2184 if ( c->valx < 0 ) {
2185 ber_bvarray_free( c->be->be_update_refs );
2186 c->be->be_update_refs = NULL;
2189 ch_free( c->be->be_update_refs[i].bv_val );
2190 for (; c->be->be_update_refs[i].bv_val; i++)
2191 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2195 if(!SLAP_SHADOW(c->be)) {
2196 sprintf( c->msg, "<%s> must appear after syncrepl or updatedn",
2198 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2203 if(validate_global_referral(c->argv[1])) {
2204 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2205 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2206 c->log, c->msg, c->argv[1]);
2209 ber_str2bv(c->argv[1], 0, 0, &val);
2210 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2215 config_include(ConfigArgs *c) {
2216 unsigned long savelineno = c->lineno;
2219 ConfigFile *cfsave = cfn;
2220 ConfigFile *cf2 = NULL;
2221 if (c->op == SLAP_CONFIG_EMIT) {
2223 ConfigFile *cf = c->private;
2224 value_add_one( &c->rvalue_vals, &cf->c_file );
2228 } else if ( c->op == LDAP_MOD_DELETE ) {
2230 cf = ch_calloc( 1, sizeof(ConfigFile));
2231 if ( cfn->c_kids ) {
2232 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2238 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2239 rc = read_config_file(c->argv[1], c->depth + 1, c);
2240 c->lineno = savelineno - 1;
2243 if ( cf2 ) cf2->c_sibs = NULL;
2244 else cfn->c_kids = NULL;
2245 ch_free( cf->c_file.bv_val );
2255 config_tls_option(ConfigArgs *c) {
2258 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2259 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2260 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2261 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2262 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2263 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2264 default: Debug(LDAP_DEBUG_ANY, "%s: "
2265 "unknown tls_option <0x%x>\n",
2266 c->log, c->type, 0);
2268 if (c->op == SLAP_CONFIG_EMIT) {
2269 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2270 } else if ( c->op == LDAP_MOD_DELETE ) {
2271 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2273 ch_free(c->value_string);
2274 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2277 /* FIXME: this ought to be provided by libldap */
2279 config_tls_config(ConfigArgs *c) {
2281 slap_verbmasks crlkeys[] = {
2282 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2283 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2284 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2287 slap_verbmasks vfykeys[] = {
2288 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2289 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2290 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2291 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2295 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2296 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2298 Debug(LDAP_DEBUG_ANY, "%s: "
2299 "unknown tls_option <0x%x>\n",
2300 c->log, c->type, 0);
2302 if (c->op == SLAP_CONFIG_EMIT) {
2303 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2304 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2305 if (keys[i].mask == c->value_int) {
2306 c->value_string = ch_strdup( keys[i].word.bv_val );
2311 } else if ( c->op == LDAP_MOD_DELETE ) {
2313 return ldap_pvt_tls_set_option( NULL, flag, &i );
2315 ch_free( c->value_string );
2316 if(isdigit((unsigned char)c->argv[1][0])) {
2317 i = atoi(c->argv[1]);
2318 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2320 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2325 static CfEntryInfo *
2326 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2336 if ( dn_match( &root->ce_entry->e_nname, dn ))
2339 c = dn->bv_val+dn->bv_len;
2340 for (;*c != ',';c--);
2344 for (--c;c>dn->bv_val && *c != ',';c--);
2348 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2350 root = root->ce_kids;
2352 for (;root;root=root->ce_sibs) {
2353 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2354 if ( cdn.bv_val == dn->bv_val ) {
2365 config_ldif_resp( Operation *op, SlapReply *rs )
2367 if ( rs->sr_type == REP_SEARCH ) {
2368 CfBackInfo *cfb = op->o_callback->sc_private;
2370 cfb->cb_got_ldif = 1;
2371 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL );
2376 /* Configure and read the underlying back-ldif store */
2378 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
2379 CfBackInfo *cfb = be->be_private;
2384 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2385 Connection conn = {0};
2386 char opbuf[OPERATION_BUFFER_SIZE];
2388 SlapReply rs = {REP_RESULT};
2389 Filter filter = { LDAP_FILTER_PRESENT };
2390 struct berval filterstr = BER_BVC("(objectclass=*)");
2393 /* Is the config directory available? */
2394 if ( stat( dir, &st ) < 0 ) {
2395 /* No, so don't bother using the backing store.
2396 * All changes will be in-memory only.
2401 cfb->cb_db.bd_info = backend_info( "ldif" );
2402 if ( !cfb->cb_db.bd_info )
2403 return 0; /* FIXME: eventually this will be a fatal error */
2405 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2407 /* Mark that back-ldif type is in use */
2408 cfb->cb_db.bd_info->bi_nDB++;
2410 cfb->cb_db.be_suffix = be->be_suffix;
2411 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2412 cfb->cb_db.be_rootdn = be->be_rootdn;
2413 cfb->cb_db.be_rootndn = be->be_rootndn;
2415 ber_str2bv( dir, 0, 1, &cfdir );
2420 argv[0] = "directory";
2421 argv[1] = (char *)dir;
2425 ct = config_find_keyword( c.be->be_cf_table, &c );
2429 if ( config_add_vals( ct, &c ))
2432 if ( backend_startup_one( &cfb->cb_db ))
2436 op = (Operation *)opbuf;
2437 connection_fake_init( &conn, op, cfb );
2439 filter.f_desc = slap_schema.si_ad_objectClass;
2441 op->o_tag = LDAP_REQ_SEARCH;
2443 op->ors_filter = &filter;
2444 op->ors_filterstr = filterstr;
2445 op->ors_scope = LDAP_SCOPE_SUBTREE;
2447 op->o_dn = be->be_rootdn;
2448 op->o_ndn = be->be_rootndn;
2450 op->o_req_dn = be->be_suffix[0];
2451 op->o_req_ndn = be->be_nsuffix[0];
2453 op->ors_tlimit = SLAP_NO_LIMIT;
2454 op->ors_slimit = SLAP_NO_LIMIT;
2456 op->ors_attrs = slap_anlist_all_attributes;
2457 op->ors_attrsonly = 0;
2459 op->o_callback = &cb;
2460 cb.sc_private = cfb;
2462 op->o_bd = &cfb->cb_db;
2463 op->o_bd->be_search( op, &rs );
2466 cfb->cb_use_ldif = 1;
2472 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2473 const CfOcInfo *co1 = c1;
2474 const CfOcInfo *co2 = c2;
2476 return ber_bvcmp( co1->co_name, co2->co_name );
2480 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2484 i = init_config_attrs( ct );
2487 /* set up the objectclasses */
2488 i = init_config_ocs( ocs );
2491 for (i=0; ocs[i].def; i++) {
2493 co = ch_malloc( sizeof(CfOcInfo) );
2494 co->co_oc = *ocs[i].oc;
2495 co->co_name = &co->co_oc->soc_cname;
2497 co->co_type = ocs[i].cft;
2498 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2505 read_config(const char *fname, const char *dir) {
2508 const char *cfdir, *cfname;
2511 /* Setup the config backend */
2512 be = backend_db_init( "config" );
2516 cfb = be->be_private;
2518 /* If no .conf, or a dir was specified, setup the dir */
2519 if ( !fname || dir ) {
2521 /* If explicitly given, check for existence */
2524 if ( stat( dir, &st ) < 0 ) {
2525 Debug( LDAP_DEBUG_ANY,
2526 "invalid config directory %s, error %d\n",
2532 cfdir = SLAPD_DEFAULT_CONFIGDIR;
2534 /* if fname is defaulted, try reading .d */
2535 if ( config_setup_ldif( be, cfdir, !fname ))
2538 /* If we read the config from back-ldif, nothing to do here */
2539 if ( cfb->cb_got_ldif )
2546 cfname = SLAPD_DEFAULT_CONFIGFILE;
2548 rc = read_config_file(cfname, 0, NULL);
2551 ber_str2bv( cfname, 0, 1, &cf_prv.c_file );
2553 /* If we got this far and failed, it may be a serious problem. In server
2554 * mode, we should never come to this. However, it may be alright if we're
2555 * using slapadd to create the conf dir.
2558 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
2560 /* If a config file was explicitly given, fail */
2564 /* Seems to be slapadd with a config dir, let it continue */
2565 if ( cfb->cb_use_ldif ) {
2567 cfb->cb_got_ldif = 1;
2575 config_back_bind( Operation *op, SlapReply *rs )
2577 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2578 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2579 /* frontend sends result */
2580 return LDAP_SUCCESS;
2583 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2584 send_ldap_result( op, rs );
2590 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2594 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2596 rs->sr_attrs = op->ors_attrs;
2597 rs->sr_entry = ce->ce_entry;
2598 rc = send_search_entry( op, rs );
2600 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2601 if ( ce->ce_kids ) {
2602 rc = config_send( op, rs, ce->ce_kids, 1 );
2603 if ( rc ) return rc;
2606 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2607 rc = config_send( op, rs, ce, 0 );
2615 static ConfigTable *
2616 config_find_table( CfOcInfo **colst, int nocs, AttributeDescription *ad )
2620 for (j=0; j<nocs; j++) {
2621 for (i=0; colst[j]->co_table[i].name; i++)
2622 if ( colst[j]->co_table[i].ad == ad )
2623 return &colst[j]->co_table[i];
2628 /* Sort the attributes of the entry according to the order defined
2629 * in the objectclass, with required attributes occurring before
2630 * allowed attributes. For any attributes with sequencing dependencies
2631 * (e.g., rootDN must be defined after suffix) the objectclass must
2632 * list the attributes in the desired sequence.
2635 sort_attrs( Entry *e, CfOcInfo **colst, int nocs )
2637 Attribute *a, *head = NULL, *tail = NULL, **prev;
2640 for (i=0; i<nocs; i++) {
2641 if ( colst[i]->co_oc->soc_required ) {
2642 AttributeType **at = colst[i]->co_oc->soc_required;
2643 for (j=0; at[j]; j++) {
2644 for (a=e->e_attrs, prev=&e->e_attrs; a;
2645 prev = &(*prev)->a_next, a=a->a_next) {
2646 if ( a->a_desc == at[j]->sat_ad ) {
2660 if ( colst[i]->co_oc->soc_allowed ) {
2661 AttributeType **at = colst[i]->co_oc->soc_allowed;
2662 for (j=0; at[j]; j++) {
2663 for (a=e->e_attrs, prev=&e->e_attrs; a;
2664 prev = &(*prev)->a_next, a=a->a_next) {
2665 if ( a->a_desc == at[j]->sat_ad ) {
2681 tail->a_next = e->e_attrs;
2687 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2689 Attribute *a = NULL;
2690 AttributeDescription *ad;
2693 int i, rc = 0, sort = 0;
2700 Modifications *ml = ptr;
2702 vals = ml->sml_values;
2705 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2707 rc = ordered_value_sort( a, 1 );
2711 for ( i=0; vals[i].bv_val; i++ ) {
2712 ca->line = vals[i].bv_val;
2714 char *idx = strchr( ca->line, '}' );
2715 if ( idx ) ca->line = idx+1;
2717 rc = config_parse_vals( ct, ca, i );
2725 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2726 SlapReply *rs, int *renum )
2729 int index = -1, gotindex = 0, nsibs;
2730 int renumber = 0, tailindex = 0;
2734 if ( renum ) *renum = 0;
2736 /* These entries don't get indexed/renumbered */
2737 if ( ce_type == Cft_Global ) return 0;
2738 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2740 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2743 /* See if the rdn has an index already */
2744 dnRdn( &e->e_name, &rdn );
2745 ptr1 = strchr( e->e_name.bv_val, '{' );
2746 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2747 ptr2 = strchr( ptr1, '}' );
2748 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2749 return LDAP_NAMING_VIOLATION;
2750 if ( ptr2-ptr1 == 1)
2751 return LDAP_NAMING_VIOLATION;
2753 index = atoi(ptr1+1);
2755 return LDAP_NAMING_VIOLATION;
2758 /* count related kids */
2759 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2760 if ( ce->ce_type == ce_type ) nsibs++;
2763 if ( index != nsibs ) {
2765 if ( index < nsibs ) {
2766 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2767 /* Siblings need to be renumbered */
2772 struct berval ival, newrdn, nnewrdn;
2773 struct berval rtype, rval;
2775 AttributeDescription *ad = NULL;
2779 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2780 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2781 rtype.bv_val = rdn.bv_val;
2782 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2785 slap_bv2ad( &rtype, &ad, &text );
2786 a = attr_find( e->e_attrs, ad );
2787 if (!a ) return LDAP_NAMING_VIOLATION;
2790 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2792 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2793 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2796 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2797 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2804 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
2806 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
2809 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2810 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
2814 /* Do the equivalent of ModRDN */
2815 /* Replace DN / NDN */
2816 newrdn.bv_len = ptr1 - newrdn.bv_val;
2817 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
2818 free( e->e_name.bv_val );
2819 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
2821 free( e->e_nname.bv_val );
2822 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
2826 free( a->a_vals[0].bv_val );
2827 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
2828 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
2829 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
2830 strcpy( a->a_vals[0].bv_val, ptr1 );
2832 if ( a->a_nvals != a->a_vals ) {
2833 free( a->a_nvals[0].bv_val );
2834 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
2835 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
2836 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
2837 strcpy( a->a_nvals[0].bv_val, ptr1 );
2839 free( nnewrdn.bv_val );
2840 free( newrdn.bv_val );
2843 if ( renum ) *renum = renumber;
2848 count_ocs( Attribute *oc_at, int *nocs )
2851 CfOcInfo co, *coptr, **colst;
2853 /* count the objectclasses */
2854 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2856 colst = (CfOcInfo **)ch_malloc( n * sizeof(CfOcInfo *));
2858 for ( i=0, j=0; i<n; i++) {
2859 co.co_name = &oc_at->a_nvals[i];
2860 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
2862 /* ignore non-config objectclasses. probably should be
2863 * an error, general data doesn't belong here.
2865 if ( !coptr ) continue;
2867 /* Ignore the root objectclass, it has no implementation.
2869 if ( coptr->co_type == Cft_Abstract ) continue;
2876 /* Parse an LDAP entry into config directives */
2878 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
2880 CfEntryInfo *ce, *last;
2882 Attribute *a, *oc_at, *type_attr;
2883 AttributeDescription *type_ad = NULL;
2884 int i, j, nocs, rc = 0;
2885 ConfigArgs ca = {0};
2887 ConfigTable *ct, *type_ct = NULL;
2890 /* Make sure parent exists and entry does not */
2891 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
2893 return LDAP_ALREADY_EXISTS;
2895 dnParent( &e->e_nname, &pdn );
2897 /* If last is NULL, the new entry is the root/suffix entry,
2898 * otherwise last should be the parent.
2900 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
2902 rs->sr_matched = last->ce_entry->e_name.bv_val;
2903 return LDAP_NO_SUCH_OBJECT;
2906 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
2907 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
2909 colst = count_ocs( oc_at, &nocs );
2911 /* Only the root can be Cft_Global, everything else must
2912 * have a parent. Only limited nesting arrangements are allowed.
2914 switch( colst[0]->co_type ) {
2917 rc = LDAP_CONSTRAINT_VIOLATION;
2925 if ( !last || ( last->ce_type != Cft_Global &&
2926 last->ce_type != colst[0]->co_type )) {
2927 rc = LDAP_CONSTRAINT_VIOLATION;
2932 if ( !last || ( last->ce_type != Cft_Global &&
2933 last->ce_type != Cft_Database &&
2934 last->ce_type != colst[0]->co_type )) {
2935 rc = LDAP_CONSTRAINT_VIOLATION;
2939 #ifdef SLAPD_MODULES
2941 if ( !last || last->ce_type != Cft_Global ) {
2942 rc = LDAP_CONSTRAINT_VIOLATION;
2949 sort_attrs( e, colst, nocs );
2951 /* Parse all the values and check for simple syntax errors before
2952 * performing any set actions.
2954 switch (colst[0]->co_type) {
2956 /* The cn=schema entry is all hardcoded, so never reparse it */
2957 if (last->ce_type == Cft_Global )
2959 cfn = ch_calloc( 1, sizeof(ConfigFile) );
2965 ca.be = frontendDB; /* just to get past check_vals */
2969 if ( last->ce_type == Cft_Backend )
2970 ca.bi = last->ce_bi;
2972 type_ad = cfAd_backend;
2975 if ( last->ce_type == Cft_Database ) {
2976 ca.be = last->ce_be;
2978 type_ad = cfAd_database;
2979 /* dummy, just to get past check_vals */
2985 ca.be = last->ce_be;
2986 type_ad = cfAd_overlay;
2991 nocs = 0; /* ignored */
2994 if ( last->ce_type == Cft_Global )
2997 cfn = last->ce_private;
2998 type_ad = cfAd_include;
3000 #ifdef SLAPD_MODULES
3005 ptr = strchr( e->e_name.bv_val, '{' );
3007 rc = LDAP_NAMING_VIOLATION;
3011 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
3012 /* There is no corresponding modpath for this load? */
3014 rc = LDAP_NAMING_VIOLATION;
3017 module_path( mp->mp_path.bv_val );
3025 /* If doing an LDAPadd, check for indexed names and any necessary
3026 * renaming/renumbering. Entries that don't need indexed names are
3027 * ignored. Entries that need an indexed name and arrive without one
3028 * are assigned to the end. Entries that arrive with an index may
3029 * cause the following entries to be renumbered/bumped down.
3031 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3032 * don't allow Adding an entry with an index that's already in use.
3033 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3035 * These entries can have auto-assigned indexes (appended to the end)
3036 * but only the other types support auto-renumbering of siblings.
3038 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3042 init_config_argv( &ca );
3044 type_attr = attr_find( e->e_attrs, type_ad );
3046 rc = LDAP_OBJECT_CLASS_VIOLATION;
3049 type_ct = config_find_table( colst, nocs, type_ad );
3051 rc = LDAP_OBJECT_CLASS_VIOLATION;
3054 rc = check_vals( type_ct, &ca, type_attr, 1);
3055 if ( rc ) goto leave;
3057 for ( a=e->e_attrs; a; a=a->a_next ) {
3058 if ( a == type_attr || a == oc_at ) continue;
3059 ct = config_find_table( colst, nocs, a->a_desc );
3060 if ( !ct ) continue; /* user data? */
3061 rc = check_vals( ct, &ca, a, 1 );
3062 if ( rc ) goto leave;
3065 /* Basic syntax checks are OK. Do the actual settings. */
3067 ca.line = type_attr->a_vals[0].bv_val;
3068 if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3069 ptr = strchr( ca.line, '}' );
3070 if ( ptr ) ca.line = ptr+1;
3073 rc = config_parse_add( type_ct, &ca );
3079 for ( a=e->e_attrs; a; a=a->a_next ) {
3080 if ( a == type_attr || a == oc_at ) continue;
3081 ct = config_find_table( colst, nocs, a->a_desc );
3082 if ( !ct ) continue; /* user data? */
3083 for (i=0; a->a_vals[i].bv_val; i++) {
3084 ca.line = a->a_vals[i].bv_val;
3085 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3086 ptr = strchr( ca.line, '}' );
3087 if ( ptr ) ca.line = ptr+1;
3090 rc = config_parse_add( ct, &ca );
3098 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3099 ce->ce_parent = last;
3100 ce->ce_entry = entry_dup( e );
3101 ce->ce_entry->e_private = ce;
3102 ce->ce_type = colst[0]->co_type;
3105 ce->ce_private = ca.private;
3108 } else if ( last->ce_kids ) {
3111 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3120 if ( colst ) ch_free( colst );
3124 /* Parse an LDAP entry into config directives, then store in underlying
3128 config_back_add( Operation *op, SlapReply *rs )
3131 CfEntryInfo *ce, *last;
3134 if ( !be_isroot( op ) ) {
3135 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3139 cfb = (CfBackInfo *)op->o_bd->be_private;
3141 ldap_pvt_thread_pool_pause( &connection_pool );
3144 * 1) check for existence of entry
3145 * 2) check for sibling renumbering
3146 * 3) perform internal add
3147 * 4) store entry in underlying database
3148 * 5) perform any necessary renumbering
3150 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3151 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3152 BackendDB *be = op->o_bd;
3153 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3154 op->o_bd = &cfb->cb_db;
3155 sc.sc_next = op->o_callback;
3156 op->o_callback = ≻
3157 op->o_bd->be_add( op, rs );
3159 op->o_callback = sc.sc_next;
3164 ldap_pvt_thread_pool_resume( &connection_pool );
3167 send_ldap_result( op, rs );
3171 typedef struct delrec {
3172 struct delrec *next;
3178 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3181 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3182 int rc = LDAP_UNWILLING_TO_PERFORM;
3184 Entry *e = ce->ce_entry;
3185 Attribute *save_attrs = e->e_attrs, *oc_at;
3190 delrec *dels = NULL, *deltail = NULL;
3192 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3193 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3195 colst = count_ocs( oc_at, &nocs );
3197 e->e_attrs = attrs_dup( e->e_attrs );
3199 init_config_argv( ca );
3202 ca->private = ce->ce_private;
3203 strcpy( ca->log, "back-config" );
3205 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3206 ct = config_find_table( colst, nocs, ml->sml_desc );
3207 switch (ml->sml_op) {
3208 case LDAP_MOD_DELETE:
3209 case LDAP_MOD_REPLACE: {
3210 BerVarray vals = NULL, nvals;
3212 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3214 snprintf( ca->msg, sizeof(ca->msg),
3215 "<%s> cannot be deleted" );
3216 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3217 ml->sml_desc->ad_cname.bv_val );
3220 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3221 vals = ml->sml_values;
3222 nvals = ml->sml_nvalues;
3223 ml->sml_values = NULL;
3224 ml->sml_nvalues = NULL;
3226 /* If we're deleting by values, remember the indexes of the
3227 * values we deleted.
3229 if ( ct && ml->sml_values ) {
3231 for (i=0; ml->sml_values[i].bv_val; i++);
3232 d = ch_malloc( sizeof(delrec) + i * sizeof(int));
3243 rc = modify_delete_vindex(e, &ml->sml_mod,
3244 get_permissiveModify(op),
3245 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3246 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3247 ml->sml_values = vals;
3248 ml->sml_nvalues = nvals;
3253 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3256 case SLAP_MOD_SOFTADD: {
3257 int mop = ml->sml_op;
3259 ml->sml_op = LDAP_MOD_ADD;
3261 if ( ct->arg_type & ARG_NO_INSERT ) {
3262 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3264 for (i = 0; a->a_vals[i].bv_val; i++ );
3268 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3269 if ( ml->sml_values[i].bv_val[0] == '{' &&
3271 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3274 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3275 ml->sml_desc->ad_cname.bv_val );
3279 rc = check_vals( ct, ca, ml, 0 );
3283 rc = modify_add_values(e, &ml->sml_mod,
3284 get_permissiveModify(op),
3285 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3287 /* If value already exists, show success here
3288 * and ignore this operation down below.
3290 if ( mop == SLAP_MOD_SOFTADD ) {
3291 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3301 case LDAP_MOD_INCREMENT: /* FIXME */
3306 if(rc != LDAP_SUCCESS) break;
3309 if(rc == LDAP_SUCCESS) {
3310 /* check that the entry still obeys the schema */
3311 rc = entry_schema_check(op->o_bd, e, NULL,
3312 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3314 if ( rc == LDAP_SUCCESS ) {
3315 /* Basic syntax checks are OK. Do the actual settings. */
3316 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3317 ct = config_find_table( colst, nocs, ml->sml_desc );
3318 if ( !ct ) continue;
3320 switch (ml->sml_op) {
3321 case LDAP_MOD_DELETE:
3322 case LDAP_MOD_REPLACE: {
3323 BerVarray vals = NULL, nvals;
3327 a = attr_find( e->e_attrs, ml->sml_desc );
3329 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3330 vals = ml->sml_values;
3331 nvals = ml->sml_nvalues;
3332 ml->sml_values = NULL;
3333 ml->sml_nvalues = NULL;
3336 if ( ml->sml_values )
3339 /* If we didn't delete the whole attribute */
3340 if ( ml->sml_values && a ) {
3341 struct berval *mvals;
3344 if ( ml->sml_nvalues )
3345 mvals = ml->sml_nvalues;
3347 mvals = ml->sml_values;
3349 /* use the indexes we saved up above */
3350 for (i=0; i < d->nidx; i++) {
3351 struct berval bv = *mvals++;
3352 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3353 bv.bv_val[0] == '{' ) {
3354 ptr = strchr( bv.bv_val, '}' ) + 1;
3355 bv.bv_len -= ptr - bv.bv_val;
3358 ca->line = bv.bv_val;
3359 ca->valx = d->idx[i];
3360 rc = config_del_vals( ct, ca );
3361 if ( rc != LDAP_SUCCESS ) break;
3362 for (j=i+1; j < d->nidx; j++)
3363 if ( d->idx[j] >d->idx[i] )
3369 rc = config_del_vals( ct, ca );
3370 if ( rc ) rc = LDAP_OTHER;
3372 if ( ml->sml_values ) {
3376 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3377 ml->sml_values = vals;
3378 ml->sml_nvalues = nvals;
3380 if ( !vals || rc != LDAP_SUCCESS )
3383 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3386 for (i=0; ml->sml_values[i].bv_val; i++) {
3387 ca->line = ml->sml_values[i].bv_val;
3389 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3390 ca->line[0] == '{' ) {
3391 ptr = strchr( ca->line, '}' );
3393 ca->valx = strtol( ca->line+1, NULL, 0 );
3397 rc = config_parse_add( ct, ca );
3412 if ( rc == LDAP_SUCCESS ) {
3413 attrs_free( save_attrs );
3415 attrs_free( e->e_attrs );
3416 e->e_attrs = save_attrs;
3418 ch_free( ca->argv );
3419 if ( colst ) ch_free( colst );
3425 config_back_modify( Operation *op, SlapReply *rs )
3428 CfEntryInfo *ce, *last;
3430 ConfigArgs ca = {0};
3433 AttributeDescription *rad = NULL;
3435 if ( !be_isroot( op ) ) {
3436 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3440 cfb = (CfBackInfo *)op->o_bd->be_private;
3442 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3445 rs->sr_matched = last->ce_entry->e_name.bv_val;
3446 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3450 /* Get type of RDN */
3451 rdn = ce->ce_entry->e_nname;
3452 ptr = strchr( rdn.bv_val, '=' );
3453 rdn.bv_len = ptr - rdn.bv_val;
3454 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3456 /* Some basic validation... */
3457 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3458 /* Don't allow Modify of RDN; must use ModRdn for that. */
3459 if ( ml->sml_desc == rad ) {
3460 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3461 rs->sr_text = "Use modrdn to change the entry name";
3466 ldap_pvt_thread_pool_pause( &connection_pool );
3469 * 1) perform the Modify on the cached Entry.
3470 * 2) verify that the Entry still satisfies the schema.
3471 * 3) perform the individual config operations.
3472 * 4) store Modified entry in underlying LDIF backend.
3474 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3476 rs->sr_text = ca.msg;
3477 } else if ( cfb->cb_use_ldif ) {
3478 BackendDB *be = op->o_bd;
3479 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3480 op->o_bd = &cfb->cb_db;
3481 sc.sc_next = op->o_callback;
3482 op->o_callback = ≻
3483 op->o_bd->be_modify( op, rs );
3485 op->o_callback = sc.sc_next;
3488 ldap_pvt_thread_pool_resume( &connection_pool );
3490 send_ldap_result( op, rs );
3495 config_back_modrdn( Operation *op, SlapReply *rs )
3498 CfEntryInfo *ce, *last;
3500 if ( !be_isroot( op ) ) {
3501 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3505 cfb = (CfBackInfo *)op->o_bd->be_private;
3507 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3510 rs->sr_matched = last->ce_entry->e_name.bv_val;
3511 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3515 /* We don't allow moving objects to new parents.
3516 * Generally we only allow reordering a set of ordered entries.
3518 if ( op->orr_newSup ) {
3519 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3522 ldap_pvt_thread_pool_pause( &connection_pool );
3524 ldap_pvt_thread_pool_resume( &connection_pool );
3526 send_ldap_result( op, rs );
3531 config_back_search( Operation *op, SlapReply *rs )
3534 CfEntryInfo *ce, *last;
3537 if ( !be_isroot( op ) ) {
3538 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3542 cfb = (CfBackInfo *)op->o_bd->be_private;
3544 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3547 rs->sr_matched = last->ce_entry->e_name.bv_val;
3548 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3551 switch ( op->ors_scope ) {
3552 case LDAP_SCOPE_BASE:
3553 case LDAP_SCOPE_SUBTREE:
3554 config_send( op, rs, ce, 0 );
3557 case LDAP_SCOPE_ONELEVEL:
3558 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3559 config_send( op, rs, ce, 1 );
3564 rs->sr_err = LDAP_SUCCESS;
3566 send_ldap_result( op, rs );
3571 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3573 Entry *e = ch_calloc( 1, sizeof(Entry) );
3574 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3579 ce->ce_parent = parent;
3581 pdn = parent->ce_entry->e_nname;
3586 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3587 ber_dupbv( &e->e_nname, &e->e_name );
3596 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3597 struct berval *rdn, ConfigTable *ct, int table )
3600 struct berval ad_name;
3601 AttributeDescription *ad = NULL;
3608 val = oc->soc_cname;
3609 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass, &val, NULL );
3610 ptr = strchr(rdn->bv_val, '=');
3611 ad_name.bv_val = rdn->bv_val;
3612 ad_name.bv_len = ptr - rdn->bv_val;
3613 rc = slap_bv2ad( &ad_name, &ad, &text );
3618 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3619 attr_merge_normalize_one(e, ad, &val, NULL );
3621 for (at=oc->soc_required; at && *at; at++) {
3622 /* Skip the naming attr */
3623 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3625 for (i=0;ct[i].name;i++) {
3626 if (ct[i].ad == (*at)->sat_ad) {
3627 rc = config_get_vals(&ct[i], c);
3628 if (rc == LDAP_SUCCESS) {
3629 if ( c->rvalue_nvals )
3630 attr_merge(e, ct[i].ad, c->rvalue_vals,
3633 attr_merge_normalize(e, ct[i].ad,
3634 c->rvalue_vals, NULL);
3635 ber_bvarray_free( c->rvalue_nvals );
3636 ber_bvarray_free( c->rvalue_vals );
3643 for (at=oc->soc_allowed; at && *at; at++) {
3644 /* Skip the naming attr */
3645 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3647 for (i=0;ct[i].name;i++) {
3648 if (ct[i].ad == (*at)->sat_ad) {
3649 rc = config_get_vals(&ct[i], c);
3650 if (rc == LDAP_SUCCESS) {
3651 if ( c->rvalue_nvals )
3652 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3654 attr_merge_normalize(e, ct[i].ad, c->rvalue_vals, NULL);
3655 ber_bvarray_free( c->rvalue_nvals );
3656 ber_bvarray_free( c->rvalue_vals );
3664 if ( table == BI_TABLE )
3665 ct = c->bi->bi_cf_table;
3667 ct = c->be->be_cf_table;
3668 for (;ct && ct->name;ct++) {
3669 if (!ct->ad) continue;
3670 rc = config_get_vals(ct, c);
3671 if (rc == LDAP_SUCCESS) {
3672 if ( c->rvalue_nvals )
3673 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3675 attr_merge_normalize(e, ct->ad, c->rvalue_vals, NULL);
3679 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3680 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3682 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3688 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3689 Operation *op, SlapReply *rs )
3692 ConfigFile *cf = c->private;
3693 CfEntryInfo *ce, *ceprev;
3697 if ( ceparent->ce_kids ) {
3698 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3699 ceprev = ceprev->ce_sibs );
3702 for (; cf; cf=cf->c_sibs, c->depth++) {
3703 c->value_dn.bv_val = c->log;
3704 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3709 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3711 ptr = strchr( bv.bv_val, '.' );
3713 bv.bv_len = ptr - bv.bv_val;
3714 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3715 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3717 c->value_dn.bv_len += bv.bv_len;
3718 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3720 e = config_alloc_entry( ceparent, &c->value_dn );
3722 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3723 c->bi->bi_cf_table, NO_TABLE );
3725 ce->ce_private = cf;
3726 ce->ce_type = Cft_Schema;
3729 op->o_bd->be_add( op, rs );
3732 if ( !ceparent->ce_kids ) {
3733 ceparent->ce_kids = ce;
3735 ceprev->ce_sibs = ce;
3739 c->private = cf->c_kids;
3740 config_build_schema_inc( c, ceparent, op, rs );
3745 static CfEntryInfo *
3746 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3747 Operation *op, SlapReply *rs )
3751 ConfigFile *cf = c->private;
3752 CfEntryInfo *ce, *ceprev;
3754 if ( ceparent->ce_kids ) {
3755 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3756 ceprev = ceprev->ce_sibs );
3759 for (i=0; cf; cf=cf->c_sibs, i++) {
3760 c->value_dn.bv_val = c->log;
3761 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3762 e = config_alloc_entry( ceparent, &c->value_dn );
3764 config_build_entry( c, e, cfOc_include, &c->value_dn,
3765 c->bi->bi_cf_table, NO_TABLE );
3768 op->o_bd->be_add( op, rs );
3771 ce->ce_private = cf;
3772 ce->ce_type = Cft_Include;
3774 if ( !ceparent->ce_kids ) {
3775 ceparent->ce_kids = ce;
3777 ceprev->ce_sibs = ce;
3781 c->private = cf->c_kids;
3782 config_build_includes( c, ce, op, rs );
3788 #ifdef SLAPD_MODULES
3790 static CfEntryInfo *
3791 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3792 Operation *op, SlapReply *rs )
3796 CfEntryInfo *ce, *ceprev;
3799 if ( ceparent->ce_kids ) {
3800 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3801 ceprev = ceprev->ce_sibs );
3804 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3805 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3807 c->value_dn.bv_val = c->log;
3808 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3809 e = config_alloc_entry( ceparent, &c->value_dn );
3811 ce->ce_type = Cft_Include;
3813 ce->ce_private = mp;
3814 config_build_entry( c, e, cfOc_module, &c->value_dn,
3815 c->bi->bi_cf_table, NO_TABLE );
3818 op->o_bd->be_add( op, rs );
3821 if ( !ceparent->ce_kids ) {
3822 ceparent->ce_kids = ce;
3824 ceprev->ce_sibs = ce;
3833 config_back_db_open( BackendDB *be )
3835 CfBackInfo *cfb = be->be_private;
3838 CfEntryInfo *ce, *ceparent, *ceprev;
3844 Connection conn = {0};
3845 char opbuf[OPERATION_BUFFER_SIZE];
3847 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3848 SlapReply rs = {REP_RESULT};
3850 /* If we read the config from back-ldif, nothing to do here */
3851 if ( cfb->cb_got_ldif )
3854 if ( cfb->cb_use_ldif ) {
3855 op = (Operation *)opbuf;
3856 connection_fake_init( &conn, op, cfb );
3858 op->o_dn = be->be_rootdn;
3859 op->o_ndn = be->be_rootndn;
3861 op->o_tag = LDAP_REQ_ADD;
3862 op->o_callback = &cb;
3863 op->o_bd = &cfb->cb_db;
3868 /* create root of tree */
3870 e = config_alloc_entry( NULL, &rdn );
3872 ce->ce_type = Cft_Global;
3876 c.private = cfb->cb_config;
3877 ct = c.bi->bi_cf_table;
3878 ce->ce_private = c.private;
3879 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
3882 op->o_bd->be_add( op, &rs );
3889 /* Create schema nodes... cn=schema will contain the hardcoded core
3890 * schema, read-only. Child objects will contain runtime loaded schema
3894 e = config_alloc_entry( ceparent, &rdn );
3896 ce->ce_type = Cft_Schema;
3898 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
3901 op->o_bd->be_add( op, &rs );
3903 if ( !ceparent->ce_kids ) {
3904 ceparent->ce_kids = ce;
3906 ceprev->ce_sibs = ce;
3910 /* Create includeFile nodes and schema nodes for included schema... */
3911 if ( cfb->cb_config->c_kids ) {
3913 c.private = cfb->cb_config->c_kids;
3914 config_build_schema_inc( &c, ce, op, &rs );
3915 c.private = cfb->cb_config->c_kids;
3916 ceprev = config_build_includes( &c, ceparent, op, &rs );
3919 #ifdef SLAPD_MODULES
3920 /* Create Module nodes... */
3921 if ( modpaths.mp_loads ) {
3922 ceprev = config_build_modules( &c, ceparent, op, &rs );
3926 /* Create backend nodes. Skip if they don't provide a cf_table.
3927 * There usually aren't any of these.
3931 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3932 if (!bi->bi_cf_table) continue;
3933 if (!bi->bi_private) continue;
3936 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3937 e = config_alloc_entry( ceparent, &rdn );
3939 ce->ce_type = Cft_Backend;
3942 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3945 op->o_bd->be_add( op, &rs );
3947 if ( !ceparent->ce_kids ) {
3948 ceparent->ce_kids = ce;
3950 ceprev->ce_sibs = ce;
3955 /* Create database nodes... */
3957 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3958 slap_overinfo *oi = NULL;
3965 if ( overlay_is_over( bptr )) {
3966 oi = bptr->bd_info->bi_private;
3972 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3974 e = config_alloc_entry( ceparent, &rdn );
3978 ce->ce_type = Cft_Database;
3981 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3984 op->o_bd->be_add( op, &rs );
3986 if ( !ceparent->ce_kids ) {
3987 ceparent->ce_kids = ce;
3989 ceprev->ce_sibs = ce;
3992 /* Iterate through overlays */
3996 CfEntryInfo *opar = ce, *oprev = NULL;
3999 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
4001 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
4002 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
4003 oe = config_alloc_entry( opar, &rdn );
4007 ce->ce_type = Cft_Overlay;
4010 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
4013 op->o_bd->be_add( op, &rs );
4015 if ( !opar->ce_kids ) {
4018 oprev->ce_sibs = ce;
4029 config_back_db_destroy( Backend *be )
4031 free( be->be_private );
4036 config_back_db_init( Backend *be )
4041 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4042 cfb->cb_config = &cf_prv;
4043 be->be_private = cfb;
4045 ber_dupbv( &be->be_rootdn, &config_rdn );
4046 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4047 ber_dupbv( &dn, &be->be_rootdn );
4048 ber_bvarray_add( &be->be_suffix, &dn );
4049 ber_dupbv( &dn, &be->be_rootdn );
4050 ber_bvarray_add( &be->be_nsuffix, &dn );
4052 /* Hide from namingContexts */
4053 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4059 config_back_destroy( BackendInfo *bi )
4061 ldif_must_b64_encode_release();
4066 config_tool_entry_open( BackendDB *be, int mode )
4068 CfBackInfo *cfb = be->be_private;
4069 BackendInfo *bi = cfb->cb_db.bd_info;
4071 if ( bi && bi->bi_tool_entry_open )
4072 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
4079 config_tool_entry_close( BackendDB *be )
4081 CfBackInfo *cfb = be->be_private;
4082 BackendInfo *bi = cfb->cb_db.bd_info;
4084 if ( bi && bi->bi_tool_entry_close )
4085 return bi->bi_tool_entry_close( &cfb->cb_db );
4091 config_tool_entry_first( BackendDB *be )
4093 CfBackInfo *cfb = be->be_private;
4094 BackendInfo *bi = cfb->cb_db.bd_info;
4096 if ( bi && bi->bi_tool_entry_first )
4097 return bi->bi_tool_entry_first( &cfb->cb_db );
4103 config_tool_entry_next( BackendDB *be )
4105 CfBackInfo *cfb = be->be_private;
4106 BackendInfo *bi = cfb->cb_db.bd_info;
4108 if ( bi && bi->bi_tool_entry_next )
4109 return bi->bi_tool_entry_next( &cfb->cb_db );
4115 config_tool_entry_get( BackendDB *be, ID id )
4117 CfBackInfo *cfb = be->be_private;
4118 BackendInfo *bi = cfb->cb_db.bd_info;
4120 if ( bi && bi->bi_tool_entry_get )
4121 return bi->bi_tool_entry_get( &cfb->cb_db, id );
4127 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
4129 CfBackInfo *cfb = be->be_private;
4130 BackendInfo *bi = cfb->cb_db.bd_info;
4132 if ( bi && bi->bi_tool_entry_put &&
4133 config_add_internal( cfb, e, NULL, NULL ) == 0 )
4134 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
4141 AttributeDescription **desc;
4143 { "backend", &cfAd_backend },
4144 { "database", &cfAd_database },
4145 { "include", &cfAd_include },
4146 { "overlay", &cfAd_overlay },
4151 * add / delete: all types that may be added or deleted must use an
4152 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4153 * should automatically renumber the index of any siblings as needed,
4154 * so that no gaps in the numbering sequence exist after the add/delete
4156 * What can be added:
4158 * backend objects for backend-specific config directives
4162 * delete: probably no support this time around.
4164 * modrdn: generally not done. Will be invoked automatically by add/
4165 * delete to update numbering sequence. Perform as an explicit operation
4166 * so that the renumbering effect may be replicated. Subtree rename must
4167 * be supported, since renumbering a database will affect all its child
4170 * modify: must be fully supported.
4174 config_back_initialize( BackendInfo *bi )
4176 ConfigTable *ct = config_back_cf_table;
4179 AttributeDescription *ad = NULL;
4181 static char *controls[] = {
4182 LDAP_CONTROL_MANAGEDSAIT,
4186 bi->bi_controls = controls;
4191 bi->bi_destroy = config_back_destroy;
4193 bi->bi_db_init = config_back_db_init;
4194 bi->bi_db_config = 0;
4195 bi->bi_db_open = config_back_db_open;
4196 bi->bi_db_close = 0;
4197 bi->bi_db_destroy = config_back_db_destroy;
4199 bi->bi_op_bind = config_back_bind;
4200 bi->bi_op_unbind = 0;
4201 bi->bi_op_search = config_back_search;
4202 bi->bi_op_compare = 0;
4203 bi->bi_op_modify = config_back_modify;
4204 bi->bi_op_modrdn = config_back_modrdn;
4205 bi->bi_op_add = config_back_add;
4206 bi->bi_op_delete = 0;
4207 bi->bi_op_abandon = 0;
4209 bi->bi_extended = 0;
4211 bi->bi_chk_referrals = 0;
4213 #ifdef SLAP_OVERLAY_ACCESS
4214 bi->bi_access_allowed = slap_access_always_allowed;
4215 #endif /* SLAP_OVERLAY_ACCESS */
4217 bi->bi_connection_init = 0;
4218 bi->bi_connection_destroy = 0;
4220 bi->bi_tool_entry_open = config_tool_entry_open;
4221 bi->bi_tool_entry_close = config_tool_entry_close;
4222 bi->bi_tool_entry_first = config_tool_entry_first;
4223 bi->bi_tool_entry_next = config_tool_entry_next;
4224 bi->bi_tool_entry_get = config_tool_entry_get;
4225 bi->bi_tool_entry_put = config_tool_entry_put;
4228 for (i=0; OidMacros[i].name; i++ ) {
4229 argv[1] = OidMacros[i].name;
4230 argv[2] = OidMacros[i].oid;
4231 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4234 bi->bi_cf_table = ct;
4236 i = config_register_schema( ct, cf_ocs );
4239 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4240 * basically, we don't care if it fails */
4241 i = slap_str2ad( "olcRootPW", &ad, &text );
4243 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4244 "warning, unable to get \"olcRootPW\" "
4245 "attribute description: %d: %s\n",
4248 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4249 ad->ad_type->sat_oid );
4252 /* set up the notable AttributeDescriptions */
4254 for (;ct->name;ct++) {
4255 if (strcmp(ct->name, ads[i].name)) continue;
4256 *ads[i].desc = ct->ad;
4258 if (!ads[i].name) break;