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 /* NOTE: be careful when defining array members
577 * that can be conditionally compiled */
578 #define CFOC_GLOBAL cf_ocs[1]
579 #define CFOC_SCHEMA cf_ocs[2]
580 #define CFOC_BACKEND cf_ocs[3]
581 #define CFOC_DATABASE cf_ocs[4]
582 #define CFOC_OVERLAY cf_ocs[5]
583 #define CFOC_INCLUDE cf_ocs[6]
584 #define CFOC_FRONTEND cf_ocs[7]
586 #define CFOC_MODULE cf_ocs[8]
587 #endif /* SLAPD_MODULES */
589 static ConfigOCs cf_ocs[] = {
592 "DESC 'OpenLDAP configuration object' "
593 "ABSTRACT SUP top )", Cft_Abstract, NULL },
596 "DESC 'OpenLDAP Global configuration options' "
597 "SUP olcConfig STRUCTURAL "
598 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
599 "olcAttributeOptions $ olcAuthIDRewrite $ "
600 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
601 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
602 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
603 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
604 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
606 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
607 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
608 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
609 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
611 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
612 "olcSecurity $ olcSizeLimit $ "
613 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
614 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
615 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
616 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
617 "olcTLSRandFile $ olcTLSVerifyClient $ "
618 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
619 "olcDitContentRules ) )", Cft_Global },
621 "NAME 'olcSchemaConfig' "
622 "DESC 'OpenLDAP schema object' "
623 "SUP olcConfig STRUCTURAL "
624 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
625 "olcObjectClasses $ olcDitContentRules ) )",
626 Cft_Schema, NULL, cfAddSchema },
628 "NAME 'olcBackendConfig' "
629 "DESC 'OpenLDAP Backend-specific options' "
630 "SUP olcConfig STRUCTURAL "
631 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
633 "NAME 'olcDatabaseConfig' "
634 "DESC 'OpenLDAP Database-specific options' "
635 "SUP olcConfig STRUCTURAL "
637 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
638 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
639 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
640 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
641 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
642 Cft_Database, NULL, cfAddDatabase },
644 "NAME 'olcOverlayConfig' "
645 "DESC 'OpenLDAP Overlay-specific options' "
646 "SUP olcConfig STRUCTURAL "
647 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
649 "NAME 'olcIncludeFile' "
650 "DESC 'OpenLDAP configuration include file' "
651 "SUP olcConfig STRUCTURAL "
653 "MAY ( cn $ olcRootDSE ) )",
654 Cft_Include, NULL, cfAddInclude },
655 /* This should be STRUCTURAL like all the other database classes, but
656 * that would mean inheriting all of the olcDatabaseConfig attributes,
657 * which causes them to be merged twice in config_build_entry.
660 "NAME 'olcFrontendConfig' "
661 "DESC 'OpenLDAP frontend configuration' "
663 "MAY olcDefaultSearchBase )",
664 Cft_Database, NULL, NULL },
667 "NAME 'olcModuleList' "
668 "DESC 'OpenLDAP dynamic module info' "
669 "SUP olcConfig STRUCTURAL "
670 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
671 Cft_Module, NULL, cfAddModule },
677 config_generic(ConfigArgs *c) {
681 if ( c->op == SLAP_CONFIG_EMIT ) {
685 c->value_int = ldap_pvt_thread_get_concurrency();
688 c->value_int = connection_pool_max;
692 c->value_string = ch_strdup( passwd_salt );
697 if ( c->be->be_limits ) {
702 for ( i=0; c->be->be_limits[i]; i++ ) {
703 bv.bv_len = sprintf( buf, IFMT, i );
704 bv.bv_val = buf+bv.bv_len;
705 limits_unparse( c->be->be_limits[i], &bv );
706 bv.bv_len += bv.bv_val - buf;
708 value_add_one( &c->rvalue_vals, &bv );
711 if ( !c->rvalue_vals ) rc = 1;
714 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
715 SLAP_RESTRICT_OP_WRITES;
718 c->value_string = ch_strdup( slap_sasl_getpolicy());
721 slap_sasl_regexp_unparse( &c->rvalue_vals );
722 if ( !c->rvalue_vals ) rc = 1;
724 #ifdef HAVE_CYRUS_SASL
726 struct berval bv = BER_BVNULL;
727 slap_sasl_secprops_unparse( &bv );
728 if ( !BER_BVISNULL( &bv )) {
729 ber_bvarray_add( &c->rvalue_vals, &bv );
737 c->value_int = c->be->be_max_deref_depth;
740 ConfigFile *cf = c->private;
742 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
743 else if ( cf->c_om_head )
744 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
746 if ( !c->rvalue_vals )
751 ConfigFile *cf = c->private;
753 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
754 else if ( cf->c_oc_head )
755 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
757 if ( !c->rvalue_vals )
762 ConfigFile *cf = c->private;
764 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
765 else if ( cf->c_at_head )
766 at_unparse( &c->rvalue_vals, cf->c_at_head,
768 if ( !c->rvalue_vals )
773 ConfigFile *cf = c->private;
775 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
776 else if ( cf->c_cr_head )
777 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
779 if ( !c->rvalue_vals )
786 char *src, *dst, ibuf[11];
787 struct berval bv, abv;
788 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
789 abv.bv_len = sprintf( ibuf, IFMT, i );
790 acl_unparse( a, &bv );
791 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
792 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
793 /* Turn TAB / EOL into plain space */
794 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
795 if (isspace(*src)) *dst++ = ' ';
799 if (dst[-1] == ' ') {
803 abv.bv_len = dst - abv.bv_val;
804 ber_bvarray_add( &c->rvalue_vals, &abv );
810 if ( c->be->be_replogfile )
811 c->value_string = ch_strdup( c->be->be_replogfile );
814 ConfigFile *cf = c->private;
815 if ( cf->c_dseFiles ) {
816 value_add( &c->rvalue_vals, cf->c_dseFiles );
824 c->value_string = ch_strdup( logfileName );
829 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
831 case CFG_SSTR_IF_MAX:
832 c->value_int = index_substr_if_maxlen;
834 case CFG_SSTR_IF_MIN:
835 c->value_int = index_substr_if_minlen;
839 ModPaths *mp = c->private;
842 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
845 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
846 mp->mp_loads[i].bv_val );
847 value_add_one( &c->rvalue_vals, &bv );
851 rc = c->rvalue_vals ? 0 : 1;
855 ModPaths *mp = c->private;
856 if ( !BER_BVISNULL( &mp->mp_path ))
857 value_add_one( &c->rvalue_vals, &mp->mp_path );
859 rc = c->rvalue_vals ? 0 : 1;
865 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
866 if ( !c->rvalue_vals ) rc = 1;
869 #ifdef SLAP_AUTH_REWRITE
871 if ( authz_rewrites ) {
872 struct berval bv, idx;
877 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
878 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
879 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
880 bv.bv_val = ch_malloc( bv.bv_len + 1 );
881 strcpy( bv.bv_val, idx.bv_val );
882 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
883 ber_bvarray_add( &c->rvalue_vals, &bv );
886 if ( !c->rvalue_vals ) rc = 1;
893 } else if ( c->op == LDAP_MOD_DELETE ) {
896 /* single-valued attrs, no-ops */
904 case CFG_SSTR_IF_MAX:
905 case CFG_SSTR_IF_MIN:
908 /* no-ops, requires slapd restart */
913 sprintf(c->log, "change requires slapd restart");
917 ch_free( passwd_salt );
922 ch_free( c->be->be_replogfile );
923 c->be->be_replogfile = NULL;
927 ch_free( logfileName );
934 if ( c->be == frontendDB )
937 end = frontendDB->be_acl;
938 acl_destroy( c->be->be_acl, end );
940 AccessControl **prev, *a;
942 for (i=0, prev = &c->be->be_acl; i < c->valx;
954 /* FIXME: there is no limits_free function */
956 /* FIXME: there is no ad_option_free function */
958 /* FIXME: there is no way to remove attributes added by
972 p = strchr(c->line,'(' /*')'*/);
976 if(!(c->bi = backend_info(c->argv[1]))) {
977 sprintf( c->msg, "<%s> failed init", c->argv[0] );
978 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
979 c->log, c->msg, c->argv[1] );
986 /* NOTE: config is always the first backend!
988 if ( !strcasecmp( c->argv[1], "config" )) {
989 c->be = LDAP_STAILQ_FIRST(&backendDB);
990 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
993 c->be = backend_db_init(c->argv[1]);
995 sprintf( c->msg, "<%s> failed init", c->argv[0] );
996 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
997 c->log, c->msg, c->argv[1] );
1004 ldap_pvt_thread_set_concurrency(c->value_int);
1008 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1009 connection_pool_max = c->value_int; /* save for reference */
1013 if ( passwd_salt ) ch_free( passwd_salt );
1014 passwd_salt = c->value_string;
1015 lutil_salt_format(passwd_salt);
1019 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1025 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1027 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1031 ch_free(c->value_string);
1032 if (slap_sasl_setpolicy( c->argv[1] )) {
1033 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1034 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1035 c->log, c->msg, c->argv[1] );
1041 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1045 #ifdef HAVE_CYRUS_SASL
1048 char *txt = slap_sasl_secprops( c->argv[1] );
1050 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1052 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1060 c->be->be_max_deref_depth = c->value_int;
1066 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1068 if (!cfn->c_om_head) cfn->c_om_head = om;
1069 cfn->c_om_tail = om;
1076 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1077 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1078 cfn->c_oc_tail = oc;
1085 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1086 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1087 cfn->c_cr_tail = cr;
1094 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1095 if (!cfn->c_at_head) cfn->c_at_head = at;
1096 cfn->c_at_tail = at;
1101 ad_define_option(NULL, NULL, 0);
1102 for(i = 1; i < c->argc; i++)
1103 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1108 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1112 if(SLAP_MONITOR(c->be)) {
1113 Debug(LDAP_DEBUG_ANY, "%s: "
1114 "\"replogfile\" should not be used "
1115 "inside monitor database\n",
1117 return(0); /* FIXME: should this be an error? */
1120 c->be->be_replogfile = c->value_string;
1124 if(read_root_dse_file(c->argv[1])) {
1125 sprintf( c->msg, "<%s> could not read file", c->argv[0] );
1126 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1127 c->log, c->msg, c->argv[1] );
1132 ber_str2bv( c->argv[1], 0, 1, &bv );
1133 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1139 if ( logfileName ) ch_free( logfileName );
1140 logfileName = c->value_string;
1141 logfile = fopen(logfileName, "w");
1142 if(logfile) lutil_debug_file(logfile);
1146 if(SLAP_NOLASTMODCMD(c->be)) {
1147 sprintf( c->msg, "<%s> not available for %s database",
1148 c->argv[0], c->be->bd_info->bi_type );
1149 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1150 c->log, c->msg, 0 );
1154 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1156 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1159 case CFG_SSTR_IF_MAX:
1160 if (c->value_int < index_substr_if_minlen) {
1161 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1162 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1163 c->log, c->msg, c->value_int );
1166 index_substr_if_maxlen = c->value_int;
1169 case CFG_SSTR_IF_MIN:
1170 if (c->value_int > index_substr_if_maxlen) {
1171 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1172 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1173 c->log, c->msg, c->value_int );
1176 index_substr_if_minlen = c->value_int;
1179 #ifdef SLAPD_MODULES
1181 /* If we're just adding a module on an existing modpath,
1182 * make sure we've selected the current path.
1184 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1185 modcur = c->private;
1186 /* This should never fail */
1187 if ( module_path( modcur->mp_path.bv_val )) {
1188 sprintf( c->msg, "<%s> module path no longer valid",
1190 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1191 c->log, c->msg, modcur->mp_path.bv_val );
1195 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1197 /* Record this load on the current path */
1201 if ( c->op == SLAP_CONFIG_ADD ) {
1202 ptr = c->line + STRLENOF("moduleload");
1203 while (!isspace(*ptr)) ptr++;
1204 while (isspace(*ptr)) ptr++;
1208 ber_str2bv(ptr, 0, 1, &bv);
1209 ber_bvarray_add( &modcur->mp_loads, &bv );
1214 if(module_path(c->argv[1])) return(1);
1215 /* Record which path was used with each module */
1219 if (!modpaths.mp_loads) {
1222 mp = ch_malloc( sizeof( ModPaths ));
1223 modlast->mp_next = mp;
1225 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1227 mp->mp_loads = NULL;
1238 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1240 slapi_plugins_used++;
1244 #ifdef SLAP_AUTH_REWRITE
1249 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1252 if ( c->argc > 1 ) {
1255 /* quote all args but the first */
1256 line = ldap_charray2str( c->argv, "\" \"" );
1257 ber_str2bv( line, 0, 0, &bv );
1258 s = strchr( bv.bv_val, '"' );
1259 assert( s != NULL );
1260 /* move the trailing quote of argv[0] to the end */
1261 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1262 bv.bv_val[ bv.bv_len - 1 ] = '"';
1265 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1268 ber_bvarray_add( &authz_rewrites, &bv );
1275 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1276 "%s: unknown CFG_TYPE %d"
1277 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1278 c->log, c->type, 0 );
1279 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1281 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1289 config_fname(ConfigArgs *c) {
1290 if(c->op == SLAP_CONFIG_EMIT) {
1292 ConfigFile *cf = c->private;
1293 value_add_one( &c->rvalue_vals, &cf->c_file );
1302 config_cfdir(ConfigArgs *c) {
1303 if(c->op == SLAP_CONFIG_EMIT) {
1304 if ( !BER_BVISEMPTY( &cfdir )) {
1305 value_add_one( &c->rvalue_vals, &cfdir );
1314 config_search_base(ConfigArgs *c) {
1315 if(c->op == SLAP_CONFIG_EMIT) {
1317 if (!BER_BVISEMPTY(&default_search_base)) {
1318 value_add_one(&c->rvalue_vals, &default_search_base);
1319 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1323 } else if( c->op == LDAP_MOD_DELETE ) {
1324 ch_free( default_search_base.bv_val );
1325 ch_free( default_search_nbase.bv_val );
1326 BER_BVZERO( &default_search_base );
1327 BER_BVZERO( &default_search_nbase );
1331 if(c->bi || c->be != frontendDB) {
1332 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1333 "prior to any backend or database definition\n",
1338 if(default_search_nbase.bv_len) {
1339 free(default_search_base.bv_val);
1340 free(default_search_nbase.bv_val);
1343 default_search_base = c->value_dn;
1344 default_search_nbase = c->value_ndn;
1349 config_passwd_hash(ConfigArgs *c) {
1351 if (c->op == SLAP_CONFIG_EMIT) {
1353 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1354 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1355 value_add_one(&c->rvalue_vals, &bv);
1358 } else if ( c->op == LDAP_MOD_DELETE ) {
1359 if ( c->valx < 0 ) {
1360 ldap_charray_free( default_passwd_hash );
1361 default_passwd_hash = NULL;
1364 ch_free( default_passwd_hash[i] );
1365 for (; default_passwd_hash[i]; i++ )
1366 default_passwd_hash[i] = default_passwd_hash[i+1];
1370 if(default_passwd_hash) {
1371 Debug(LDAP_DEBUG_ANY, "%s: "
1372 "already set default password_hash\n",
1376 for(i = 1; i < c->argc; i++) {
1377 if(!lutil_passwd_scheme(c->argv[i])) {
1378 sprintf( c->msg, "<%s> schema not available", c->argv[0] );
1379 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1380 c->log, c->msg, c->argv[i]);
1382 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1384 if(!default_passwd_hash) {
1385 sprintf( c->msg, "<%s> no valid hashes found", c->argv[0] );
1386 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1387 c->log, c->msg, 0 );
1395 config_schema_dn(ConfigArgs *c) {
1396 if ( c->op == SLAP_CONFIG_EMIT ) {
1398 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1399 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1400 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1404 } else if ( c->op == LDAP_MOD_DELETE ) {
1405 ch_free( c->be->be_schemadn.bv_val );
1406 ch_free( c->be->be_schemandn.bv_val );
1407 BER_BVZERO( &c->be->be_schemadn );
1408 BER_BVZERO( &c->be->be_schemandn );
1411 ch_free( c->be->be_schemadn.bv_val );
1412 ch_free( c->be->be_schemandn.bv_val );
1413 c->be->be_schemadn = c->value_dn;
1414 c->be->be_schemandn = c->value_ndn;
1419 config_sizelimit(ConfigArgs *c) {
1422 struct slap_limits_set *lim = &c->be->be_def_limit;
1423 if (c->op == SLAP_CONFIG_EMIT) {
1428 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1429 if ( !BER_BVISEMPTY( &bv ))
1430 value_add_one( &c->rvalue_vals, &bv );
1434 } else if ( c->op == LDAP_MOD_DELETE ) {
1435 /* Reset to defaults */
1436 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1437 lim->lms_s_hard = 0;
1438 lim->lms_s_unchecked = -1;
1440 lim->lms_s_pr_hide = 0;
1441 lim->lms_s_pr_total = 0;
1444 for(i = 1; i < c->argc; i++) {
1445 if(!strncasecmp(c->argv[i], "size", 4)) {
1446 rc = limits_parse_one(c->argv[i], lim);
1448 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1449 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1450 c->log, c->msg, c->argv[i]);
1454 if(!strcasecmp(c->argv[i], "unlimited")) {
1455 lim->lms_s_soft = -1;
1457 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1458 if(next == c->argv[i]) {
1459 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1460 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1461 c->log, c->msg, c->argv[i]);
1463 } else if(next[0] != '\0') {
1464 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1465 "trailing chars \"%s\" in \"sizelimit <limit>\" line"
1466 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1468 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1470 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1473 lim->lms_s_hard = 0;
1480 config_timelimit(ConfigArgs *c) {
1483 struct slap_limits_set *lim = &c->be->be_def_limit;
1484 if (c->op == SLAP_CONFIG_EMIT) {
1489 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1490 if ( !BER_BVISEMPTY( &bv ))
1491 value_add_one( &c->rvalue_vals, &bv );
1495 } else if ( c->op == LDAP_MOD_DELETE ) {
1496 /* Reset to defaults */
1497 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1498 lim->lms_t_hard = 0;
1501 for(i = 1; i < c->argc; i++) {
1502 if(!strncasecmp(c->argv[i], "time", 4)) {
1503 rc = limits_parse_one(c->argv[i], lim);
1505 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1506 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1507 c->log, c->msg, c->argv[i]);
1511 if(!strcasecmp(c->argv[i], "unlimited")) {
1512 lim->lms_t_soft = -1;
1514 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1515 if(next == c->argv[i]) {
1516 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1517 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1518 c->log, c->msg, c->argv[i]);
1520 } else if(next[0] != '\0') {
1521 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
1522 "trailing chars \"%s\" in \"timelimit <limit>\" line"
1523 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1525 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1527 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1530 lim->lms_t_hard = 0;
1537 config_overlay(ConfigArgs *c) {
1539 if (c->op == SLAP_CONFIG_EMIT) {
1541 } else if ( c->op == LDAP_MOD_DELETE ) {
1544 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1546 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: (optional) %s overlay \"%s\" configuration failed"
1547 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1548 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
1549 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1551 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1552 } else if(overlay_config(c->be, c->argv[1])) {
1555 /* Setup context for subsequent config directives.
1556 * The newly added overlay is at the head of the list.
1558 oi = (slap_overinfo *)c->be->bd_info;
1559 c->bi = &oi->oi_list->on_bi;
1564 config_suffix(ConfigArgs *c)
1567 struct berval pdn, ndn;
1568 char *notallowed = NULL;
1570 if ( c->be == frontendDB ) {
1571 notallowed = "frontend";
1573 } else if ( SLAP_MONITOR(c->be) ) {
1574 notallowed = "monitor";
1576 } else if ( SLAP_CONFIG(c->be) ) {
1577 notallowed = "config";
1580 if ( notallowed != NULL ) {
1581 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
1585 case LDAP_MOD_DELETE:
1586 case LDAP_MOD_REPLACE:
1587 case LDAP_MOD_INCREMENT:
1588 case SLAP_CONFIG_ADD:
1589 if ( !BER_BVISNULL( &c->value_dn ) ) {
1590 snprintf( buf, sizeof( buf ), "<%s> ",
1591 c->value_dn.bv_val );
1594 Debug(LDAP_DEBUG_ANY,
1595 "%s: suffix %snot allowed in %s database.\n",
1596 c->log, buf, notallowed );
1599 case SLAP_CONFIG_EMIT:
1600 /* don't complain when emitting... */
1604 /* FIXME: don't know what values may be valid;
1605 * please remove assertion, or add legal values
1606 * to either block */
1614 if (c->op == SLAP_CONFIG_EMIT) {
1615 if ( c->be->be_suffix == NULL
1616 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1620 value_add( &c->rvalue_vals, c->be->be_suffix );
1621 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1624 } else if ( c->op == LDAP_MOD_DELETE ) {
1625 if ( c->valx < 0 ) {
1626 ber_bvarray_free( c->be->be_suffix );
1627 ber_bvarray_free( c->be->be_nsuffix );
1628 c->be->be_suffix = NULL;
1629 c->be->be_nsuffix = NULL;
1632 ch_free( c->be->be_suffix[i].bv_val );
1633 ch_free( c->be->be_nsuffix[i].bv_val );
1634 for (; c->be->be_suffix[i].bv_val; i++) {
1635 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1636 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1642 #ifdef SLAPD_MONITOR_DN
1643 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1644 sprintf( c->msg, "<%s> DN is reserved for monitoring slapd",
1646 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1647 c->log, c->msg, SLAPD_MONITOR_DN);
1654 tbe = select_backend(&ndn, 0, 0);
1656 Debug( SLAPD_DEBUG_CONFIG_ERROR,
1657 "%s: suffix already served by this backend!"
1658 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1660 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1662 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1666 sprintf( c->msg, "<%s> suffix already served by a preceding backend",
1668 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1669 c->log, c->msg, tbe->be_suffix[0].bv_val);
1673 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1674 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1675 "base provided \"%s\" (assuming okay)\n",
1676 c->log, default_search_base.bv_val, 0);
1678 ber_bvarray_add(&c->be->be_suffix, &pdn);
1679 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1684 config_rootdn(ConfigArgs *c) {
1685 if (c->op == SLAP_CONFIG_EMIT) {
1686 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1687 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1688 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1693 } else if ( c->op == LDAP_MOD_DELETE ) {
1694 ch_free( c->be->be_rootdn.bv_val );
1695 ch_free( c->be->be_rootndn.bv_val );
1696 BER_BVZERO( &c->be->be_rootdn );
1697 BER_BVZERO( &c->be->be_rootndn );
1700 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1701 ch_free( c->be->be_rootdn.bv_val );
1702 ch_free( c->be->be_rootndn.bv_val );
1704 c->be->be_rootdn = c->value_dn;
1705 c->be->be_rootndn = c->value_ndn;
1710 config_rootpw(ConfigArgs *c) {
1713 if (c->op == SLAP_CONFIG_EMIT) {
1714 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1715 /* don't copy, because "rootpw" is marked
1717 c->value_bv = c->be->be_rootpw;
1721 } else if ( c->op == LDAP_MOD_DELETE ) {
1722 ch_free( c->be->be_rootpw.bv_val );
1723 BER_BVZERO( &c->be->be_rootpw );
1727 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1729 sprintf( c->msg, "<%s> can only be set when rootdn is under suffix",
1731 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1735 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1736 ch_free( c->be->be_rootpw.bv_val );
1737 c->be->be_rootpw = c->value_bv;
1742 config_restrict(ConfigArgs *c) {
1743 slap_mask_t restrictops = 0;
1745 slap_verbmasks restrictable_ops[] = {
1746 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1747 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1748 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1749 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1750 { BER_BVC("modrdn"), 0 },
1751 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1752 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1753 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1754 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1755 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1756 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1757 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1758 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1759 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1760 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1764 if (c->op == SLAP_CONFIG_EMIT) {
1765 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1767 } else if ( c->op == LDAP_MOD_DELETE ) {
1769 c->be->be_restrictops = 0;
1771 restrictops = verb_to_mask( c->line, restrictable_ops );
1772 c->be->be_restrictops ^= restrictops;
1776 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1778 sprintf( c->msg, "<%s> unknown operation", c->argv[0] );
1779 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1780 c->log, c->msg, c->argv[i]);
1783 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1784 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1785 c->be->be_restrictops |= restrictops;
1790 config_allows(ConfigArgs *c) {
1791 slap_mask_t allows = 0;
1793 slap_verbmasks allowable_ops[] = {
1794 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1795 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1796 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1797 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1800 if (c->op == SLAP_CONFIG_EMIT) {
1801 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1802 } else if ( c->op == LDAP_MOD_DELETE ) {
1806 allows = verb_to_mask( c->line, allowable_ops );
1807 global_allows ^= allows;
1811 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1813 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1814 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1815 c->log, c->msg, c->argv[i]);
1818 global_allows |= allows;
1823 config_disallows(ConfigArgs *c) {
1824 slap_mask_t disallows = 0;
1826 slap_verbmasks disallowable_ops[] = {
1827 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1828 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1829 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1830 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1831 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1834 if (c->op == SLAP_CONFIG_EMIT) {
1835 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1836 } else if ( c->op == LDAP_MOD_DELETE ) {
1838 global_disallows = 0;
1840 disallows = verb_to_mask( c->line, disallowable_ops );
1841 global_disallows ^= disallows;
1845 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1847 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1848 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1849 c->log, c->msg, c->argv[i]);
1852 global_disallows |= disallows;
1857 config_requires(ConfigArgs *c) {
1858 slap_mask_t requires = 0;
1860 slap_verbmasks requires_ops[] = {
1861 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1862 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1863 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1864 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1865 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1868 if (c->op == SLAP_CONFIG_EMIT) {
1869 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1870 } else if ( c->op == LDAP_MOD_DELETE ) {
1872 c->be->be_requires = 0;
1874 requires = verb_to_mask( c->line, requires_ops );
1875 c->be->be_requires ^= requires;
1879 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1881 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1882 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1883 c->log, c->msg, c->argv[i]);
1886 c->be->be_requires = requires;
1890 static slap_verbmasks *loglevel_ops;
1893 loglevel_init( void )
1895 slap_verbmasks lo[] = {
1896 { BER_BVC("Any"), -1 },
1897 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1898 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1899 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1900 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1901 { BER_BVC("BER"), LDAP_DEBUG_BER },
1902 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1903 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1904 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1905 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1906 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1907 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1908 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1909 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1910 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1911 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
1915 return slap_verbmasks_init( &loglevel_ops, lo );
1919 loglevel_destroy( void )
1921 if ( loglevel_ops ) {
1922 (void)slap_verbmasks_destroy( loglevel_ops );
1924 loglevel_ops = NULL;
1927 static slap_mask_t loglevel_ignore[] = { -1, 0 };
1930 slap_loglevel_register( slap_mask_t m, struct berval *s )
1934 if ( loglevel_ops == NULL ) {
1938 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
1941 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
1949 str2loglevel( const char *s, int *l )
1953 if ( loglevel_ops == NULL ) {
1957 i = verb_to_mask( s, loglevel_ops );
1959 if ( BER_BVISNULL( &loglevel_ops[ i ].word) ) {
1963 *l = loglevel_ops[ i ].mask;
1969 config_loglevel(ConfigArgs *c) {
1973 if ( loglevel_ops == NULL ) {
1977 if (c->op == SLAP_CONFIG_EMIT) {
1978 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1979 } else if ( c->op == LDAP_MOD_DELETE ) {
1983 int level = verb_to_mask( c->line, loglevel_ops );
1984 ldap_syslog ^= level;
1991 for( i=1; i < c->argc; i++ ) {
1994 if ( isdigit( c->argv[i][0] ) || c->argv[i][0] == '-' ) {
1995 level = strtol( c->argv[i], &next, 10 );
1996 if ( next == NULL || next[0] != '\0' ) {
1997 sprintf( c->msg, "<%s> unable to parse level", c->argv[0] );
1998 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1999 c->log, c->msg, c->argv[i]);
2003 if ( str2loglevel( c->argv[i], &level ) ) {
2004 sprintf( c->msg, "<%s> unknown level", c->argv[0] );
2005 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2006 c->log, c->msg, c->argv[i]);
2010 ldap_syslog |= level;
2016 config_referral(ConfigArgs *c) {
2018 if (c->op == SLAP_CONFIG_EMIT) {
2019 if ( default_referral ) {
2020 value_add( &c->rvalue_vals, default_referral );
2025 } else if ( c->op == LDAP_MOD_DELETE ) {
2026 if ( c->valx < 0 ) {
2027 ber_bvarray_free( default_referral );
2028 default_referral = NULL;
2031 ch_free( default_referral[i].bv_val );
2032 for (; default_referral[i].bv_val; i++ )
2033 default_referral[i] = default_referral[i+1];
2037 if(validate_global_referral(c->argv[1])) {
2038 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2039 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2040 c->log, c->msg, c->argv[1]);
2044 ber_str2bv(c->argv[1], 0, 0, &val);
2045 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2053 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2054 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2055 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2056 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2057 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2058 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2059 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2060 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2061 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2066 config_security(ConfigArgs *c) {
2067 slap_ssf_set_t *set = &c->be->be_ssf_set;
2070 if (c->op == SLAP_CONFIG_EMIT) {
2076 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2077 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2080 bv.bv_len = sprintf( numbuf, "%u", *tgt );
2081 bv.bv_len += sec_keys[i].key.bv_len;
2082 bv.bv_val = ch_malloc( bv.bv_len + 1);
2083 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2084 strcpy( next, numbuf );
2085 ber_bvarray_add( &c->rvalue_vals, &bv );
2090 for(i = 1; i < c->argc; i++) {
2091 slap_ssf_t *tgt = NULL;
2093 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2094 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2095 sec_keys[j].key.bv_len)) {
2096 src = c->argv[i] + sec_keys[j].key.bv_len;
2097 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2102 sprintf( c->msg, "<%s> unknown factor", c->argv[0] );
2103 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2104 c->log, c->msg, c->argv[i]);
2108 *tgt = strtol(src, &next, 10);
2109 if(next == NULL || next[0] != '\0' ) {
2110 sprintf( c->msg, "<%s> unable to parse factor", c->argv[0] );
2111 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2112 c->log, c->msg, c->argv[i]);
2120 anlist_unparse( AttributeName *an, char *ptr ) {
2123 for (; !BER_BVISNULL( &an->an_name ); an++) {
2124 if ( comma ) *ptr++ = ',';
2125 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2132 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2136 struct berval bc = BER_BVNULL;
2139 len = sprintf(numbuf, IFMT, i );
2141 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2142 if ( ri->ri_nsuffix ) {
2143 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2144 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2147 if ( ri->ri_attrs ) {
2148 len += STRLENOF("attr");
2149 if ( ri->ri_exclude ) len++;
2150 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2151 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2154 bindconf_unparse( &ri->ri_bindconf, &bc );
2157 bv->bv_val = ch_malloc(len + 1);
2160 ptr = lutil_strcopy( bv->bv_val, numbuf );
2161 ptr = lutil_strcopy( ptr, "uri=" );
2162 ptr = lutil_strcopy( ptr, ri->ri_uri );
2164 if ( ri->ri_nsuffix ) {
2165 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2166 ptr = lutil_strcopy( ptr, " suffix=\"" );
2167 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2171 if ( ri->ri_attrs ) {
2172 ptr = lutil_strcopy( ptr, "attr" );
2173 if ( ri->ri_exclude ) *ptr++ = '!';
2175 ptr = anlist_unparse( ri->ri_attrs, ptr );
2178 strcpy( ptr, bc.bv_val );
2179 ch_free( bc.bv_val );
2184 config_replica(ConfigArgs *c) {
2185 int i, nr = -1, len;
2186 char *replicahost, *replicauri;
2189 if (c->op == SLAP_CONFIG_EMIT) {
2190 if (c->be->be_replica) {
2192 for (i=0;c->be->be_replica[i]; i++) {
2193 replica_unparse( c->be->be_replica[i], i, &bv );
2194 ber_bvarray_add( &c->rvalue_vals, &bv );
2199 } else if ( c->op == LDAP_MOD_DELETE ) {
2200 /* FIXME: there is no replica_free function */
2201 if ( c->valx < 0 ) {
2205 if(SLAP_MONITOR(c->be)) {
2206 Debug(LDAP_DEBUG_ANY, "%s: "
2207 "\"replica\" should not be used inside monitor database\n",
2209 return(0); /* FIXME: should this be an error? */
2212 for(i = 1; i < c->argc; i++) {
2213 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2214 replicahost = c->argv[i] + STRLENOF("host=");
2215 len = strlen( replicahost );
2216 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2217 sprintf( replicauri, "ldap://%s", replicahost );
2218 replicahost = replicauri + STRLENOF( "ldap://");
2219 nr = add_replica_info(c->be, replicauri, replicahost);
2221 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2222 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2223 sprintf( c->msg, "<%s> invalid uri", c->argv[0] );
2224 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2227 if(!ludp->lud_host) {
2228 ldap_free_urldesc(ludp);
2229 sprintf( c->msg, "<%s> invalid uri - missing hostname",
2231 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2234 ldap_free_urldesc(ludp);
2235 replicauri = c->argv[i] + STRLENOF("uri=");
2236 replicauri = ch_strdup( replicauri );
2237 replicahost = strchr( replicauri, '/' );
2239 nr = add_replica_info(c->be, replicauri, replicahost);
2244 sprintf( c->msg, "<%s> missing host or uri", c->argv[0] );
2245 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2247 } else if(nr == -1) {
2248 sprintf( c->msg, "<%s> unable to add replica", c->argv[0] );
2249 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2252 for(i = 1; i < c->argc; i++) {
2253 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2254 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2256 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2257 "suffix \"%s\" in \"replica\" line is not valid for backend"
2258 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2259 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2260 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2262 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2265 Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
2266 "unable to normalize suffix in \"replica\" line"
2267 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
2269 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
2271 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
2275 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2277 char *arg = c->argv[i] + STRLENOF("attr");
2285 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2286 sprintf( c->msg, "<%s> unknown attribute", c->argv[0] );
2287 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2288 c->log, c->msg, arg + 1);
2291 } else if ( bindconf_parse( c->argv[i],
2292 &c->be->be_replica[nr]->ri_bindconf ) ) {
2301 config_updatedn(ConfigArgs *c) {
2302 if (c->op == SLAP_CONFIG_EMIT) {
2303 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2304 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2305 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2309 } else if ( c->op == LDAP_MOD_DELETE ) {
2310 ch_free( c->be->be_update_ndn.bv_val );
2311 BER_BVZERO( &c->be->be_update_ndn );
2312 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2315 if(SLAP_SHADOW(c->be)) {
2316 sprintf( c->msg, "<%s> database already shadowed", c->argv[0] );
2317 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2322 ber_memfree_x( c->value_dn.bv_val, NULL );
2323 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2324 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2326 c->be->be_update_ndn = c->value_ndn;
2327 BER_BVZERO( &c->value_dn );
2328 BER_BVZERO( &c->value_ndn );
2330 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2335 config_updateref(ConfigArgs *c) {
2337 if (c->op == SLAP_CONFIG_EMIT) {
2338 if ( c->be->be_update_refs ) {
2339 value_add( &c->rvalue_vals, c->be->be_update_refs );
2344 } else if ( c->op == LDAP_MOD_DELETE ) {
2345 if ( c->valx < 0 ) {
2346 ber_bvarray_free( c->be->be_update_refs );
2347 c->be->be_update_refs = NULL;
2350 ch_free( c->be->be_update_refs[i].bv_val );
2351 for (; c->be->be_update_refs[i].bv_val; i++)
2352 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2356 if(!SLAP_SHADOW(c->be)) {
2357 sprintf( c->msg, "<%s> must appear after syncrepl or updatedn",
2359 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2364 if(validate_global_referral(c->argv[1])) {
2365 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2366 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2367 c->log, c->msg, c->argv[1]);
2370 ber_str2bv(c->argv[1], 0, 0, &val);
2371 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2376 config_include(ConfigArgs *c) {
2377 int savelineno = c->lineno;
2380 ConfigFile *cfsave = cfn;
2381 ConfigFile *cf2 = NULL;
2382 if (c->op == SLAP_CONFIG_EMIT) {
2384 ConfigFile *cf = c->private;
2385 value_add_one( &c->rvalue_vals, &cf->c_file );
2389 } else if ( c->op == LDAP_MOD_DELETE ) {
2391 cf = ch_calloc( 1, sizeof(ConfigFile));
2392 if ( cfn->c_kids ) {
2393 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2399 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2400 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2401 c->lineno = savelineno - 1;
2404 if ( cf2 ) cf2->c_sibs = NULL;
2405 else cfn->c_kids = NULL;
2406 ch_free( cf->c_file.bv_val );
2416 config_tls_option(ConfigArgs *c) {
2419 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2420 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2421 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2422 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2423 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2424 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2425 default: Debug(LDAP_DEBUG_ANY, "%s: "
2426 "unknown tls_option <0x%x>\n",
2427 c->log, c->type, 0);
2429 if (c->op == SLAP_CONFIG_EMIT) {
2430 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2431 } else if ( c->op == LDAP_MOD_DELETE ) {
2432 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2434 ch_free(c->value_string);
2435 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2438 /* FIXME: this ought to be provided by libldap */
2440 config_tls_config(ConfigArgs *c) {
2442 slap_verbmasks crlkeys[] = {
2443 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2444 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2445 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2448 slap_verbmasks vfykeys[] = {
2449 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2450 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2451 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2452 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2456 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2457 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2459 Debug(LDAP_DEBUG_ANY, "%s: "
2460 "unknown tls_option <0x%x>\n",
2461 c->log, c->type, 0);
2463 if (c->op == SLAP_CONFIG_EMIT) {
2464 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2465 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2466 if (keys[i].mask == c->value_int) {
2467 c->value_string = ch_strdup( keys[i].word.bv_val );
2472 } else if ( c->op == LDAP_MOD_DELETE ) {
2474 return ldap_pvt_tls_set_option( NULL, flag, &i );
2476 ch_free( c->value_string );
2477 if(isdigit((unsigned char)c->argv[1][0])) {
2478 i = atoi(c->argv[1]);
2479 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2481 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2486 static CfEntryInfo *
2487 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2497 if ( dn_match( &root->ce_entry->e_nname, dn ))
2500 c = dn->bv_val+dn->bv_len;
2501 for (;*c != ',';c--);
2505 for (--c;c>dn->bv_val && *c != ',';c--);
2509 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2511 root = root->ce_kids;
2513 for (;root;root=root->ce_sibs) {
2514 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2515 if ( cdn.bv_val == dn->bv_val ) {
2525 typedef struct setup_cookie {
2531 config_ldif_resp( Operation *op, SlapReply *rs )
2533 if ( rs->sr_type == REP_SEARCH ) {
2534 setup_cookie *sc = op->o_callback->sc_private;
2536 sc->cfb->cb_got_ldif = 1;
2537 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL );
2538 if ( rs->sr_err != LDAP_SUCCESS ) {
2539 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
2540 rs->sr_entry->e_name.bv_val, sc->ca->msg, 0 );
2546 /* Configure and read the underlying back-ldif store */
2548 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
2549 CfBackInfo *cfb = be->be_private;
2555 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2556 Connection conn = {0};
2557 char opbuf[OPERATION_BUFFER_SIZE];
2559 SlapReply rs = {REP_RESULT};
2560 Filter filter = { LDAP_FILTER_PRESENT };
2561 struct berval filterstr = BER_BVC("(objectclass=*)");
2564 /* Is the config directory available? */
2565 if ( stat( dir, &st ) < 0 ) {
2566 /* No, so don't bother using the backing store.
2567 * All changes will be in-memory only.
2572 cfb->cb_db.bd_info = backend_info( "ldif" );
2573 if ( !cfb->cb_db.bd_info )
2574 return 0; /* FIXME: eventually this will be a fatal error */
2576 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2578 /* Mark that back-ldif type is in use */
2579 cfb->cb_db.bd_info->bi_nDB++;
2581 cfb->cb_db.be_suffix = be->be_suffix;
2582 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2583 cfb->cb_db.be_rootdn = be->be_rootdn;
2584 cfb->cb_db.be_rootndn = be->be_rootndn;
2586 ber_str2bv( dir, 0, 1, &cfdir );
2591 argv[0] = "directory";
2592 argv[1] = (char *)dir;
2596 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
2600 if ( config_add_vals( ct, &c ))
2603 if ( backend_startup_one( &cfb->cb_db ))
2607 void *thrctx = ldap_pvt_thread_pool_context();
2609 op = (Operation *)opbuf;
2610 connection_fake_init( &conn, op, thrctx );
2612 filter.f_desc = slap_schema.si_ad_objectClass;
2614 op->o_tag = LDAP_REQ_SEARCH;
2616 op->ors_filter = &filter;
2617 op->ors_filterstr = filterstr;
2618 op->ors_scope = LDAP_SCOPE_SUBTREE;
2620 op->o_dn = be->be_rootdn;
2621 op->o_ndn = be->be_rootndn;
2623 op->o_req_dn = be->be_suffix[0];
2624 op->o_req_ndn = be->be_nsuffix[0];
2626 op->ors_tlimit = SLAP_NO_LIMIT;
2627 op->ors_slimit = SLAP_NO_LIMIT;
2629 op->ors_attrs = slap_anlist_all_attributes;
2630 op->ors_attrsonly = 0;
2632 op->o_callback = &cb;
2635 cb.sc_private = ≻
2637 op->o_bd = &cfb->cb_db;
2638 rc = op->o_bd->be_search( op, &rs );
2640 ldap_pvt_thread_pool_context_reset( thrctx );
2643 cfb->cb_use_ldif = 1;
2649 CfOc_cmp( const void *c1, const void *c2 ) {
2650 const ConfigOCs *co1 = c1;
2651 const ConfigOCs *co2 = c2;
2653 return ber_bvcmp( co1->co_name, co2->co_name );
2657 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2660 i = init_config_attrs( ct );
2663 /* set up the objectclasses */
2664 i = init_config_ocs( ocs );
2667 for (i=0; ocs[i].co_def; i++) {
2668 if ( ocs[i].co_oc ) {
2669 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
2670 if ( !ocs[i].co_table )
2671 ocs[i].co_table = ct;
2672 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
2679 read_config(const char *fname, const char *dir) {
2682 const char *cfdir, *cfname;
2685 /* Setup the config backend */
2686 be = backend_db_init( "config" );
2690 cfb = be->be_private;
2692 /* If no .conf, or a dir was specified, setup the dir */
2693 if ( !fname || dir ) {
2695 /* If explicitly given, check for existence */
2698 if ( stat( dir, &st ) < 0 ) {
2699 Debug( LDAP_DEBUG_ANY,
2700 "invalid config directory %s, error %d\n",
2706 cfdir = SLAPD_DEFAULT_CONFIGDIR;
2708 /* if fname is defaulted, try reading .d */
2709 rc = config_setup_ldif( be, cfdir, !fname );
2711 /* It's OK if the base object doesn't exist yet */
2712 if ( rc && rc != LDAP_NO_SUCH_OBJECT )
2715 /* If we read the config from back-ldif, nothing to do here */
2716 if ( cfb->cb_got_ldif ) {
2725 cfname = SLAPD_DEFAULT_CONFIGFILE;
2727 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
2730 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
2732 /* If we got this far and failed, it may be a serious problem. In server
2733 * mode, we should never come to this. However, it may be alright if we're
2734 * using slapadd to create the conf dir.
2737 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
2739 /* If a config file was explicitly given, fail */
2743 /* Seems to be slapadd with a config dir, let it continue */
2744 if ( cfb->cb_use_ldif ) {
2746 cfb->cb_got_ldif = 1;
2752 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
2753 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
2754 &frontendDB->be_schemadn );
2755 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
2756 if ( rc != LDAP_SUCCESS ) {
2757 Debug(LDAP_DEBUG_ANY, "read_config: "
2758 "unable to normalize default schema DN \"%s\"\n",
2759 frontendDB->be_schemadn.bv_val, 0, 0 );
2760 /* must not happen */
2768 config_back_bind( Operation *op, SlapReply *rs )
2770 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2771 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2772 /* frontend sends result */
2773 return LDAP_SUCCESS;
2776 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2777 send_ldap_result( op, rs );
2783 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2787 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2789 rs->sr_attrs = op->ors_attrs;
2790 rs->sr_entry = ce->ce_entry;
2791 rc = send_search_entry( op, rs );
2793 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2794 if ( ce->ce_kids ) {
2795 rc = config_send( op, rs, ce->ce_kids, 1 );
2796 if ( rc ) return rc;
2799 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2800 rc = config_send( op, rs, ce, 0 );
2808 static ConfigTable *
2809 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad )
2813 for (j=0; j<nocs; j++) {
2814 for (i=0; colst[j]->co_table[i].name; i++)
2815 if ( colst[j]->co_table[i].ad == ad )
2816 return &colst[j]->co_table[i];
2821 /* Sort the attributes of the entry according to the order defined
2822 * in the objectclass, with required attributes occurring before
2823 * allowed attributes. For any attributes with sequencing dependencies
2824 * (e.g., rootDN must be defined after suffix) the objectclass must
2825 * list the attributes in the desired sequence.
2828 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
2830 Attribute *a, *head = NULL, *tail = NULL, **prev;
2833 for (i=0; i<nocs; i++) {
2834 if ( colst[i]->co_oc->soc_required ) {
2835 AttributeType **at = colst[i]->co_oc->soc_required;
2836 for (j=0; at[j]; j++) {
2837 for (a=e->e_attrs, prev=&e->e_attrs; a;
2838 prev = &(*prev)->a_next, a=a->a_next) {
2839 if ( a->a_desc == at[j]->sat_ad ) {
2853 if ( colst[i]->co_oc->soc_allowed ) {
2854 AttributeType **at = colst[i]->co_oc->soc_allowed;
2855 for (j=0; at[j]; j++) {
2856 for (a=e->e_attrs, prev=&e->e_attrs; a;
2857 prev = &(*prev)->a_next, a=a->a_next) {
2858 if ( a->a_desc == at[j]->sat_ad ) {
2874 tail->a_next = e->e_attrs;
2880 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2882 Attribute *a = NULL;
2883 AttributeDescription *ad;
2886 int i, rc = 0, sort = 0;
2893 Modifications *ml = ptr;
2895 vals = ml->sml_values;
2898 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2900 rc = ordered_value_sort( a, 1 );
2904 for ( i=0; vals[i].bv_val; i++ ) {
2905 ca->line = vals[i].bv_val;
2907 char *idx = strchr( ca->line, '}' );
2908 if ( idx ) ca->line = idx+1;
2910 rc = config_parse_vals( ct, ca, i );
2919 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2920 SlapReply *rs, int *renum )
2923 int index = -1, gotindex = 0, nsibs;
2924 int renumber = 0, tailindex = 0;
2928 if ( renum ) *renum = 0;
2930 /* These entries don't get indexed/renumbered */
2931 if ( ce_type == Cft_Global ) return 0;
2932 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2934 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2937 /* See if the rdn has an index already */
2938 dnRdn( &e->e_name, &rdn );
2939 ptr1 = strchr( e->e_name.bv_val, '{' );
2940 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2941 ptr2 = strchr( ptr1, '}' );
2942 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2943 return LDAP_NAMING_VIOLATION;
2944 if ( ptr2-ptr1 == 1)
2945 return LDAP_NAMING_VIOLATION;
2947 index = atoi(ptr1+1);
2949 /* Special case, we allow -1 for the frontendDB */
2950 if ( index != -1 || ce_type != Cft_Database ||
2951 strncmp( ptr2+1, "frontend,", STRLENOF("frontend,") ))
2953 return LDAP_NAMING_VIOLATION;
2957 /* count related kids */
2958 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2959 if ( ce->ce_type == ce_type ) nsibs++;
2962 if ( index != nsibs ) {
2964 if ( index < nsibs ) {
2965 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2966 /* Siblings need to be renumbered */
2971 struct berval ival, newrdn, nnewrdn;
2972 struct berval rtype, rval;
2974 AttributeDescription *ad = NULL;
2978 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2979 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2980 rtype.bv_val = rdn.bv_val;
2981 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2984 slap_bv2ad( &rtype, &ad, &text );
2985 a = attr_find( e->e_attrs, ad );
2986 if (!a ) return LDAP_NAMING_VIOLATION;
2989 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2991 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2992 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2995 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2996 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3003 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3005 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
3008 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3009 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3013 /* Do the equivalent of ModRDN */
3014 /* Replace DN / NDN */
3015 newrdn.bv_len = ptr1 - newrdn.bv_val;
3016 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3017 free( e->e_name.bv_val );
3018 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
3020 free( e->e_nname.bv_val );
3021 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
3025 free( a->a_vals[0].bv_val );
3026 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
3027 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
3028 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3029 strcpy( a->a_vals[0].bv_val, ptr1 );
3031 if ( a->a_nvals != a->a_vals ) {
3032 free( a->a_nvals[0].bv_val );
3033 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
3034 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
3035 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3036 strcpy( a->a_nvals[0].bv_val, ptr1 );
3038 free( nnewrdn.bv_val );
3039 free( newrdn.bv_val );
3042 if ( renum ) *renum = renumber;
3047 count_ocs( Attribute *oc_at, int *nocs )
3050 ConfigOCs co, *coptr, **colst;
3052 /* count the objectclasses */
3053 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
3055 colst = (ConfigOCs **)ch_malloc( n * sizeof(ConfigOCs *));
3057 for ( i=0, j=0; i<n; i++) {
3058 co.co_name = &oc_at->a_nvals[i];
3059 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
3061 /* ignore non-config objectclasses. probably should be
3062 * an error, general data doesn't belong here.
3064 if ( !coptr ) continue;
3066 /* Ignore the root objectclass, it has no implementation.
3068 if ( coptr->co_type == Cft_Abstract ) continue;
3076 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3078 if ( p->ce_type != Cft_Global && p->ce_type != Cft_Include )
3079 return LDAP_CONSTRAINT_VIOLATION;
3081 /* If we're reading from a configdir, don't parse this entry */
3083 return LDAP_COMPARE_TRUE;
3085 cfn = p->ce_private;
3087 return LDAP_SUCCESS;
3091 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3095 /* This entry is hardcoded, don't re-parse it */
3096 if ( p->ce_type == Cft_Global ) {
3097 cfn = p->ce_private;
3099 return LDAP_COMPARE_TRUE;
3101 if ( p->ce_type != Cft_Schema )
3102 return LDAP_CONSTRAINT_VIOLATION;
3104 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3106 cfo = p->ce_private;
3107 cfn->c_sibs = cfo->c_kids;
3109 return LDAP_SUCCESS;
3113 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3115 if ( p->ce_type != Cft_Global )
3116 return LDAP_CONSTRAINT_VIOLATION;
3117 ca->be = frontendDB; /* just to get past check_vals */
3118 return LDAP_SUCCESS;
3122 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3124 if ( p->ce_type != Cft_Global )
3125 return LDAP_CONSTRAINT_VIOLATION;
3126 return LDAP_SUCCESS;
3130 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3132 if ( p->ce_type != Cft_Global )
3133 return LDAP_CONSTRAINT_VIOLATION;
3134 return LDAP_SUCCESS;
3138 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3140 if ( p->ce_type != Cft_Database )
3141 return LDAP_CONSTRAINT_VIOLATION;
3143 return LDAP_SUCCESS;
3146 /* Parse an LDAP entry into config directives */
3148 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs, int *renum )
3150 CfEntryInfo *ce, *last;
3152 Attribute *a, *oc_at;
3153 int i, nocs, rc = 0;
3158 /* Make sure parent exists and entry does not */
3159 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3161 return LDAP_ALREADY_EXISTS;
3163 dnParent( &e->e_nname, &pdn );
3165 /* If last is NULL, the new entry is the root/suffix entry,
3166 * otherwise last should be the parent.
3168 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3170 rs->sr_matched = last->ce_entry->e_name.bv_val;
3171 return LDAP_NO_SUCH_OBJECT;
3174 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3175 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3177 memset( ca, 0, sizeof(ConfigArgs));
3179 /* Fake the coordinates based on whether we're part of an
3180 * LDAP Add or if reading the config dir
3183 ca->fname = "slapd";
3186 ca->fname = cfdir.bv_val;
3190 colst = count_ocs( oc_at, &nocs );
3192 /* Only the root can be Cft_Global, everything else must
3193 * have a parent. Only limited nesting arrangements are allowed.
3195 rc = LDAP_CONSTRAINT_VIOLATION;
3196 if ( colst[0]->co_type == Cft_Global && !last ) {
3197 cfn = cfb->cb_config;
3199 ca->be = frontendDB; /* just to get past check_vals */
3203 /* Check whether the Add is allowed by its parent, and do
3204 * any necessary arg setup
3207 for ( i=0; i<nocs; i++ ) {
3208 if ( colst[i]->co_ldadd &&
3209 ( rc = colst[i]->co_ldadd( last, e, ca ))
3210 != LDAP_CONSTRAINT_VIOLATION ) {
3216 /* Add the entry but don't parse it, we already have its contents */
3217 if ( rc == LDAP_COMPARE_TRUE ) {
3222 if ( rc != LDAP_SUCCESS )
3225 /* Parse all the values and check for simple syntax errors before
3226 * performing any set actions.
3228 * If doing an LDAPadd, check for indexed names and any necessary
3229 * renaming/renumbering. Entries that don't need indexed names are
3230 * ignored. Entries that need an indexed name and arrive without one
3231 * are assigned to the end. Entries that arrive with an index may
3232 * cause the following entries to be renumbered/bumped down.
3234 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3235 * don't allow Adding an entry with an index that's already in use.
3236 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3238 * These entries can have auto-assigned indexes (appended to the end)
3239 * but only the other types support auto-renumbering of siblings.
3241 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3245 init_config_argv( ca );
3247 /* Make sure we process attrs in the required order */
3248 sort_attrs( e, colst, nocs );
3250 for ( a=e->e_attrs; a; a=a->a_next ) {
3251 if ( a == oc_at ) continue;
3252 ct = config_find_table( colst, nocs, a->a_desc );
3253 if ( !ct ) continue; /* user data? */
3254 rc = check_vals( ct, ca, a, 1 );
3255 if ( rc ) goto done;
3258 /* Basic syntax checks are OK. Do the actual settings. */
3259 for ( a=e->e_attrs; a; a=a->a_next ) {
3260 if ( a == oc_at ) continue;
3261 ct = config_find_table( colst, nocs, a->a_desc );
3262 if ( !ct ) continue; /* user data? */
3263 for (i=0; a->a_vals[i].bv_val; i++) {
3264 ca->line = a->a_vals[i].bv_val;
3265 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3266 ptr = strchr( ca->line, '}' );
3267 if ( ptr ) ca->line = ptr+1;
3270 rc = config_parse_add( ct, ca );
3278 /* Newly added databases and overlays need to be started up */
3279 if ( CONFIG_ONLINE_ADD( ca )) {
3280 if ( colst[0]->co_type == Cft_Database ) {
3281 rc = backend_startup_one( ca->be );
3283 } else if ( colst[0]->co_type == Cft_Overlay ) {
3284 if ( ca->bi->bi_db_open ) {
3285 BackendInfo *bi_orig = ca->be->bd_info;
3286 ca->be->bd_info = ca->bi;
3287 rc = ca->bi->bi_db_open( ca->be );
3288 ca->be->bd_info = bi_orig;
3292 sprintf( ca->msg, "<%s> failed startup", ca->argv[0] );
3293 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
3294 ca->log, ca->msg, ca->argv[1] );
3300 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3301 ce->ce_parent = last;
3302 ce->ce_entry = entry_dup( e );
3303 ce->ce_entry->e_private = ce;
3304 ce->ce_type = colst[0]->co_type;
3307 ce->ce_private = ca->private;
3310 } else if ( last->ce_kids ) {
3313 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3322 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
3323 if ( ca->be != frontendDB )
3324 backend_destroy_one( ca->be, 1 );
3325 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
3326 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
3330 ch_free( ca->argv );
3331 if ( colst ) ch_free( colst );
3335 /* Parse an LDAP entry into config directives, then store in underlying
3339 config_back_add( Operation *op, SlapReply *rs )
3345 if ( !be_isroot( op ) ) {
3346 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3350 cfb = (CfBackInfo *)op->o_bd->be_private;
3352 ldap_pvt_thread_pool_pause( &connection_pool );
3355 * 1) check for existence of entry
3356 * 2) check for sibling renumbering
3357 * 3) perform internal add
3358 * 4) store entry in underlying database
3359 * 5) perform any necessary renumbering
3361 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber );
3362 if ( rs->sr_err != LDAP_SUCCESS ) {
3363 rs->sr_text = ca.msg;
3364 } else if ( cfb->cb_use_ldif ) {
3365 BackendDB *be = op->o_bd;
3366 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3367 op->o_bd = &cfb->cb_db;
3368 sc.sc_next = op->o_callback;
3369 op->o_callback = ≻
3370 op->o_bd->be_add( op, rs );
3372 op->o_callback = sc.sc_next;
3377 ldap_pvt_thread_pool_resume( &connection_pool );
3380 send_ldap_result( op, rs );
3384 typedef struct delrec {
3385 struct delrec *next;
3391 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3394 int rc = LDAP_UNWILLING_TO_PERFORM;
3396 Entry *e = ce->ce_entry;
3397 Attribute *save_attrs = e->e_attrs, *oc_at;
3402 delrec *dels = NULL, *deltail = NULL;
3404 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3405 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3407 colst = count_ocs( oc_at, &nocs );
3409 e->e_attrs = attrs_dup( e->e_attrs );
3411 init_config_argv( ca );
3414 ca->private = ce->ce_private;
3416 strcpy( ca->log, "back-config" );
3418 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3419 ct = config_find_table( colst, nocs, ml->sml_desc );
3420 switch (ml->sml_op) {
3421 case LDAP_MOD_DELETE:
3422 case LDAP_MOD_REPLACE: {
3423 BerVarray vals = NULL, nvals;
3425 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3427 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3428 ml->sml_desc->ad_cname.bv_val );
3431 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3432 vals = ml->sml_values;
3433 nvals = ml->sml_nvalues;
3434 ml->sml_values = NULL;
3435 ml->sml_nvalues = NULL;
3437 /* If we're deleting by values, remember the indexes of the
3438 * values we deleted.
3440 if ( ct && ml->sml_values ) {
3442 for (i=0; ml->sml_values[i].bv_val; i++);
3443 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
3454 rc = modify_delete_vindex(e, &ml->sml_mod,
3455 get_permissiveModify(op),
3456 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3457 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3458 ml->sml_values = vals;
3459 ml->sml_nvalues = nvals;
3464 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3467 case SLAP_MOD_SOFTADD: {
3468 int mop = ml->sml_op;
3470 ml->sml_op = LDAP_MOD_ADD;
3472 if ( ct->arg_type & ARG_NO_INSERT ) {
3473 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3475 for (i = 0; a->a_vals[i].bv_val; i++ );
3479 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3480 if ( ml->sml_values[i].bv_val[0] == '{' &&
3482 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3485 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3486 ml->sml_desc->ad_cname.bv_val );
3490 rc = check_vals( ct, ca, ml, 0 );
3494 rc = modify_add_values(e, &ml->sml_mod,
3495 get_permissiveModify(op),
3496 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3498 /* If value already exists, show success here
3499 * and ignore this operation down below.
3501 if ( mop == SLAP_MOD_SOFTADD ) {
3502 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3512 case LDAP_MOD_INCREMENT: /* FIXME */
3517 if(rc != LDAP_SUCCESS) break;
3520 if(rc == LDAP_SUCCESS) {
3521 /* check that the entry still obeys the schema */
3522 rc = entry_schema_check(op, e, NULL, 0,
3523 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3525 if ( rc == LDAP_SUCCESS ) {
3526 /* Basic syntax checks are OK. Do the actual settings. */
3527 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3528 ct = config_find_table( colst, nocs, ml->sml_desc );
3529 if ( !ct ) continue;
3531 switch (ml->sml_op) {
3532 case LDAP_MOD_DELETE:
3533 case LDAP_MOD_REPLACE: {
3534 BerVarray vals = NULL, nvals;
3538 a = attr_find( e->e_attrs, ml->sml_desc );
3540 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3541 vals = ml->sml_values;
3542 nvals = ml->sml_nvalues;
3543 ml->sml_values = NULL;
3544 ml->sml_nvalues = NULL;
3547 if ( ml->sml_values )
3550 /* If we didn't delete the whole attribute */
3551 if ( ml->sml_values && a ) {
3552 struct berval *mvals;
3555 if ( ml->sml_nvalues )
3556 mvals = ml->sml_nvalues;
3558 mvals = ml->sml_values;
3560 /* use the indexes we saved up above */
3561 for (i=0; i < d->nidx; i++) {
3562 struct berval bv = *mvals++;
3563 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3564 bv.bv_val[0] == '{' ) {
3565 ptr = strchr( bv.bv_val, '}' ) + 1;
3566 bv.bv_len -= ptr - bv.bv_val;
3569 ca->line = bv.bv_val;
3570 ca->valx = d->idx[i];
3571 rc = config_del_vals( ct, ca );
3572 if ( rc != LDAP_SUCCESS ) break;
3573 for (j=i+1; j < d->nidx; j++)
3574 if ( d->idx[j] >d->idx[i] )
3580 rc = config_del_vals( ct, ca );
3581 if ( rc ) rc = LDAP_OTHER;
3583 if ( ml->sml_values ) {
3587 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3588 ml->sml_values = vals;
3589 ml->sml_nvalues = nvals;
3591 if ( !vals || rc != LDAP_SUCCESS )
3594 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3597 for (i=0; ml->sml_values[i].bv_val; i++) {
3598 ca->line = ml->sml_values[i].bv_val;
3600 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3601 ca->line[0] == '{' ) {
3602 ptr = strchr( ca->line, '}' );
3604 ca->valx = strtol( ca->line+1, NULL, 0 );
3608 rc = config_parse_add( ct, ca );
3623 if ( rc == LDAP_SUCCESS ) {
3624 attrs_free( save_attrs );
3626 attrs_free( e->e_attrs );
3627 e->e_attrs = save_attrs;
3629 ch_free( ca->argv );
3630 if ( colst ) ch_free( colst );
3636 config_back_modify( Operation *op, SlapReply *rs )
3639 CfEntryInfo *ce, *last;
3641 ConfigArgs ca = {0};
3644 AttributeDescription *rad = NULL;
3646 if ( !be_isroot( op ) ) {
3647 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3651 cfb = (CfBackInfo *)op->o_bd->be_private;
3653 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3656 rs->sr_matched = last->ce_entry->e_name.bv_val;
3657 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3661 /* Get type of RDN */
3662 rdn = ce->ce_entry->e_nname;
3663 ptr = strchr( rdn.bv_val, '=' );
3664 rdn.bv_len = ptr - rdn.bv_val;
3665 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3667 /* Some basic validation... */
3668 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3669 /* Don't allow Modify of RDN; must use ModRdn for that. */
3670 if ( ml->sml_desc == rad ) {
3671 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3672 rs->sr_text = "Use modrdn to change the entry name";
3677 ldap_pvt_thread_pool_pause( &connection_pool );
3680 * 1) perform the Modify on the cached Entry.
3681 * 2) verify that the Entry still satisfies the schema.
3682 * 3) perform the individual config operations.
3683 * 4) store Modified entry in underlying LDIF backend.
3685 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3687 rs->sr_text = ca.msg;
3688 } else if ( cfb->cb_use_ldif ) {
3689 BackendDB *be = op->o_bd;
3690 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3691 op->o_bd = &cfb->cb_db;
3692 sc.sc_next = op->o_callback;
3693 op->o_callback = ≻
3694 op->o_bd->be_modify( op, rs );
3696 op->o_callback = sc.sc_next;
3699 ldap_pvt_thread_pool_resume( &connection_pool );
3701 send_ldap_result( op, rs );
3706 config_back_modrdn( Operation *op, SlapReply *rs )
3709 CfEntryInfo *ce, *last;
3711 if ( !be_isroot( op ) ) {
3712 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3716 cfb = (CfBackInfo *)op->o_bd->be_private;
3718 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3721 rs->sr_matched = last->ce_entry->e_name.bv_val;
3722 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3726 /* We don't allow moving objects to new parents.
3727 * Generally we only allow reordering a set of ordered entries.
3729 if ( op->orr_newSup ) {
3730 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3733 ldap_pvt_thread_pool_pause( &connection_pool );
3735 ldap_pvt_thread_pool_resume( &connection_pool );
3737 send_ldap_result( op, rs );
3742 config_back_search( Operation *op, SlapReply *rs )
3745 CfEntryInfo *ce, *last;
3747 if ( !be_isroot( op ) ) {
3748 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3752 cfb = (CfBackInfo *)op->o_bd->be_private;
3754 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3757 rs->sr_matched = last->ce_entry->e_name.bv_val;
3758 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3761 switch ( op->ors_scope ) {
3762 case LDAP_SCOPE_BASE:
3763 case LDAP_SCOPE_SUBTREE:
3764 config_send( op, rs, ce, 0 );
3767 case LDAP_SCOPE_ONELEVEL:
3768 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3769 config_send( op, rs, ce, 1 );
3774 rs->sr_err = LDAP_SUCCESS;
3776 send_ldap_result( op, rs );
3781 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
3782 ConfigTable *ct, ConfigArgs *c )
3786 for (; at && *at; at++) {
3787 /* Skip the naming attr */
3788 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3790 for (i=0;ct[i].name;i++) {
3791 if (ct[i].ad == (*at)->sat_ad) {
3792 rc = config_get_vals(&ct[i], c);
3793 if (rc == LDAP_SUCCESS) {
3794 if ( c->rvalue_nvals )
3795 attr_merge(e, ct[i].ad, c->rvalue_vals,
3798 attr_merge_normalize(e, ct[i].ad,
3799 c->rvalue_vals, NULL);
3800 ber_bvarray_free( c->rvalue_nvals );
3801 ber_bvarray_free( c->rvalue_vals );
3810 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3811 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
3813 Entry *e = ch_calloc( 1, sizeof(Entry) );
3814 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3816 struct berval ad_name;
3817 AttributeDescription *ad = NULL;
3824 CfEntryInfo *ceprev = NULL;
3828 ce->ce_parent = parent;
3830 pdn = parent->ce_entry->e_nname;
3831 if ( parent->ce_kids )
3832 for ( ceprev = parent->ce_kids; ceprev->ce_sibs;
3833 ceprev = ceprev->ce_sibs );
3838 ce->ce_type = main->co_type;
3839 ce->ce_private = c->private;
3843 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3844 ber_dupbv( &e->e_nname, &e->e_name );
3846 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3847 main->co_name, NULL );
3849 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
3850 extra->co_name, NULL );
3851 ptr = strchr(rdn->bv_val, '=');
3852 ad_name.bv_val = rdn->bv_val;
3853 ad_name.bv_len = ptr - rdn->bv_val;
3854 rc = slap_bv2ad( &ad_name, &ad, &text );
3859 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3860 attr_merge_normalize_one(e, ad, &val, NULL );
3863 if ( oc->soc_required )
3864 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
3866 if ( oc->soc_allowed )
3867 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
3871 if ( oc->soc_required )
3872 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
3874 if ( oc->soc_allowed )
3875 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
3878 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3879 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3881 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3884 op->o_bd->be_add( op, rs );
3887 ceprev->ce_sibs = ce;
3888 } else if ( parent ) {
3889 parent->ce_kids = ce;
3896 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3897 Operation *op, SlapReply *rs )
3900 ConfigFile *cf = c->private;
3904 for (; cf; cf=cf->c_sibs, c->depth++) {
3905 c->value_dn.bv_val = c->log;
3906 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3911 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3913 ptr = strchr( bv.bv_val, '.' );
3915 bv.bv_len = ptr - bv.bv_val;
3916 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3917 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3919 c->value_dn.bv_len += bv.bv_len;
3920 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3923 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3924 &CFOC_SCHEMA, NULL );
3925 if ( e && cf->c_kids ) {
3926 c->private = cf->c_kids;
3927 config_build_schema_inc( c, e->e_private, op, rs );
3933 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3934 Operation *op, SlapReply *rs )
3938 ConfigFile *cf = c->private;
3940 for (i=0; cf; cf=cf->c_sibs, i++) {
3941 c->value_dn.bv_val = c->log;
3942 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3944 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
3945 &CFOC_INCLUDE, NULL );
3946 if ( e && cf->c_kids ) {
3947 c->private = cf->c_kids;
3948 config_build_includes( c, e->e_private, op, rs );
3953 #ifdef SLAPD_MODULES
3956 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3957 Operation *op, SlapReply *rs )
3962 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3963 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3965 c->value_dn.bv_val = c->log;
3966 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3968 config_build_entry( op, rs, ceparent, c, &c->value_dn,
3969 &CFOC_MODULE, NULL );
3975 config_back_db_open( BackendDB *be )
3977 CfBackInfo *cfb = be->be_private;
3980 CfEntryInfo *ce, *ceparent;
3984 Connection conn = {0};
3985 char opbuf[OPERATION_BUFFER_SIZE];
3987 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3988 SlapReply rs = {REP_RESULT};
3989 void *thrctx = NULL;
3991 /* If we read the config from back-ldif, nothing to do here */
3992 if ( cfb->cb_got_ldif )
3995 if ( cfb->cb_use_ldif ) {
3996 thrctx = ldap_pvt_thread_pool_context();
3997 op = (Operation *)opbuf;
3998 connection_fake_init( &conn, op, thrctx );
4000 op->o_dn = be->be_rootdn;
4001 op->o_ndn = be->be_rootndn;
4003 op->o_tag = LDAP_REQ_ADD;
4004 op->o_callback = &cb;
4005 op->o_bd = &cfb->cb_db;
4010 /* create root of tree */
4012 c.private = cfb->cb_config;
4014 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
4021 /* Create includeFile nodes */
4022 if ( cfb->cb_config->c_kids ) {
4024 c.private = cfb->cb_config->c_kids;
4025 config_build_includes( &c, ceparent, op, &rs );
4028 #ifdef SLAPD_MODULES
4029 /* Create Module nodes... */
4030 if ( modpaths.mp_loads ) {
4031 config_build_modules( &c, ceparent, op, &rs );
4035 /* Create schema nodes... cn=schema will contain the hardcoded core
4036 * schema, read-only. Child objects will contain runtime loaded schema
4041 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
4044 /* Create schema nodes for included schema... */
4045 if ( cfb->cb_config->c_kids ) {
4047 c.private = cfb->cb_config->c_kids;
4048 config_build_schema_inc( &c, ce, op, &rs );
4051 /* Create backend nodes. Skip if they don't provide a cf_table.
4052 * There usually aren't any of these.
4056 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
4057 if (!bi->bi_cf_ocs) continue;
4058 if (!bi->bi_private) continue;
4061 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
4063 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
4067 /* Create database nodes... */
4068 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4069 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
4070 for ( i = -1, be = frontendDB ; be;
4071 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
4072 slap_overinfo *oi = NULL;
4074 if ( overlay_is_over( be )) {
4075 oi = be->bd_info->bi_private;
4081 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
4085 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
4088 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
4089 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
4090 /* Iterate through overlays */
4096 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
4098 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
4099 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
4102 oe = config_build_entry( op, &rs, ce, &c, &rdn,
4103 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
4104 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
4105 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
4110 ldap_pvt_thread_pool_context_reset( thrctx );
4116 cfb_free_cffile( ConfigFile *cf )
4120 for (; cf; cf=next) {
4123 cfb_free_cffile( cf->c_kids );
4124 ch_free( cf->c_file.bv_val );
4125 ber_bvarray_free( cf->c_dseFiles );
4131 cfb_free_entries( CfEntryInfo *ce )
4135 for (; ce; ce=next) {
4138 cfb_free_entries( ce->ce_kids );
4139 ce->ce_entry->e_private = NULL;
4140 entry_free( ce->ce_entry );
4146 config_back_db_close( BackendDB *be )
4148 CfBackInfo *cfb = be->be_private;
4150 cfb_free_entries( cfb->cb_root );
4151 cfb->cb_root = NULL;
4153 if ( cfb->cb_db.bd_info ) {
4154 backend_shutdown( &cfb->cb_db );
4161 config_back_db_destroy( BackendDB *be )
4163 CfBackInfo *cfb = be->be_private;
4165 cfb_free_cffile( cfb->cb_config );
4167 ch_free( cfdir.bv_val );
4169 avl_free( CfOcTree, NULL );
4171 if ( cfb->cb_db.bd_info ) {
4172 cfb->cb_db.be_suffix = NULL;
4173 cfb->cb_db.be_nsuffix = NULL;
4174 BER_BVZERO( &cfb->cb_db.be_rootdn );
4175 BER_BVZERO( &cfb->cb_db.be_rootndn );
4177 backend_destroy_one( &cfb->cb_db, 0 );
4180 free( be->be_private );
4188 config_back_db_init( BackendDB *be )
4193 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4194 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
4195 cfn = cfb->cb_config;
4196 be->be_private = cfb;
4198 ber_dupbv( &be->be_rootdn, &config_rdn );
4199 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4200 ber_dupbv( &dn, &be->be_rootdn );
4201 ber_bvarray_add( &be->be_suffix, &dn );
4202 ber_dupbv( &dn, &be->be_rootdn );
4203 ber_bvarray_add( &be->be_nsuffix, &dn );
4205 /* Hide from namingContexts */
4206 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4212 config_back_destroy( BackendInfo *bi )
4214 ldif_must_b64_encode_release();
4219 config_tool_entry_open( BackendDB *be, int mode )
4221 CfBackInfo *cfb = be->be_private;
4222 BackendInfo *bi = cfb->cb_db.bd_info;
4224 if ( bi && bi->bi_tool_entry_open )
4225 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
4232 config_tool_entry_close( BackendDB *be )
4234 CfBackInfo *cfb = be->be_private;
4235 BackendInfo *bi = cfb->cb_db.bd_info;
4237 if ( bi && bi->bi_tool_entry_close )
4238 return bi->bi_tool_entry_close( &cfb->cb_db );
4244 config_tool_entry_first( BackendDB *be )
4246 CfBackInfo *cfb = be->be_private;
4247 BackendInfo *bi = cfb->cb_db.bd_info;
4249 if ( bi && bi->bi_tool_entry_first )
4250 return bi->bi_tool_entry_first( &cfb->cb_db );
4256 config_tool_entry_next( BackendDB *be )
4258 CfBackInfo *cfb = be->be_private;
4259 BackendInfo *bi = cfb->cb_db.bd_info;
4261 if ( bi && bi->bi_tool_entry_next )
4262 return bi->bi_tool_entry_next( &cfb->cb_db );
4268 config_tool_entry_get( BackendDB *be, ID id )
4270 CfBackInfo *cfb = be->be_private;
4271 BackendInfo *bi = cfb->cb_db.bd_info;
4273 if ( bi && bi->bi_tool_entry_get )
4274 return bi->bi_tool_entry_get( &cfb->cb_db, id );
4280 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
4282 CfBackInfo *cfb = be->be_private;
4283 BackendInfo *bi = cfb->cb_db.bd_info;
4286 if ( bi && bi->bi_tool_entry_put &&
4287 config_add_internal( cfb, e, &ca, NULL, NULL ) == 0 )
4288 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
4295 AttributeDescription **desc;
4297 { "backend", &cfAd_backend },
4298 { "database", &cfAd_database },
4299 { "include", &cfAd_include },
4300 { "overlay", &cfAd_overlay },
4305 * add / delete: all types that may be added or deleted must use an
4306 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4307 * should automatically renumber the index of any siblings as needed,
4308 * so that no gaps in the numbering sequence exist after the add/delete
4310 * What can be added:
4312 * backend objects for backend-specific config directives
4316 * delete: probably no support this time around.
4318 * modrdn: generally not done. Will be invoked automatically by add/
4319 * delete to update numbering sequence. Perform as an explicit operation
4320 * so that the renumbering effect may be replicated. Subtree rename must
4321 * be supported, since renumbering a database will affect all its child
4324 * modify: must be fully supported.
4328 config_back_initialize( BackendInfo *bi )
4330 ConfigTable *ct = config_back_cf_table;
4333 AttributeDescription *ad = NULL;
4335 static char *controls[] = {
4336 LDAP_CONTROL_MANAGEDSAIT,
4340 bi->bi_controls = controls;
4345 bi->bi_destroy = config_back_destroy;
4347 bi->bi_db_init = config_back_db_init;
4348 bi->bi_db_config = 0;
4349 bi->bi_db_open = config_back_db_open;
4350 bi->bi_db_close = config_back_db_close;
4351 bi->bi_db_destroy = config_back_db_destroy;
4353 bi->bi_op_bind = config_back_bind;
4354 bi->bi_op_unbind = 0;
4355 bi->bi_op_search = config_back_search;
4356 bi->bi_op_compare = 0;
4357 bi->bi_op_modify = config_back_modify;
4358 bi->bi_op_modrdn = config_back_modrdn;
4359 bi->bi_op_add = config_back_add;
4360 bi->bi_op_delete = 0;
4361 bi->bi_op_abandon = 0;
4363 bi->bi_extended = 0;
4365 bi->bi_chk_referrals = 0;
4367 #ifdef SLAP_OVERLAY_ACCESS
4368 bi->bi_access_allowed = slap_access_always_allowed;
4369 #endif /* SLAP_OVERLAY_ACCESS */
4371 bi->bi_connection_init = 0;
4372 bi->bi_connection_destroy = 0;
4374 bi->bi_tool_entry_open = config_tool_entry_open;
4375 bi->bi_tool_entry_close = config_tool_entry_close;
4376 bi->bi_tool_entry_first = config_tool_entry_first;
4377 bi->bi_tool_entry_next = config_tool_entry_next;
4378 bi->bi_tool_entry_get = config_tool_entry_get;
4379 bi->bi_tool_entry_put = config_tool_entry_put;
4381 /* Make sure we don't exceed the bits reserved for userland */
4382 assert( ( ( CFG_LAST - 1 ) & ARGS_USERLAND ) == ( CFG_LAST - 1 ) );
4385 for (i=0; OidMacros[i].name; i++ ) {
4386 argv[1] = OidMacros[i].name;
4387 argv[2] = OidMacros[i].oid;
4388 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4391 bi->bi_cf_ocs = cf_ocs;
4393 i = config_register_schema( ct, cf_ocs );
4396 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4397 * basically, we don't care if it fails */
4398 i = slap_str2ad( "olcRootPW", &ad, &text );
4400 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4401 "warning, unable to get \"olcRootPW\" "
4402 "attribute description: %d: %s\n",
4405 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4406 ad->ad_type->sat_oid );
4409 /* set up the notable AttributeDescriptions */
4411 for (;ct->name;ct++) {
4412 if (strcmp(ct->name, ads[i].name)) continue;
4413 *ads[i].desc = ct->ad;
4415 if (!ads[i].name) break;