1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
39 static struct berval config_rdn = BER_BVC("cn=config");
40 static struct berval schema_rdn = BER_BVC("cn=schema");
45 typedef struct modpath_s {
46 struct modpath_s *mp_next;
47 struct berval mp_path;
51 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
54 typedef struct ConfigFile {
55 struct ConfigFile *c_sibs;
56 struct ConfigFile *c_kids;
58 AttributeType *c_at_head, *c_at_tail;
59 ContentRule *c_cr_head, *c_cr_tail;
60 ObjectClass *c_oc_head, *c_oc_tail;
61 OidMacro *c_om_head, *c_om_tail;
65 typedef struct CfOcInfo {
66 struct berval *co_name;
67 ConfigTable *co_table;
72 typedef struct CfEntryInfo {
73 struct CfEntryInfo *ce_parent;
74 struct CfEntryInfo *ce_sibs;
75 struct CfEntryInfo *ce_kids;
83 ConfigFile *cb_config;
85 BackendDB cb_db; /* underlying database */
90 /* These do nothing in slapd, they're kept only to make them
93 static char *replica_pidFile, *replica_argsFile;
94 static int replicationInterval;
96 static char *passwd_salt;
97 static char *logfileName;
98 static BerVarray authz_rewrites;
100 static struct berval cfdir;
103 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
106 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
107 *cfOc_include, *cfOc_overlay, *cfOc_module;
109 static ConfigFile cf_prv, *cfn = &cf_prv;
111 static Avlnode *CfOcTree;
113 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
114 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
115 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
116 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs,
119 static ConfigDriver config_fname;
120 static ConfigDriver config_cfdir;
121 static ConfigDriver config_generic;
122 static ConfigDriver config_search_base;
123 static ConfigDriver config_passwd_hash;
124 static ConfigDriver config_schema_dn;
125 static ConfigDriver config_sizelimit;
126 static ConfigDriver config_timelimit;
127 static ConfigDriver config_limits;
128 static ConfigDriver config_overlay;
129 static ConfigDriver config_suffix;
130 static ConfigDriver config_deref_depth;
131 static ConfigDriver config_rootdn;
132 static ConfigDriver config_rootpw;
133 static ConfigDriver config_restrict;
134 static ConfigDriver config_allows;
135 static ConfigDriver config_disallows;
136 static ConfigDriver config_requires;
137 static ConfigDriver config_security;
138 static ConfigDriver config_referral;
139 static ConfigDriver config_loglevel;
140 static ConfigDriver config_syncrepl;
141 static ConfigDriver config_replica;
142 static ConfigDriver config_updatedn;
143 static ConfigDriver config_updateref;
144 static ConfigDriver config_include;
146 static ConfigDriver config_tls_option;
147 static ConfigDriver config_tls_config;
196 static OidRec OidMacros[] = {
197 /* OpenLDAProot:666.11.1 */
198 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
199 { "OLcfgAt", "OLcfg:3" },
200 { "OLcfgGlAt", "OLcfgAt:0" },
201 { "OLcfgBkAt", "OLcfgAt:1" },
202 { "OLcfgDbAt", "OLcfgAt:2" },
203 { "OLcfgOvAt", "OLcfgAt:3" },
204 { "OLcfgOc", "OLcfg:4" },
205 { "OLcfgGlOc", "OLcfgOc:0" },
206 { "OLcfgBkOc", "OLcfgOc:1" },
207 { "OLcfgDbOc", "OLcfgOc:2" },
208 { "OLcfgOvOc", "OLcfgOc:3" },
209 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
210 { "OMsInteger", "OMsyn:27" },
211 { "OMsBoolean", "OMsyn:7" },
212 { "OMsDN", "OMsyn:12" },
213 { "OMsDirectoryString", "OMsyn:15" },
214 { "OMsOctetString", "OMsyn:40" },
219 * OLcfg{Bk|Db}{Oc|At}:0 -> common
220 * OLcfg{Bk|Db}{Oc|At}:1 -> bdb
221 * OLcfg{Bk|Db}{Oc|At}:2 -> ldif
222 * OLcfg{Bk|Db}{Oc|At}:3 -> ldap?
225 /* alphabetical ordering */
227 ConfigTable config_back_cf_table[] = {
228 /* This attr is read-only */
229 { "", "", 0, 0, 0, ARG_MAGIC,
230 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
231 "DESC 'File for slapd configuration directives' "
232 "EQUALITY caseIgnoreMatch "
233 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
234 { "", "", 0, 0, 0, ARG_MAGIC,
235 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
236 "DESC 'Directory for slapd configuration backend' "
237 "EQUALITY caseIgnoreMatch "
238 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
239 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
240 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
241 "DESC 'Access Control List' "
242 "EQUALITY caseIgnoreMatch "
243 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
244 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
245 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
246 "DESC 'Allowed set of deprecated features' "
247 "EQUALITY caseIgnoreMatch "
248 "SYNTAX OMsDirectoryString )", NULL, NULL },
249 { "argsfile", "file", 2, 2, 0, ARG_STRING,
250 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
251 "DESC 'File for slapd command line options' "
252 "EQUALITY caseIgnoreMatch "
253 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
254 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
255 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
256 "DESC 'OpenLDAP attributeTypes' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
260 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
261 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
262 "EQUALITY caseIgnoreMatch "
263 "SYNTAX OMsDirectoryString )", NULL, NULL },
264 { "authid-rewrite", NULL, 2, 0, 0,
265 #ifdef SLAP_AUTH_REWRITE
266 ARG_MAGIC|CFG_REWRITE, &config_generic,
270 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
271 "EQUALITY caseIgnoreMatch "
272 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
273 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
274 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
275 "EQUALITY caseIgnoreMatch "
276 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
277 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
278 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
279 "EQUALITY caseIgnoreMatch "
280 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
281 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
282 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
283 "DESC 'A type of backend' "
284 "EQUALITY caseIgnoreMatch "
285 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
287 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
288 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
289 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
290 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
291 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
292 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
293 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
294 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
295 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
296 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
297 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
298 "DESC 'The backend type for a database instance' "
299 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
300 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
301 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
302 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
303 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
304 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString )", NULL, NULL },
307 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
308 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
309 "DESC 'OpenLDAP DIT content rules' "
310 "EQUALITY caseIgnoreMatch "
311 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
313 { "gentlehup", "on|off", 2, 2, 0,
315 ARG_ON_OFF, &global_gentlehup,
319 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
320 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
321 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
322 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
323 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
324 /* XXX -- special case? */
325 { "include", "file", 2, 2, 0, ARG_MAGIC,
326 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
327 "SUP labeledURI )", NULL, NULL },
328 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
329 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
330 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
331 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
332 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
333 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
334 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
335 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
336 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
337 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
338 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
339 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
340 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
341 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
342 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
343 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
344 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
345 "SYNTAX OMsDirectoryString )", NULL, NULL },
346 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
347 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
348 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
349 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
350 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
351 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
352 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
353 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
354 "SYNTAX OMsDirectoryString )", NULL, NULL },
355 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
356 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
357 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
358 { "moduleload", "file", 2, 0, 0,
360 ARG_MAGIC|CFG_MODLOAD, &config_generic,
364 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
365 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
366 { "modulepath", "path", 2, 2, 0,
368 ARG_MAGIC|CFG_MODPATH, &config_generic,
372 "( OLcfgGlAt:31 NAME 'olcModulePath' "
373 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
374 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
375 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
376 "DESC 'OpenLDAP object classes' "
377 "EQUALITY caseIgnoreMatch "
378 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
380 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
381 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
382 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
383 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
384 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
385 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
386 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
387 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
388 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
389 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
390 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
391 "SYNTAX OMsDirectoryString )", NULL, NULL },
392 { "pidfile", "file", 2, 2, 0, ARG_STRING,
393 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
394 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
395 { "plugin", NULL, 0, 0, 0,
397 ARG_MAGIC|CFG_PLUGIN, &config_generic,
401 "( OLcfgGlAt:38 NAME 'olcPlugin' "
402 "SYNTAX OMsDirectoryString )", NULL, NULL },
403 { "pluginlog", "filename", 2, 2, 0,
405 ARG_STRING, &slapi_log_file,
409 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
410 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
411 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
412 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
413 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
414 { "referral", "url", 2, 2, 0, ARG_MAGIC,
415 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
416 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
417 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
418 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
419 "SUP labeledURI )", NULL, NULL },
420 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
421 &replica_argsFile, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
422 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
423 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
424 &replica_pidFile, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
425 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
426 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
427 &replicationInterval, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
428 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
429 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
430 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
431 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
432 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
433 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
434 "SYNTAX OMsDirectoryString )", NULL, NULL },
435 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
436 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
437 "SYNTAX OMsDirectoryString )", NULL, NULL },
438 { "reverse-lookup", "on|off", 2, 2, 0,
439 #ifdef SLAPD_RLOOKUPS
440 ARG_ON_OFF, &use_reverse_lookup,
444 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
445 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
446 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
447 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
448 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
449 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
450 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
451 "SYNTAX OMsDirectoryString )", NULL, NULL },
452 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
453 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
454 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
455 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
456 &config_generic, NULL, NULL, NULL },
457 { "sasl-host", "host", 2, 2, 0,
458 #ifdef HAVE_CYRUS_SASL
459 ARG_STRING|ARG_UNIQUE, &global_host,
463 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
464 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
465 { "sasl-realm", "realm", 2, 2, 0,
466 #ifdef HAVE_CYRUS_SASL
467 ARG_STRING|ARG_UNIQUE, &global_realm,
471 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
472 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
473 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
474 &config_generic, NULL, NULL, NULL },
475 { "sasl-secprops", "properties", 2, 2, 0,
476 #ifdef HAVE_CYRUS_SASL
477 ARG_MAGIC|CFG_SASLSECP, &config_generic,
481 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
482 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
483 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
484 &config_generic, NULL, NULL, NULL },
485 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
486 &config_generic, "( OLcfgGlAt:57 NAME 'olcSchemaCheck' "
487 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
488 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
489 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
490 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
491 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
492 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
493 "SYNTAX OMsDirectoryString )", NULL, NULL },
494 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
495 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
496 "SYNTAX OMsInteger )", NULL, NULL },
497 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
498 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
499 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
500 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
501 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
502 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
503 { "srvtab", "file", 2, 2, 0,
504 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
505 ARG_STRING, &ldap_srvtab,
509 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
510 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
511 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
512 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
513 "SYNTAX OMsDN )", NULL, NULL },
514 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
515 &config_syncrepl, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
516 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
517 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
518 &config_generic, "( OLcfgGlAt:66 NAME 'olcThreads' "
519 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
520 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
521 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
522 "SYNTAX OMsInteger )", NULL, NULL },
523 { "TLSCACertificateFile", NULL, 0, 0, 0,
525 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
529 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
530 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
531 { "TLSCACertificatePath", NULL, 0, 0, 0,
533 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
537 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
538 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
539 { "TLSCertificateFile", NULL, 0, 0, 0,
541 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
545 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
546 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
547 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
549 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
553 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
554 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
555 { "TLSCipherSuite", NULL, 0, 0, 0,
557 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
561 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
562 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
563 { "TLSCRLCheck", NULL, 0, 0, 0,
564 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
565 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
569 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
570 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
571 { "TLSRandFile", NULL, 0, 0, 0,
573 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
577 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
578 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
579 { "TLSVerifyClient", NULL, 0, 0, 0,
581 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
585 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
586 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
587 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
588 NULL, NULL, NULL, NULL },
589 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
590 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
591 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
592 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
593 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
594 "SUP labeledURI )", NULL, NULL },
595 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
596 NULL, NULL, NULL, NULL }
599 static ConfigOCs cf_ocs[] = {
602 "DESC 'OpenLDAP configuration object' "
603 "ABSTRACT SUP top )", Cft_Abstract, NULL },
606 "DESC 'OpenLDAP Global configuration options' "
607 "SUP olcConfig STRUCTURAL "
608 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
609 "olcAttributeOptions $ olcAuthIDRewrite $ "
610 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
611 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
612 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
613 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
614 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
615 "olcLogLevel $ olcModulePath $ "
616 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
617 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
618 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
619 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
620 "olcRootDSE $ olcRootPW $ "
621 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
622 "olcSchemaCheck $ olcSecurity $ olcSizeLimit $ "
623 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
624 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
625 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
626 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
627 "olcTLSRandFile $ olcTLSVerifyClient $ "
628 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
629 "olcDitContentRules ) )", Cft_Global, &cfOc_global },
631 "NAME 'olcSchemaConfig' "
632 "DESC 'OpenLDAP schema object' "
633 "SUP olcConfig STRUCTURAL "
634 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
635 "olcObjectClasses $ olcDitContentRules ) )",
636 Cft_Schema, &cfOc_schema },
638 "NAME 'olcBackendConfig' "
639 "DESC 'OpenLDAP Backend-specific options' "
640 "SUP olcConfig STRUCTURAL "
641 "MUST olcBackend )", Cft_Backend, &cfOc_backend },
643 "NAME 'olcDatabaseConfig' "
644 "DESC 'OpenLDAP Database-specific options' "
645 "SUP olcConfig STRUCTURAL "
647 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
648 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
649 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
650 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
651 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
652 Cft_Database, &cfOc_database },
654 "NAME 'olcOverlayConfig' "
655 "DESC 'OpenLDAP Overlay-specific options' "
656 "SUP olcConfig STRUCTURAL "
657 "MUST olcOverlay )", Cft_Overlay, &cfOc_overlay },
659 "NAME 'olcIncludeFile' "
660 "DESC 'OpenLDAP configuration include file' "
661 "SUP olcConfig STRUCTURAL "
663 "MAY ( cn $ olcRootDSE ) )",
664 Cft_Include, &cfOc_include },
667 "NAME 'olcModuleList' "
668 "DESC 'OpenLDAP dynamic module info' "
669 "SUP olcConfig STRUCTURAL "
670 "MUST olcModuleLoad "
671 "MAY cn )", Cft_Module, &cfOc_module },
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) != 0;
717 c->value_string = ch_strdup( slap_sasl_getpolicy());
720 slap_sasl_regexp_unparse( &c->rvalue_vals );
721 if ( !c->rvalue_vals ) rc = 1;
723 #ifdef HAVE_CYRUS_SASL
725 struct berval bv = BER_BVNULL;
726 slap_sasl_secprops_unparse( &bv );
727 if ( !BER_BVISNULL( &bv )) {
728 ber_bvarray_add( &c->rvalue_vals, &bv );
736 c->value_int = c->be->be_max_deref_depth;
739 ConfigFile *cf = c->private;
741 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
742 else if ( cf->c_om_head )
743 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
745 if ( !c->rvalue_vals )
750 ConfigFile *cf = c->private;
752 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
753 else if ( cf->c_oc_head )
754 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
756 if ( !c->rvalue_vals )
761 ConfigFile *cf = c->private;
763 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
764 else if ( cf->c_at_head )
765 at_unparse( &c->rvalue_vals, cf->c_at_head,
767 if ( !c->rvalue_vals )
772 ConfigFile *cf = c->private;
774 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
775 else if ( cf->c_cr_head )
776 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
778 if ( !c->rvalue_vals )
784 c->value_int = global_schemacheck;
788 char *src, *dst, ibuf[11];
789 struct berval bv, abv;
790 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
791 abv.bv_len = sprintf( ibuf, IFMT, i );
792 acl_unparse( a, &bv );
793 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
794 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
795 /* Turn TAB / EOL into plain space */
796 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
797 if (isspace(*src)) *dst++ = ' ';
801 if (dst[-1] == ' ') {
805 abv.bv_len = dst - abv.bv_val;
806 ber_bvarray_add( &c->rvalue_vals, &abv );
812 if ( c->be->be_replogfile )
813 c->value_string = ch_strdup( c->be->be_replogfile );
816 ConfigFile *cf = c->private;
817 if ( cf->c_dseFiles ) {
818 value_add( &c->rvalue_vals, cf->c_dseFiles );
826 c->value_string = ch_strdup( logfileName );
831 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
833 case CFG_SSTR_IF_MAX:
834 c->value_int = index_substr_if_maxlen;
836 case CFG_SSTR_IF_MIN:
837 c->value_int = index_substr_if_minlen;
841 ModPaths *mp = c->private;
844 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
847 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
848 mp->mp_loads[i].bv_val );
849 value_add_one( &c->rvalue_vals, &bv );
853 rc = c->rvalue_vals ? 0 : 1;
858 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
860 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
863 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
864 mp->mp_path.bv_val );
865 value_add_one( &c->rvalue_vals, &bv );
867 rc = c->rvalue_vals ? 0 : 1;
873 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
874 if ( !c->rvalue_vals ) rc = 1;
877 #ifdef SLAP_AUTH_REWRITE
879 if ( authz_rewrites ) {
880 struct berval bv, idx;
885 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
886 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
887 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
888 bv.bv_val = ch_malloc( bv.bv_len + 1 );
889 strcpy( bv.bv_val, idx.bv_val );
890 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
891 ber_bvarray_add( &c->rvalue_vals, &bv );
894 if ( !c->rvalue_vals ) rc = 1;
903 p = strchr(c->line,'(' /*')'*/);
904 if ( c->op == LDAP_MOD_DELETE ) {
912 ldap_pvt_thread_set_concurrency(c->value_int);
919 if(!(c->bi = backend_info(c->argv[1]))) {
920 Debug(LDAP_DEBUG_ANY, "%s: "
921 "backend %s failed init!\n", c->log, c->argv[1], 0);
928 /* NOTE: config is always the first backend!
930 if ( !strcasecmp( c->argv[1], "config" )) {
931 c->be = LDAP_STAILQ_FIRST(&backendDB);
932 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
934 } else if(!(c->be = backend_db_init(c->argv[1]))) {
935 Debug(LDAP_DEBUG_ANY, "%s: "
936 "database %s failed init!\n", c->log, c->argv[1], 0);
942 ldap_pvt_thread_set_concurrency(c->value_int);
946 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
947 connection_pool_max = c->value_int; /* save for reference */
951 if ( passwd_salt ) ch_free( passwd_salt );
952 passwd_salt = c->value_string;
953 lutil_salt_format(passwd_salt);
957 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
963 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
965 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
969 ch_free(c->value_string);
970 if (slap_sasl_setpolicy( c->argv[1] )) {
971 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
972 " \"authz-policy <policy>\"\n",
973 c->log, c->argv[1], 0 );
979 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
983 #ifdef HAVE_CYRUS_SASL
986 char *txt = slap_sasl_secprops( c->argv[1] );
988 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
997 c->be->be_max_deref_depth = c->value_int;
1003 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1005 if (!cfn->c_om_head) cfn->c_om_head = om;
1006 cfn->c_om_tail = om;
1013 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1014 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1015 cfn->c_oc_tail = oc;
1022 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1023 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1024 cfn->c_cr_tail = cr;
1031 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1032 if (!cfn->c_at_head) cfn->c_at_head = at;
1033 cfn->c_at_tail = at;
1038 ad_define_option(NULL, NULL, 0);
1039 for(i = 1; i < c->argc; i++)
1040 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1045 global_schemacheck = c->value_int;
1046 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1047 "schema checking disabled! your mileage may vary!\n",
1052 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1056 if(SLAP_MONITOR(c->be)) {
1057 Debug(LDAP_DEBUG_ANY, "%s: "
1058 "\"replogfile\" should not be used "
1059 "inside monitor database\n",
1061 return(0); /* FIXME: should this be an error? */
1064 c->be->be_replogfile = c->value_string;
1068 if(read_root_dse_file(c->argv[1])) {
1069 Debug(LDAP_DEBUG_ANY, "%s: "
1070 "could not read \"rootDSE <filename>\" line\n",
1076 ber_str2bv( c->argv[1], 0, 1, &bv );
1077 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1083 if ( logfileName ) ch_free( logfileName );
1084 logfileName = c->value_string;
1085 logfile = fopen(logfileName, "w");
1086 if(logfile) lutil_debug_file(logfile);
1090 if(SLAP_NOLASTMODCMD(c->be)) {
1091 Debug(LDAP_DEBUG_ANY, "%s: "
1092 "lastmod not available for %s databases\n",
1093 c->log, c->be->bd_info->bi_type, 0);
1097 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1099 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1102 case CFG_SSTR_IF_MAX:
1103 if (c->value_int < index_substr_if_minlen) {
1104 Debug(LDAP_DEBUG_ANY, "%s: "
1105 "invalid max value (%d)\n",
1106 c->log, c->value_int, 0 );
1109 index_substr_if_maxlen = c->value_int;
1112 case CFG_SSTR_IF_MIN:
1113 if (c->value_int > index_substr_if_maxlen) {
1114 Debug(LDAP_DEBUG_ANY, "%s: "
1115 "invalid min value (%d)\n",
1116 c->log, c->value_int, 0 );
1119 index_substr_if_minlen = c->value_int;
1122 #ifdef SLAPD_MODULES
1124 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1126 /* Record this load on the current path */
1129 char *ptr = c->line + STRLENOF("moduleload");
1130 while (!isspace(*ptr)) ptr++;
1131 while (isspace(*ptr)) ptr++;
1132 ber_str2bv(ptr, 0, 1, &bv);
1133 ber_bvarray_add( &modcur->mp_loads, &bv );
1138 if(module_path(c->argv[1])) return(1);
1139 /* Record which path was used with each module */
1143 if (!modpaths.mp_loads) {
1146 mp = ch_malloc( sizeof( ModPaths ));
1147 modlast->mp_next = mp;
1149 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1151 mp->mp_loads = NULL;
1153 if ( c->op == SLAP_CONFIG_ADD )
1162 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1164 slapi_plugins_used++;
1168 #ifdef SLAP_AUTH_REWRITE
1171 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1173 ber_str2bv( c->line, 0, 1, &bv );
1174 ber_bvarray_add( &authz_rewrites, &bv );
1181 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1182 "(ignored)\n", c->log, c->type, 0);
1190 config_fname(ConfigArgs *c) {
1191 if(c->op == SLAP_CONFIG_EMIT) {
1193 ConfigFile *cf = c->private;
1194 value_add_one( &c->rvalue_vals, &cf->c_file );
1203 config_cfdir(ConfigArgs *c) {
1204 if(c->op == SLAP_CONFIG_EMIT) {
1205 value_add_one( &c->rvalue_vals, &cfdir );
1212 config_search_base(ConfigArgs *c) {
1215 if(c->op == SLAP_CONFIG_EMIT) {
1217 if (!BER_BVISEMPTY(&default_search_base)) {
1218 value_add_one(&c->rvalue_vals, &default_search_base);
1219 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1225 if(c->bi || c->be != frontendDB) {
1226 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1227 "prior to any backend or database definition\n",
1232 if(default_search_nbase.bv_len) {
1233 Debug(LDAP_DEBUG_ANY, "%s: "
1234 "default search base \"%s\" already defined "
1235 "(discarding old)\n",
1236 c->log, default_search_base.bv_val, 0);
1237 free(default_search_base.bv_val);
1238 free(default_search_nbase.bv_val);
1241 default_search_base = c->value_dn;
1242 default_search_nbase = c->value_ndn;
1247 config_passwd_hash(ConfigArgs *c) {
1249 if (c->op == SLAP_CONFIG_EMIT) {
1251 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1252 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1253 value_add_one(&c->rvalue_vals, &bv);
1257 if(default_passwd_hash) {
1258 Debug(LDAP_DEBUG_ANY, "%s: "
1259 "already set default password_hash\n",
1263 for(i = 1; i < c->argc; i++) {
1264 if(!lutil_passwd_scheme(c->argv[i])) {
1265 Debug(LDAP_DEBUG_ANY, "%s: "
1266 "password scheme \"%s\" not available\n",
1267 c->log, c->argv[i], 0);
1269 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1271 if(!default_passwd_hash) {
1272 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1281 config_schema_dn(ConfigArgs *c) {
1282 if ( c->op == SLAP_CONFIG_EMIT ) {
1284 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1285 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1286 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1291 c->be->be_schemadn = c->value_dn;
1292 c->be->be_schemandn = c->value_ndn;
1297 config_sizelimit(ConfigArgs *c) {
1300 struct slap_limits_set *lim = &c->be->be_def_limit;
1301 if (c->op == SLAP_CONFIG_EMIT) {
1306 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1307 if ( !BER_BVISEMPTY( &bv ))
1308 value_add_one( &c->rvalue_vals, &bv );
1313 for(i = 1; i < c->argc; i++) {
1314 if(!strncasecmp(c->argv[i], "size", 4)) {
1315 rc = limits_parse_one(c->argv[i], lim);
1317 Debug(LDAP_DEBUG_ANY, "%s: "
1318 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1319 c->log, c->argv[i], 0);
1323 if(!strcasecmp(c->argv[i], "unlimited")) {
1324 lim->lms_s_soft = -1;
1326 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1327 if(next == c->argv[i]) {
1328 Debug(LDAP_DEBUG_ANY, "%s: "
1329 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1330 c->log, c->argv[i], 0);
1332 } else if(next[0] != '\0') {
1333 Debug(LDAP_DEBUG_ANY, "%s: "
1334 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1338 lim->lms_s_hard = 0;
1345 config_timelimit(ConfigArgs *c) {
1348 struct slap_limits_set *lim = &c->be->be_def_limit;
1349 if (c->op == SLAP_CONFIG_EMIT) {
1354 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1355 if ( !BER_BVISEMPTY( &bv ))
1356 value_add_one( &c->rvalue_vals, &bv );
1361 for(i = 1; i < c->argc; i++) {
1362 if(!strncasecmp(c->argv[i], "time", 4)) {
1363 rc = limits_parse_one(c->argv[i], lim);
1365 Debug(LDAP_DEBUG_ANY, "%s: "
1366 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1367 c->log, c->argv[i], 0);
1371 if(!strcasecmp(c->argv[i], "unlimited")) {
1372 lim->lms_t_soft = -1;
1374 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1375 if(next == c->argv[i]) {
1376 Debug(LDAP_DEBUG_ANY, "%s: "
1377 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1378 c->log, c->argv[i], 0);
1380 } else if(next[0] != '\0') {
1381 Debug(LDAP_DEBUG_ANY, "%s: "
1382 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1386 lim->lms_t_hard = 0;
1393 config_overlay(ConfigArgs *c) {
1394 if (c->op == SLAP_CONFIG_EMIT) {
1397 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1399 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1400 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1401 } else if(overlay_config(c->be, c->argv[1])) {
1408 config_suffix(ConfigArgs *c) {
1410 struct berval pdn, ndn;
1413 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1414 SLAP_CONFIG(c->be)) return 1;
1416 if (c->op == SLAP_CONFIG_EMIT) {
1417 if ( c->be->be_suffix == NULL
1418 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1422 value_add( &c->rvalue_vals, c->be->be_suffix );
1423 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1427 #ifdef SLAPD_MONITOR_DN
1428 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1429 Debug(LDAP_DEBUG_ANY, "%s: "
1430 "\"%s\" is reserved for monitoring slapd\n",
1431 c->log, SLAPD_MONITOR_DN, 0);
1438 tbe = select_backend(&ndn, 0, 0);
1440 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1445 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1446 c->log, tbe->be_suffix[0].bv_val, 0);
1450 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1451 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1452 "base provided \"%s\" (assuming okay)\n",
1453 c->log, default_search_base.bv_val, 0);
1455 ber_bvarray_add(&c->be->be_suffix, &pdn);
1456 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1461 config_rootdn(ConfigArgs *c) {
1462 if (c->op == SLAP_CONFIG_EMIT) {
1463 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1464 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1465 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1471 c->be->be_rootdn = c->value_dn;
1472 c->be->be_rootndn = c->value_ndn;
1477 config_rootpw(ConfigArgs *c) {
1479 if (c->op == SLAP_CONFIG_EMIT) {
1480 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1481 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1487 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1489 Debug(LDAP_DEBUG_ANY, "%s: "
1490 "rootpw can only be set when rootdn is under suffix\n",
1494 c->be->be_rootpw = c->value_bv;
1499 config_restrict(ConfigArgs *c) {
1500 slap_mask_t restrictops = 0;
1502 slap_verbmasks restrictable_ops[] = {
1503 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1504 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1505 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1506 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1507 { BER_BVC("modrdn"), 0 },
1508 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1509 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1510 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1511 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1512 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1513 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1514 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1515 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1516 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1517 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1521 if (c->op == SLAP_CONFIG_EMIT) {
1522 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1525 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1527 Debug(LDAP_DEBUG_ANY, "%s: "
1528 "unknown operation %s in \"restrict <features>\" line\n",
1529 c->log, c->argv[i], 0);
1532 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1533 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1534 c->be->be_restrictops |= restrictops;
1539 config_allows(ConfigArgs *c) {
1540 slap_mask_t allows = 0;
1542 slap_verbmasks allowable_ops[] = {
1543 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1544 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1545 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1546 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1549 if (c->op == SLAP_CONFIG_EMIT) {
1550 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1552 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1554 Debug(LDAP_DEBUG_ANY, "%s: "
1555 "unknown feature %s in \"allow <features>\" line\n",
1556 c->log, c->argv[i], 0);
1559 global_allows |= allows;
1564 config_disallows(ConfigArgs *c) {
1565 slap_mask_t disallows = 0;
1567 slap_verbmasks disallowable_ops[] = {
1568 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1569 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1570 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1571 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1572 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1575 if (c->op == SLAP_CONFIG_EMIT) {
1576 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1578 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1580 Debug(LDAP_DEBUG_ANY, "%s: "
1581 "unknown feature %s in \"disallow <features>\" line\n",
1582 c->log, c->argv[i], 0);
1585 global_disallows |= disallows;
1590 config_requires(ConfigArgs *c) {
1591 slap_mask_t requires = 0;
1593 slap_verbmasks requires_ops[] = {
1594 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1595 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1596 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1597 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1598 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1601 if (c->op == SLAP_CONFIG_EMIT) {
1602 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1604 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1606 Debug(LDAP_DEBUG_ANY, "%s: "
1607 "unknown feature %s in \"require <features>\" line\n",
1608 c->log, c->argv[i], 0);
1611 c->be->be_requires = requires;
1616 config_loglevel(ConfigArgs *c) {
1619 slap_verbmasks loglevel_ops[] = {
1620 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1621 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1622 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1623 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1624 { BER_BVC("BER"), LDAP_DEBUG_BER },
1625 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1626 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1627 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1628 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1629 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1630 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1631 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1632 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1633 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1634 { BER_BVC("Any"), -1 },
1638 if (c->op == SLAP_CONFIG_EMIT) {
1639 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1644 for( i=1; i < c->argc; i++ ) {
1647 if ( isdigit( c->argv[i][0] ) ) {
1648 level = strtol( c->argv[i], &next, 10 );
1649 if ( next == NULL || next[0] != '\0' ) {
1650 Debug( LDAP_DEBUG_ANY,
1651 "%s: unable to parse level \"%s\" "
1652 "in \"loglevel <level> [...]\" line.\n",
1653 c->log, c->argv[i], 0);
1657 int j = verb_to_mask(c->argv[i], loglevel_ops);
1658 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1659 Debug( LDAP_DEBUG_ANY,
1660 "%s: unknown level \"%s\" "
1661 "in \"loglevel <level> [...]\" line.\n",
1662 c->log, c->argv[i], 0);
1665 level = loglevel_ops[j].mask;
1667 ldap_syslog |= level;
1673 config_syncrepl(ConfigArgs *c) {
1674 if (c->op == SLAP_CONFIG_EMIT) {
1675 if ( c->be->be_syncinfo ) {
1677 syncrepl_unparse( c->be->be_syncinfo, &bv );
1678 ber_bvarray_add( &c->rvalue_vals, &bv );
1683 if(SLAP_SHADOW(c->be)) {
1684 Debug(LDAP_DEBUG_ANY, "%s: "
1685 "syncrepl: database already shadowed.\n",
1688 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1691 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1696 config_referral(ConfigArgs *c) {
1697 struct berval vals[2];
1698 if (c->op == SLAP_CONFIG_EMIT) {
1699 if ( default_referral ) {
1700 value_add( &c->rvalue_vals, default_referral );
1706 if(validate_global_referral(c->argv[1])) {
1707 Debug(LDAP_DEBUG_ANY, "%s: "
1708 "invalid URL (%s) in \"referral\" line.\n",
1709 c->log, c->argv[1], 0);
1713 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1714 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1715 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1723 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1724 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1725 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1726 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1727 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1728 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1729 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1730 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1731 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1736 config_security(ConfigArgs *c) {
1737 slap_ssf_set_t *set = &c->be->be_ssf_set;
1740 if (c->op == SLAP_CONFIG_EMIT) {
1746 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1747 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1750 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1751 bv.bv_len += sec_keys[i].key.bv_len;
1752 bv.bv_val = ch_malloc( bv.bv_len + 1);
1753 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1754 strcpy( next, numbuf );
1755 ber_bvarray_add( &c->rvalue_vals, &bv );
1760 for(i = 1; i < c->argc; i++) {
1761 slap_ssf_t *tgt = NULL;
1763 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1764 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1765 sec_keys[j].key.bv_len)) {
1766 src = c->argv[i] + sec_keys[j].key.bv_len;
1767 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1772 Debug(LDAP_DEBUG_ANY, "%s: "
1773 "unknown factor %s in \"security <factors>\" line\n",
1774 c->log, c->argv[i], 0);
1778 *tgt = strtol(src, &next, 10);
1779 if(next == NULL || next[0] != '\0' ) {
1780 Debug(LDAP_DEBUG_ANY, "%s: "
1781 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1782 c->log, c->argv[i], 0);
1790 anlist_unparse( AttributeName *an, char *ptr ) {
1793 for (; !BER_BVISNULL( &an->an_name ); an++) {
1794 if ( comma ) *ptr++ = ',';
1795 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1802 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1806 struct berval bc = {0};
1809 len = sprintf(numbuf, IFMT, i );
1811 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1812 if ( ri->ri_nsuffix ) {
1813 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1814 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1817 if ( ri->ri_attrs ) {
1818 len += STRLENOF("attr");
1819 if ( ri->ri_exclude ) len++;
1820 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1821 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1824 bindconf_unparse( &ri->ri_bindconf, &bc );
1827 bv->bv_val = ch_malloc(len + 1);
1830 ptr = lutil_strcopy( bv->bv_val, numbuf );
1831 ptr = lutil_strcopy( ptr, "uri=" );
1832 ptr = lutil_strcopy( ptr, ri->ri_uri );
1834 if ( ri->ri_nsuffix ) {
1835 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1836 ptr = lutil_strcopy( ptr, " suffix=\"" );
1837 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
1841 if ( ri->ri_attrs ) {
1842 ptr = lutil_strcopy( ptr, "attr" );
1843 if ( ri->ri_exclude ) *ptr++ = '!';
1845 ptr = anlist_unparse( ri->ri_attrs, ptr );
1848 strcpy( ptr, bc.bv_val );
1849 ch_free( bc.bv_val );
1854 config_replica(ConfigArgs *c) {
1855 int i, nr = -1, len;
1856 char *replicahost, *replicauri;
1859 if (c->op == SLAP_CONFIG_EMIT) {
1860 if (c->be->be_replica) {
1862 for (i=0;c->be->be_replica[i]; i++) {
1863 replica_unparse( c->be->be_replica[i], i, &bv );
1864 ber_bvarray_add( &c->rvalue_vals, &bv );
1870 if(SLAP_MONITOR(c->be)) {
1871 Debug(LDAP_DEBUG_ANY, "%s: "
1872 "\"replica\" should not be used inside monitor database\n",
1874 return(0); /* FIXME: should this be an error? */
1877 for(i = 1; i < c->argc; i++) {
1878 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
1879 replicahost = c->argv[i] + STRLENOF("host=");
1880 len = strlen( replicahost );
1881 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
1882 sprintf( replicauri, "ldap://%s", replicahost );
1883 replicahost = replicauri + STRLENOF( "ldap://");
1884 nr = add_replica_info(c->be, replicauri, replicahost);
1886 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
1887 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
1888 Debug(LDAP_DEBUG_ANY, "%s: "
1889 "replica line contains invalid "
1890 "uri definition.\n", c->log, 0, 0);
1893 if(!ludp->lud_host) {
1894 Debug(LDAP_DEBUG_ANY, "%s: "
1895 "replica line contains invalid "
1896 "uri definition - missing hostname.\n",
1900 ldap_free_urldesc(ludp);
1901 replicauri = c->argv[i] + STRLENOF("uri=");
1902 replicauri = ch_strdup( replicauri );
1903 replicahost = strchr( replicauri, '/' );
1905 nr = add_replica_info(c->be, replicauri, replicahost);
1910 Debug(LDAP_DEBUG_ANY, "%s: "
1911 "missing host or uri in \"replica\" line\n",
1914 } else if(nr == -1) {
1915 Debug(LDAP_DEBUG_ANY, "%s: "
1916 "unable to add replica \"%s\"\n",
1917 c->log, replicauri, 0);
1920 for(i = 1; i < c->argc; i++) {
1921 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
1922 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
1924 Debug(LDAP_DEBUG_ANY, "%s: "
1925 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1926 c->log, c->argv[i] + STRLENOF("suffix="), 0);
1929 Debug(LDAP_DEBUG_ANY, "%s: "
1930 "unable to normalize suffix in \"replica\" line (ignored)\n",
1935 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
1937 char *arg = c->argv[i] + STRLENOF("attr");
1945 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
1946 Debug(LDAP_DEBUG_ANY, "%s: "
1947 "attribute \"%s\" in \"replica\" line is unknown\n",
1948 c->log, arg + 1, 0);
1951 } else if ( bindconf_parse( c->argv[i],
1952 &c->be->be_replica[nr]->ri_bindconf ) ) {
1961 config_updatedn(ConfigArgs *c) {
1964 if (c->op == SLAP_CONFIG_EMIT) {
1965 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
1966 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
1967 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
1972 if(SLAP_SHADOW(c->be)) {
1973 Debug(LDAP_DEBUG_ANY, "%s: "
1974 "updatedn: database already shadowed.\n",
1979 ber_str2bv(c->argv[1], 0, 0, &dn);
1981 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
1983 if(rc != LDAP_SUCCESS) {
1984 Debug(LDAP_DEBUG_ANY, "%s: "
1985 "updatedn DN is invalid: %d (%s)\n",
1986 c->log, rc, ldap_err2string( rc ));
1990 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
1995 config_updateref(ConfigArgs *c) {
1996 struct berval vals[2];
1997 if (c->op == SLAP_CONFIG_EMIT) {
1998 if ( c->be->be_update_refs ) {
1999 value_add( &c->rvalue_vals, c->be->be_update_refs );
2005 if(!SLAP_SHADOW(c->be)) {
2006 Debug(LDAP_DEBUG_ANY, "%s: "
2007 "updateref line must come after syncrepl or updatedn.\n",
2012 if(validate_global_referral(c->argv[1])) {
2013 Debug(LDAP_DEBUG_ANY, "%s: "
2014 "invalid URL (%s) in \"updateref\" line.\n",
2015 c->log, c->argv[1], 0);
2018 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
2019 vals[1].bv_val = NULL;
2020 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
2025 config_include(ConfigArgs *c) {
2026 unsigned long savelineno = c->lineno;
2029 ConfigFile *cfsave = cfn;
2030 ConfigFile *cf2 = NULL;
2031 if (c->op == SLAP_CONFIG_EMIT) {
2033 ConfigFile *cf = c->private;
2034 value_add_one( &c->rvalue_vals, &cf->c_file );
2039 cf = ch_calloc( 1, sizeof(ConfigFile));
2040 if ( cfn->c_kids ) {
2041 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2047 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2048 rc = read_config_file(c->argv[1], c->depth + 1, c);
2049 c->lineno = savelineno - 1;
2052 if ( cf2 ) cf2->c_sibs = NULL;
2053 else cfn->c_kids = NULL;
2054 ch_free( cf->c_file.bv_val );
2062 config_tls_option(ConfigArgs *c) {
2065 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2066 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2067 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2068 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2069 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2070 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2071 default: Debug(LDAP_DEBUG_ANY, "%s: "
2072 "unknown tls_option <0x%x>\n",
2073 c->log, c->type, 0);
2075 if (c->op == SLAP_CONFIG_EMIT) {
2076 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2078 ch_free(c->value_string);
2079 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2082 /* FIXME: this ought to be provided by libldap */
2084 config_tls_config(ConfigArgs *c) {
2086 slap_verbmasks crlkeys[] = {
2087 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2088 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2089 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2092 slap_verbmasks vfykeys[] = {
2093 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2094 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2095 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2096 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2100 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2101 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2103 Debug(LDAP_DEBUG_ANY, "%s: "
2104 "unknown tls_option <0x%x>\n",
2105 c->log, c->type, 0);
2107 if (c->op == SLAP_CONFIG_EMIT) {
2108 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2109 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2110 if (keys[i].mask == c->value_int) {
2111 c->value_string = ch_strdup( keys[i].word.bv_val );
2117 ch_free( c->value_string );
2118 if(isdigit((unsigned char)c->argv[1][0])) {
2119 i = atoi(c->argv[1]);
2120 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2122 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2137 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2140 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2144 si->si_bindconf.sb_tls = SB_TLS_OFF;
2145 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2146 si->si_schemachecking = 0;
2147 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2148 &si->si_filterstr );
2149 si->si_base.bv_val = NULL;
2150 si->si_scope = LDAP_SCOPE_SUBTREE;
2151 si->si_attrsonly = 0;
2152 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2153 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2154 si->si_attrs = NULL;
2155 si->si_allattrs = 0;
2156 si->si_allopattrs = 0;
2157 si->si_exattrs = NULL;
2158 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2159 si->si_interval = 86400;
2160 si->si_retryinterval = NULL;
2161 si->si_retrynum_init = NULL;
2162 si->si_retrynum = NULL;
2163 si->si_manageDSAit = 0;
2167 si->si_presentlist = NULL;
2168 LDAP_LIST_INIT( &si->si_nonpresentlist );
2169 ldap_pvt_thread_mutex_init( &si->si_mutex );
2171 rc = parse_syncrepl_line( cargv, cargc, si );
2174 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2175 syncinfo_free( si );
2178 Debug( LDAP_DEBUG_CONFIG,
2179 "Config: ** successfully added syncrepl \"%s\"\n",
2180 BER_BVISNULL( &si->si_provideruri ) ?
2181 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2182 if ( !si->si_schemachecking ) {
2183 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2186 be->be_syncinfo = si;
2191 /* NOTE: used & documented in slapd.conf(5) */
2193 #define PROVIDERSTR "provider"
2194 #define TYPESTR "type"
2195 #define INTERVALSTR "interval"
2196 #define SEARCHBASESTR "searchbase"
2197 #define FILTERSTR "filter"
2198 #define SCOPESTR "scope"
2199 #define ATTRSSTR "attrs"
2200 #define ATTRSONLYSTR "attrsonly"
2201 #define SLIMITSTR "sizelimit"
2202 #define TLIMITSTR "timelimit"
2203 #define SCHEMASTR "schemachecking"
2205 /* FIXME: undocumented */
2206 #define OLDAUTHCSTR "bindprincipal"
2207 #define EXATTRSSTR "exattrs"
2208 #define RETRYSTR "retry"
2211 #define LASTMODSTR "lastmod"
2212 #define LMGENSTR "gen"
2213 #define LMNOSTR "no"
2214 #define LMREQSTR "req"
2215 #define SRVTABSTR "srvtab"
2216 #define SUFFIXSTR "suffix"
2217 #define MANAGEDSAITSTR "manageDSAit"
2220 #define GOT_ID 0x0001
2221 #define GOT_PROVIDER 0x0002
2224 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2230 { BER_BVC("base"), LDAP_SCOPE_BASE },
2231 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2232 #ifdef LDAP_SCOPE_SUBORDINATE
2233 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2234 { BER_BVC("subordinate"), 0 },
2236 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2241 parse_syncrepl_line(
2251 for ( i = 1; i < cargc; i++ ) {
2252 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2253 STRLENOF( IDSTR "=" ) ) )
2256 /* '\0' string terminator accounts for '=' */
2257 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2259 if ( tmp >= 1000 || tmp < 0 ) {
2260 fprintf( stderr, "Error: parse_syncrepl_line: "
2261 "syncrepl id %d is out of range [0..999]\n", tmp );
2266 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2267 STRLENOF( PROVIDERSTR "=" ) ) )
2269 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2270 ber_str2bv( val, 0, 1, &si->si_provideruri );
2271 gots |= GOT_PROVIDER;
2272 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2273 STRLENOF( SCHEMASTR "=" ) ) )
2275 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2276 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2277 si->si_schemachecking = 1;
2278 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2279 si->si_schemachecking = 0;
2281 si->si_schemachecking = 1;
2283 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2284 STRLENOF( FILTERSTR "=" ) ) )
2286 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2287 ber_str2bv( val, 0, 1, &si->si_filterstr );
2288 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2289 STRLENOF( SEARCHBASESTR "=" ) ) )
2294 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2295 if ( si->si_base.bv_val ) {
2296 ch_free( si->si_base.bv_val );
2298 ber_str2bv( val, 0, 0, &bv );
2299 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2300 if ( rc != LDAP_SUCCESS ) {
2301 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2302 val, rc, ldap_err2string( rc ) );
2305 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2306 STRLENOF( SCOPESTR "=" ) ) )
2309 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2310 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2311 if (!strncasecmp( val, scopes[j].key.bv_val,
2312 scopes[j].key.bv_len )) {
2313 while (!scopes[j].val) j--;
2314 si->si_scope = scopes[j].val;
2318 if ( BER_BVISNULL(&scopes[j].key) ) {
2319 fprintf( stderr, "Error: parse_syncrepl_line: "
2320 "unknown scope \"%s\"\n", val);
2323 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2324 STRLENOF( ATTRSONLYSTR "=" ) ) )
2326 si->si_attrsonly = 1;
2327 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2328 STRLENOF( ATTRSSTR "=" ) ) )
2330 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2331 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2333 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2334 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2335 if ( si->si_anlist == NULL ) {
2336 ch_free( attr_fname );
2339 si->si_anfile = attr_fname;
2341 char *str, *s, *next;
2342 char delimstr[] = " ,\t";
2343 str = ch_strdup( val );
2344 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2346 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2348 if ( strlen(s) == 1 && *s == '*' ) {
2349 si->si_allattrs = 1;
2350 *(val + ( s - str )) = delimstr[0];
2352 if ( strlen(s) == 1 && *s == '+' ) {
2353 si->si_allopattrs = 1;
2354 *(val + ( s - str )) = delimstr[0];
2358 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2359 if ( si->si_anlist == NULL ) {
2363 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2364 STRLENOF( EXATTRSSTR "=" ) ) )
2366 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2367 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2369 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2370 si->si_exanlist = file2anlist(
2371 si->si_exanlist, attr_fname, " ,\t" );
2372 if ( si->si_exanlist == NULL ) {
2373 ch_free( attr_fname );
2376 ch_free( attr_fname );
2378 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2379 if ( si->si_exanlist == NULL ) {
2383 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2384 STRLENOF( TYPESTR "=" ) ) )
2386 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2387 if ( !strncasecmp( val, "refreshOnly",
2388 STRLENOF("refreshOnly") ))
2390 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2391 } else if ( !strncasecmp( val, "refreshAndPersist",
2392 STRLENOF("refreshAndPersist") ))
2394 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2395 si->si_interval = 60;
2397 fprintf( stderr, "Error: parse_syncrepl_line: "
2398 "unknown sync type \"%s\"\n", val);
2401 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2402 STRLENOF( INTERVALSTR "=" ) ) )
2404 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2405 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2406 si->si_interval = 0;
2414 hstr = strchr( dstr, ':' );
2415 if ( hstr == NULL ) {
2416 fprintf( stderr, "Error: parse_syncrepl_line: "
2417 "invalid interval \"%s\"\n", val );
2421 mstr = strchr( hstr, ':' );
2422 if ( mstr == NULL ) {
2423 fprintf( stderr, "Error: parse_syncrepl_line: "
2424 "invalid interval \"%s\"\n", val );
2428 sstr = strchr( mstr, ':' );
2429 if ( sstr == NULL ) {
2430 fprintf( stderr, "Error: parse_syncrepl_line: "
2431 "invalid interval \"%s\"\n", val );
2440 if (( hh > 24 ) || ( hh < 0 ) ||
2441 ( mm > 60 ) || ( mm < 0 ) ||
2442 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2443 fprintf( stderr, "Error: parse_syncrepl_line: "
2444 "invalid interval \"%s\"\n", val );
2447 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2449 if ( si->si_interval < 0 ) {
2450 fprintf( stderr, "Error: parse_syncrepl_line: "
2451 "invalid interval \"%ld\"\n",
2452 (long) si->si_interval);
2455 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2456 STRLENOF( RETRYSTR "=" ) ) )
2461 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2462 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2463 retry_list[0] = NULL;
2465 slap_str2clist( &retry_list, val, " ,\t" );
2467 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2471 "Error: incomplete syncrepl retry list\n" );
2472 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2473 ch_free( retry_list[k] );
2475 ch_free( retry_list );
2476 exit( EXIT_FAILURE );
2478 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2479 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2480 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2481 for ( j = 0; j < n; j++ ) {
2482 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2483 if ( *retry_list[j*2+1] == '+' ) {
2484 si->si_retrynum_init[j] = -1;
2485 si->si_retrynum[j] = -1;
2489 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2490 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2493 si->si_retrynum_init[j] = -2;
2494 si->si_retrynum[j] = -2;
2495 si->si_retryinterval[j] = 0;
2497 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2498 ch_free( retry_list[k] );
2500 ch_free( retry_list );
2501 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2502 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2504 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2505 si->si_manageDSAit = atoi( val );
2506 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2507 STRLENOF( SLIMITSTR "=") ) )
2509 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2510 si->si_slimit = atoi( val );
2511 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2512 STRLENOF( TLIMITSTR "=" ) ) )
2514 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2515 si->si_tlimit = atoi( val );
2516 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2517 fprintf( stderr, "Error: parse_syncrepl_line: "
2518 "unknown keyword \"%s\"\n", cargv[ i ] );
2523 if ( gots != GOT_ALL ) {
2525 "Error: Malformed \"syncrepl\" line in slapd config file" );
2533 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2536 char buf[BUFSIZ*2], *ptr;
2539 bindconf_unparse( &si->si_bindconf, &bc );
2541 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
2542 si->si_rid, si->si_provideruri.bv_val );
2543 if ( !BER_BVISNULL( &bc )) {
2544 ptr = lutil_strcopy( ptr, bc.bv_val );
2547 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2548 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2549 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2552 if ( !BER_BVISNULL( &si->si_base )) {
2553 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2554 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2557 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2558 if ( si->si_scope == scopes[i].val ) {
2559 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2560 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2564 if ( si->si_attrsonly ) {
2565 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2567 if ( si->si_anfile ) {
2568 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2569 ptr = lutil_strcopy( ptr, si->si_anfile );
2570 } else if ( si->si_allattrs || si->si_allopattrs ||
2571 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2573 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2575 ptr = anlist_unparse( si->si_anlist, ptr );
2576 if ( si->si_allattrs ) {
2577 if ( old != ptr ) *ptr++ = ',';
2580 if ( si->si_allopattrs ) {
2581 if ( old != ptr ) *ptr++ = ',';
2586 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
2587 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
2588 ptr = anlist_unparse( si->si_exanlist, ptr );
2590 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
2591 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
2593 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
2594 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
2595 "refreshAndPersist" : "refreshOnly" );
2597 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
2600 dd = si->si_interval;
2607 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
2608 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
2609 } else if ( si->si_retryinterval ) {
2611 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
2612 for (i=0; si->si_retryinterval[i]; i++) {
2613 if ( space ) *ptr++ = ' ';
2615 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
2616 if ( si->si_retrynum_init[i] == -1 )
2619 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
2624 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
2625 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
2626 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
2629 if ( si->si_slimit ) {
2630 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
2631 ptr += sprintf( ptr, "%d", si->si_slimit );
2634 if ( si->si_tlimit ) {
2635 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
2636 ptr += sprintf( ptr, "%d", si->si_tlimit );
2638 bc.bv_len = ptr - buf;
2640 ber_dupbv( bv, &bc );
2643 static CfEntryInfo *
2644 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2654 if ( dn_match( &root->ce_entry->e_nname, dn ))
2657 c = dn->bv_val+dn->bv_len;
2658 for (;*c != ',';c--);
2662 for (--c;c>dn->bv_val && *c != ',';c--);
2666 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2668 root = root->ce_kids;
2670 for (;root;root=root->ce_sibs) {
2671 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2672 if ( cdn.bv_val == dn->bv_val ) {
2683 config_ldif_resp( Operation *op, SlapReply *rs )
2685 if ( rs->sr_type == REP_SEARCH ) {
2686 CfBackInfo *cfb = op->o_callback->sc_private;
2688 cfb->cb_got_ldif = 1;
2689 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL );
2694 /* Configure and read the underlying back-ldif store */
2696 config_setup_ldif( BackendDB *be, const char *dir ) {
2697 CfBackInfo *cfb = be->be_private;
2702 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2703 Connection conn = {0};
2704 char opbuf[OPERATION_BUFFER_SIZE];
2706 SlapReply rs = {REP_RESULT};
2707 Filter filter = { LDAP_FILTER_PRESENT };
2708 struct berval filterstr = BER_BVC("(objectclass=*)");
2711 /* Is the config directory available? */
2712 if ( stat( dir, &st ) < 0 ) {
2713 /* No, so don't bother using the backing store.
2714 * All changes will be in-memory only.
2719 cfb->cb_db.bd_info = backend_info( "ldif" );
2720 if ( !cfb->cb_db.bd_info )
2721 return 0; /* FIXME: eventually this will be a fatal error */
2723 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2725 /* Mark that back-ldif type is in use */
2726 cfb->cb_db.bd_info->bi_nDB++;
2728 cfb->cb_db.be_suffix = be->be_suffix;
2729 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2730 cfb->cb_db.be_rootdn = be->be_rootdn;
2731 cfb->cb_db.be_rootndn = be->be_rootndn;
2733 ber_str2bv( dir, 0, 1, &cfdir );
2738 argv[0] = "directory";
2739 argv[1] = (char *)dir;
2743 ct = config_find_keyword( c.be->be_cf_table, &c );
2747 if ( config_add_vals( ct, &c ))
2750 if ( backend_startup_one( &cfb->cb_db ))
2753 op = (Operation *)opbuf;
2754 connection_fake_init( &conn, op, cfb );
2756 filter.f_desc = slap_schema.si_ad_objectClass;
2758 op->o_tag = LDAP_REQ_SEARCH;
2760 op->ors_filter = &filter;
2761 op->ors_filterstr = filterstr;
2762 op->ors_scope = LDAP_SCOPE_SUBTREE;
2764 op->o_dn = be->be_rootdn;
2765 op->o_ndn = be->be_rootndn;
2767 op->o_req_dn = be->be_suffix[0];
2768 op->o_req_ndn = be->be_nsuffix[0];
2770 op->ors_tlimit = SLAP_NO_LIMIT;
2771 op->ors_slimit = SLAP_NO_LIMIT;
2773 op->ors_attrs = slap_anlist_all_attributes;
2774 op->ors_attrsonly = 0;
2776 op->o_callback = &cb;
2777 cb.sc_private = cfb;
2779 op->o_bd = &cfb->cb_db;
2780 op->o_bd->be_search( op, &rs );
2782 cfb->cb_use_ldif = 1;
2788 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2789 const CfOcInfo *co1 = c1;
2790 const CfOcInfo *co2 = c2;
2792 return ber_bvcmp( co1->co_name, co2->co_name );
2796 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2800 i = init_config_attrs( ct );
2803 /* set up the objectclasses */
2804 i = init_config_ocs( ocs );
2807 for (i=0; ocs[i].def; i++) {
2809 co = ch_malloc( sizeof(CfOcInfo) );
2810 co->co_oc = *ocs[i].oc;
2811 co->co_name = &co->co_oc->soc_cname;
2813 co->co_type = ocs[i].cft;
2814 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2821 read_config(const char *fname, const char *dir) {
2825 /* Setup the config backend */
2826 be = backend_db_init( "config" );
2830 cfb = be->be_private;
2832 /* Setup the underlying back-ldif backend */
2833 if ( config_setup_ldif( be, dir ))
2836 #ifdef SLAP_USE_CONFDIR
2837 /* If we read the config from back-ldif, nothing to do here */
2838 if ( cfb->cb_got_ldif )
2841 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2843 return read_config_file(fname, 0, NULL);
2847 config_back_bind( Operation *op, SlapReply *rs )
2849 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2850 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2851 /* frontend sends result */
2852 return LDAP_SUCCESS;
2855 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2856 send_ldap_result( op, rs );
2862 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2866 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2868 rs->sr_attrs = op->ors_attrs;
2869 rs->sr_entry = ce->ce_entry;
2870 rc = send_search_entry( op, rs );
2872 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2873 if ( ce->ce_kids ) {
2874 rc = config_send( op, rs, ce->ce_kids, 1 );
2875 if ( rc ) return rc;
2878 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2879 rc = config_send( op, rs, ce, 0 );
2887 static ConfigTable *
2888 config_find_table( CfOcInfo **colst, int nocs, AttributeDescription *ad )
2892 for (j=0; j<nocs; j++) {
2893 for (i=0; colst[j]->co_table[i].name; i++)
2894 if ( colst[j]->co_table[i].ad == ad )
2895 return &colst[j]->co_table[i];
2900 /* Sort the attributes of the entry according to the order defined
2901 * in the objectclass, with required attributes occurring before
2902 * allowed attributes. For any attributes with sequencing dependencies
2903 * (e.g., rootDN must be defined after suffix) the objectclass must
2904 * list the attributes in the desired sequence.
2907 sort_attrs( Entry *e, CfOcInfo **colst, int nocs )
2909 Attribute *a, *head = NULL, *tail = NULL, **prev;
2912 for (i=0; i<nocs; i++) {
2913 if ( colst[i]->co_oc->soc_required ) {
2914 AttributeType **at = colst[i]->co_oc->soc_required;
2915 for (j=0; at[j]; j++) {
2916 for (a=e->e_attrs, prev=&e->e_attrs; a;
2917 prev = &(*prev)->a_next, a=a->a_next) {
2918 if ( a->a_desc == at[j]->sat_ad ) {
2932 if ( colst[i]->co_oc->soc_allowed ) {
2933 AttributeType **at = colst[i]->co_oc->soc_allowed;
2934 for (j=0; at[j]; j++) {
2935 for (a=e->e_attrs, prev=&e->e_attrs; a;
2936 prev = &(*prev)->a_next, a=a->a_next) {
2937 if ( a->a_desc == at[j]->sat_ad ) {
2953 tail->a_next = e->e_attrs;
2959 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2961 Attribute *a = NULL;
2962 AttributeDescription *ad;
2965 int i, rc = 0, sort = 0;
2972 Modifications *ml = ptr;
2974 vals = ml->sml_values;
2977 if ( a && ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
2979 rc = ordered_value_sort( a, 1 );
2983 for ( i=0; vals[i].bv_val; i++ ) {
2984 ca->line = vals[i].bv_val;
2986 char *idx = strchr( ca->line, '}' );
2987 if ( idx ) ca->line = idx+1;
2989 rc = config_parse_vals( ct, ca, i );
2997 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2998 SlapReply *rs, int *renum )
3001 int index = -1, gotindex = 0, nsibs;
3002 int renumber = 0, tailindex = 0;
3006 if ( renum ) *renum = 0;
3008 /* These entries don't get indexed/renumbered */
3009 if ( ce_type == Cft_Global ) return 0;
3010 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3012 if ( ce_type == Cft_Include || ce_type == Cft_Module )
3015 /* See if the rdn has an index already */
3016 dnRdn( &e->e_name, &rdn );
3017 ptr1 = strchr( e->e_name.bv_val, '{' );
3018 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3019 ptr2 = strchr( ptr1, '}' );
3020 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3021 return LDAP_NAMING_VIOLATION;
3022 if ( ptr2-ptr1 == 1)
3023 return LDAP_NAMING_VIOLATION;
3025 index = atoi(ptr1+1);
3027 return LDAP_NAMING_VIOLATION;
3030 /* count related kids */
3031 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3032 if ( ce->ce_type == ce_type ) nsibs++;
3035 if ( index != nsibs ) {
3037 if ( index < nsibs ) {
3038 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3039 /* Siblings need to be renumbered */
3044 struct berval ival, newrdn, nnewrdn;
3045 struct berval rtype, rval;
3047 AttributeDescription *ad = NULL;
3051 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
3052 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
3053 rtype.bv_val = rdn.bv_val;
3054 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3057 slap_bv2ad( &rtype, &ad, &text );
3058 a = attr_find( e->e_attrs, ad );
3059 if (!a ) return LDAP_NAMING_VIOLATION;
3062 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
3064 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3065 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3068 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3069 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3076 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3078 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
3081 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3082 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3086 /* Do the equivalent of ModRDN */
3087 /* Replace DN / NDN */
3088 newrdn.bv_len = ptr1 - newrdn.bv_val;
3089 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3090 free( e->e_name.bv_val );
3091 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
3093 free( e->e_nname.bv_val );
3094 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
3098 free( a->a_vals[0].bv_val );
3099 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
3100 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
3101 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3102 strcpy( a->a_vals[0].bv_val, ptr1 );
3104 if ( a->a_nvals != a->a_vals ) {
3105 free( a->a_nvals[0].bv_val );
3106 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
3107 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
3108 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3109 strcpy( a->a_nvals[0].bv_val, ptr1 );
3111 free( nnewrdn.bv_val );
3112 free( newrdn.bv_val );
3115 if ( renum ) *renum = renumber;
3120 count_ocs( Attribute *oc_at, int *nocs )
3123 CfOcInfo co, *coptr, **colst;
3125 /* count the objectclasses */
3126 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
3128 colst = (CfOcInfo **)ch_malloc( n * sizeof(CfOcInfo *));
3130 for ( i=0, j=0; i<n; i++) {
3131 co.co_name = &oc_at->a_nvals[i];
3132 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
3134 /* ignore non-config objectclasses. probably should be
3135 * an error, general data doesn't belong here.
3137 if ( !coptr ) continue;
3139 /* Ignore the root objectclass, it has no implementation.
3141 if ( coptr->co_type == Cft_Abstract ) continue;
3148 /* Only the root can be Cft_Global, everything else must
3149 /* Parse an LDAP entry into config directives */
3151 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
3153 CfEntryInfo *ce, *last;
3155 Attribute *a, *oc_at, *type_attr;
3156 AttributeDescription *type_ad = NULL;
3158 ConfigArgs ca = {0};
3160 ConfigTable *ct, *type_ct = NULL;
3163 /* Make sure parent exists and entry does not */
3164 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3166 return LDAP_ALREADY_EXISTS;
3168 dnParent( &e->e_nname, &pdn );
3170 /* If last is NULL, the new entry is the root/suffix entry,
3171 * otherwise last should be the parent.
3173 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3175 rs->sr_matched = last->ce_entry->e_name.bv_val;
3176 return LDAP_NO_SUCH_OBJECT;
3179 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3180 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3182 colst = count_ocs( oc_at, &nocs );
3184 /* Only the root can be Cft_Global, everything else must
3185 * have a parent. Only limited nesting arrangements are allowed.
3187 switch( colst[0]->co_type ) {
3190 rc = LDAP_CONSTRAINT_VIOLATION;
3198 if ( !last || ( last->ce_type != Cft_Global &&
3199 last->ce_type != colst[0]->co_type )) {
3200 rc = LDAP_CONSTRAINT_VIOLATION;
3205 if ( !last || ( last->ce_type != Cft_Global &&
3206 last->ce_type != Cft_Database &&
3207 last->ce_type != colst[0]->co_type )) {
3208 rc = LDAP_CONSTRAINT_VIOLATION;
3212 #ifdef SLAPD_MODULES
3214 if ( !last || last->ce_type != Cft_Global ) {
3215 rc = LDAP_CONSTRAINT_VIOLATION;
3222 sort_attrs( e, colst, nocs );
3224 /* Parse all the values and check for simple syntax errors before
3225 * performing any set actions.
3227 switch (colst[0]->co_type) {
3229 /* The cn=schema entry is all hardcoded, so never reparse it */
3230 if (last->ce_type == Cft_Global )
3234 ca.be = LDAP_STAILQ_FIRST(&backendDB);
3238 if ( last->ce_type == Cft_Backend )
3239 ca.bi = last->ce_bi;
3241 type_ad = cfAd_backend;
3244 if ( last->ce_type == Cft_Database ) {
3245 ca.be = last->ce_be;
3247 type_ad = cfAd_database;
3248 /* dummy, just to get past check_attr */
3254 ca.be = last->ce_be;
3255 type_ad = cfAd_overlay;
3260 nocs = 0; /* ignored */
3263 type_ad = cfAd_include;
3265 #ifdef SLAPD_MODULES
3269 ptr = strchr( e->e_name.bv_val, '{' );
3271 rc = LDAP_NAMING_VIOLATION;
3275 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
3276 /* There is no corresponding modpath for this load? */
3278 rc = LDAP_NAMING_VIOLATION;
3281 module_path( mp->mp_path.bv_val );
3288 /* If doing an LDAPadd, check for indexed names and any necessary
3289 * renaming/renumbering. Entries that don't need indexed names are
3290 * ignored. Entries that need an indexed name and arrive without one
3291 * are assigned to the end. Entries that arrive with an index may
3292 * cause the following entries to be renumbered/bumped down.
3294 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3295 * don't allow Adding an entry with an index that's already in use.
3296 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3298 * These entries can have auto-assigned indexes (appended to the end)
3299 * but only the other types support auto-renumbering of siblings.
3301 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3305 init_config_argv( &ca );
3307 type_attr = attr_find( e->e_attrs, type_ad );
3309 rc = LDAP_OBJECT_CLASS_VIOLATION;
3312 type_ct = config_find_table( colst, nocs, type_ad );
3314 rc = LDAP_OBJECT_CLASS_VIOLATION;
3317 rc = check_vals( type_ct, &ca, type_attr, 1);
3318 if ( rc ) goto leave;
3320 for ( a=e->e_attrs; a; a=a->a_next ) {
3321 if ( a == type_attr || a == oc_at ) continue;
3322 ct = config_find_table( colst, nocs, a->a_desc );
3323 if ( !ct ) continue; /* user data? */
3324 rc = check_vals( ct, &ca, a, 1 );
3325 if ( rc ) goto leave;
3328 /* Basic syntax checks are OK. Do the actual settings. */
3330 ca.line = type_attr->a_vals[0].bv_val;
3331 if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3332 ptr = strchr( ca.line, '}' );
3333 if ( ptr ) ca.line = ptr+1;
3336 rc = config_parse_add( type_ct, &ca );
3342 for ( a=e->e_attrs; a; a=a->a_next ) {
3343 if ( a == type_attr || a == oc_at ) continue;
3344 ct = config_find_table( colst, nocs, a->a_desc );
3345 if ( !ct ) continue; /* user data? */
3346 for (i=0; a->a_vals[i].bv_val; i++) {
3347 ca.line = a->a_vals[i].bv_val;
3348 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3349 ptr = strchr( ca.line, '}' );
3350 if ( ptr ) ca.line = ptr+1;
3353 rc = config_parse_add( ct, &ca );
3361 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3362 ce->ce_parent = last;
3363 ce->ce_entry = entry_dup( e );
3364 ce->ce_entry->e_private = ce;
3365 ce->ce_type = colst[0]->co_type;
3370 } else if ( last->ce_kids ) {
3373 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3382 if ( colst ) ch_free( colst );
3386 /* Parse an LDAP entry into config directives, then store in underlying
3390 config_back_add( Operation *op, SlapReply *rs )
3393 CfEntryInfo *ce, *last;
3396 if ( !be_isroot( op ) ) {
3397 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3401 cfb = (CfBackInfo *)op->o_bd->be_private;
3403 ldap_pvt_thread_pool_pause( &connection_pool );
3406 * 1) check for existence of entry
3407 * 2) check for sibling renumbering
3408 * 3) perform internal add
3409 * 4) store entry in underlying database
3410 * 5) perform any necessary renumbering
3412 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3413 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3414 BackendDB *be = op->o_bd;
3415 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3416 op->o_bd = &cfb->cb_db;
3417 sc.sc_next = op->o_callback;
3418 op->o_callback = ≻
3419 op->o_bd->be_add( op, rs );
3421 op->o_callback = sc.sc_next;
3426 ldap_pvt_thread_pool_resume( &connection_pool );
3429 send_ldap_result( op, rs );
3434 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3435 char *textbuf, int textsize )
3437 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3438 int rc = LDAP_UNWILLING_TO_PERFORM;
3440 Entry *e = ce->ce_entry;
3441 Attribute *save_attrs = e->e_attrs, *oc_at;
3442 ConfigArgs ca = {0};
3448 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3449 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3451 colst = count_ocs( oc_at, &nocs );
3453 e->e_attrs = attrs_dup( e->e_attrs );
3455 init_config_argv( &ca );
3459 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3460 switch (ml->sml_op) {
3461 case LDAP_MOD_DELETE:
3462 case LDAP_MOD_REPLACE: {
3463 BerVarray vals = NULL, nvals;
3464 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3465 vals = ml->sml_values;
3466 nvals = ml->sml_nvalues;
3467 ml->sml_values = NULL;
3468 ml->sml_nvalues = NULL;
3470 rc = modify_delete_values(e, &ml->sml_mod,
3471 get_permissiveModify(op),
3472 &rs->sr_text, textbuf, textsize );
3473 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3474 ml->sml_values = vals;
3475 ml->sml_nvalues = nvals;
3480 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3483 case SLAP_MOD_SOFTADD: {
3484 int mop = ml->sml_op;
3485 ml->sml_op = LDAP_MOD_ADD;
3486 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3487 ct = config_find_table( colst, nocs, ml->sml_desc );
3488 if ( !ct ) continue;
3489 rc = check_vals( ct, &ca, ml, 0 );
3492 rc = modify_add_values(e, &ml->sml_mod,
3493 get_permissiveModify(op),
3494 &rs->sr_text, textbuf, textsize );
3496 /* If value already exists, show success here
3497 * and ignore this operation down below.
3499 if ( mop == SLAP_MOD_SOFTADD ) {
3500 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3510 case LDAP_MOD_INCREMENT: /* FIXME */
3515 if(rc != LDAP_SUCCESS) break;
3518 if(rc == LDAP_SUCCESS) {
3519 /* check that the entry still obeys the schema */
3520 rc = entry_schema_check(op->o_bd, e, NULL,
3521 &rs->sr_text, textbuf, textsize );
3523 if ( rc == LDAP_SUCCESS ) {
3524 /* Basic syntax checks are OK. Do the actual settings. */
3525 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3526 /* Ignore single-value deletes */
3527 if ( is_at_single_value( ml->sml_desc->ad_type ) &&
3528 ml->sml_op == LDAP_MOD_DELETE ) continue;
3530 ct = config_find_table( colst, nocs, ml->sml_desc );
3531 if ( !ct ) continue;
3533 switch (ml->sml_op) {
3534 case LDAP_MOD_DELETE:
3535 case LDAP_MOD_REPLACE: {
3536 BerVarray vals = NULL, nvals;
3537 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3538 vals = ml->sml_values;
3539 nvals = ml->sml_nvalues;
3540 ml->sml_values = NULL;
3541 ml->sml_nvalues = NULL;
3544 rc = config_del_vals( ct, &ca, ml->sml_values );
3546 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3547 ml->sml_values = vals;
3548 ml->sml_nvalues = nvals;
3553 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3556 for (i=0; ml->sml_values[i].bv_val; i++) {
3557 ca.line = ml->sml_values[i].bv_val;
3558 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3559 ptr = strchr( ca.line, '}' );
3560 if ( ptr ) ca.line = ptr+1;
3563 rc = config_parse_add( ct, &ca );
3576 if ( rc == LDAP_SUCCESS ) {
3577 attrs_free( save_attrs );
3579 attrs_free( e->e_attrs );
3580 e->e_attrs = save_attrs;
3583 if ( colst ) ch_free( colst );
3589 config_back_modify( Operation *op, SlapReply *rs )
3592 CfEntryInfo *ce, *last;
3594 char textbuf[SLAP_TEXT_BUFLEN];
3597 AttributeDescription *rad = NULL;
3599 if ( !be_isroot( op ) ) {
3600 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3604 cfb = (CfBackInfo *)op->o_bd->be_private;
3606 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3609 rs->sr_matched = last->ce_entry->e_name.bv_val;
3610 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3614 /* Get type of RDN */
3615 rdn = ce->ce_entry->e_nname;
3616 ptr = strchr( rdn.bv_val, '=' );
3617 rdn.bv_len = ptr - rdn.bv_val;
3618 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3620 /* Some basic validation... */
3621 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3622 /* Braindead single-value check - the ADD must immediately follow
3623 * the DELETE. We don't check that there's only one ADD; for multiple
3624 * ADDs only the last one will be saved. The drivers don't distinguish
3627 if ( is_at_single_value( ml->sml_desc->ad_type )) {
3628 if (( ml->sml_op == LDAP_MOD_DELETE &&
3629 ( !ml->sml_next || ml->sml_next->sml_desc != ml->sml_desc ||
3630 ml->sml_next->sml_op != LDAP_MOD_ADD )) ||
3632 /* Also check for REPLACE with no values */
3633 ( ml->sml_op == LDAP_MOD_REPLACE && !ml->sml_values )) {
3634 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
3635 rs->sr_text = "Single-Value Delete must be followed by Add";
3639 /* Don't allow Modify of RDN; must use ModRdn for that. */
3640 if ( ml->sml_desc == rad ) {
3641 rs->sr_err = LDAP_OBJECT_CLASS_VIOLATION;
3642 rs->sr_text = "Use modrdn to change the entry name";
3647 ldap_pvt_thread_pool_pause( &connection_pool );
3650 * 1) perform the Modify on the cached Entry.
3651 * 2) verify that the Entry still satisfies the schema.
3652 * 3) perform the individual config operations.
3653 * 4) store Modified entry in underlying LDIF backend.
3655 rs->sr_err = config_modify_internal( ce, op, rs, textbuf, sizeof(textbuf) );
3656 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3657 BackendDB *be = op->o_bd;
3658 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3659 op->o_bd = &cfb->cb_db;
3660 sc.sc_next = op->o_callback;
3661 op->o_callback = ≻
3662 op->o_bd->be_modify( op, rs );
3664 op->o_callback = sc.sc_next;
3667 ldap_pvt_thread_pool_resume( &connection_pool );
3669 send_ldap_result( op, rs );
3674 config_back_modrdn( Operation *op, SlapReply *rs )
3677 CfEntryInfo *ce, *last;
3679 if ( !be_isroot( op ) ) {
3680 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3684 cfb = (CfBackInfo *)op->o_bd->be_private;
3686 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3689 rs->sr_matched = last->ce_entry->e_name.bv_val;
3690 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3694 /* We don't allow moving objects to new parents.
3695 * Generally we only allow reordering a set of ordered entries.
3697 if ( op->orr_newSup ) {
3698 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3701 ldap_pvt_thread_pool_pause( &connection_pool );
3703 ldap_pvt_thread_pool_resume( &connection_pool );
3705 send_ldap_result( op, rs );
3710 config_back_search( Operation *op, SlapReply *rs )
3713 CfEntryInfo *ce, *last;
3716 if ( !be_isroot( op ) ) {
3717 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3721 cfb = (CfBackInfo *)op->o_bd->be_private;
3723 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3726 rs->sr_matched = last->ce_entry->e_name.bv_val;
3727 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3730 switch ( op->ors_scope ) {
3731 case LDAP_SCOPE_BASE:
3732 case LDAP_SCOPE_SUBTREE:
3733 config_send( op, rs, ce, 0 );
3736 case LDAP_SCOPE_ONELEVEL:
3737 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3738 config_send( op, rs, ce, 1 );
3743 rs->sr_err = LDAP_SUCCESS;
3745 send_ldap_result( op, rs );
3750 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3752 Entry *e = ch_calloc( 1, sizeof(Entry) );
3753 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3758 ce->ce_parent = parent;
3760 pdn = parent->ce_entry->e_nname;
3765 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3766 ber_dupbv( &e->e_nname, &e->e_name );
3775 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3776 struct berval *rdn, ConfigTable *ct, int table )
3778 struct berval vals[2];
3779 struct berval ad_name;
3780 AttributeDescription *ad = NULL;
3784 char textbuf[SLAP_TEXT_BUFLEN];
3785 size_t textlen = sizeof(textbuf);
3789 BER_BVZERO( &vals[1] );
3791 vals[0] = oc->soc_cname;
3792 attr_merge_normalize(e, slap_schema.si_ad_objectClass, vals, NULL );
3793 ptr = strchr(rdn->bv_val, '=');
3794 ad_name.bv_val = rdn->bv_val;
3795 ad_name.bv_len = ptr - rdn->bv_val;
3796 rc = slap_bv2ad( &ad_name, &ad, &text );
3800 vals[0].bv_val = ptr+1;
3801 vals[0].bv_len = rdn->bv_len - (vals[0].bv_val - rdn->bv_val);
3802 attr_merge_normalize(e, ad, vals, NULL );
3804 for (at=oc->soc_required; at && *at; at++) {
3805 /* Skip the naming attr */
3806 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3808 for (i=0;ct[i].name;i++) {
3809 if (ct[i].ad == (*at)->sat_ad) {
3810 rc = config_get_vals(&ct[i], c);
3811 if (rc == LDAP_SUCCESS) {
3812 if ( c->rvalue_nvals )
3813 attr_merge(e, ct[i].ad, c->rvalue_vals,
3816 attr_merge_normalize(e, ct[i].ad,
3817 c->rvalue_vals, NULL);
3818 ber_bvarray_free( c->rvalue_nvals );
3819 ber_bvarray_free( c->rvalue_vals );
3826 for (at=oc->soc_allowed; at && *at; at++) {
3827 /* Skip the naming attr */
3828 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3830 for (i=0;ct[i].name;i++) {
3831 if (ct[i].ad == (*at)->sat_ad) {
3832 rc = config_get_vals(&ct[i], c);
3833 if (rc == LDAP_SUCCESS) {
3834 if ( c->rvalue_nvals )
3835 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3837 attr_merge_normalize(e, ct[i].ad, c->rvalue_vals, NULL);
3838 ber_bvarray_free( c->rvalue_nvals );
3839 ber_bvarray_free( c->rvalue_vals );
3847 if ( table == BI_TABLE )
3848 ct = c->bi->bi_cf_table;
3850 ct = c->be->be_cf_table;
3851 for (;ct && ct->name;ct++) {
3852 if (!ct->ad) continue;
3853 rc = config_get_vals(ct, c);
3854 if (rc == LDAP_SUCCESS) {
3855 if ( c->rvalue_nvals )
3856 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3858 attr_merge_normalize(e, ct->ad, c->rvalue_vals, NULL);
3862 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3863 rc = structural_class(oc_at->a_vals, vals, NULL, &text, textbuf, textlen);
3864 BER_BVZERO( &vals[1] );
3865 attr_merge_normalize(e, slap_schema.si_ad_structuralObjectClass, vals, NULL );
3871 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3872 Operation *op, SlapReply *rs )
3875 ConfigFile *cf = c->private;
3876 CfEntryInfo *ce, *ceprev;
3880 if ( ceparent->ce_kids ) {
3881 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3882 ceprev = ceprev->ce_sibs );
3885 for (; cf; cf=cf->c_sibs, c->depth++) {
3886 c->value_dn.bv_val = c->log;
3887 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3892 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3894 ptr = strchr( bv.bv_val, '.' );
3896 bv.bv_len = ptr - bv.bv_val;
3897 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3898 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3900 c->value_dn.bv_len += bv.bv_len;
3901 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3903 e = config_alloc_entry( ceparent, &c->value_dn );
3905 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3906 c->bi->bi_cf_table, NO_TABLE );
3908 ce->ce_type = Cft_Schema;
3911 op->o_bd->be_add( op, rs );
3914 if ( !ceparent->ce_kids ) {
3915 ceparent->ce_kids = ce;
3917 ceprev->ce_sibs = ce;
3921 c->private = cf->c_kids;
3922 config_build_schema_inc( c, ceparent, op, rs );
3927 static CfEntryInfo *
3928 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3929 Operation *op, SlapReply *rs )
3933 ConfigFile *cf = c->private;
3934 CfEntryInfo *ce, *ceprev;
3936 if ( ceparent->ce_kids ) {
3937 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3938 ceprev = ceprev->ce_sibs );
3941 for (i=0; cf; cf=cf->c_sibs, i++) {
3942 c->value_dn.bv_val = c->log;
3943 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3944 e = config_alloc_entry( ceparent, &c->value_dn );
3946 config_build_entry( c, e, cfOc_include, &c->value_dn,
3947 c->bi->bi_cf_table, NO_TABLE );
3950 op->o_bd->be_add( op, rs );
3953 ce->ce_type = Cft_Include;
3955 if ( !ceparent->ce_kids ) {
3956 ceparent->ce_kids = ce;
3958 ceprev->ce_sibs = ce;
3962 c->private = cf->c_kids;
3963 config_build_includes( c, ce, op, rs );
3969 #ifdef SLAPD_MODULES
3971 static CfEntryInfo *
3972 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3973 Operation *op, SlapReply *rs )
3977 CfEntryInfo *ce, *ceprev;
3980 if ( ceparent->ce_kids ) {
3981 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3982 ceprev = ceprev->ce_sibs );
3985 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3986 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3988 c->value_dn.bv_val = c->log;
3989 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3990 e = config_alloc_entry( ceparent, &c->value_dn );
3992 ce->ce_type = Cft_Include;
3994 config_build_entry( c, e, cfOc_module, &c->value_dn,
3995 c->bi->bi_cf_table, NO_TABLE );
3998 op->o_bd->be_add( op, rs );
4001 if ( !ceparent->ce_kids ) {
4002 ceparent->ce_kids = ce;
4004 ceprev->ce_sibs = ce;
4013 config_back_db_open( BackendDB *be )
4015 CfBackInfo *cfb = be->be_private;
4018 CfEntryInfo *ce, *ceparent, *ceprev;
4024 Connection conn = {0};
4025 char opbuf[OPERATION_BUFFER_SIZE];
4027 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
4028 SlapReply rs = {REP_RESULT};
4030 /* If we read the config from back-ldif, nothing to do here */
4031 if ( cfb->cb_got_ldif )
4034 if ( cfb->cb_use_ldif ) {
4035 op = (Operation *)opbuf;
4036 connection_fake_init( &conn, op, cfb );
4038 op->o_dn = be->be_rootdn;
4039 op->o_ndn = be->be_rootndn;
4041 op->o_tag = LDAP_REQ_ADD;
4042 op->o_callback = &cb;
4043 op->o_bd = &cfb->cb_db;
4048 /* create root of tree */
4050 e = config_alloc_entry( NULL, &rdn );
4052 ce->ce_type = Cft_Global;
4056 c.private = cfb->cb_config;
4057 ct = c.bi->bi_cf_table;
4058 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
4061 op->o_bd->be_add( op, &rs );
4068 /* Create schema nodes... cn=schema will contain the hardcoded core
4069 * schema, read-only. Child objects will contain runtime loaded schema
4073 e = config_alloc_entry( ceparent, &rdn );
4075 ce->ce_type = Cft_Schema;
4077 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
4080 op->o_bd->be_add( op, &rs );
4082 if ( !ceparent->ce_kids ) {
4083 ceparent->ce_kids = ce;
4085 ceprev->ce_sibs = ce;
4089 /* Create includeFile nodes and schema nodes for included schema... */
4090 if ( cfb->cb_config->c_kids ) {
4092 c.private = cfb->cb_config->c_kids;
4093 config_build_schema_inc( &c, ce, op, &rs );
4094 c.private = cfb->cb_config->c_kids;
4095 ceprev = config_build_includes( &c, ceparent, op, &rs );
4098 #ifdef SLAPD_MODULES
4099 /* Create Module nodes... */
4100 if ( modpaths.mp_loads ) {
4101 ceprev = config_build_modules( &c, ceparent, op, &rs );
4105 /* Create backend nodes. Skip if they don't provide a cf_table.
4106 * There usually aren't any of these.
4110 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
4111 if (!bi->bi_cf_table) continue;
4112 if (!bi->bi_private) continue;
4115 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
4116 e = config_alloc_entry( ceparent, &rdn );
4118 ce->ce_type = Cft_Backend;
4121 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
4124 op->o_bd->be_add( op, &rs );
4126 if ( !ceparent->ce_kids ) {
4127 ceparent->ce_kids = ce;
4129 ceprev->ce_sibs = ce;
4134 /* Create database nodes... */
4136 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
4137 slap_overinfo *oi = NULL;
4144 if ( overlay_is_over( bptr )) {
4145 oi = bptr->bd_info->bi_private;
4151 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
4153 e = config_alloc_entry( ceparent, &rdn );
4157 ce->ce_type = Cft_Database;
4160 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
4163 op->o_bd->be_add( op, &rs );
4165 if ( !ceparent->ce_kids ) {
4166 ceparent->ce_kids = ce;
4168 ceprev->ce_sibs = ce;
4171 /* Iterate through overlays */
4175 CfEntryInfo *opar = ce, *oprev = NULL;
4178 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
4180 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
4181 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
4182 oe = config_alloc_entry( opar, &rdn );
4186 ce->ce_type = Cft_Overlay;
4189 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
4192 op->o_bd->be_add( op, &rs );
4194 if ( !opar->ce_kids ) {
4197 oprev->ce_sibs = ce;
4208 config_back_db_destroy( Backend *be )
4210 free( be->be_private );
4215 config_back_db_init( Backend *be )
4220 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4221 cfb->cb_config = &cf_prv;
4222 be->be_private = cfb;
4224 ber_dupbv( &be->be_rootdn, &config_rdn );
4225 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4226 ber_dupbv( &dn, &be->be_rootdn );
4227 ber_bvarray_add( &be->be_suffix, &dn );
4228 ber_dupbv( &dn, &be->be_rootdn );
4229 ber_bvarray_add( &be->be_nsuffix, &dn );
4231 /* Hide from namingContexts */
4232 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4238 config_back_destroy( BackendInfo *bi )
4240 ldif_must_b64_encode_release();
4246 AttributeDescription **desc;
4248 { "backend", &cfAd_backend },
4249 { "database", &cfAd_database },
4250 { "include", &cfAd_include },
4251 { "overlay", &cfAd_overlay },
4256 * add / delete: all types that may be added or deleted must use an
4257 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4258 * should automatically renumber the index of any siblings as needed,
4259 * so that no gaps in the numbering sequence exist after the add/delete
4261 * What can be added:
4263 * backend objects for backend-specific config directives
4267 * delete: probably no support this time around.
4269 * modrdn: generally not done. Will be invoked automatically by add/
4270 * delete to update numbering sequence. Perform as an explicit operation
4271 * so that the renumbering effect may be replicated. Subtree rename must
4272 * be supported, since renumbering a database will affect all its child
4275 * modify: must be fully supported.
4279 config_back_initialize( BackendInfo *bi )
4281 ConfigTable *ct = config_back_cf_table;
4284 AttributeDescription *ad = NULL;
4286 static char *controls[] = {
4287 LDAP_CONTROL_MANAGEDSAIT,
4291 bi->bi_controls = controls;
4296 bi->bi_destroy = config_back_destroy;
4298 bi->bi_db_init = config_back_db_init;
4299 bi->bi_db_config = 0;
4300 bi->bi_db_open = config_back_db_open;
4301 bi->bi_db_close = 0;
4302 bi->bi_db_destroy = config_back_db_destroy;
4304 bi->bi_op_bind = config_back_bind;
4305 bi->bi_op_unbind = 0;
4306 bi->bi_op_search = config_back_search;
4307 bi->bi_op_compare = 0;
4308 bi->bi_op_modify = config_back_modify;
4309 bi->bi_op_modrdn = config_back_modrdn;
4310 bi->bi_op_add = config_back_add;
4311 bi->bi_op_delete = 0;
4312 bi->bi_op_abandon = 0;
4314 bi->bi_extended = 0;
4316 bi->bi_chk_referrals = 0;
4318 #ifdef SLAP_OVERLAY_ACCESS
4319 bi->bi_access_allowed = slap_access_always_allowed;
4320 #endif /* SLAP_OVERLAY_ACCESS */
4322 bi->bi_connection_init = 0;
4323 bi->bi_connection_destroy = 0;
4326 for (i=0; OidMacros[i].name; i++ ) {
4327 argv[1] = OidMacros[i].name;
4328 argv[2] = OidMacros[i].oid;
4329 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4332 bi->bi_cf_table = ct;
4334 i = config_register_schema( ct, cf_ocs );
4337 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4338 * basically, we don't care if it fails */
4339 i = slap_str2ad( "olcRootPW", &ad, &text );
4341 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4342 "warning, unable to get \"olcRootPW\" "
4343 "attribute description: %d: %s\n",
4346 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4347 ad->ad_type->sat_oid );
4350 /* set up the notable AttributeDescriptions */
4352 for (;ct->name;ct++) {
4353 if (strcmp(ct->name, ads[i].name)) continue;
4354 *ads[i].desc = ct->ad;
4356 if (!ads[i].name) break;