1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 static struct berval config_rdn = BER_BVC("cn=config");
41 static struct berval schema_rdn = BER_BVC("cn=schema");
46 typedef struct modpath_s {
47 struct modpath_s *mp_next;
48 struct berval mp_path;
52 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
55 typedef struct ConfigFile {
56 struct ConfigFile *c_sibs;
57 struct ConfigFile *c_kids;
59 AttributeType *c_at_head, *c_at_tail;
60 ContentRule *c_cr_head, *c_cr_tail;
61 ObjectClass *c_oc_head, *c_oc_tail;
62 OidMacro *c_om_head, *c_om_tail;
67 ConfigFile *cb_config;
69 BackendDB cb_db; /* underlying database */
74 /* These do nothing in slapd, they're kept only to make them
77 static char *replica_pidFile, *replica_argsFile;
78 static int replicationInterval;
80 static char *passwd_salt;
81 static char *logfileName;
82 #ifdef SLAP_AUTH_REWRITE
83 static BerVarray authz_rewrites;
86 static struct berval cfdir;
89 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
92 static ConfigFile *cfn;
94 static Avlnode *CfOcTree;
96 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
97 SlapReply *rs, int *renumber );
99 static ConfigDriver config_fname;
100 static ConfigDriver config_cfdir;
101 static ConfigDriver config_generic;
102 static ConfigDriver config_search_base;
103 static ConfigDriver config_passwd_hash;
104 static ConfigDriver config_schema_dn;
105 static ConfigDriver config_sizelimit;
106 static ConfigDriver config_timelimit;
107 static ConfigDriver config_overlay;
108 static ConfigDriver config_suffix;
109 static ConfigDriver config_rootdn;
110 static ConfigDriver config_rootpw;
111 static ConfigDriver config_restrict;
112 static ConfigDriver config_allows;
113 static ConfigDriver config_disallows;
114 static ConfigDriver config_requires;
115 static ConfigDriver config_security;
116 static ConfigDriver config_referral;
117 static ConfigDriver config_loglevel;
118 static ConfigDriver config_replica;
119 static ConfigDriver config_updatedn;
120 static ConfigDriver config_updateref;
121 static ConfigDriver config_include;
123 static ConfigDriver config_tls_option;
124 static ConfigDriver config_tls_config;
126 extern ConfigDriver syncrepl_config;
172 static OidRec OidMacros[] = {
173 /* OpenLDAProot:666.11.1 */
174 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
175 { "OLcfgAt", "OLcfg:3" },
176 { "OLcfgGlAt", "OLcfgAt:0" },
177 { "OLcfgBkAt", "OLcfgAt:1" },
178 { "OLcfgDbAt", "OLcfgAt:2" },
179 { "OLcfgOvAt", "OLcfgAt:3" },
180 { "OLcfgOc", "OLcfg:4" },
181 { "OLcfgGlOc", "OLcfgOc:0" },
182 { "OLcfgBkOc", "OLcfgOc:1" },
183 { "OLcfgDbOc", "OLcfgOc:2" },
184 { "OLcfgOvOc", "OLcfgOc:3" },
185 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
186 { "OMsInteger", "OMsyn:27" },
187 { "OMsBoolean", "OMsyn:7" },
188 { "OMsDN", "OMsyn:12" },
189 { "OMsDirectoryString", "OMsyn:15" },
190 { "OMsOctetString", "OMsyn:40" },
195 * OLcfg{Bk|Db}{Oc|At}:0 -> common
196 * OLcfg{Bk|Db}{Oc|At}:1 -> bdb
197 * OLcfg{Bk|Db}{Oc|At}:2 -> ldif
198 * OLcfg{Bk|Db}{Oc|At}:3 -> ldap?
201 /* alphabetical ordering */
203 static ConfigTable config_back_cf_table[] = {
204 /* This attr is read-only */
205 { "", "", 0, 0, 0, ARG_MAGIC,
206 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
207 "DESC 'File for slapd configuration directives' "
208 "EQUALITY caseIgnoreMatch "
209 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
210 { "", "", 0, 0, 0, ARG_MAGIC,
211 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
212 "DESC 'Directory for slapd configuration backend' "
213 "EQUALITY caseIgnoreMatch "
214 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
215 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
216 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
217 "DESC 'Access Control List' "
218 "EQUALITY caseIgnoreMatch "
219 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
220 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
221 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
222 "DESC 'Allowed set of deprecated features' "
223 "EQUALITY caseIgnoreMatch "
224 "SYNTAX OMsDirectoryString )", NULL, NULL },
225 { "argsfile", "file", 2, 2, 0, ARG_STRING,
226 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
227 "DESC 'File for slapd command line options' "
228 "EQUALITY caseIgnoreMatch "
229 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
230 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
231 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
232 "EQUALITY caseIgnoreMatch "
233 "SYNTAX OMsDirectoryString )", NULL, NULL },
234 { "attribute", "attribute", 2, 0, 9,
235 ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT,
236 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
237 "DESC 'OpenLDAP attributeTypes' "
238 "EQUALITY caseIgnoreMatch "
239 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
241 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
242 #ifdef SLAP_AUTH_REWRITE
243 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
247 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
248 "EQUALITY caseIgnoreMatch "
249 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
250 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
251 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
252 "EQUALITY caseIgnoreMatch "
253 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
254 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
255 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
256 "EQUALITY caseIgnoreMatch "
257 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
258 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
259 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
260 "DESC 'A type of backend' "
261 "EQUALITY caseIgnoreMatch "
262 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
264 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
265 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
266 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
267 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
268 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
269 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
270 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
271 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
272 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
273 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
274 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
275 "DESC 'The backend type for a database instance' "
276 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
277 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
278 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
279 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
280 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
281 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
282 "EQUALITY caseIgnoreMatch "
283 "SYNTAX OMsDirectoryString )", NULL, NULL },
284 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
285 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
286 "DESC 'OpenLDAP DIT content rules' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
290 { "gentlehup", "on|off", 2, 2, 0,
292 ARG_ON_OFF, &global_gentlehup,
296 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
297 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
298 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
299 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
300 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
301 { "include", "file", 2, 2, 0, ARG_MAGIC,
302 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
303 "SUP labeledURI )", NULL, NULL },
304 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
305 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
306 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
307 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
308 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
309 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
310 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
311 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
312 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
313 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
314 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
315 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
316 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
317 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
318 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
319 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
320 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
321 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
322 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
323 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
324 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
325 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
326 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
327 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
328 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
329 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
330 "SYNTAX OMsDirectoryString )", NULL, NULL },
331 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
332 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
333 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
334 { "moduleload", "file", 2, 0, 0,
336 ARG_MAGIC|CFG_MODLOAD, &config_generic,
340 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
341 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
342 { "modulepath", "path", 2, 2, 0,
344 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
348 "( OLcfgGlAt:31 NAME 'olcModulePath' "
349 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
350 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT,
351 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
352 "DESC 'OpenLDAP object classes' "
353 "EQUALITY caseIgnoreMatch "
354 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
356 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
357 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
358 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
359 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
360 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
361 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
362 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
363 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
364 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
365 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
366 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
367 "SYNTAX OMsDirectoryString )", NULL, NULL },
368 { "pidfile", "file", 2, 2, 0, ARG_STRING,
369 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
370 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
371 { "plugin", NULL, 0, 0, 0,
373 ARG_MAGIC|CFG_PLUGIN, &config_generic,
377 "( OLcfgGlAt:38 NAME 'olcPlugin' "
378 "SYNTAX OMsDirectoryString )", NULL, NULL },
379 { "pluginlog", "filename", 2, 2, 0,
381 ARG_STRING, &slapi_log_file,
385 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
386 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
387 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
388 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
389 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
390 { "referral", "url", 2, 2, 0, ARG_MAGIC,
391 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
392 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
393 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
394 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
395 "SUP labeledURI )", NULL, NULL },
396 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
397 &replica_argsFile, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
398 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
399 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
400 &replica_pidFile, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
401 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
402 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
403 &replicationInterval, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
404 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
405 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
406 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
407 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
408 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
409 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
410 "SYNTAX OMsDirectoryString )", NULL, NULL },
411 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
412 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
413 "SYNTAX OMsDirectoryString )", NULL, NULL },
414 { "reverse-lookup", "on|off", 2, 2, 0,
415 #ifdef SLAPD_RLOOKUPS
416 ARG_ON_OFF, &use_reverse_lookup,
420 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
421 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
422 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
423 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
424 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
425 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
426 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
427 "SYNTAX OMsDirectoryString )", NULL, NULL },
428 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
429 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
430 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
431 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
432 &config_generic, NULL, NULL, NULL },
433 { "sasl-host", "host", 2, 2, 0,
434 #ifdef HAVE_CYRUS_SASL
435 ARG_STRING|ARG_UNIQUE, &global_host,
439 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
440 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
441 { "sasl-realm", "realm", 2, 2, 0,
442 #ifdef HAVE_CYRUS_SASL
443 ARG_STRING|ARG_UNIQUE, &global_realm,
447 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
448 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
449 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
450 &config_generic, NULL, NULL, NULL },
451 { "sasl-secprops", "properties", 2, 2, 0,
452 #ifdef HAVE_CYRUS_SASL
453 ARG_MAGIC|CFG_SASLSECP, &config_generic,
457 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
458 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
459 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
460 &config_generic, NULL, NULL, NULL },
461 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
462 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
463 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
464 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
465 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
466 "SYNTAX OMsDirectoryString )", NULL, NULL },
467 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
468 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
469 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
470 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
471 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
472 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
473 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
474 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
475 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
476 { "srvtab", "file", 2, 2, 0,
477 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
478 ARG_STRING, &ldap_srvtab,
482 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
483 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
484 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
485 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
486 "SYNTAX OMsDN )", NULL, NULL },
487 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
488 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
489 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
490 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
491 &config_generic, "( OLcfgGlAt:66 NAME 'olcThreads' "
492 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
493 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
494 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
495 "SYNTAX OMsDirectoryString )", NULL, NULL },
496 { "TLSCACertificateFile", NULL, 0, 0, 0,
498 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
502 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
503 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
504 { "TLSCACertificatePath", NULL, 0, 0, 0,
506 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
510 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
511 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
512 { "TLSCertificateFile", NULL, 0, 0, 0,
514 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
518 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
519 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
520 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
522 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
526 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
527 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
528 { "TLSCipherSuite", NULL, 0, 0, 0,
530 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
534 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
535 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
536 { "TLSCRLCheck", NULL, 0, 0, 0,
537 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
538 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
542 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
543 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
544 { "TLSRandFile", NULL, 0, 0, 0,
546 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
550 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
551 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
552 { "TLSVerifyClient", NULL, 0, 0, 0,
554 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
558 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
559 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
560 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
561 NULL, NULL, NULL, NULL },
562 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
563 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
564 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
565 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
566 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
567 "SUP labeledURI )", NULL, NULL },
568 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
569 NULL, NULL, NULL, NULL }
572 /* Routines to check if a child can be added to this type */
573 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
574 cfAddBackend, cfAddModule, cfAddOverlay;
576 #define CFOC_GLOBAL cf_ocs[1]
577 #define CFOC_SCHEMA cf_ocs[2]
578 #define CFOC_BACKEND cf_ocs[3]
579 #define CFOC_DATABASE cf_ocs[4]
580 #define CFOC_OVERLAY cf_ocs[5]
581 #define CFOC_INCLUDE cf_ocs[6]
582 #define CFOC_MODULE cf_ocs[7]
584 static ConfigOCs cf_ocs[] = {
587 "DESC 'OpenLDAP configuration object' "
588 "ABSTRACT SUP top )", Cft_Abstract, NULL },
591 "DESC 'OpenLDAP Global configuration options' "
592 "SUP olcConfig STRUCTURAL "
593 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
594 "olcAttributeOptions $ olcAuthIDRewrite $ "
595 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
596 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
597 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
598 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
599 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
601 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
602 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
603 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
604 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
605 "olcRootDSE $ olcRootPW $ "
606 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
607 "olcSecurity $ olcSizeLimit $ "
608 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
609 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
610 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
611 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
612 "olcTLSRandFile $ olcTLSVerifyClient $ "
613 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
614 "olcDitContentRules ) )", Cft_Global },
616 "NAME 'olcSchemaConfig' "
617 "DESC 'OpenLDAP schema object' "
618 "SUP olcConfig STRUCTURAL "
619 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
620 "olcObjectClasses $ olcDitContentRules ) )",
621 Cft_Schema, NULL, cfAddSchema },
623 "NAME 'olcBackendConfig' "
624 "DESC 'OpenLDAP Backend-specific options' "
625 "SUP olcConfig STRUCTURAL "
626 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
628 "NAME 'olcDatabaseConfig' "
629 "DESC 'OpenLDAP Database-specific options' "
630 "SUP olcConfig STRUCTURAL "
632 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
633 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
634 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
635 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
636 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
637 Cft_Database, NULL, cfAddDatabase },
639 "NAME 'olcOverlayConfig' "
640 "DESC 'OpenLDAP Overlay-specific options' "
641 "SUP olcConfig STRUCTURAL "
642 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
644 "NAME 'olcIncludeFile' "
645 "DESC 'OpenLDAP configuration include file' "
646 "SUP olcConfig STRUCTURAL "
648 "MAY ( cn $ olcRootDSE ) )",
649 Cft_Include, NULL, cfAddInclude },
652 "NAME 'olcModuleList' "
653 "DESC 'OpenLDAP dynamic module info' "
654 "SUP olcConfig STRUCTURAL "
655 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
656 Cft_Module, NULL, cfAddModule },
662 config_generic(ConfigArgs *c) {
666 if ( c->op == SLAP_CONFIG_EMIT ) {
670 c->value_int = ldap_pvt_thread_get_concurrency();
673 c->value_int = connection_pool_max;
677 c->value_string = ch_strdup( passwd_salt );
682 if ( c->be->be_limits ) {
687 for ( i=0; c->be->be_limits[i]; i++ ) {
688 bv.bv_len = sprintf( buf, IFMT, i );
689 bv.bv_val = buf+bv.bv_len;
690 limits_unparse( c->be->be_limits[i], &bv );
691 bv.bv_len += bv.bv_val - buf;
693 value_add_one( &c->rvalue_vals, &bv );
696 if ( !c->rvalue_vals ) rc = 1;
699 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
700 SLAP_RESTRICT_OP_WRITES;
703 c->value_string = ch_strdup( slap_sasl_getpolicy());
706 slap_sasl_regexp_unparse( &c->rvalue_vals );
707 if ( !c->rvalue_vals ) rc = 1;
709 #ifdef HAVE_CYRUS_SASL
711 struct berval bv = BER_BVNULL;
712 slap_sasl_secprops_unparse( &bv );
713 if ( !BER_BVISNULL( &bv )) {
714 ber_bvarray_add( &c->rvalue_vals, &bv );
722 c->value_int = c->be->be_max_deref_depth;
725 ConfigFile *cf = c->private;
727 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
728 else if ( cf->c_om_head )
729 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
731 if ( !c->rvalue_vals )
736 ConfigFile *cf = c->private;
738 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
739 else if ( cf->c_oc_head )
740 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
742 if ( !c->rvalue_vals )
747 ConfigFile *cf = c->private;
749 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
750 else if ( cf->c_at_head )
751 at_unparse( &c->rvalue_vals, cf->c_at_head,
753 if ( !c->rvalue_vals )
758 ConfigFile *cf = c->private;
760 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
761 else if ( cf->c_cr_head )
762 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
764 if ( !c->rvalue_vals )
771 char *src, *dst, ibuf[11];
772 struct berval bv, abv;
773 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
774 abv.bv_len = sprintf( ibuf, IFMT, i );
775 acl_unparse( a, &bv );
776 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
777 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
778 /* Turn TAB / EOL into plain space */
779 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
780 if (isspace(*src)) *dst++ = ' ';
784 if (dst[-1] == ' ') {
788 abv.bv_len = dst - abv.bv_val;
789 ber_bvarray_add( &c->rvalue_vals, &abv );
795 if ( c->be->be_replogfile )
796 c->value_string = ch_strdup( c->be->be_replogfile );
799 ConfigFile *cf = c->private;
800 if ( cf->c_dseFiles ) {
801 value_add( &c->rvalue_vals, cf->c_dseFiles );
809 c->value_string = ch_strdup( logfileName );
814 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
816 case CFG_SSTR_IF_MAX:
817 c->value_int = index_substr_if_maxlen;
819 case CFG_SSTR_IF_MIN:
820 c->value_int = index_substr_if_minlen;
824 ModPaths *mp = c->private;
827 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
830 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
831 mp->mp_loads[i].bv_val );
832 value_add_one( &c->rvalue_vals, &bv );
836 rc = c->rvalue_vals ? 0 : 1;
840 ModPaths *mp = c->private;
841 if ( !BER_BVISNULL( &mp->mp_path ))
842 value_add_one( &c->rvalue_vals, &mp->mp_path );
844 rc = c->rvalue_vals ? 0 : 1;
850 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
851 if ( !c->rvalue_vals ) rc = 1;
854 #ifdef SLAP_AUTH_REWRITE
856 if ( authz_rewrites ) {
857 struct berval bv, idx;
862 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
863 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
864 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
865 bv.bv_val = ch_malloc( bv.bv_len + 1 );
866 strcpy( bv.bv_val, idx.bv_val );
867 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
868 ber_bvarray_add( &c->rvalue_vals, &bv );
871 if ( !c->rvalue_vals ) rc = 1;
878 } else if ( c->op == LDAP_MOD_DELETE ) {
881 /* single-valued attrs, no-ops */
889 case CFG_SSTR_IF_MAX:
890 case CFG_SSTR_IF_MIN:
893 /* no-ops, requires slapd restart */
898 sprintf(c->log, "change requires slapd restart");
902 ch_free( passwd_salt );
907 ch_free( c->be->be_replogfile );
908 c->be->be_replogfile = NULL;
912 ch_free( logfileName );
919 if ( c->be == frontendDB )
922 end = frontendDB->be_acl;
923 acl_destroy( c->be->be_acl, end );
925 AccessControl **prev, *a;
927 for (i=0, prev = &c->be->be_acl; i < c->valx;
939 /* FIXME: there is no limits_free function */
941 /* FIXME: there is no ad_option_free function */
943 /* FIXME: there is no way to remove attributes added by
957 p = strchr(c->line,'(' /*')'*/);
961 if(!(c->bi = backend_info(c->argv[1]))) {
962 sprintf( c->msg, "<%s> failed init", c->argv[0] );
963 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
964 c->log, c->msg, c->argv[1] );
971 /* NOTE: config is always the first backend!
973 if ( !strcasecmp( c->argv[1], "config" )) {
974 c->be = LDAP_STAILQ_FIRST(&backendDB);
975 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
978 c->be = backend_db_init(c->argv[1]);
980 sprintf( c->msg, "<%s> failed init", c->argv[0] );
981 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
982 c->log, c->msg, c->argv[1] );
989 ldap_pvt_thread_set_concurrency(c->value_int);
993 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
994 connection_pool_max = c->value_int; /* save for reference */
998 if ( passwd_salt ) ch_free( passwd_salt );
999 passwd_salt = c->value_string;
1000 lutil_salt_format(passwd_salt);
1004 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1010 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1012 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1016 ch_free(c->value_string);
1017 if (slap_sasl_setpolicy( c->argv[1] )) {
1018 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1019 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1020 c->log, c->msg, c->argv[1] );
1026 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1030 #ifdef HAVE_CYRUS_SASL
1033 char *txt = slap_sasl_secprops( c->argv[1] );
1035 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1037 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1045 c->be->be_max_deref_depth = c->value_int;
1051 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1053 if (!cfn->c_om_head) cfn->c_om_head = om;
1054 cfn->c_om_tail = om;
1061 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1062 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1063 cfn->c_oc_tail = oc;
1070 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1071 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1072 cfn->c_cr_tail = cr;
1079 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1080 if (!cfn->c_at_head) cfn->c_at_head = at;
1081 cfn->c_at_tail = at;
1086 ad_define_option(NULL, NULL, 0);
1087 for(i = 1; i < c->argc; i++)
1088 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1093 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1097 if(SLAP_MONITOR(c->be)) {
1098 Debug(LDAP_DEBUG_ANY, "%s: "
1099 "\"replogfile\" should not be used "
1100 "inside monitor database\n",
1102 return(0); /* FIXME: should this be an error? */
1105 c->be->be_replogfile = c->value_string;
1109 if(read_root_dse_file(c->argv[1])) {
1110 sprintf( c->msg, "<%s> could not read file", c->argv[0] );
1111 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1112 c->log, c->msg, c->argv[1] );
1117 ber_str2bv( c->argv[1], 0, 1, &bv );
1118 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1124 if ( logfileName ) ch_free( logfileName );
1125 logfileName = c->value_string;
1126 logfile = fopen(logfileName, "w");
1127 if(logfile) lutil_debug_file(logfile);
1131 if(SLAP_NOLASTMODCMD(c->be)) {
1132 sprintf( c->msg, "<%s> not available for %s database",
1133 c->argv[0], c->be->bd_info->bi_type );
1134 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1135 c->log, c->msg, 0 );
1139 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1141 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1144 case CFG_SSTR_IF_MAX:
1145 if (c->value_int < index_substr_if_minlen) {
1146 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1147 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1148 c->log, c->msg, c->value_int );
1151 index_substr_if_maxlen = c->value_int;
1154 case CFG_SSTR_IF_MIN:
1155 if (c->value_int > index_substr_if_maxlen) {
1156 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1157 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1158 c->log, c->msg, c->value_int );
1161 index_substr_if_minlen = c->value_int;
1164 #ifdef SLAPD_MODULES
1166 /* If we're just adding a module on an existing modpath,
1167 * make sure we've selected the current path.
1169 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1170 modcur = c->private;
1171 /* This should never fail */
1172 if ( module_path( modcur->mp_path.bv_val )) {
1173 sprintf( c->msg, "<%s> module path no longer valid",
1175 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1176 c->log, c->msg, modcur->mp_path.bv_val );
1180 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1182 /* Record this load on the current path */
1186 if ( c->op == SLAP_CONFIG_ADD ) {
1187 ptr = c->line + STRLENOF("moduleload");
1188 while (!isspace(*ptr)) ptr++;
1189 while (isspace(*ptr)) ptr++;
1193 ber_str2bv(ptr, 0, 1, &bv);
1194 ber_bvarray_add( &modcur->mp_loads, &bv );
1199 if(module_path(c->argv[1])) return(1);
1200 /* Record which path was used with each module */
1204 if (!modpaths.mp_loads) {
1207 mp = ch_malloc( sizeof( ModPaths ));
1208 modlast->mp_next = mp;
1210 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1212 mp->mp_loads = NULL;
1223 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1225 slapi_plugins_used++;
1229 #ifdef SLAP_AUTH_REWRITE
1234 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1237 if ( c->argc > 1 ) {
1240 /* quote all args but the first */
1241 line = ldap_charray2str( c->argv, "\" \"" );
1242 ber_str2bv( line, 0, 0, &bv );
1243 s = strchr( bv.bv_val, '"' );
1244 assert( s != NULL );
1245 /* move the trailing quote of argv[0] to the end */
1246 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1247 bv.bv_val[ bv.bv_len - 1 ] = '"';
1250 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1253 ber_bvarray_add( &authz_rewrites, &bv );
1260 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1261 "%s: unknown CFG_TYPE %d"
1262 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1263 c->log, c->type, 0 );
1264 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1266 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1274 config_fname(ConfigArgs *c) {
1275 if(c->op == SLAP_CONFIG_EMIT) {
1277 ConfigFile *cf = c->private;
1278 value_add_one( &c->rvalue_vals, &cf->c_file );
1287 config_cfdir(ConfigArgs *c) {
1288 if(c->op == SLAP_CONFIG_EMIT) {
1289 if ( !BER_BVISEMPTY( &cfdir )) {
1290 value_add_one( &c->rvalue_vals, &cfdir );
1299 config_search_base(ConfigArgs *c) {
1300 if(c->op == SLAP_CONFIG_EMIT) {
1302 if (!BER_BVISEMPTY(&default_search_base)) {
1303 value_add_one(&c->rvalue_vals, &default_search_base);
1304 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1308 } else if( c->op == LDAP_MOD_DELETE ) {
1309 ch_free( default_search_base.bv_val );
1310 ch_free( default_search_nbase.bv_val );
1311 BER_BVZERO( &default_search_base );
1312 BER_BVZERO( &default_search_nbase );
1316 if(c->bi || c->be != frontendDB) {
1317 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1318 "prior to any backend or database definition\n",
1323 if(default_search_nbase.bv_len) {
1324 free(default_search_base.bv_val);
1325 free(default_search_nbase.bv_val);
1328 default_search_base = c->value_dn;
1329 default_search_nbase = c->value_ndn;
1334 config_passwd_hash(ConfigArgs *c) {
1336 if (c->op == SLAP_CONFIG_EMIT) {
1338 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1339 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1340 value_add_one(&c->rvalue_vals, &bv);
1343 } else if ( c->op == LDAP_MOD_DELETE ) {
1344 if ( c->valx < 0 ) {
1345 ldap_charray_free( default_passwd_hash );
1346 default_passwd_hash = NULL;
1349 ch_free( default_passwd_hash[i] );
1350 for (; default_passwd_hash[i]; i++ )
1351 default_passwd_hash[i] = default_passwd_hash[i+1];
1355 if(default_passwd_hash) {
1356 Debug(LDAP_DEBUG_ANY, "%s: "
1357 "already set default password_hash\n",
1361 for(i = 1; i < c->argc; i++) {
1362 if(!lutil_passwd_scheme(c->argv[i])) {
1363 sprintf( c->msg, "<%s> schema not available", c->argv[0] );
1364 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1365 c->log, c->msg, c->argv[i]);
1367 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1369 if(!default_passwd_hash) {
1370 sprintf( c->msg, "<%s> no valid hashes found", c->argv[0] );
1371 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1372 c->log, c->msg, 0 );
1380 config_schema_dn(ConfigArgs *c) {
1381 if ( c->op == SLAP_CONFIG_EMIT ) {
1383 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1384 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1385 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1389 } else if ( c->op == LDAP_MOD_DELETE ) {
1390 ch_free( c->be->be_schemadn.bv_val );
1391 ch_free( c->be->be_schemandn.bv_val );
1392 BER_BVZERO( &c->be->be_schemadn );
1393 BER_BVZERO( &c->be->be_schemandn );
1396 ch_free( c->be->be_schemadn.bv_val );
1397 ch_free( c->be->be_schemandn.bv_val );
1398 c->be->be_schemadn = c->value_dn;
1399 c->be->be_schemandn = c->value_ndn;
1404 config_sizelimit(ConfigArgs *c) {
1407 struct slap_limits_set *lim = &c->be->be_def_limit;
1408 if (c->op == SLAP_CONFIG_EMIT) {
1413 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1414 if ( !BER_BVISEMPTY( &bv ))
1415 value_add_one( &c->rvalue_vals, &bv );
1419 } else if ( c->op == LDAP_MOD_DELETE ) {
1420 /* Reset to defaults */
1421 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1422 lim->lms_s_hard = 0;
1423 lim->lms_s_unchecked = -1;
1425 lim->lms_s_pr_hide = 0;
1426 lim->lms_s_pr_total = 0;
1429 for(i = 1; i < c->argc; i++) {
1430 if(!strncasecmp(c->argv[i], "size", 4)) {
1431 rc = limits_parse_one(c->argv[i], lim);
1433 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1434 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1435 c->log, c->msg, c->argv[i]);
1439 if(!strcasecmp(c->argv[i], "unlimited")) {
1440 lim->lms_s_soft = -1;
1442 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1443 if(next == c->argv[i]) {
1444 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1445 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1446 c->log, c->msg, c->argv[i]);
1448 } else if(next[0] != '\0') {
1449 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1450 "trailing chars \"%s\" in \"sizelimit <limit>\" line"
1451 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1453 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1455 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1458 lim->lms_s_hard = 0;
1465 config_timelimit(ConfigArgs *c) {
1468 struct slap_limits_set *lim = &c->be->be_def_limit;
1469 if (c->op == SLAP_CONFIG_EMIT) {
1474 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1475 if ( !BER_BVISEMPTY( &bv ))
1476 value_add_one( &c->rvalue_vals, &bv );
1480 } else if ( c->op == LDAP_MOD_DELETE ) {
1481 /* Reset to defaults */
1482 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1483 lim->lms_t_hard = 0;
1486 for(i = 1; i < c->argc; i++) {
1487 if(!strncasecmp(c->argv[i], "time", 4)) {
1488 rc = limits_parse_one(c->argv[i], lim);
1490 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1491 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1492 c->log, c->msg, c->argv[i]);
1496 if(!strcasecmp(c->argv[i], "unlimited")) {
1497 lim->lms_t_soft = -1;
1499 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1500 if(next == c->argv[i]) {
1501 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1502 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1503 c->log, c->msg, c->argv[i]);
1505 } else if(next[0] != '\0') {
1506 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1507 "trailing chars \"%s\" in \"timelimit <limit>\" line"
1508 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1510 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1512 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1515 lim->lms_t_hard = 0;
1522 config_overlay(ConfigArgs *c) {
1524 if (c->op == SLAP_CONFIG_EMIT) {
1526 } else if ( c->op == LDAP_MOD_DELETE ) {
1529 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1531 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: (optional) %s overlay \"%s\" configuration failed"
1532 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1533 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
1534 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1536 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1537 } else if(overlay_config(c->be, c->argv[1])) {
1540 /* Setup context for subsequent config directives.
1541 * The newly added overlay is at the head of the list.
1543 oi = (slap_overinfo *)c->be->bd_info;
1544 c->bi = &oi->oi_list->on_bi;
1549 config_suffix(ConfigArgs *c)
1552 struct berval pdn, ndn;
1553 char *notallowed = NULL;
1555 if ( c->be == frontendDB ) {
1556 notallowed = "frontend";
1558 } else if ( SLAP_MONITOR(c->be) ) {
1559 notallowed = "monitor";
1561 } else if ( SLAP_CONFIG(c->be) ) {
1562 notallowed = "config";
1565 if ( notallowed != NULL ) {
1566 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
1568 if ( !BER_BVISNULL( &c->value_dn ) ) {
1569 snprintf( buf, sizeof( buf ), "<%s> ", c->value_dn.bv_val );
1572 Debug(LDAP_DEBUG_ANY,
1573 "%s: suffix %snot allowed in %s database.\n",
1574 c->log, buf, notallowed );
1578 if (c->op == SLAP_CONFIG_EMIT) {
1579 if ( c->be->be_suffix == NULL
1580 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1584 value_add( &c->rvalue_vals, c->be->be_suffix );
1585 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1588 } else if ( c->op == LDAP_MOD_DELETE ) {
1589 if ( c->valx < 0 ) {
1590 ber_bvarray_free( c->be->be_suffix );
1591 ber_bvarray_free( c->be->be_nsuffix );
1592 c->be->be_suffix = NULL;
1593 c->be->be_nsuffix = NULL;
1596 ch_free( c->be->be_suffix[i].bv_val );
1597 ch_free( c->be->be_nsuffix[i].bv_val );
1598 for (; c->be->be_suffix[i].bv_val; i++) {
1599 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1600 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1606 #ifdef SLAPD_MONITOR_DN
1607 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1608 sprintf( c->msg, "<%s> DN is reserved for monitoring slapd",
1610 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1611 c->log, c->msg, SLAPD_MONITOR_DN);
1618 tbe = select_backend(&ndn, 0, 0);
1620 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1621 "%s: suffix already served by this backend!"
1622 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1624 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1626 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1630 sprintf( c->msg, "<%s> suffix already served by a preceding backend",
1632 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1633 c->log, c->msg, tbe->be_suffix[0].bv_val);
1637 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1638 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1639 "base provided \"%s\" (assuming okay)\n",
1640 c->log, default_search_base.bv_val, 0);
1642 ber_bvarray_add(&c->be->be_suffix, &pdn);
1643 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1648 config_rootdn(ConfigArgs *c) {
1649 if (c->op == SLAP_CONFIG_EMIT) {
1650 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1651 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1652 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1657 } else if ( c->op == LDAP_MOD_DELETE ) {
1658 ch_free( c->be->be_rootdn.bv_val );
1659 ch_free( c->be->be_rootndn.bv_val );
1660 BER_BVZERO( &c->be->be_rootdn );
1661 BER_BVZERO( &c->be->be_rootndn );
1664 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1665 ch_free( c->be->be_rootdn.bv_val );
1666 ch_free( c->be->be_rootndn.bv_val );
1668 c->be->be_rootdn = c->value_dn;
1669 c->be->be_rootndn = c->value_ndn;
1674 config_rootpw(ConfigArgs *c) {
1676 /* config_add_internal sets c->be = frontendDB. While the cn=config
1677 * rootpw is technically inside a backend, we expose it in the
1678 * global entry, and need to point to it properly here.
1680 if (c->be == frontendDB)
1681 c->be = LDAP_STAILQ_FIRST(&backendDB);
1683 if (c->op == SLAP_CONFIG_EMIT) {
1684 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1685 /* don't copy, because "rootpw" is marked
1687 c->value_bv = c->be->be_rootpw;
1691 } else if ( c->op == LDAP_MOD_DELETE ) {
1692 ch_free( c->be->be_rootpw.bv_val );
1693 BER_BVZERO( &c->be->be_rootpw );
1697 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1699 sprintf( c->msg, "<%s> can only be set when rootdn is under suffix",
1701 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1705 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1706 ch_free( c->be->be_rootpw.bv_val );
1707 c->be->be_rootpw = c->value_bv;
1712 config_restrict(ConfigArgs *c) {
1713 slap_mask_t restrictops = 0;
1715 slap_verbmasks restrictable_ops[] = {
1716 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1717 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1718 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1719 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1720 { BER_BVC("modrdn"), 0 },
1721 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1722 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1723 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1724 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1725 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1726 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1727 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1728 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1729 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1730 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1734 if (c->op == SLAP_CONFIG_EMIT) {
1735 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1737 } else if ( c->op == LDAP_MOD_DELETE ) {
1739 c->be->be_restrictops = 0;
1741 restrictops = verb_to_mask( c->line, restrictable_ops );
1742 c->be->be_restrictops ^= restrictops;
1746 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1748 sprintf( c->msg, "<%s> unknown operation", c->argv[0] );
1749 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1750 c->log, c->msg, c->argv[i]);
1753 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1754 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1755 c->be->be_restrictops |= restrictops;
1760 config_allows(ConfigArgs *c) {
1761 slap_mask_t allows = 0;
1763 slap_verbmasks allowable_ops[] = {
1764 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1765 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1766 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1767 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1770 if (c->op == SLAP_CONFIG_EMIT) {
1771 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1772 } else if ( c->op == LDAP_MOD_DELETE ) {
1776 allows = verb_to_mask( c->line, allowable_ops );
1777 global_allows ^= allows;
1781 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1783 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1784 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1785 c->log, c->msg, c->argv[i]);
1788 global_allows |= allows;
1793 config_disallows(ConfigArgs *c) {
1794 slap_mask_t disallows = 0;
1796 slap_verbmasks disallowable_ops[] = {
1797 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1798 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1799 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1800 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1801 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1804 if (c->op == SLAP_CONFIG_EMIT) {
1805 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1806 } else if ( c->op == LDAP_MOD_DELETE ) {
1808 global_disallows = 0;
1810 disallows = verb_to_mask( c->line, disallowable_ops );
1811 global_disallows ^= disallows;
1815 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1817 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1818 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1819 c->log, c->msg, c->argv[i]);
1822 global_disallows |= disallows;
1827 config_requires(ConfigArgs *c) {
1828 slap_mask_t requires = 0;
1830 slap_verbmasks requires_ops[] = {
1831 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1832 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1833 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1834 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1835 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1838 if (c->op == SLAP_CONFIG_EMIT) {
1839 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1840 } else if ( c->op == LDAP_MOD_DELETE ) {
1842 c->be->be_requires = 0;
1844 requires = verb_to_mask( c->line, requires_ops );
1845 c->be->be_requires ^= requires;
1849 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1851 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1852 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1853 c->log, c->msg, c->argv[i]);
1856 c->be->be_requires = requires;
1860 static slap_verbmasks *loglevel_ops;
1863 loglevel_init( void )
1865 slap_verbmasks lo[] = {
1866 { BER_BVC("Any"), -1 },
1867 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1868 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1869 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1870 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1871 { BER_BVC("BER"), LDAP_DEBUG_BER },
1872 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1873 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1874 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1875 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1876 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1877 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1878 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1879 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1880 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1881 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
1885 return slap_verbmasks_init( &loglevel_ops, lo );
1889 loglevel_destroy( void )
1891 if ( loglevel_ops ) {
1892 (void)slap_verbmasks_destroy( loglevel_ops );
1894 loglevel_ops = NULL;
1897 static slap_mask_t loglevel_ignore[] = { -1, 0 };
1900 slap_loglevel_register( slap_mask_t m, struct berval *s )
1904 if ( loglevel_ops == NULL ) {
1908 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
1911 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
1919 config_loglevel(ConfigArgs *c) {
1923 if ( loglevel_ops == NULL ) {
1927 if (c->op == SLAP_CONFIG_EMIT) {
1928 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1929 } else if ( c->op == LDAP_MOD_DELETE ) {
1933 int level = verb_to_mask( c->line, loglevel_ops );
1934 ldap_syslog ^= level;
1941 for( i=1; i < c->argc; i++ ) {
1944 if ( isdigit( c->argv[i][0] ) || c->argv[i][0] == '-' ) {
1945 level = strtol( c->argv[i], &next, 10 );
1946 if ( next == NULL || next[0] != '\0' ) {
1947 sprintf( c->msg, "<%s> unable to parse level", c->argv[0] );
1948 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1949 c->log, c->msg, c->argv[i]);
1953 int j = verb_to_mask(c->argv[i], loglevel_ops);
1954 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1955 sprintf( c->msg, "<%s> unknown level", c->argv[0] );
1956 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1957 c->log, c->msg, c->argv[i]);
1960 level = loglevel_ops[j].mask;
1962 ldap_syslog |= level;
1968 config_referral(ConfigArgs *c) {
1970 if (c->op == SLAP_CONFIG_EMIT) {
1971 if ( default_referral ) {
1972 value_add( &c->rvalue_vals, default_referral );
1977 } else if ( c->op == LDAP_MOD_DELETE ) {
1978 if ( c->valx < 0 ) {
1979 ber_bvarray_free( default_referral );
1980 default_referral = NULL;
1983 ch_free( default_referral[i].bv_val );
1984 for (; default_referral[i].bv_val; i++ )
1985 default_referral[i] = default_referral[i+1];
1989 if(validate_global_referral(c->argv[1])) {
1990 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
1991 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1992 c->log, c->msg, c->argv[1]);
1996 ber_str2bv(c->argv[1], 0, 0, &val);
1997 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2005 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2006 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2007 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2008 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2009 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2010 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2011 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2012 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2013 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2018 config_security(ConfigArgs *c) {
2019 slap_ssf_set_t *set = &c->be->be_ssf_set;
2022 if (c->op == SLAP_CONFIG_EMIT) {
2028 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2029 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2032 bv.bv_len = sprintf( numbuf, "%u", *tgt );
2033 bv.bv_len += sec_keys[i].key.bv_len;
2034 bv.bv_val = ch_malloc( bv.bv_len + 1);
2035 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2036 strcpy( next, numbuf );
2037 ber_bvarray_add( &c->rvalue_vals, &bv );
2042 for(i = 1; i < c->argc; i++) {
2043 slap_ssf_t *tgt = NULL;
2045 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2046 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2047 sec_keys[j].key.bv_len)) {
2048 src = c->argv[i] + sec_keys[j].key.bv_len;
2049 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2054 sprintf( c->msg, "<%s> unknown factor", c->argv[0] );
2055 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2056 c->log, c->msg, c->argv[i]);
2060 *tgt = strtol(src, &next, 10);
2061 if(next == NULL || next[0] != '\0' ) {
2062 sprintf( c->msg, "<%s> unable to parse factor", c->argv[0] );
2063 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2064 c->log, c->msg, c->argv[i]);
2072 anlist_unparse( AttributeName *an, char *ptr ) {
2075 for (; !BER_BVISNULL( &an->an_name ); an++) {
2076 if ( comma ) *ptr++ = ',';
2077 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2084 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2088 struct berval bc = {0};
2091 len = sprintf(numbuf, IFMT, i );
2093 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2094 if ( ri->ri_nsuffix ) {
2095 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2096 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2099 if ( ri->ri_attrs ) {
2100 len += STRLENOF("attr");
2101 if ( ri->ri_exclude ) len++;
2102 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2103 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2106 bindconf_unparse( &ri->ri_bindconf, &bc );
2109 bv->bv_val = ch_malloc(len + 1);
2112 ptr = lutil_strcopy( bv->bv_val, numbuf );
2113 ptr = lutil_strcopy( ptr, "uri=" );
2114 ptr = lutil_strcopy( ptr, ri->ri_uri );
2116 if ( ri->ri_nsuffix ) {
2117 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2118 ptr = lutil_strcopy( ptr, " suffix=\"" );
2119 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2123 if ( ri->ri_attrs ) {
2124 ptr = lutil_strcopy( ptr, "attr" );
2125 if ( ri->ri_exclude ) *ptr++ = '!';
2127 ptr = anlist_unparse( ri->ri_attrs, ptr );
2130 strcpy( ptr, bc.bv_val );
2131 ch_free( bc.bv_val );
2136 config_replica(ConfigArgs *c) {
2137 int i, nr = -1, len;
2138 char *replicahost, *replicauri;
2141 if (c->op == SLAP_CONFIG_EMIT) {
2142 if (c->be->be_replica) {
2144 for (i=0;c->be->be_replica[i]; i++) {
2145 replica_unparse( c->be->be_replica[i], i, &bv );
2146 ber_bvarray_add( &c->rvalue_vals, &bv );
2151 } else if ( c->op == LDAP_MOD_DELETE ) {
2152 /* FIXME: there is no replica_free function */
2153 if ( c->valx < 0 ) {
2157 if(SLAP_MONITOR(c->be)) {
2158 Debug(LDAP_DEBUG_ANY, "%s: "
2159 "\"replica\" should not be used inside monitor database\n",
2161 return(0); /* FIXME: should this be an error? */
2164 for(i = 1; i < c->argc; i++) {
2165 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2166 replicahost = c->argv[i] + STRLENOF("host=");
2167 len = strlen( replicahost );
2168 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2169 sprintf( replicauri, "ldap://%s", replicahost );
2170 replicahost = replicauri + STRLENOF( "ldap://");
2171 nr = add_replica_info(c->be, replicauri, replicahost);
2173 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2174 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2175 sprintf( c->msg, "<%s> invalid uri", c->argv[0] );
2176 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2179 if(!ludp->lud_host) {
2180 sprintf( c->msg, "<%s> invalid uri - missing hostname",
2182 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2185 ldap_free_urldesc(ludp);
2186 replicauri = c->argv[i] + STRLENOF("uri=");
2187 replicauri = ch_strdup( replicauri );
2188 replicahost = strchr( replicauri, '/' );
2190 nr = add_replica_info(c->be, replicauri, replicahost);
2195 sprintf( c->msg, "<%s> missing host or uri", c->argv[0] );
2196 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2198 } else if(nr == -1) {
2199 sprintf( c->msg, "<%s> unable to add replica", c->argv[0] );
2200 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2203 for(i = 1; i < c->argc; i++) {
2204 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2205 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2207 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2208 "suffix \"%s\" in \"replica\" line is not valid for backend"
2209 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2210 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2211 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2213 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2216 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2217 "unable to normalize suffix in \"replica\" line"
2218 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2220 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2222 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2226 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2228 char *arg = c->argv[i] + STRLENOF("attr");
2236 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2237 sprintf( c->msg, "<%s> unknown attribute", c->argv[0] );
2238 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2239 c->log, c->msg, arg + 1);
2242 } else if ( bindconf_parse( c->argv[i],
2243 &c->be->be_replica[nr]->ri_bindconf ) ) {
2252 config_updatedn(ConfigArgs *c) {
2255 if (c->op == SLAP_CONFIG_EMIT) {
2256 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2257 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2258 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2262 } else if ( c->op == LDAP_MOD_DELETE ) {
2263 ch_free( c->be->be_update_ndn.bv_val );
2264 c->be->be_update_ndn.bv_val = NULL;
2265 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2268 if(SLAP_SHADOW(c->be)) {
2269 sprintf( c->msg, "<%s> database already shadowed", c->argv[0] );
2270 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2275 ber_str2bv(c->argv[1], 0, 0, &dn);
2277 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2279 if(rc != LDAP_SUCCESS) {
2280 sprintf( c->msg, "<%s> invalid DN %d (%s)", c->argv[0],
2281 rc, ldap_err2string(rc));
2282 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2283 c->log, c->msg, 0 );
2287 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2292 config_updateref(ConfigArgs *c) {
2294 if (c->op == SLAP_CONFIG_EMIT) {
2295 if ( c->be->be_update_refs ) {
2296 value_add( &c->rvalue_vals, c->be->be_update_refs );
2301 } else if ( c->op == LDAP_MOD_DELETE ) {
2302 if ( c->valx < 0 ) {
2303 ber_bvarray_free( c->be->be_update_refs );
2304 c->be->be_update_refs = NULL;
2307 ch_free( c->be->be_update_refs[i].bv_val );
2308 for (; c->be->be_update_refs[i].bv_val; i++)
2309 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2313 if(!SLAP_SHADOW(c->be)) {
2314 sprintf( c->msg, "<%s> must appear after syncrepl or updatedn",
2316 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2321 if(validate_global_referral(c->argv[1])) {
2322 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2323 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2324 c->log, c->msg, c->argv[1]);
2327 ber_str2bv(c->argv[1], 0, 0, &val);
2328 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2333 config_include(ConfigArgs *c) {
2334 int savelineno = c->lineno;
2337 ConfigFile *cfsave = cfn;
2338 ConfigFile *cf2 = NULL;
2339 if (c->op == SLAP_CONFIG_EMIT) {
2341 ConfigFile *cf = c->private;
2342 value_add_one( &c->rvalue_vals, &cf->c_file );
2346 } else if ( c->op == LDAP_MOD_DELETE ) {
2348 cf = ch_calloc( 1, sizeof(ConfigFile));
2349 if ( cfn->c_kids ) {
2350 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2356 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2357 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2358 c->lineno = savelineno - 1;
2361 if ( cf2 ) cf2->c_sibs = NULL;
2362 else cfn->c_kids = NULL;
2363 ch_free( cf->c_file.bv_val );
2373 config_tls_option(ConfigArgs *c) {
2376 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2377 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2378 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2379 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2380 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2381 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2382 default: Debug(LDAP_DEBUG_ANY, "%s: "
2383 "unknown tls_option <0x%x>\n",
2384 c->log, c->type, 0);
2386 if (c->op == SLAP_CONFIG_EMIT) {
2387 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2388 } else if ( c->op == LDAP_MOD_DELETE ) {
2389 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2391 ch_free(c->value_string);
2392 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2395 /* FIXME: this ought to be provided by libldap */
2397 config_tls_config(ConfigArgs *c) {
2399 slap_verbmasks crlkeys[] = {
2400 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2401 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2402 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2405 slap_verbmasks vfykeys[] = {
2406 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2407 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2408 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2409 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2413 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2414 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2416 Debug(LDAP_DEBUG_ANY, "%s: "
2417 "unknown tls_option <0x%x>\n",
2418 c->log, c->type, 0);
2420 if (c->op == SLAP_CONFIG_EMIT) {
2421 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2422 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2423 if (keys[i].mask == c->value_int) {
2424 c->value_string = ch_strdup( keys[i].word.bv_val );
2429 } else if ( c->op == LDAP_MOD_DELETE ) {
2431 return ldap_pvt_tls_set_option( NULL, flag, &i );
2433 ch_free( c->value_string );
2434 if(isdigit((unsigned char)c->argv[1][0])) {
2435 i = atoi(c->argv[1]);
2436 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2438 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2443 static CfEntryInfo *
2444 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2454 if ( dn_match( &root->ce_entry->e_nname, dn ))
2457 c = dn->bv_val+dn->bv_len;
2458 for (;*c != ',';c--);
2462 for (--c;c>dn->bv_val && *c != ',';c--);
2466 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2468 root = root->ce_kids;
2470 for (;root;root=root->ce_sibs) {
2471 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2472 if ( cdn.bv_val == dn->bv_val ) {
2482 typedef struct setup_cookie {
2488 config_ldif_resp( Operation *op, SlapReply *rs )
2490 if ( rs->sr_type == REP_SEARCH ) {
2491 setup_cookie *sc = op->o_callback->sc_private;
2493 sc->cfb->cb_got_ldif = 1;
2494 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL );
2499 /* Configure and read the underlying back-ldif store */
2501 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
2502 CfBackInfo *cfb = be->be_private;
2508 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2509 Connection conn = {0};
2510 char opbuf[OPERATION_BUFFER_SIZE];
2512 SlapReply rs = {REP_RESULT};
2513 Filter filter = { LDAP_FILTER_PRESENT };
2514 struct berval filterstr = BER_BVC("(objectclass=*)");
2517 /* Is the config directory available? */
2518 if ( stat( dir, &st ) < 0 ) {
2519 /* No, so don't bother using the backing store.
2520 * All changes will be in-memory only.
2525 cfb->cb_db.bd_info = backend_info( "ldif" );
2526 if ( !cfb->cb_db.bd_info )
2527 return 0; /* FIXME: eventually this will be a fatal error */
2529 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2531 /* Mark that back-ldif type is in use */
2532 cfb->cb_db.bd_info->bi_nDB++;
2534 cfb->cb_db.be_suffix = be->be_suffix;
2535 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2536 cfb->cb_db.be_rootdn = be->be_rootdn;
2537 cfb->cb_db.be_rootndn = be->be_rootndn;
2539 ber_str2bv( dir, 0, 1, &cfdir );
2544 argv[0] = "directory";
2545 argv[1] = (char *)dir;
2549 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
2553 if ( config_add_vals( ct, &c ))
2556 if ( backend_startup_one( &cfb->cb_db ))
2560 op = (Operation *)opbuf;
2561 connection_fake_init( &conn, op, cfb );
2563 filter.f_desc = slap_schema.si_ad_objectClass;
2565 op->o_tag = LDAP_REQ_SEARCH;
2567 op->ors_filter = &filter;
2568 op->ors_filterstr = filterstr;
2569 op->ors_scope = LDAP_SCOPE_SUBTREE;
2571 op->o_dn = be->be_rootdn;
2572 op->o_ndn = be->be_rootndn;
2574 op->o_req_dn = be->be_suffix[0];
2575 op->o_req_ndn = be->be_nsuffix[0];
2577 op->ors_tlimit = SLAP_NO_LIMIT;
2578 op->ors_slimit = SLAP_NO_LIMIT;
2580 op->ors_attrs = slap_anlist_all_attributes;
2581 op->ors_attrsonly = 0;
2583 op->o_callback = &cb;
2586 cb.sc_private = ≻
2588 op->o_bd = &cfb->cb_db;
2589 rc = op->o_bd->be_search( op, &rs );
2591 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
2594 cfb->cb_use_ldif = 1;
2600 CfOc_cmp( const void *c1, const void *c2 ) {
2601 const ConfigOCs *co1 = c1;
2602 const ConfigOCs *co2 = c2;
2604 return ber_bvcmp( co1->co_name, co2->co_name );
2608 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2611 i = init_config_attrs( ct );
2614 /* set up the objectclasses */
2615 i = init_config_ocs( ocs );
2618 for (i=0; ocs[i].co_def; i++) {
2619 if ( ocs[i].co_oc ) {
2620 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
2621 if ( !ocs[i].co_table )
2622 ocs[i].co_table = ct;
2623 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
2630 read_config(const char *fname, const char *dir) {
2633 const char *cfdir, *cfname;
2636 /* Setup the config backend */
2637 be = backend_db_init( "config" );
2641 cfb = be->be_private;
2643 /* If no .conf, or a dir was specified, setup the dir */
2644 if ( !fname || dir ) {
2646 /* If explicitly given, check for existence */
2649 if ( stat( dir, &st ) < 0 ) {
2650 Debug( LDAP_DEBUG_ANY,
2651 "invalid config directory %s, error %d\n",
2657 cfdir = SLAPD_DEFAULT_CONFIGDIR;
2659 /* if fname is defaulted, try reading .d */
2660 rc = config_setup_ldif( be, cfdir, !fname );
2662 /* It's OK if the base object doesn't exist yet */
2663 if ( rc && rc != LDAP_NO_SUCH_OBJECT )
2666 /* If we read the config from back-ldif, nothing to do here */
2667 if ( cfb->cb_got_ldif ) {
2676 cfname = SLAPD_DEFAULT_CONFIGFILE;
2678 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
2681 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
2683 /* If we got this far and failed, it may be a serious problem. In server
2684 * mode, we should never come to this. However, it may be alright if we're
2685 * using slapadd to create the conf dir.
2688 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
2690 /* If a config file was explicitly given, fail */
2694 /* Seems to be slapadd with a config dir, let it continue */
2695 if ( cfb->cb_use_ldif ) {
2697 cfb->cb_got_ldif = 1;
2703 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2704 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
2705 &frontendDB->be_schemadn );
2706 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2707 if ( rc != LDAP_SUCCESS ) {
2708 Debug(LDAP_DEBUG_ANY, "read_config: "
2709 "unable to normalize default schema DN \"%s\"\n",
2710 frontendDB->be_schemadn.bv_val, 0, 0 );
2711 /* must not happen */
2719 config_back_bind( Operation *op, SlapReply *rs )
2721 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2722 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2723 /* frontend sends result */
2724 return LDAP_SUCCESS;
2727 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2728 send_ldap_result( op, rs );
2734 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2738 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2740 rs->sr_attrs = op->ors_attrs;
2741 rs->sr_entry = ce->ce_entry;
2742 rc = send_search_entry( op, rs );
2744 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2745 if ( ce->ce_kids ) {
2746 rc = config_send( op, rs, ce->ce_kids, 1 );
2747 if ( rc ) return rc;
2750 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2751 rc = config_send( op, rs, ce, 0 );
2759 static ConfigTable *
2760 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
2764 for (j=0; j<nocs; j++) {
2765 for (i=0; colst[j]->co_table[i].name; i++)
2766 if ( colst[j]->co_table[i].ad == ad )
2767 return &colst[j]->co_table[i];
2772 /* Sort the attributes of the entry according to the order defined
2773 * in the objectclass, with required attributes occurring before
2774 * allowed attributes. For any attributes with sequencing dependencies
2775 * (e.g., rootDN must be defined after suffix) the objectclass must
2776 * list the attributes in the desired sequence.
2779 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
2781 Attribute *a, *head = NULL, *tail = NULL, **prev;
2784 for (i=0; i<nocs; i++) {
2785 if ( colst[i]->co_oc->soc_required ) {
2786 AttributeType **at = colst[i]->co_oc->soc_required;
2787 for (j=0; at[j]; j++) {
2788 for (a=e->e_attrs, prev=&e->e_attrs; a;
2789 prev = &(*prev)->a_next, a=a->a_next) {
2790 if ( a->a_desc == at[j]->sat_ad ) {
2804 if ( colst[i]->co_oc->soc_allowed ) {
2805 AttributeType **at = colst[i]->co_oc->soc_allowed;
2806 for (j=0; at[j]; j++) {
2807 for (a=e->e_attrs, prev=&e->e_attrs; a;
2808 prev = &(*prev)->a_next, a=a->a_next) {
2809 if ( a->a_desc == at[j]->sat_ad ) {
2825 tail->a_next = e->e_attrs;
2831 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2833 Attribute *a = NULL;
2834 AttributeDescription *ad;
2837 int i, rc = 0, sort = 0;
2844 Modifications *ml = ptr;
2846 vals = ml->sml_values;
2849 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2851 rc = ordered_value_sort( a, 1 );
2855 for ( i=0; vals[i].bv_val; i++ ) {
2856 ca->line = vals[i].bv_val;
2858 char *idx = strchr( ca->line, '}' );
2859 if ( idx ) ca->line = idx+1;
2861 rc = config_parse_vals( ct, ca, i );
2870 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2871 SlapReply *rs, int *renum )
2874 int index = -1, gotindex = 0, nsibs;
2875 int renumber = 0, tailindex = 0;
2879 if ( renum ) *renum = 0;
2881 /* These entries don't get indexed/renumbered */
2882 if ( ce_type == Cft_Global ) return 0;
2883 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2885 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2888 /* See if the rdn has an index already */
2889 dnRdn( &e->e_name, &rdn );
2890 ptr1 = strchr( e->e_name.bv_val, '{' );
2891 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2892 ptr2 = strchr( ptr1, '}' );
2893 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2894 return LDAP_NAMING_VIOLATION;
2895 if ( ptr2-ptr1 == 1)
2896 return LDAP_NAMING_VIOLATION;
2898 index = atoi(ptr1+1);
2900 return LDAP_NAMING_VIOLATION;
2903 /* count related kids */
2904 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2905 if ( ce->ce_type == ce_type ) nsibs++;
2908 if ( index != nsibs ) {
2910 if ( index < nsibs ) {
2911 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2912 /* Siblings need to be renumbered */
2917 struct berval ival, newrdn, nnewrdn;
2918 struct berval rtype, rval;
2920 AttributeDescription *ad = NULL;
2924 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2925 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2926 rtype.bv_val = rdn.bv_val;
2927 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2930 slap_bv2ad( &rtype, &ad, &text );
2931 a = attr_find( e->e_attrs, ad );
2932 if (!a ) return LDAP_NAMING_VIOLATION;
2935 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2937 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2938 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2941 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2942 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2949 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
2951 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
2954 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2955 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
2959 /* Do the equivalent of ModRDN */
2960 /* Replace DN / NDN */
2961 newrdn.bv_len = ptr1 - newrdn.bv_val;
2962 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
2963 free( e->e_name.bv_val );
2964 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
2966 free( e->e_nname.bv_val );
2967 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
2971 free( a->a_vals[0].bv_val );
2972 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
2973 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
2974 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
2975 strcpy( a->a_vals[0].bv_val, ptr1 );
2977 if ( a->a_nvals != a->a_vals ) {
2978 free( a->a_nvals[0].bv_val );
2979 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
2980 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
2981 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
2982 strcpy( a->a_nvals[0].bv_val, ptr1 );
2984 free( nnewrdn.bv_val );
2985 free( newrdn.bv_val );
2988 if ( renum ) *renum = renumber;
2993 count_ocs( Attribute *oc_at, int *nocs )
2996 ConfigOCs co, *coptr, **colst;
2998 /* count the objectclasses */
2999 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
3001 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
3003 for ( i=0, j=0; i<n; i++) {
3004 co.co_name = &oc_at->a_nvals[i];
3005 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
3007 /* ignore non-config objectclasses. probably should be
3008 * an error, general data doesn't belong here.
3010 if ( !coptr ) continue;
3012 /* Ignore the root objectclass, it has no implementation.
3014 if ( coptr->co_type == Cft_Abstract ) continue;
3022 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3024 if ( p->ce_type != Cft_Global && p->ce_type != Cft_Include )
3025 return LDAP_CONSTRAINT_VIOLATION;
3027 /* If we're reading from a configdir, don't parse this entry */
3029 return LDAP_COMPARE_TRUE;
3031 cfn = p->ce_private;
3033 return LDAP_SUCCESS;
3037 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3041 /* This entry is hardcoded, don't re-parse it */
3042 if ( p->ce_type == Cft_Global ) {
3043 cfn = p->ce_private;
3045 return LDAP_COMPARE_TRUE;
3047 if ( p->ce_type != Cft_Schema )
3048 return LDAP_CONSTRAINT_VIOLATION;
3050 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3052 cfo = p->ce_private;
3053 cfn->c_sibs = cfo->c_kids;
3055 return LDAP_SUCCESS;
3059 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3061 if ( p->ce_type != Cft_Global )
3062 return LDAP_CONSTRAINT_VIOLATION;
3063 ca->be = frontendDB; /* just to get past check_vals */
3064 return LDAP_SUCCESS;
3068 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3070 if ( p->ce_type != Cft_Global )
3071 return LDAP_CONSTRAINT_VIOLATION;
3072 return LDAP_SUCCESS;
3076 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3078 if ( p->ce_type != Cft_Global )
3079 return LDAP_CONSTRAINT_VIOLATION;
3080 return LDAP_SUCCESS;
3084 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3086 if ( p->ce_type != Cft_Database )
3087 return LDAP_CONSTRAINT_VIOLATION;
3089 return LDAP_SUCCESS;
3092 /* Parse an LDAP entry into config directives */
3094 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs, int *renum )
3096 CfEntryInfo *ce, *last;
3098 Attribute *a, *oc_at;
3099 int i, nocs, rc = 0;
3104 /* Make sure parent exists and entry does not */
3105 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3107 return LDAP_ALREADY_EXISTS;
3109 dnParent( &e->e_nname, &pdn );
3111 /* If last is NULL, the new entry is the root/suffix entry,
3112 * otherwise last should be the parent.
3114 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3116 rs->sr_matched = last->ce_entry->e_name.bv_val;
3117 return LDAP_NO_SUCH_OBJECT;
3120 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3121 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3123 memset( ca, 0, sizeof(ConfigArgs));
3125 /* Fake the coordinates based on whether we're part of an
3126 * LDAP Add or if reading the config dir
3129 ca->fname = "slapd";
3132 ca->fname = cfdir.bv_val;
3136 colst = count_ocs( oc_at, &nocs );
3138 /* Only the root can be Cft_Global, everything else must
3139 * have a parent. Only limited nesting arrangements are allowed.
3141 rc = LDAP_CONSTRAINT_VIOLATION;
3142 if ( colst[0]->co_type == Cft_Global && !last ) {
3143 cfn = cfb->cb_config;
3145 ca->be = frontendDB; /* just to get past check_vals */
3149 /* Check whether the Add is allowed by its parent, and do
3150 * any necessary arg setup
3153 for ( i=0; i<nocs; i++ ) {
3154 if ( colst[i]->co_ldadd &&
3155 ( rc = colst[i]->co_ldadd( last, e, ca ))
3156 != LDAP_CONSTRAINT_VIOLATION ) {
3162 /* Add the entry but don't parse it, we already have its contents */
3163 if ( rc == LDAP_COMPARE_TRUE ) {
3168 if ( rc != LDAP_SUCCESS )
3171 /* Parse all the values and check for simple syntax errors before
3172 * performing any set actions.
3174 * If doing an LDAPadd, check for indexed names and any necessary
3175 * renaming/renumbering. Entries that don't need indexed names are
3176 * ignored. Entries that need an indexed name and arrive without one
3177 * are assigned to the end. Entries that arrive with an index may
3178 * cause the following entries to be renumbered/bumped down.
3180 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3181 * don't allow Adding an entry with an index that's already in use.
3182 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3184 * These entries can have auto-assigned indexes (appended to the end)
3185 * but only the other types support auto-renumbering of siblings.
3187 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3191 init_config_argv( ca );
3193 /* Make sure we process attrs in the required order */
3194 sort_attrs( e, colst, nocs );
3196 for ( a=e->e_attrs; a; a=a->a_next ) {
3197 if ( a == oc_at ) continue;
3198 ct = config_find_table( colst, nocs, a->a_desc );
3199 if ( !ct ) continue; /* user data? */
3200 rc = check_vals( ct, ca, a, 1 );
3201 if ( rc ) goto leave;
3204 /* Basic syntax checks are OK. Do the actual settings. */
3205 for ( a=e->e_attrs; a; a=a->a_next ) {
3206 if ( a == oc_at ) continue;
3207 ct = config_find_table( colst, nocs, a->a_desc );
3208 if ( !ct ) continue; /* user data? */
3209 for (i=0; a->a_vals[i].bv_val; i++) {
3210 ca->line = a->a_vals[i].bv_val;
3211 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3212 ptr = strchr( ca->line, '}' );
3213 if ( ptr ) ca->line = ptr+1;
3216 rc = config_parse_add( ct, ca );
3224 /* Newly added databases and overlays need to be started up */
3225 if ( CONFIG_ONLINE_ADD( ca )) {
3226 if ( colst[0]->co_type == Cft_Database ) {
3227 rc = backend_startup_one( ca->be );
3229 } else if ( colst[0]->co_type == Cft_Overlay ) {
3230 if ( ca->bi->bi_db_open ) {
3231 BackendInfo *bi_orig = ca->be->bd_info;
3232 ca->be->bd_info = ca->bi;
3233 rc = ca->bi->bi_db_open( ca->be );
3234 ca->be->bd_info = bi_orig;
3238 sprintf( ca->msg, "<%s> failed startup", ca->argv[0] );
3239 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
3240 ca->log, ca->msg, ca->argv[1] );
3246 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3247 ce->ce_parent = last;
3248 ce->ce_entry = entry_dup( e );
3249 ce->ce_entry->e_private = ce;
3250 ce->ce_type = colst[0]->co_type;
3253 ce->ce_private = ca->private;
3256 } else if ( last->ce_kids ) {
3259 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3268 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
3269 backend_destroy_one( ca->be, 1 );
3270 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
3271 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
3275 ch_free( ca->argv );
3276 if ( colst ) ch_free( colst );
3280 /* Parse an LDAP entry into config directives, then store in underlying
3284 config_back_add( Operation *op, SlapReply *rs )
3290 if ( !be_isroot( op ) ) {
3291 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3295 cfb = (CfBackInfo *)op->o_bd->be_private;
3297 ldap_pvt_thread_pool_pause( &connection_pool );
3300 * 1) check for existence of entry
3301 * 2) check for sibling renumbering
3302 * 3) perform internal add
3303 * 4) store entry in underlying database
3304 * 5) perform any necessary renumbering
3306 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber );
3307 if ( rs->sr_err != LDAP_SUCCESS ) {
3308 rs->sr_text = ca.msg;
3309 } else if ( cfb->cb_use_ldif ) {
3310 BackendDB *be = op->o_bd;
3311 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3312 op->o_bd = &cfb->cb_db;
3313 sc.sc_next = op->o_callback;
3314 op->o_callback = ≻
3315 op->o_bd->be_add( op, rs );
3317 op->o_callback = sc.sc_next;
3322 ldap_pvt_thread_pool_resume( &connection_pool );
3325 send_ldap_result( op, rs );
3329 typedef struct delrec {
3330 struct delrec *next;
3336 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3339 int rc = LDAP_UNWILLING_TO_PERFORM;
3341 Entry *e = ce->ce_entry;
3342 Attribute *save_attrs = e->e_attrs, *oc_at;
3347 delrec *dels = NULL, *deltail = NULL;
3349 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3350 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3352 colst = count_ocs( oc_at, &nocs );
3354 e->e_attrs = attrs_dup( e->e_attrs );
3356 init_config_argv( ca );
3359 ca->private = ce->ce_private;
3361 strcpy( ca->log, "back-config" );
3363 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3364 ct = config_find_table( colst, nocs, ml->sml_desc );
3365 switch (ml->sml_op) {
3366 case LDAP_MOD_DELETE:
3367 case LDAP_MOD_REPLACE: {
3368 BerVarray vals = NULL, nvals;
3370 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3372 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3373 ml->sml_desc->ad_cname.bv_val );
3376 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3377 vals = ml->sml_values;
3378 nvals = ml->sml_nvalues;
3379 ml->sml_values = NULL;
3380 ml->sml_nvalues = NULL;
3382 /* If we're deleting by values, remember the indexes of the
3383 * values we deleted.
3385 if ( ct && ml->sml_values ) {
3387 for (i=0; ml->sml_values[i].bv_val; i++);
3388 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
3399 rc = modify_delete_vindex(e, &ml->sml_mod,
3400 get_permissiveModify(op),
3401 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3402 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3403 ml->sml_values = vals;
3404 ml->sml_nvalues = nvals;
3409 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3412 case SLAP_MOD_SOFTADD: {
3413 int mop = ml->sml_op;
3415 ml->sml_op = LDAP_MOD_ADD;
3417 if ( ct->arg_type & ARG_NO_INSERT ) {
3418 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3420 for (i = 0; a->a_vals[i].bv_val; i++ );
3424 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3425 if ( ml->sml_values[i].bv_val[0] == '{' &&
3427 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3430 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3431 ml->sml_desc->ad_cname.bv_val );
3435 rc = check_vals( ct, ca, ml, 0 );
3439 rc = modify_add_values(e, &ml->sml_mod,
3440 get_permissiveModify(op),
3441 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3443 /* If value already exists, show success here
3444 * and ignore this operation down below.
3446 if ( mop == SLAP_MOD_SOFTADD ) {
3447 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3457 case LDAP_MOD_INCREMENT: /* FIXME */
3462 if(rc != LDAP_SUCCESS) break;
3465 if(rc == LDAP_SUCCESS) {
3466 /* check that the entry still obeys the schema */
3467 rc = entry_schema_check(op->o_bd, e, NULL, 0,
3468 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3470 if ( rc == LDAP_SUCCESS ) {
3471 /* Basic syntax checks are OK. Do the actual settings. */
3472 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3473 ct = config_find_table( colst, nocs, ml->sml_desc );
3474 if ( !ct ) continue;
3476 switch (ml->sml_op) {
3477 case LDAP_MOD_DELETE:
3478 case LDAP_MOD_REPLACE: {
3479 BerVarray vals = NULL, nvals;
3483 a = attr_find( e->e_attrs, ml->sml_desc );
3485 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3486 vals = ml->sml_values;
3487 nvals = ml->sml_nvalues;
3488 ml->sml_values = NULL;
3489 ml->sml_nvalues = NULL;
3492 if ( ml->sml_values )
3495 /* If we didn't delete the whole attribute */
3496 if ( ml->sml_values && a ) {
3497 struct berval *mvals;
3500 if ( ml->sml_nvalues )
3501 mvals = ml->sml_nvalues;
3503 mvals = ml->sml_values;
3505 /* use the indexes we saved up above */
3506 for (i=0; i < d->nidx; i++) {
3507 struct berval bv = *mvals++;
3508 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3509 bv.bv_val[0] == '{' ) {
3510 ptr = strchr( bv.bv_val, '}' ) + 1;
3511 bv.bv_len -= ptr - bv.bv_val;
3514 ca->line = bv.bv_val;
3515 ca->valx = d->idx[i];
3516 rc = config_del_vals( ct, ca );
3517 if ( rc != LDAP_SUCCESS ) break;
3518 for (j=i+1; j < d->nidx; j++)
3519 if ( d->idx[j] >d->idx[i] )
3525 rc = config_del_vals( ct, ca );
3526 if ( rc ) rc = LDAP_OTHER;
3528 if ( ml->sml_values ) {
3532 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3533 ml->sml_values = vals;
3534 ml->sml_nvalues = nvals;
3536 if ( !vals || rc != LDAP_SUCCESS )
3539 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3542 for (i=0; ml->sml_values[i].bv_val; i++) {
3543 ca->line = ml->sml_values[i].bv_val;
3545 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3546 ca->line[0] == '{' ) {
3547 ptr = strchr( ca->line, '}' );
3549 ca->valx = strtol( ca->line+1, NULL, 0 );
3553 rc = config_parse_add( ct, ca );
3568 if ( rc == LDAP_SUCCESS ) {
3569 attrs_free( save_attrs );
3571 attrs_free( e->e_attrs );
3572 e->e_attrs = save_attrs;
3574 ch_free( ca->argv );
3575 if ( colst ) ch_free( colst );
3581 config_back_modify( Operation *op, SlapReply *rs )
3584 CfEntryInfo *ce, *last;
3586 ConfigArgs ca = {0};
3589 AttributeDescription *rad = NULL;
3591 if ( !be_isroot( op ) ) {
3592 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3596 cfb = (CfBackInfo *)op->o_bd->be_private;
3598 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3601 rs->sr_matched = last->ce_entry->e_name.bv_val;
3602 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3606 /* Get type of RDN */
3607 rdn = ce->ce_entry->e_nname;
3608 ptr = strchr( rdn.bv_val, '=' );
3609 rdn.bv_len = ptr - rdn.bv_val;
3610 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3612 /* Some basic validation... */
3613 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3614 /* Don't allow Modify of RDN; must use ModRdn for that. */
3615 if ( ml->sml_desc == rad ) {
3616 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3617 rs->sr_text = "Use modrdn to change the entry name";
3622 ldap_pvt_thread_pool_pause( &connection_pool );
3625 * 1) perform the Modify on the cached Entry.
3626 * 2) verify that the Entry still satisfies the schema.
3627 * 3) perform the individual config operations.
3628 * 4) store Modified entry in underlying LDIF backend.
3630 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3632 rs->sr_text = ca.msg;
3633 } else if ( cfb->cb_use_ldif ) {
3634 BackendDB *be = op->o_bd;
3635 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3636 op->o_bd = &cfb->cb_db;
3637 sc.sc_next = op->o_callback;
3638 op->o_callback = ≻
3639 op->o_bd->be_modify( op, rs );
3641 op->o_callback = sc.sc_next;
3644 ldap_pvt_thread_pool_resume( &connection_pool );
3646 send_ldap_result( op, rs );
3651 config_back_modrdn( Operation *op, SlapReply *rs )
3654 CfEntryInfo *ce, *last;
3656 if ( !be_isroot( op ) ) {
3657 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3661 cfb = (CfBackInfo *)op->o_bd->be_private;
3663 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3666 rs->sr_matched = last->ce_entry->e_name.bv_val;
3667 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3671 /* We don't allow moving objects to new parents.
3672 * Generally we only allow reordering a set of ordered entries.
3674 if ( op->orr_newSup ) {
3675 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3678 ldap_pvt_thread_pool_pause( &connection_pool );
3680 ldap_pvt_thread_pool_resume( &connection_pool );
3682 send_ldap_result( op, rs );
3687 config_back_search( Operation *op, SlapReply *rs )
3690 CfEntryInfo *ce, *last;
3692 if ( !be_isroot( op ) ) {
3693 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3697 cfb = (CfBackInfo *)op->o_bd->be_private;
3699 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3702 rs->sr_matched = last->ce_entry->e_name.bv_val;
3703 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3706 switch ( op->ors_scope ) {
3707 case LDAP_SCOPE_BASE:
3708 case LDAP_SCOPE_SUBTREE:
3709 config_send( op, rs, ce, 0 );
3712 case LDAP_SCOPE_ONELEVEL:
3713 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3714 config_send( op, rs, ce, 1 );
3719 rs->sr_err = LDAP_SUCCESS;
3721 send_ldap_result( op, rs );
3726 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
3727 ConfigTable *ct, ConfigArgs *c )
3731 for (; at && *at; at++) {
3732 /* Skip the naming attr */
3733 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3735 for (i=0;ct[i].name;i++) {
3736 if (ct[i].ad == (*at)->sat_ad) {
3737 rc = config_get_vals(&ct[i], c);
3738 if (rc == LDAP_SUCCESS) {
3739 if ( c->rvalue_nvals )
3740 attr_merge(e, ct[i].ad, c->rvalue_vals,
3743 attr_merge_normalize(e, ct[i].ad,
3744 c->rvalue_vals, NULL);
3745 ber_bvarray_free( c->rvalue_nvals );
3746 ber_bvarray_free( c->rvalue_vals );
3755 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3756 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
3758 Entry *e = ch_calloc( 1, sizeof(Entry) );
3759 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3761 struct berval ad_name;
3762 AttributeDescription *ad = NULL;
3769 CfEntryInfo *ceprev = NULL;
3773 ce->ce_parent = parent;
3775 pdn = parent->ce_entry->e_nname;
3776 if ( parent->ce_kids )
3777 for ( ceprev = parent->ce_kids; ceprev->ce_sibs;
3778 ceprev = ceprev->ce_sibs );
3783 ce->ce_type = main->co_type;
3784 ce->ce_private = c->private;
3788 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3789 ber_dupbv( &e->e_nname, &e->e_name );
3791 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3792 main->co_name, NULL );
3794 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3795 extra->co_name, NULL );
3796 ptr = strchr(rdn->bv_val, '=');
3797 ad_name.bv_val = rdn->bv_val;
3798 ad_name.bv_len = ptr - rdn->bv_val;
3799 rc = slap_bv2ad( &ad_name, &ad, &text );
3804 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3805 attr_merge_normalize_one(e, ad, &val, NULL );
3808 if ( oc->soc_required )
3809 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
3811 if ( oc->soc_allowed )
3812 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
3816 if ( oc->soc_required )
3817 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
3819 if ( oc->soc_allowed )
3820 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
3823 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3824 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3826 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3829 op->o_bd->be_add( op, rs );
3832 ceprev->ce_sibs = ce;
3833 } else if ( parent ) {
3834 parent->ce_kids = ce;
3841 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3842 Operation *op, SlapReply *rs )
3845 ConfigFile *cf = c->private;
3849 for (; cf; cf=cf->c_sibs, c->depth++) {
3850 c->value_dn.bv_val = c->log;
3851 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3856 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3858 ptr = strchr( bv.bv_val, '.' );
3860 bv.bv_len = ptr - bv.bv_val;
3861 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3862 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3864 c->value_dn.bv_len += bv.bv_len;
3865 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3868 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3869 &CFOC_SCHEMA, NULL );
3870 if ( e && cf->c_kids ) {
3871 c->private = cf->c_kids;
3872 config_build_schema_inc( c, e->e_private, op, rs );
3878 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3879 Operation *op, SlapReply *rs )
3883 ConfigFile *cf = c->private;
3885 for (i=0; cf; cf=cf->c_sibs, i++) {
3886 c->value_dn.bv_val = c->log;
3887 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3889 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3890 &CFOC_INCLUDE, NULL );
3891 if ( e && cf->c_kids ) {
3892 c->private = cf->c_kids;
3893 config_build_includes( c, e->e_private, op, rs );
3898 #ifdef SLAPD_MODULES
3901 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3902 Operation *op, SlapReply *rs )
3907 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3908 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3910 c->value_dn.bv_val = c->log;
3911 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3913 config_build_entry( op, rs, ceparent, c, &c->value_dn,
3914 &CFOC_MODULE, NULL );
3920 config_back_db_open( BackendDB *be )
3922 CfBackInfo *cfb = be->be_private;
3925 CfEntryInfo *ce, *ceparent;
3930 Connection conn = {0};
3931 char opbuf[OPERATION_BUFFER_SIZE];
3933 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3934 SlapReply rs = {REP_RESULT};
3936 /* If we read the config from back-ldif, nothing to do here */
3937 if ( cfb->cb_got_ldif )
3940 if ( cfb->cb_use_ldif ) {
3941 op = (Operation *)opbuf;
3942 connection_fake_init( &conn, op, cfb );
3944 op->o_dn = be->be_rootdn;
3945 op->o_ndn = be->be_rootndn;
3947 op->o_tag = LDAP_REQ_ADD;
3948 op->o_callback = &cb;
3949 op->o_bd = &cfb->cb_db;
3954 /* create root of tree */
3956 c.private = cfb->cb_config;
3958 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
3965 /* Create includeFile nodes */
3966 if ( cfb->cb_config->c_kids ) {
3968 c.private = cfb->cb_config->c_kids;
3969 config_build_includes( &c, ceparent, op, &rs );
3972 #ifdef SLAPD_MODULES
3973 /* Create Module nodes... */
3974 if ( modpaths.mp_loads ) {
3975 config_build_modules( &c, ceparent, op, &rs );
3979 /* Create schema nodes... cn=schema will contain the hardcoded core
3980 * schema, read-only. Child objects will contain runtime loaded schema
3985 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
3988 /* Create schema nodes for included schema... */
3989 if ( cfb->cb_config->c_kids ) {
3991 c.private = cfb->cb_config->c_kids;
3992 config_build_schema_inc( &c, ce, op, &rs );
3995 /* Create backend nodes. Skip if they don't provide a cf_table.
3996 * There usually aren't any of these.
4000 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
4001 if (!bi->bi_cf_ocs) continue;
4002 if (!bi->bi_private) continue;
4005 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
4007 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
4011 /* Create database nodes... */
4013 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
4014 slap_overinfo *oi = NULL;
4021 if ( overlay_is_over( bptr )) {
4022 oi = bptr->bd_info->bi_private;
4028 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
4032 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
4035 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
4036 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
4037 /* Iterate through overlays */
4043 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
4045 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
4046 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
4049 oe = config_build_entry( op, &rs, ce, &c, &rdn,
4050 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
4051 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
4052 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
4057 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
4063 cfb_free_cffile( ConfigFile *cf )
4067 for (; cf; cf=next) {
4070 cfb_free_cffile( cf->c_kids );
4071 ch_free( cf->c_file.bv_val );
4072 ber_bvarray_free( cf->c_dseFiles );
4078 cfb_free_entries( CfEntryInfo *ce )
4082 for (; ce; ce=next) {
4085 cfb_free_entries( ce->ce_kids );
4086 ce->ce_entry->e_private = NULL;
4087 entry_free( ce->ce_entry );
4093 config_back_db_close( BackendDB *be )
4095 CfBackInfo *cfb = be->be_private;
4097 cfb_free_entries( cfb->cb_root );
4098 cfb->cb_root = NULL;
4100 if ( cfb->cb_db.bd_info ) {
4101 backend_shutdown( &cfb->cb_db );
4108 config_back_db_destroy( BackendDB *be )
4110 CfBackInfo *cfb = be->be_private;
4112 cfb_free_cffile( cfb->cb_config );
4114 ch_free( cfdir.bv_val );
4116 avl_free( CfOcTree, NULL );
4118 if ( cfb->cb_db.bd_info ) {
4119 cfb->cb_db.be_suffix = NULL;
4120 cfb->cb_db.be_nsuffix = NULL;
4121 BER_BVZERO( &cfb->cb_db.be_rootdn );
4122 BER_BVZERO( &cfb->cb_db.be_rootndn );
4124 backend_destroy_one( &cfb->cb_db, 0 );
4127 free( be->be_private );
4135 config_back_db_init( BackendDB *be )
4140 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4141 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
4142 cfn = cfb->cb_config;
4143 be->be_private = cfb;
4145 ber_dupbv( &be->be_rootdn, &config_rdn );
4146 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4147 ber_dupbv( &dn, &be->be_rootdn );
4148 ber_bvarray_add( &be->be_suffix, &dn );
4149 ber_dupbv( &dn, &be->be_rootdn );
4150 ber_bvarray_add( &be->be_nsuffix, &dn );
4152 /* Hide from namingContexts */
4153 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4159 config_back_destroy( BackendInfo *bi )
4161 ldif_must_b64_encode_release();
4166 config_tool_entry_open( BackendDB *be, int mode )
4168 CfBackInfo *cfb = be->be_private;
4169 BackendInfo *bi = cfb->cb_db.bd_info;
4171 if ( bi && bi->bi_tool_entry_open )
4172 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
4179 config_tool_entry_close( BackendDB *be )
4181 CfBackInfo *cfb = be->be_private;
4182 BackendInfo *bi = cfb->cb_db.bd_info;
4184 if ( bi && bi->bi_tool_entry_close )
4185 return bi->bi_tool_entry_close( &cfb->cb_db );
4191 config_tool_entry_first( BackendDB *be )
4193 CfBackInfo *cfb = be->be_private;
4194 BackendInfo *bi = cfb->cb_db.bd_info;
4196 if ( bi && bi->bi_tool_entry_first )
4197 return bi->bi_tool_entry_first( &cfb->cb_db );
4203 config_tool_entry_next( BackendDB *be )
4205 CfBackInfo *cfb = be->be_private;
4206 BackendInfo *bi = cfb->cb_db.bd_info;
4208 if ( bi && bi->bi_tool_entry_next )
4209 return bi->bi_tool_entry_next( &cfb->cb_db );
4215 config_tool_entry_get( BackendDB *be, ID id )
4217 CfBackInfo *cfb = be->be_private;
4218 BackendInfo *bi = cfb->cb_db.bd_info;
4220 if ( bi && bi->bi_tool_entry_get )
4221 return bi->bi_tool_entry_get( &cfb->cb_db, id );
4227 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
4229 CfBackInfo *cfb = be->be_private;
4230 BackendInfo *bi = cfb->cb_db.bd_info;
4233 if ( bi && bi->bi_tool_entry_put &&
4234 config_add_internal( cfb, e, &ca, NULL, NULL ) == 0 )
4235 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
4242 AttributeDescription **desc;
4244 { "backend", &cfAd_backend },
4245 { "database", &cfAd_database },
4246 { "include", &cfAd_include },
4247 { "overlay", &cfAd_overlay },
4252 * add / delete: all types that may be added or deleted must use an
4253 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4254 * should automatically renumber the index of any siblings as needed,
4255 * so that no gaps in the numbering sequence exist after the add/delete
4257 * What can be added:
4259 * backend objects for backend-specific config directives
4263 * delete: probably no support this time around.
4265 * modrdn: generally not done. Will be invoked automatically by add/
4266 * delete to update numbering sequence. Perform as an explicit operation
4267 * so that the renumbering effect may be replicated. Subtree rename must
4268 * be supported, since renumbering a database will affect all its child
4271 * modify: must be fully supported.
4275 config_back_initialize( BackendInfo *bi )
4277 ConfigTable *ct = config_back_cf_table;
4280 AttributeDescription *ad = NULL;
4282 static char *controls[] = {
4283 LDAP_CONTROL_MANAGEDSAIT,
4287 bi->bi_controls = controls;
4292 bi->bi_destroy = config_back_destroy;
4294 bi->bi_db_init = config_back_db_init;
4295 bi->bi_db_config = 0;
4296 bi->bi_db_open = config_back_db_open;
4297 bi->bi_db_close = config_back_db_close;
4298 bi->bi_db_destroy = config_back_db_destroy;
4300 bi->bi_op_bind = config_back_bind;
4301 bi->bi_op_unbind = 0;
4302 bi->bi_op_search = config_back_search;
4303 bi->bi_op_compare = 0;
4304 bi->bi_op_modify = config_back_modify;
4305 bi->bi_op_modrdn = config_back_modrdn;
4306 bi->bi_op_add = config_back_add;
4307 bi->bi_op_delete = 0;
4308 bi->bi_op_abandon = 0;
4310 bi->bi_extended = 0;
4312 bi->bi_chk_referrals = 0;
4314 #ifdef SLAP_OVERLAY_ACCESS
4315 bi->bi_access_allowed = slap_access_always_allowed;
4316 #endif /* SLAP_OVERLAY_ACCESS */
4318 bi->bi_connection_init = 0;
4319 bi->bi_connection_destroy = 0;
4321 bi->bi_tool_entry_open = config_tool_entry_open;
4322 bi->bi_tool_entry_close = config_tool_entry_close;
4323 bi->bi_tool_entry_first = config_tool_entry_first;
4324 bi->bi_tool_entry_next = config_tool_entry_next;
4325 bi->bi_tool_entry_get = config_tool_entry_get;
4326 bi->bi_tool_entry_put = config_tool_entry_put;
4328 /* Make sure we don't exceed the bits reserved for userland */
4329 assert( ( ( CFG_LAST - 1 ) & ARGS_USERLAND ) == ( CFG_LAST - 1 ) );
4332 for (i=0; OidMacros[i].name; i++ ) {
4333 argv[1] = OidMacros[i].name;
4334 argv[2] = OidMacros[i].oid;
4335 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4338 bi->bi_cf_ocs = cf_ocs;
4340 i = config_register_schema( ct, cf_ocs );
4343 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4344 * basically, we don't care if it fails */
4345 i = slap_str2ad( "olcRootPW", &ad, &text );
4347 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4348 "warning, unable to get \"olcRootPW\" "
4349 "attribute description: %d: %s\n",
4352 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4353 ad->ad_type->sat_oid );
4356 /* set up the notable AttributeDescriptions */
4358 for (;ct->name;ct++) {
4359 if (strcmp(ct->name, ads[i].name)) continue;
4360 *ads[i].desc = ct->ad;
4362 if (!ads[i].name) break;