1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 static struct berval config_rdn = BER_BVC("cn=config");
41 static struct berval schema_rdn = BER_BVC("cn=schema");
46 typedef struct modpath_s {
47 struct modpath_s *mp_next;
48 struct berval mp_path;
52 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
55 typedef struct ConfigFile {
56 struct ConfigFile *c_sibs;
57 struct ConfigFile *c_kids;
59 AttributeType *c_at_head, *c_at_tail;
60 ContentRule *c_cr_head, *c_cr_tail;
61 ObjectClass *c_oc_head, *c_oc_tail;
62 OidMacro *c_om_head, *c_om_tail;
66 typedef struct CfOcInfo {
67 struct berval *co_name;
68 ConfigTable *co_table;
73 typedef struct CfEntryInfo {
74 struct CfEntryInfo *ce_parent;
75 struct CfEntryInfo *ce_sibs;
76 struct CfEntryInfo *ce_kids;
84 ConfigFile *cb_config;
86 BackendDB cb_db; /* underlying database */
91 /* These do nothing in slapd, they're kept only to make them
94 static char *replica_pidFile, *replica_argsFile;
95 static int replicationInterval;
97 static char *passwd_salt;
98 static char *logfileName;
99 static BerVarray authz_rewrites;
101 static struct berval cfdir;
104 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
107 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
108 *cfOc_include, *cfOc_overlay, *cfOc_module;
110 static ConfigFile cf_prv, *cfn = &cf_prv;
112 static Avlnode *CfOcTree;
114 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
115 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
116 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
117 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs,
120 static ConfigDriver config_fname;
121 static ConfigDriver config_cfdir;
122 static ConfigDriver config_generic;
123 static ConfigDriver config_search_base;
124 static ConfigDriver config_passwd_hash;
125 static ConfigDriver config_schema_dn;
126 static ConfigDriver config_sizelimit;
127 static ConfigDriver config_timelimit;
128 static ConfigDriver config_limits;
129 static ConfigDriver config_overlay;
130 static ConfigDriver config_suffix;
131 static ConfigDriver config_deref_depth;
132 static ConfigDriver config_rootdn;
133 static ConfigDriver config_rootpw;
134 static ConfigDriver config_restrict;
135 static ConfigDriver config_allows;
136 static ConfigDriver config_disallows;
137 static ConfigDriver config_requires;
138 static ConfigDriver config_security;
139 static ConfigDriver config_referral;
140 static ConfigDriver config_loglevel;
141 static ConfigDriver config_syncrepl;
142 static ConfigDriver config_replica;
143 static ConfigDriver config_updatedn;
144 static ConfigDriver config_updateref;
145 static ConfigDriver config_include;
147 static ConfigDriver config_tls_option;
148 static ConfigDriver config_tls_config;
194 static OidRec OidMacros[] = {
195 /* OpenLDAProot:666.11.1 */
196 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
197 { "OLcfgAt", "OLcfg:3" },
198 { "OLcfgGlAt", "OLcfgAt:0" },
199 { "OLcfgBkAt", "OLcfgAt:1" },
200 { "OLcfgDbAt", "OLcfgAt:2" },
201 { "OLcfgOvAt", "OLcfgAt:3" },
202 { "OLcfgOc", "OLcfg:4" },
203 { "OLcfgGlOc", "OLcfgOc:0" },
204 { "OLcfgBkOc", "OLcfgOc:1" },
205 { "OLcfgDbOc", "OLcfgOc:2" },
206 { "OLcfgOvOc", "OLcfgOc:3" },
207 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
208 { "OMsInteger", "OMsyn:27" },
209 { "OMsBoolean", "OMsyn:7" },
210 { "OMsDN", "OMsyn:12" },
211 { "OMsDirectoryString", "OMsyn:15" },
212 { "OMsOctetString", "OMsyn:40" },
217 * OLcfg{Bk|Db}{Oc|At}:0 -> common
218 * OLcfg{Bk|Db}{Oc|At}:1 -> bdb
219 * OLcfg{Bk|Db}{Oc|At}:2 -> ldif
220 * OLcfg{Bk|Db}{Oc|At}:3 -> ldap?
223 /* alphabetical ordering */
225 ConfigTable config_back_cf_table[] = {
226 /* This attr is read-only */
227 { "", "", 0, 0, 0, ARG_MAGIC,
228 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
229 "DESC 'File for slapd configuration directives' "
230 "EQUALITY caseIgnoreMatch "
231 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
232 { "", "", 0, 0, 0, ARG_MAGIC,
233 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
234 "DESC 'Directory for slapd configuration backend' "
235 "EQUALITY caseIgnoreMatch "
236 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
237 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
238 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
239 "DESC 'Access Control List' "
240 "EQUALITY caseIgnoreMatch "
241 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
242 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
243 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
244 "DESC 'Allowed set of deprecated features' "
245 "EQUALITY caseIgnoreMatch "
246 "SYNTAX OMsDirectoryString )", NULL, NULL },
247 { "argsfile", "file", 2, 2, 0, ARG_STRING,
248 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
249 "DESC 'File for slapd command line options' "
250 "EQUALITY caseIgnoreMatch "
251 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
252 { "attribute", "attribute", 2, 0, 9,
253 ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT,
254 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
255 "DESC 'OpenLDAP attributeTypes' "
256 "EQUALITY caseIgnoreMatch "
257 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
259 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
260 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
261 "EQUALITY caseIgnoreMatch "
262 "SYNTAX OMsDirectoryString )", NULL, NULL },
263 { "authid-rewrite", NULL, 2, 0, 0,
264 #ifdef SLAP_AUTH_REWRITE
265 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
269 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
270 "EQUALITY caseIgnoreMatch "
271 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
272 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
273 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
274 "EQUALITY caseIgnoreMatch "
275 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
276 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
277 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
278 "EQUALITY caseIgnoreMatch "
279 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
280 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
281 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
282 "DESC 'A type of backend' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
286 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
287 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
288 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
289 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
290 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
291 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
292 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
293 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
294 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
295 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
296 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
297 "DESC 'The backend type for a database instance' "
298 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
299 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
300 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
301 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
302 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
303 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
304 "EQUALITY caseIgnoreMatch "
305 "SYNTAX OMsDirectoryString )", NULL, NULL },
306 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
307 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
308 "DESC 'OpenLDAP DIT content rules' "
309 "EQUALITY caseIgnoreMatch "
310 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
312 { "gentlehup", "on|off", 2, 2, 0,
314 ARG_ON_OFF, &global_gentlehup,
318 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
319 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
320 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
321 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
322 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
323 { "include", "file", 2, 2, 0, ARG_MAGIC,
324 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
325 "SUP labeledURI )", NULL, NULL },
326 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
327 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
328 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
329 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
330 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
331 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
332 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
333 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
334 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
335 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
336 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
337 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
338 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
339 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
340 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
341 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
342 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
343 "SYNTAX OMsDirectoryString )", NULL, NULL },
344 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
345 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
346 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
347 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
348 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
349 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
350 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
351 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
352 "SYNTAX OMsDirectoryString )", NULL, NULL },
353 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
354 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
355 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
356 { "moduleload", "file", 2, 0, 0,
358 ARG_MAGIC|CFG_MODLOAD, &config_generic,
362 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
363 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
364 { "modulepath", "path", 2, 2, 0,
366 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
370 "( OLcfgGlAt:31 NAME 'olcModulePath' "
371 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
372 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT,
373 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
374 "DESC 'OpenLDAP object classes' "
375 "EQUALITY caseIgnoreMatch "
376 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
378 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
379 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
380 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
381 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
382 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
383 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
384 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
385 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
386 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
387 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
388 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
389 "SYNTAX OMsDirectoryString )", NULL, NULL },
390 { "pidfile", "file", 2, 2, 0, ARG_STRING,
391 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
392 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
393 { "plugin", NULL, 0, 0, 0,
395 ARG_MAGIC|CFG_PLUGIN, &config_generic,
399 "( OLcfgGlAt:38 NAME 'olcPlugin' "
400 "SYNTAX OMsDirectoryString )", NULL, NULL },
401 { "pluginlog", "filename", 2, 2, 0,
403 ARG_STRING, &slapi_log_file,
407 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
408 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
409 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
410 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
411 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
412 { "referral", "url", 2, 2, 0, ARG_MAGIC,
413 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
414 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
415 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
416 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
417 "SUP labeledURI )", NULL, NULL },
418 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
419 &replica_argsFile, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
420 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
421 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
422 &replica_pidFile, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
423 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
424 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
425 &replicationInterval, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
426 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
427 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
428 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
429 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
430 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
431 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
432 "SYNTAX OMsDirectoryString )", NULL, NULL },
433 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
434 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
435 "SYNTAX OMsDirectoryString )", NULL, NULL },
436 { "reverse-lookup", "on|off", 2, 2, 0,
437 #ifdef SLAPD_RLOOKUPS
438 ARG_ON_OFF, &use_reverse_lookup,
442 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
443 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
444 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
445 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
446 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
447 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
448 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
449 "SYNTAX OMsDirectoryString )", NULL, NULL },
450 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
451 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
452 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
453 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
454 &config_generic, NULL, NULL, NULL },
455 { "sasl-host", "host", 2, 2, 0,
456 #ifdef HAVE_CYRUS_SASL
457 ARG_STRING|ARG_UNIQUE, &global_host,
461 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
462 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
463 { "sasl-realm", "realm", 2, 2, 0,
464 #ifdef HAVE_CYRUS_SASL
465 ARG_STRING|ARG_UNIQUE, &global_realm,
469 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
470 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
471 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
472 &config_generic, NULL, NULL, NULL },
473 { "sasl-secprops", "properties", 2, 2, 0,
474 #ifdef HAVE_CYRUS_SASL
475 ARG_MAGIC|CFG_SASLSECP, &config_generic,
479 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
480 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
481 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
482 &config_generic, NULL, NULL, NULL },
483 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
484 &config_generic, "( OLcfgGlAt:57 NAME 'olcSchemaCheck' "
485 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
486 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
487 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
488 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
489 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
490 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
491 "SYNTAX OMsDirectoryString )", NULL, NULL },
492 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
493 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
494 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
495 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
496 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
497 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
498 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
499 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
500 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
501 { "srvtab", "file", 2, 2, 0,
502 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
503 ARG_STRING, &ldap_srvtab,
507 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
508 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
509 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
510 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
511 "SYNTAX OMsDN )", NULL, NULL },
512 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
513 &config_syncrepl, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
514 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
515 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
516 &config_generic, "( OLcfgGlAt:66 NAME 'olcThreads' "
517 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
518 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
519 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
520 "SYNTAX OMsDirectoryString )", NULL, NULL },
521 { "TLSCACertificateFile", NULL, 0, 0, 0,
523 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
527 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
528 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
529 { "TLSCACertificatePath", NULL, 0, 0, 0,
531 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
535 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
536 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
537 { "TLSCertificateFile", NULL, 0, 0, 0,
539 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
543 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
544 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
545 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
547 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
551 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
552 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
553 { "TLSCipherSuite", NULL, 0, 0, 0,
555 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
559 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
560 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
561 { "TLSCRLCheck", NULL, 0, 0, 0,
562 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
563 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
567 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
568 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
569 { "TLSRandFile", NULL, 0, 0, 0,
571 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
575 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
576 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
577 { "TLSVerifyClient", NULL, 0, 0, 0,
579 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
583 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
584 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
585 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
586 NULL, NULL, NULL, NULL },
587 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
588 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
589 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
590 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
591 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
592 "SUP labeledURI )", NULL, NULL },
593 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
594 NULL, NULL, NULL, NULL }
597 static ConfigOCs cf_ocs[] = {
600 "DESC 'OpenLDAP configuration object' "
601 "ABSTRACT SUP top )", Cft_Abstract, NULL },
604 "DESC 'OpenLDAP Global configuration options' "
605 "SUP olcConfig STRUCTURAL "
606 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
607 "olcAttributeOptions $ olcAuthIDRewrite $ "
608 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
609 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
610 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
611 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
612 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
613 "olcLogLevel $ olcModulePath $ "
614 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
615 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
616 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
617 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
618 "olcRootDSE $ olcRootPW $ "
619 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
620 "olcSchemaCheck $ olcSecurity $ olcSizeLimit $ "
621 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
622 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
623 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
624 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
625 "olcTLSRandFile $ olcTLSVerifyClient $ "
626 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
627 "olcDitContentRules ) )", Cft_Global, &cfOc_global },
629 "NAME 'olcSchemaConfig' "
630 "DESC 'OpenLDAP schema object' "
631 "SUP olcConfig STRUCTURAL "
632 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
633 "olcObjectClasses $ olcDitContentRules ) )",
634 Cft_Schema, &cfOc_schema },
636 "NAME 'olcBackendConfig' "
637 "DESC 'OpenLDAP Backend-specific options' "
638 "SUP olcConfig STRUCTURAL "
639 "MUST olcBackend )", Cft_Backend, &cfOc_backend },
641 "NAME 'olcDatabaseConfig' "
642 "DESC 'OpenLDAP Database-specific options' "
643 "SUP olcConfig STRUCTURAL "
645 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
646 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
647 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
648 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
649 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
650 Cft_Database, &cfOc_database },
652 "NAME 'olcOverlayConfig' "
653 "DESC 'OpenLDAP Overlay-specific options' "
654 "SUP olcConfig STRUCTURAL "
655 "MUST olcOverlay )", Cft_Overlay, &cfOc_overlay },
657 "NAME 'olcIncludeFile' "
658 "DESC 'OpenLDAP configuration include file' "
659 "SUP olcConfig STRUCTURAL "
661 "MAY ( cn $ olcRootDSE ) )",
662 Cft_Include, &cfOc_include },
665 "NAME 'olcModuleList' "
666 "DESC 'OpenLDAP dynamic module info' "
667 "SUP olcConfig STRUCTURAL "
668 "MUST olcModuleLoad "
669 "MAY cn )", Cft_Module, &cfOc_module },
675 config_generic(ConfigArgs *c) {
679 if ( c->op == SLAP_CONFIG_EMIT ) {
683 c->value_int = ldap_pvt_thread_get_concurrency();
686 c->value_int = connection_pool_max;
690 c->value_string = ch_strdup( passwd_salt );
695 if ( c->be->be_limits ) {
700 for ( i=0; c->be->be_limits[i]; i++ ) {
701 bv.bv_len = sprintf( buf, IFMT, i );
702 bv.bv_val = buf+bv.bv_len;
703 limits_unparse( c->be->be_limits[i], &bv );
704 bv.bv_len += bv.bv_val - buf;
706 value_add_one( &c->rvalue_vals, &bv );
709 if ( !c->rvalue_vals ) rc = 1;
712 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
715 c->value_string = ch_strdup( slap_sasl_getpolicy());
718 slap_sasl_regexp_unparse( &c->rvalue_vals );
719 if ( !c->rvalue_vals ) rc = 1;
721 #ifdef HAVE_CYRUS_SASL
723 struct berval bv = BER_BVNULL;
724 slap_sasl_secprops_unparse( &bv );
725 if ( !BER_BVISNULL( &bv )) {
726 ber_bvarray_add( &c->rvalue_vals, &bv );
734 c->value_int = c->be->be_max_deref_depth;
737 ConfigFile *cf = c->private;
739 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
740 else if ( cf->c_om_head )
741 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
743 if ( !c->rvalue_vals )
748 ConfigFile *cf = c->private;
750 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
751 else if ( cf->c_oc_head )
752 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
754 if ( !c->rvalue_vals )
759 ConfigFile *cf = c->private;
761 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
762 else if ( cf->c_at_head )
763 at_unparse( &c->rvalue_vals, cf->c_at_head,
765 if ( !c->rvalue_vals )
770 ConfigFile *cf = c->private;
772 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
773 else if ( cf->c_cr_head )
774 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
776 if ( !c->rvalue_vals )
782 c->value_int = global_schemacheck;
786 char *src, *dst, ibuf[11];
787 struct berval bv, abv;
788 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
789 abv.bv_len = sprintf( ibuf, IFMT, i );
790 acl_unparse( a, &bv );
791 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
792 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
793 /* Turn TAB / EOL into plain space */
794 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
795 if (isspace(*src)) *dst++ = ' ';
799 if (dst[-1] == ' ') {
803 abv.bv_len = dst - abv.bv_val;
804 ber_bvarray_add( &c->rvalue_vals, &abv );
810 if ( c->be->be_replogfile )
811 c->value_string = ch_strdup( c->be->be_replogfile );
814 ConfigFile *cf = c->private;
815 if ( cf->c_dseFiles ) {
816 value_add( &c->rvalue_vals, cf->c_dseFiles );
824 c->value_string = ch_strdup( logfileName );
829 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
831 case CFG_SSTR_IF_MAX:
832 c->value_int = index_substr_if_maxlen;
834 case CFG_SSTR_IF_MIN:
835 c->value_int = index_substr_if_minlen;
839 ModPaths *mp = c->private;
842 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
845 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
846 mp->mp_loads[i].bv_val );
847 value_add_one( &c->rvalue_vals, &bv );
851 rc = c->rvalue_vals ? 0 : 1;
856 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
858 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
861 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
862 mp->mp_path.bv_val );
863 value_add_one( &c->rvalue_vals, &bv );
865 rc = c->rvalue_vals ? 0 : 1;
871 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
872 if ( !c->rvalue_vals ) rc = 1;
875 #ifdef SLAP_AUTH_REWRITE
877 if ( authz_rewrites ) {
878 struct berval bv, idx;
883 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
884 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
885 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
886 bv.bv_val = ch_malloc( bv.bv_len + 1 );
887 strcpy( bv.bv_val, idx.bv_val );
888 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
889 ber_bvarray_add( &c->rvalue_vals, &bv );
892 if ( !c->rvalue_vals ) rc = 1;
899 } else if ( c->op == LDAP_MOD_DELETE ) {
902 /* single-valued attrs, no-ops */
911 case CFG_SSTR_IF_MAX:
912 case CFG_SSTR_IF_MIN:
915 /* no-ops, requires slapd restart */
920 sprintf(c->log, "change requires slapd restart");
924 ch_free( passwd_salt );
929 ch_free( c->be->be_replogfile );
930 c->be->be_replogfile = NULL;
934 ch_free( logfileName );
941 if ( c->be == frontendDB )
944 end = frontendDB->be_acl;
945 acl_destroy( c->be->be_acl, end );
947 AccessControl **prev, *a;
949 for (i=0, prev = &c->be->be_acl; i < c->valx;
961 /* FIXME: there is no limits_free function */
963 /* FIXME: there is no ad_option_free function */
965 /* FIXME: there is no way to remove attributes added by
979 p = strchr(c->line,'(' /*')'*/);
983 if(!(c->bi = backend_info(c->argv[1]))) {
984 Debug(LDAP_DEBUG_ANY, "%s: "
985 "backend %s failed init!\n", c->log, c->argv[1], 0);
992 /* NOTE: config is always the first backend!
994 if ( !strcasecmp( c->argv[1], "config" )) {
995 c->be = LDAP_STAILQ_FIRST(&backendDB);
996 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
998 } else if(!(c->be = backend_db_init(c->argv[1]))) {
999 Debug(LDAP_DEBUG_ANY, "%s: "
1000 "database %s failed init!\n", c->log, c->argv[1], 0);
1006 ldap_pvt_thread_set_concurrency(c->value_int);
1010 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1011 connection_pool_max = c->value_int; /* save for reference */
1015 if ( passwd_salt ) ch_free( passwd_salt );
1016 passwd_salt = c->value_string;
1017 lutil_salt_format(passwd_salt);
1021 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1027 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1029 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1033 ch_free(c->value_string);
1034 if (slap_sasl_setpolicy( c->argv[1] )) {
1035 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
1036 " \"authz-policy <policy>\"\n",
1037 c->log, c->argv[1], 0 );
1043 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1047 #ifdef HAVE_CYRUS_SASL
1050 char *txt = slap_sasl_secprops( c->argv[1] );
1052 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
1061 c->be->be_max_deref_depth = c->value_int;
1067 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1069 if (!cfn->c_om_head) cfn->c_om_head = om;
1070 cfn->c_om_tail = om;
1077 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1078 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1079 cfn->c_oc_tail = oc;
1086 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1087 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1088 cfn->c_cr_tail = cr;
1095 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1096 if (!cfn->c_at_head) cfn->c_at_head = at;
1097 cfn->c_at_tail = at;
1102 ad_define_option(NULL, NULL, 0);
1103 for(i = 1; i < c->argc; i++)
1104 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1109 global_schemacheck = c->value_int;
1110 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1111 "schema checking disabled! your mileage may vary!\n",
1116 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1120 if(SLAP_MONITOR(c->be)) {
1121 Debug(LDAP_DEBUG_ANY, "%s: "
1122 "\"replogfile\" should not be used "
1123 "inside monitor database\n",
1125 return(0); /* FIXME: should this be an error? */
1128 c->be->be_replogfile = c->value_string;
1132 if(read_root_dse_file(c->argv[1])) {
1133 Debug(LDAP_DEBUG_ANY, "%s: "
1134 "could not read \"rootDSE <filename>\" line\n",
1140 ber_str2bv( c->argv[1], 0, 1, &bv );
1141 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1147 if ( logfileName ) ch_free( logfileName );
1148 logfileName = c->value_string;
1149 logfile = fopen(logfileName, "w");
1150 if(logfile) lutil_debug_file(logfile);
1154 if(SLAP_NOLASTMODCMD(c->be)) {
1155 Debug(LDAP_DEBUG_ANY, "%s: "
1156 "lastmod not available for %s databases\n",
1157 c->log, c->be->bd_info->bi_type, 0);
1161 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1163 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1166 case CFG_SSTR_IF_MAX:
1167 if (c->value_int < index_substr_if_minlen) {
1168 Debug(LDAP_DEBUG_ANY, "%s: "
1169 "invalid max value (%d)\n",
1170 c->log, c->value_int, 0 );
1173 index_substr_if_maxlen = c->value_int;
1176 case CFG_SSTR_IF_MIN:
1177 if (c->value_int > index_substr_if_maxlen) {
1178 Debug(LDAP_DEBUG_ANY, "%s: "
1179 "invalid min value (%d)\n",
1180 c->log, c->value_int, 0 );
1183 index_substr_if_minlen = c->value_int;
1186 #ifdef SLAPD_MODULES
1188 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1190 /* Record this load on the current path */
1193 char *ptr = c->line + STRLENOF("moduleload");
1194 while (!isspace(*ptr)) ptr++;
1195 while (isspace(*ptr)) ptr++;
1196 ber_str2bv(ptr, 0, 1, &bv);
1197 ber_bvarray_add( &modcur->mp_loads, &bv );
1202 if(module_path(c->argv[1])) return(1);
1203 /* Record which path was used with each module */
1207 if (!modpaths.mp_loads) {
1210 mp = ch_malloc( sizeof( ModPaths ));
1211 modlast->mp_next = mp;
1213 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1215 mp->mp_loads = NULL;
1217 if ( c->op == SLAP_CONFIG_ADD )
1226 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1228 slapi_plugins_used++;
1232 #ifdef SLAP_AUTH_REWRITE
1235 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1237 ber_str2bv( c->line, 0, 1, &bv );
1238 ber_bvarray_add( &authz_rewrites, &bv );
1245 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1246 "(ignored)\n", c->log, c->type, 0);
1254 config_fname(ConfigArgs *c) {
1255 if(c->op == SLAP_CONFIG_EMIT) {
1257 ConfigFile *cf = c->private;
1258 value_add_one( &c->rvalue_vals, &cf->c_file );
1267 config_cfdir(ConfigArgs *c) {
1268 if(c->op == SLAP_CONFIG_EMIT) {
1269 value_add_one( &c->rvalue_vals, &cfdir );
1276 config_search_base(ConfigArgs *c) {
1279 if(c->op == SLAP_CONFIG_EMIT) {
1281 if (!BER_BVISEMPTY(&default_search_base)) {
1282 value_add_one(&c->rvalue_vals, &default_search_base);
1283 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1287 } else if( c->op == LDAP_MOD_DELETE ) {
1288 ch_free( default_search_base.bv_val );
1289 ch_free( default_search_nbase.bv_val );
1290 BER_BVZERO( &default_search_base );
1291 BER_BVZERO( &default_search_nbase );
1295 if(c->bi || c->be != frontendDB) {
1296 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1297 "prior to any backend or database definition\n",
1302 if(default_search_nbase.bv_len) {
1303 Debug(LDAP_DEBUG_ANY, "%s: "
1304 "default search base \"%s\" already defined "
1305 "(discarding old)\n",
1306 c->log, default_search_base.bv_val, 0);
1307 free(default_search_base.bv_val);
1308 free(default_search_nbase.bv_val);
1311 default_search_base = c->value_dn;
1312 default_search_nbase = c->value_ndn;
1317 config_passwd_hash(ConfigArgs *c) {
1319 if (c->op == SLAP_CONFIG_EMIT) {
1321 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1322 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1323 value_add_one(&c->rvalue_vals, &bv);
1326 } else if ( c->op == LDAP_MOD_DELETE ) {
1327 if ( c->valx < 0 ) {
1328 ldap_charray_free( default_passwd_hash );
1329 default_passwd_hash = NULL;
1332 ch_free( default_passwd_hash[i] );
1333 for (; default_passwd_hash[i]; i++ )
1334 default_passwd_hash[i] = default_passwd_hash[i+1];
1338 if(default_passwd_hash) {
1339 Debug(LDAP_DEBUG_ANY, "%s: "
1340 "already set default password_hash\n",
1344 for(i = 1; i < c->argc; i++) {
1345 if(!lutil_passwd_scheme(c->argv[i])) {
1346 Debug(LDAP_DEBUG_ANY, "%s: "
1347 "password scheme \"%s\" not available\n",
1348 c->log, c->argv[i], 0);
1350 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1352 if(!default_passwd_hash) {
1353 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1362 config_schema_dn(ConfigArgs *c) {
1363 if ( c->op == SLAP_CONFIG_EMIT ) {
1365 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1366 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1367 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1371 } else if ( c->op == LDAP_MOD_DELETE ) {
1372 ch_free( c->be->be_schemadn.bv_val );
1373 ch_free( c->be->be_schemandn.bv_val );
1374 BER_BVZERO( &c->be->be_schemadn );
1375 BER_BVZERO( &c->be->be_schemandn );
1378 ch_free( c->be->be_schemadn.bv_val );
1379 ch_free( c->be->be_schemandn.bv_val );
1380 c->be->be_schemadn = c->value_dn;
1381 c->be->be_schemandn = c->value_ndn;
1386 config_sizelimit(ConfigArgs *c) {
1389 struct slap_limits_set *lim = &c->be->be_def_limit;
1390 if (c->op == SLAP_CONFIG_EMIT) {
1395 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1396 if ( !BER_BVISEMPTY( &bv ))
1397 value_add_one( &c->rvalue_vals, &bv );
1401 } else if ( c->op == LDAP_MOD_DELETE ) {
1402 /* Reset to defaults */
1403 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1404 lim->lms_s_hard = 0;
1405 lim->lms_s_unchecked = -1;
1407 lim->lms_s_pr_hide = 0;
1408 lim->lms_s_pr_total = 0;
1411 for(i = 1; i < c->argc; i++) {
1412 if(!strncasecmp(c->argv[i], "size", 4)) {
1413 rc = limits_parse_one(c->argv[i], lim);
1415 Debug(LDAP_DEBUG_ANY, "%s: "
1416 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1417 c->log, c->argv[i], 0);
1421 if(!strcasecmp(c->argv[i], "unlimited")) {
1422 lim->lms_s_soft = -1;
1424 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1425 if(next == c->argv[i]) {
1426 Debug(LDAP_DEBUG_ANY, "%s: "
1427 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1428 c->log, c->argv[i], 0);
1430 } else if(next[0] != '\0') {
1431 Debug(LDAP_DEBUG_ANY, "%s: "
1432 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1436 lim->lms_s_hard = 0;
1443 config_timelimit(ConfigArgs *c) {
1446 struct slap_limits_set *lim = &c->be->be_def_limit;
1447 if (c->op == SLAP_CONFIG_EMIT) {
1452 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1453 if ( !BER_BVISEMPTY( &bv ))
1454 value_add_one( &c->rvalue_vals, &bv );
1458 } else if ( c->op == LDAP_MOD_DELETE ) {
1459 /* Reset to defaults */
1460 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1461 lim->lms_t_hard = 0;
1464 for(i = 1; i < c->argc; i++) {
1465 if(!strncasecmp(c->argv[i], "time", 4)) {
1466 rc = limits_parse_one(c->argv[i], lim);
1468 Debug(LDAP_DEBUG_ANY, "%s: "
1469 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1470 c->log, c->argv[i], 0);
1474 if(!strcasecmp(c->argv[i], "unlimited")) {
1475 lim->lms_t_soft = -1;
1477 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1478 if(next == c->argv[i]) {
1479 Debug(LDAP_DEBUG_ANY, "%s: "
1480 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1481 c->log, c->argv[i], 0);
1483 } else if(next[0] != '\0') {
1484 Debug(LDAP_DEBUG_ANY, "%s: "
1485 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1489 lim->lms_t_hard = 0;
1496 config_overlay(ConfigArgs *c) {
1497 if (c->op == SLAP_CONFIG_EMIT) {
1499 } else if ( c->op == LDAP_MOD_DELETE ) {
1502 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1504 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1505 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1506 } else if(overlay_config(c->be, c->argv[1])) {
1513 config_suffix(ConfigArgs *c) {
1515 struct berval pdn, ndn;
1518 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1519 SLAP_CONFIG(c->be)) return 1;
1521 if (c->op == SLAP_CONFIG_EMIT) {
1522 if ( c->be->be_suffix == NULL
1523 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1527 value_add( &c->rvalue_vals, c->be->be_suffix );
1528 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1531 } else if ( c->op == LDAP_MOD_DELETE ) {
1532 if ( c->valx < 0 ) {
1533 ber_bvarray_free( c->be->be_suffix );
1534 ber_bvarray_free( c->be->be_nsuffix );
1535 c->be->be_suffix = NULL;
1536 c->be->be_nsuffix = NULL;
1539 ch_free( c->be->be_suffix[i].bv_val );
1540 ch_free( c->be->be_nsuffix[i].bv_val );
1541 for (; c->be->be_suffix[i].bv_val; i++) {
1542 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1543 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1548 #ifdef SLAPD_MONITOR_DN
1549 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1550 Debug(LDAP_DEBUG_ANY, "%s: "
1551 "\"%s\" is reserved for monitoring slapd\n",
1552 c->log, SLAPD_MONITOR_DN, 0);
1559 tbe = select_backend(&ndn, 0, 0);
1561 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1566 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1567 c->log, tbe->be_suffix[0].bv_val, 0);
1571 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1572 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1573 "base provided \"%s\" (assuming okay)\n",
1574 c->log, default_search_base.bv_val, 0);
1576 ber_bvarray_add(&c->be->be_suffix, &pdn);
1577 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1582 config_rootdn(ConfigArgs *c) {
1583 if (c->op == SLAP_CONFIG_EMIT) {
1584 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1585 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1586 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1591 } else if ( c->op == LDAP_MOD_DELETE ) {
1592 ch_free( c->be->be_rootdn.bv_val );
1593 ch_free( c->be->be_rootndn.bv_val );
1594 BER_BVZERO( &c->be->be_rootdn );
1595 BER_BVZERO( &c->be->be_rootndn );
1598 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1599 ch_free( c->be->be_rootdn.bv_val );
1600 ch_free( c->be->be_rootndn.bv_val );
1602 c->be->be_rootdn = c->value_dn;
1603 c->be->be_rootndn = c->value_ndn;
1608 config_rootpw(ConfigArgs *c) {
1610 if (c->op == SLAP_CONFIG_EMIT) {
1611 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1612 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1616 } else if ( c->op == LDAP_MOD_DELETE ) {
1617 ch_free( c->be->be_rootpw.bv_val );
1618 BER_BVZERO( &c->be->be_rootpw );
1622 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1624 Debug(LDAP_DEBUG_ANY, "%s: "
1625 "rootpw can only be set when rootdn is under suffix\n",
1629 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1630 ch_free( c->be->be_rootpw.bv_val );
1631 c->be->be_rootpw = c->value_bv;
1636 config_restrict(ConfigArgs *c) {
1637 slap_mask_t restrictops = 0;
1639 slap_verbmasks restrictable_ops[] = {
1640 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1641 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1642 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1643 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1644 { BER_BVC("modrdn"), 0 },
1645 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1646 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1647 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1648 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1649 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1650 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1651 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1652 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1653 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1654 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1658 if (c->op == SLAP_CONFIG_EMIT) {
1659 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1661 } else if ( c->op == LDAP_MOD_DELETE ) {
1663 c->be->be_restrictops = 0;
1665 restrictops = verb_to_mask( c->line, restrictable_ops );
1666 c->be->be_restrictops ^= restrictops;
1670 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1672 Debug(LDAP_DEBUG_ANY, "%s: "
1673 "unknown operation %s in \"restrict <features>\" line\n",
1674 c->log, c->argv[i], 0);
1677 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1678 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1679 c->be->be_restrictops |= restrictops;
1684 config_allows(ConfigArgs *c) {
1685 slap_mask_t allows = 0;
1687 slap_verbmasks allowable_ops[] = {
1688 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1689 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1690 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1691 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1694 if (c->op == SLAP_CONFIG_EMIT) {
1695 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1696 } else if ( c->op == LDAP_MOD_DELETE ) {
1700 allows = verb_to_mask( c->line, allowable_ops );
1701 global_allows ^= allows;
1705 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1707 Debug(LDAP_DEBUG_ANY, "%s: "
1708 "unknown feature %s in \"allow <features>\" line\n",
1709 c->log, c->argv[i], 0);
1712 global_allows |= allows;
1717 config_disallows(ConfigArgs *c) {
1718 slap_mask_t disallows = 0;
1720 slap_verbmasks disallowable_ops[] = {
1721 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1722 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1723 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1724 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1725 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1728 if (c->op == SLAP_CONFIG_EMIT) {
1729 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1730 } else if ( c->op == LDAP_MOD_DELETE ) {
1732 global_disallows = 0;
1734 disallows = verb_to_mask( c->line, disallowable_ops );
1735 global_disallows ^= disallows;
1739 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1741 Debug(LDAP_DEBUG_ANY, "%s: "
1742 "unknown feature %s in \"disallow <features>\" line\n",
1743 c->log, c->argv[i], 0);
1746 global_disallows |= disallows;
1751 config_requires(ConfigArgs *c) {
1752 slap_mask_t requires = 0;
1754 slap_verbmasks requires_ops[] = {
1755 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1756 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1757 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1758 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1759 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1762 if (c->op == SLAP_CONFIG_EMIT) {
1763 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1764 } else if ( c->op == LDAP_MOD_DELETE ) {
1766 c->be->be_requires = 0;
1768 requires = verb_to_mask( c->line, requires_ops );
1769 c->be->be_requires ^= requires;
1773 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1775 Debug(LDAP_DEBUG_ANY, "%s: "
1776 "unknown feature %s in \"require <features>\" line\n",
1777 c->log, c->argv[i], 0);
1780 c->be->be_requires = requires;
1785 config_loglevel(ConfigArgs *c) {
1788 slap_verbmasks loglevel_ops[] = {
1789 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1790 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1791 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1792 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1793 { BER_BVC("BER"), LDAP_DEBUG_BER },
1794 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1795 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1796 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1797 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1798 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1799 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1800 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1801 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1802 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1803 { BER_BVC("Any"), -1 },
1807 if (c->op == SLAP_CONFIG_EMIT) {
1808 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1809 } else if ( c->op == LDAP_MOD_DELETE ) {
1813 int level = verb_to_mask( c->line, loglevel_ops );
1814 ldap_syslog ^= level;
1821 for( i=1; i < c->argc; i++ ) {
1824 if ( isdigit( c->argv[i][0] ) ) {
1825 level = strtol( c->argv[i], &next, 10 );
1826 if ( next == NULL || next[0] != '\0' ) {
1827 Debug( LDAP_DEBUG_ANY,
1828 "%s: unable to parse level \"%s\" "
1829 "in \"loglevel <level> [...]\" line.\n",
1830 c->log, c->argv[i], 0);
1834 int j = verb_to_mask(c->argv[i], loglevel_ops);
1835 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1836 Debug( LDAP_DEBUG_ANY,
1837 "%s: unknown level \"%s\" "
1838 "in \"loglevel <level> [...]\" line.\n",
1839 c->log, c->argv[i], 0);
1842 level = loglevel_ops[j].mask;
1844 ldap_syslog |= level;
1850 config_syncrepl(ConfigArgs *c) {
1851 if (c->op == SLAP_CONFIG_EMIT) {
1852 if ( c->be->be_syncinfo ) {
1854 syncrepl_unparse( c->be->be_syncinfo, &bv );
1855 ber_bvarray_add( &c->rvalue_vals, &bv );
1859 } else if ( c->op == LDAP_MOD_DELETE ) {
1862 if ( c->be->be_syncinfo ) {
1863 re = ldap_pvt_runqueue_find( &slapd_rq, do_syncrepl, c->be->be_syncinfo );
1865 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
1866 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
1867 ldap_pvt_runqueue_remove( &slapd_rq, re );
1869 syncinfo_free( c->be->be_syncinfo );
1870 c->be->be_syncinfo = NULL;
1874 if(SLAP_SHADOW(c->be)) {
1875 Debug(LDAP_DEBUG_ANY, "%s: "
1876 "syncrepl: database already shadowed.\n",
1879 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1882 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1887 config_referral(ConfigArgs *c) {
1889 if (c->op == SLAP_CONFIG_EMIT) {
1890 if ( default_referral ) {
1891 value_add( &c->rvalue_vals, default_referral );
1896 } else if ( c->op == LDAP_MOD_DELETE ) {
1897 if ( c->valx < 0 ) {
1898 ber_bvarray_free( default_referral );
1899 default_referral = NULL;
1902 ch_free( default_referral[i].bv_val );
1903 for (; default_referral[i].bv_val; i++ )
1904 default_referral[i] = default_referral[i+1];
1908 if(validate_global_referral(c->argv[1])) {
1909 Debug(LDAP_DEBUG_ANY, "%s: "
1910 "invalid URL (%s) in \"referral\" line.\n",
1911 c->log, c->argv[1], 0);
1915 ber_str2bv(c->argv[1], 0, 0, &val);
1916 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
1924 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1925 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1926 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1927 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1928 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1929 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1930 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1931 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1932 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1937 config_security(ConfigArgs *c) {
1938 slap_ssf_set_t *set = &c->be->be_ssf_set;
1941 if (c->op == SLAP_CONFIG_EMIT) {
1947 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1948 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1951 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1952 bv.bv_len += sec_keys[i].key.bv_len;
1953 bv.bv_val = ch_malloc( bv.bv_len + 1);
1954 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1955 strcpy( next, numbuf );
1956 ber_bvarray_add( &c->rvalue_vals, &bv );
1961 for(i = 1; i < c->argc; i++) {
1962 slap_ssf_t *tgt = NULL;
1964 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1965 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1966 sec_keys[j].key.bv_len)) {
1967 src = c->argv[i] + sec_keys[j].key.bv_len;
1968 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1973 Debug(LDAP_DEBUG_ANY, "%s: "
1974 "unknown factor %s in \"security <factors>\" line\n",
1975 c->log, c->argv[i], 0);
1979 *tgt = strtol(src, &next, 10);
1980 if(next == NULL || next[0] != '\0' ) {
1981 Debug(LDAP_DEBUG_ANY, "%s: "
1982 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1983 c->log, c->argv[i], 0);
1991 anlist_unparse( AttributeName *an, char *ptr ) {
1994 for (; !BER_BVISNULL( &an->an_name ); an++) {
1995 if ( comma ) *ptr++ = ',';
1996 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2003 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2007 struct berval bc = {0};
2010 len = sprintf(numbuf, IFMT, i );
2012 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2013 if ( ri->ri_nsuffix ) {
2014 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2015 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2018 if ( ri->ri_attrs ) {
2019 len += STRLENOF("attr");
2020 if ( ri->ri_exclude ) len++;
2021 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2022 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2025 bindconf_unparse( &ri->ri_bindconf, &bc );
2028 bv->bv_val = ch_malloc(len + 1);
2031 ptr = lutil_strcopy( bv->bv_val, numbuf );
2032 ptr = lutil_strcopy( ptr, "uri=" );
2033 ptr = lutil_strcopy( ptr, ri->ri_uri );
2035 if ( ri->ri_nsuffix ) {
2036 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2037 ptr = lutil_strcopy( ptr, " suffix=\"" );
2038 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2042 if ( ri->ri_attrs ) {
2043 ptr = lutil_strcopy( ptr, "attr" );
2044 if ( ri->ri_exclude ) *ptr++ = '!';
2046 ptr = anlist_unparse( ri->ri_attrs, ptr );
2049 strcpy( ptr, bc.bv_val );
2050 ch_free( bc.bv_val );
2055 config_replica(ConfigArgs *c) {
2056 int i, nr = -1, len;
2057 char *replicahost, *replicauri;
2060 if (c->op == SLAP_CONFIG_EMIT) {
2061 if (c->be->be_replica) {
2063 for (i=0;c->be->be_replica[i]; i++) {
2064 replica_unparse( c->be->be_replica[i], i, &bv );
2065 ber_bvarray_add( &c->rvalue_vals, &bv );
2070 } else if ( c->op == LDAP_MOD_DELETE ) {
2071 /* FIXME: there is no replica_free function */
2072 if ( c->valx < 0 ) {
2076 if(SLAP_MONITOR(c->be)) {
2077 Debug(LDAP_DEBUG_ANY, "%s: "
2078 "\"replica\" should not be used inside monitor database\n",
2080 return(0); /* FIXME: should this be an error? */
2083 for(i = 1; i < c->argc; i++) {
2084 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2085 replicahost = c->argv[i] + STRLENOF("host=");
2086 len = strlen( replicahost );
2087 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2088 sprintf( replicauri, "ldap://%s", replicahost );
2089 replicahost = replicauri + STRLENOF( "ldap://");
2090 nr = add_replica_info(c->be, replicauri, replicahost);
2092 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2093 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2094 Debug(LDAP_DEBUG_ANY, "%s: "
2095 "replica line contains invalid "
2096 "uri definition.\n", c->log, 0, 0);
2099 if(!ludp->lud_host) {
2100 Debug(LDAP_DEBUG_ANY, "%s: "
2101 "replica line contains invalid "
2102 "uri definition - missing hostname.\n",
2106 ldap_free_urldesc(ludp);
2107 replicauri = c->argv[i] + STRLENOF("uri=");
2108 replicauri = ch_strdup( replicauri );
2109 replicahost = strchr( replicauri, '/' );
2111 nr = add_replica_info(c->be, replicauri, replicahost);
2116 Debug(LDAP_DEBUG_ANY, "%s: "
2117 "missing host or uri in \"replica\" line\n",
2120 } else if(nr == -1) {
2121 Debug(LDAP_DEBUG_ANY, "%s: "
2122 "unable to add replica \"%s\"\n",
2123 c->log, replicauri, 0);
2126 for(i = 1; i < c->argc; i++) {
2127 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2128 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2130 Debug(LDAP_DEBUG_ANY, "%s: "
2131 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2132 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2135 Debug(LDAP_DEBUG_ANY, "%s: "
2136 "unable to normalize suffix in \"replica\" line (ignored)\n",
2141 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2143 char *arg = c->argv[i] + STRLENOF("attr");
2151 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2152 Debug(LDAP_DEBUG_ANY, "%s: "
2153 "attribute \"%s\" in \"replica\" line is unknown\n",
2154 c->log, arg + 1, 0);
2157 } else if ( bindconf_parse( c->argv[i],
2158 &c->be->be_replica[nr]->ri_bindconf ) ) {
2167 config_updatedn(ConfigArgs *c) {
2170 if (c->op == SLAP_CONFIG_EMIT) {
2171 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2172 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2173 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2177 } else if ( c->op == LDAP_MOD_DELETE ) {
2178 ch_free( c->be->be_update_ndn.bv_val );
2179 c->be->be_update_ndn.bv_val = NULL;
2180 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2183 if(SLAP_SHADOW(c->be)) {
2184 Debug(LDAP_DEBUG_ANY, "%s: "
2185 "updatedn: database already shadowed.\n",
2190 ber_str2bv(c->argv[1], 0, 0, &dn);
2192 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2194 if(rc != LDAP_SUCCESS) {
2195 Debug(LDAP_DEBUG_ANY, "%s: "
2196 "updatedn DN is invalid: %d (%s)\n",
2197 c->log, rc, ldap_err2string( rc ));
2201 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2206 config_updateref(ConfigArgs *c) {
2208 if (c->op == SLAP_CONFIG_EMIT) {
2209 if ( c->be->be_update_refs ) {
2210 value_add( &c->rvalue_vals, c->be->be_update_refs );
2215 } else if ( c->op == LDAP_MOD_DELETE ) {
2216 if ( c->valx < 0 ) {
2217 ber_bvarray_free( c->be->be_update_refs );
2218 c->be->be_update_refs = NULL;
2221 ch_free( c->be->be_update_refs[i].bv_val );
2222 for (; c->be->be_update_refs[i].bv_val; i++)
2223 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2227 if(!SLAP_SHADOW(c->be)) {
2228 Debug(LDAP_DEBUG_ANY, "%s: "
2229 "updateref line must come after syncrepl or updatedn.\n",
2234 if(validate_global_referral(c->argv[1])) {
2235 Debug(LDAP_DEBUG_ANY, "%s: "
2236 "invalid URL (%s) in \"updateref\" line.\n",
2237 c->log, c->argv[1], 0);
2240 ber_str2bv(c->argv[1], 0, 0, &val);
2241 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2246 config_include(ConfigArgs *c) {
2247 unsigned long savelineno = c->lineno;
2250 ConfigFile *cfsave = cfn;
2251 ConfigFile *cf2 = NULL;
2252 if (c->op == SLAP_CONFIG_EMIT) {
2254 ConfigFile *cf = c->private;
2255 value_add_one( &c->rvalue_vals, &cf->c_file );
2259 } else if ( c->op == LDAP_MOD_DELETE ) {
2261 cf = ch_calloc( 1, sizeof(ConfigFile));
2262 if ( cfn->c_kids ) {
2263 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2269 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2270 rc = read_config_file(c->argv[1], c->depth + 1, c);
2271 c->lineno = savelineno - 1;
2274 if ( cf2 ) cf2->c_sibs = NULL;
2275 else cfn->c_kids = NULL;
2276 ch_free( cf->c_file.bv_val );
2284 config_tls_option(ConfigArgs *c) {
2287 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2288 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2289 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2290 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2291 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2292 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2293 default: Debug(LDAP_DEBUG_ANY, "%s: "
2294 "unknown tls_option <0x%x>\n",
2295 c->log, c->type, 0);
2297 if (c->op == SLAP_CONFIG_EMIT) {
2298 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2299 } else if ( c->op == LDAP_MOD_DELETE ) {
2300 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2302 ch_free(c->value_string);
2303 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2306 /* FIXME: this ought to be provided by libldap */
2308 config_tls_config(ConfigArgs *c) {
2310 slap_verbmasks crlkeys[] = {
2311 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2312 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2313 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2316 slap_verbmasks vfykeys[] = {
2317 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2318 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2319 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2320 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2324 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2325 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2327 Debug(LDAP_DEBUG_ANY, "%s: "
2328 "unknown tls_option <0x%x>\n",
2329 c->log, c->type, 0);
2331 if (c->op == SLAP_CONFIG_EMIT) {
2332 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2333 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2334 if (keys[i].mask == c->value_int) {
2335 c->value_string = ch_strdup( keys[i].word.bv_val );
2340 } else if ( c->op == LDAP_MOD_DELETE ) {
2342 return ldap_pvt_tls_set_option( NULL, flag, &i );
2344 ch_free( c->value_string );
2345 if(isdigit((unsigned char)c->argv[1][0])) {
2346 i = atoi(c->argv[1]);
2347 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2349 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2364 if ( !( be->be_search && be->be_add && be->be_modify && be->be_delete )) {
2365 Debug( LDAP_DEBUG_ANY, "database %s does not support operations "
2366 "required for syncrepl\n", be->be_type, 0, 0 );
2369 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2372 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2376 si->si_bindconf.sb_tls = SB_TLS_OFF;
2377 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2378 si->si_schemachecking = 0;
2379 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2380 &si->si_filterstr );
2381 si->si_base.bv_val = NULL;
2382 si->si_scope = LDAP_SCOPE_SUBTREE;
2383 si->si_attrsonly = 0;
2384 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2385 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2386 si->si_attrs = NULL;
2387 si->si_allattrs = 0;
2388 si->si_allopattrs = 0;
2389 si->si_exattrs = NULL;
2390 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2391 si->si_interval = 86400;
2392 si->si_retryinterval = NULL;
2393 si->si_retrynum_init = NULL;
2394 si->si_retrynum = NULL;
2395 si->si_manageDSAit = 0;
2399 si->si_presentlist = NULL;
2400 LDAP_LIST_INIT( &si->si_nonpresentlist );
2401 ldap_pvt_thread_mutex_init( &si->si_mutex );
2403 rc = parse_syncrepl_line( cargv, cargc, si );
2406 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2407 syncinfo_free( si );
2410 Debug( LDAP_DEBUG_CONFIG,
2411 "Config: ** successfully added syncrepl \"%s\"\n",
2412 BER_BVISNULL( &si->si_provideruri ) ?
2413 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2414 if ( !si->si_schemachecking ) {
2415 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2418 be->be_syncinfo = si;
2419 init_syncrepl( si );
2420 ldap_pvt_runqueue_insert( &slapd_rq,si->si_interval,do_syncrepl,si );
2425 /* NOTE: used & documented in slapd.conf(5) */
2427 #define PROVIDERSTR "provider"
2428 #define TYPESTR "type"
2429 #define INTERVALSTR "interval"
2430 #define SEARCHBASESTR "searchbase"
2431 #define FILTERSTR "filter"
2432 #define SCOPESTR "scope"
2433 #define ATTRSSTR "attrs"
2434 #define ATTRSONLYSTR "attrsonly"
2435 #define SLIMITSTR "sizelimit"
2436 #define TLIMITSTR "timelimit"
2437 #define SCHEMASTR "schemachecking"
2439 /* FIXME: undocumented */
2440 #define OLDAUTHCSTR "bindprincipal"
2441 #define EXATTRSSTR "exattrs"
2442 #define RETRYSTR "retry"
2445 #define LASTMODSTR "lastmod"
2446 #define LMGENSTR "gen"
2447 #define LMNOSTR "no"
2448 #define LMREQSTR "req"
2449 #define SRVTABSTR "srvtab"
2450 #define SUFFIXSTR "suffix"
2451 #define MANAGEDSAITSTR "manageDSAit"
2454 #define GOT_ID 0x0001
2455 #define GOT_PROVIDER 0x0002
2458 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2464 { BER_BVC("base"), LDAP_SCOPE_BASE },
2465 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2466 #ifdef LDAP_SCOPE_SUBORDINATE
2467 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2468 { BER_BVC("subordinate"), 0 },
2470 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2475 parse_syncrepl_line(
2485 for ( i = 1; i < cargc; i++ ) {
2486 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2487 STRLENOF( IDSTR "=" ) ) )
2490 /* '\0' string terminator accounts for '=' */
2491 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2493 if ( tmp >= 1000 || tmp < 0 ) {
2494 fprintf( stderr, "Error: parse_syncrepl_line: "
2495 "syncrepl id %d is out of range [0..999]\n", tmp );
2500 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2501 STRLENOF( PROVIDERSTR "=" ) ) )
2503 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2504 ber_str2bv( val, 0, 1, &si->si_provideruri );
2505 gots |= GOT_PROVIDER;
2506 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2507 STRLENOF( SCHEMASTR "=" ) ) )
2509 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2510 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2511 si->si_schemachecking = 1;
2512 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2513 si->si_schemachecking = 0;
2515 si->si_schemachecking = 1;
2517 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2518 STRLENOF( FILTERSTR "=" ) ) )
2520 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2521 ber_str2bv( val, 0, 1, &si->si_filterstr );
2522 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2523 STRLENOF( SEARCHBASESTR "=" ) ) )
2528 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2529 if ( si->si_base.bv_val ) {
2530 ch_free( si->si_base.bv_val );
2532 ber_str2bv( val, 0, 0, &bv );
2533 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2534 if ( rc != LDAP_SUCCESS ) {
2535 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2536 val, rc, ldap_err2string( rc ) );
2539 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2540 STRLENOF( SCOPESTR "=" ) ) )
2543 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2544 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2545 if (!strncasecmp( val, scopes[j].key.bv_val,
2546 scopes[j].key.bv_len )) {
2547 while (!scopes[j].val) j--;
2548 si->si_scope = scopes[j].val;
2552 if ( BER_BVISNULL(&scopes[j].key) ) {
2553 fprintf( stderr, "Error: parse_syncrepl_line: "
2554 "unknown scope \"%s\"\n", val);
2557 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2558 STRLENOF( ATTRSONLYSTR "=" ) ) )
2560 si->si_attrsonly = 1;
2561 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2562 STRLENOF( ATTRSSTR "=" ) ) )
2564 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2565 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2567 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2568 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2569 if ( si->si_anlist == NULL ) {
2570 ch_free( attr_fname );
2573 si->si_anfile = attr_fname;
2575 char *str, *s, *next;
2576 char delimstr[] = " ,\t";
2577 str = ch_strdup( val );
2578 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2580 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2582 if ( strlen(s) == 1 && *s == '*' ) {
2583 si->si_allattrs = 1;
2584 *(val + ( s - str )) = delimstr[0];
2586 if ( strlen(s) == 1 && *s == '+' ) {
2587 si->si_allopattrs = 1;
2588 *(val + ( s - str )) = delimstr[0];
2592 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2593 if ( si->si_anlist == NULL ) {
2597 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2598 STRLENOF( EXATTRSSTR "=" ) ) )
2600 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2601 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2603 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2604 si->si_exanlist = file2anlist(
2605 si->si_exanlist, attr_fname, " ,\t" );
2606 if ( si->si_exanlist == NULL ) {
2607 ch_free( attr_fname );
2610 ch_free( attr_fname );
2612 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2613 if ( si->si_exanlist == NULL ) {
2617 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2618 STRLENOF( TYPESTR "=" ) ) )
2620 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2621 if ( !strncasecmp( val, "refreshOnly",
2622 STRLENOF("refreshOnly") ))
2624 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2625 } else if ( !strncasecmp( val, "refreshAndPersist",
2626 STRLENOF("refreshAndPersist") ))
2628 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2629 si->si_interval = 60;
2631 fprintf( stderr, "Error: parse_syncrepl_line: "
2632 "unknown sync type \"%s\"\n", val);
2635 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2636 STRLENOF( INTERVALSTR "=" ) ) )
2638 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2639 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2640 si->si_interval = 0;
2648 hstr = strchr( dstr, ':' );
2649 if ( hstr == NULL ) {
2650 fprintf( stderr, "Error: parse_syncrepl_line: "
2651 "invalid interval \"%s\"\n", val );
2655 mstr = strchr( hstr, ':' );
2656 if ( mstr == NULL ) {
2657 fprintf( stderr, "Error: parse_syncrepl_line: "
2658 "invalid interval \"%s\"\n", val );
2662 sstr = strchr( mstr, ':' );
2663 if ( sstr == NULL ) {
2664 fprintf( stderr, "Error: parse_syncrepl_line: "
2665 "invalid interval \"%s\"\n", val );
2674 if (( hh > 24 ) || ( hh < 0 ) ||
2675 ( mm > 60 ) || ( mm < 0 ) ||
2676 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2677 fprintf( stderr, "Error: parse_syncrepl_line: "
2678 "invalid interval \"%s\"\n", val );
2681 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2683 if ( si->si_interval < 0 ) {
2684 fprintf( stderr, "Error: parse_syncrepl_line: "
2685 "invalid interval \"%ld\"\n",
2686 (long) si->si_interval);
2689 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2690 STRLENOF( RETRYSTR "=" ) ) )
2695 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2696 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2697 retry_list[0] = NULL;
2699 slap_str2clist( &retry_list, val, " ,\t" );
2701 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2705 "Error: incomplete syncrepl retry list\n" );
2706 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2707 ch_free( retry_list[k] );
2709 ch_free( retry_list );
2710 exit( EXIT_FAILURE );
2712 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2713 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2714 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2715 for ( j = 0; j < n; j++ ) {
2716 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2717 if ( *retry_list[j*2+1] == '+' ) {
2718 si->si_retrynum_init[j] = -1;
2719 si->si_retrynum[j] = -1;
2723 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2724 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2727 si->si_retrynum_init[j] = -2;
2728 si->si_retrynum[j] = -2;
2729 si->si_retryinterval[j] = 0;
2731 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2732 ch_free( retry_list[k] );
2734 ch_free( retry_list );
2735 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2736 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2738 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2739 si->si_manageDSAit = atoi( val );
2740 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2741 STRLENOF( SLIMITSTR "=") ) )
2743 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2744 si->si_slimit = atoi( val );
2745 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2746 STRLENOF( TLIMITSTR "=" ) ) )
2748 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2749 si->si_tlimit = atoi( val );
2750 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2751 fprintf( stderr, "Error: parse_syncrepl_line: "
2752 "unknown keyword \"%s\"\n", cargv[ i ] );
2757 if ( gots != GOT_ALL ) {
2759 "Error: Malformed \"syncrepl\" line in slapd config file" );
2767 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2770 char buf[BUFSIZ*2], *ptr;
2773 bindconf_unparse( &si->si_bindconf, &bc );
2775 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
2776 si->si_rid, si->si_provideruri.bv_val );
2777 if ( !BER_BVISNULL( &bc )) {
2778 ptr = lutil_strcopy( ptr, bc.bv_val );
2781 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2782 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2783 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2786 if ( !BER_BVISNULL( &si->si_base )) {
2787 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2788 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2791 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2792 if ( si->si_scope == scopes[i].val ) {
2793 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2794 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2798 if ( si->si_attrsonly ) {
2799 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2801 if ( si->si_anfile ) {
2802 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2803 ptr = lutil_strcopy( ptr, si->si_anfile );
2804 } else if ( si->si_allattrs || si->si_allopattrs ||
2805 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2807 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2809 ptr = anlist_unparse( si->si_anlist, ptr );
2810 if ( si->si_allattrs ) {
2811 if ( old != ptr ) *ptr++ = ',';
2814 if ( si->si_allopattrs ) {
2815 if ( old != ptr ) *ptr++ = ',';
2820 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
2821 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
2822 ptr = anlist_unparse( si->si_exanlist, ptr );
2824 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
2825 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
2827 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
2828 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
2829 "refreshAndPersist" : "refreshOnly" );
2831 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
2834 dd = si->si_interval;
2841 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
2842 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
2843 } else if ( si->si_retryinterval ) {
2845 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
2846 for (i=0; si->si_retryinterval[i]; i++) {
2847 if ( space ) *ptr++ = ' ';
2849 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
2850 if ( si->si_retrynum_init[i] == -1 )
2853 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
2858 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
2859 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
2860 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
2863 if ( si->si_slimit ) {
2864 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
2865 ptr += sprintf( ptr, "%d", si->si_slimit );
2868 if ( si->si_tlimit ) {
2869 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
2870 ptr += sprintf( ptr, "%d", si->si_tlimit );
2872 bc.bv_len = ptr - buf;
2874 ber_dupbv( bv, &bc );
2877 static CfEntryInfo *
2878 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2888 if ( dn_match( &root->ce_entry->e_nname, dn ))
2891 c = dn->bv_val+dn->bv_len;
2892 for (;*c != ',';c--);
2896 for (--c;c>dn->bv_val && *c != ',';c--);
2900 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2902 root = root->ce_kids;
2904 for (;root;root=root->ce_sibs) {
2905 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2906 if ( cdn.bv_val == dn->bv_val ) {
2917 config_ldif_resp( Operation *op, SlapReply *rs )
2919 if ( rs->sr_type == REP_SEARCH ) {
2920 CfBackInfo *cfb = op->o_callback->sc_private;
2922 cfb->cb_got_ldif = 1;
2923 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL );
2928 /* Configure and read the underlying back-ldif store */
2930 config_setup_ldif( BackendDB *be, const char *dir ) {
2931 CfBackInfo *cfb = be->be_private;
2936 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2937 Connection conn = {0};
2938 char opbuf[OPERATION_BUFFER_SIZE];
2940 SlapReply rs = {REP_RESULT};
2941 Filter filter = { LDAP_FILTER_PRESENT };
2942 struct berval filterstr = BER_BVC("(objectclass=*)");
2945 /* Is the config directory available? */
2946 if ( stat( dir, &st ) < 0 ) {
2947 /* No, so don't bother using the backing store.
2948 * All changes will be in-memory only.
2953 cfb->cb_db.bd_info = backend_info( "ldif" );
2954 if ( !cfb->cb_db.bd_info )
2955 return 0; /* FIXME: eventually this will be a fatal error */
2957 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2959 /* Mark that back-ldif type is in use */
2960 cfb->cb_db.bd_info->bi_nDB++;
2962 cfb->cb_db.be_suffix = be->be_suffix;
2963 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2964 cfb->cb_db.be_rootdn = be->be_rootdn;
2965 cfb->cb_db.be_rootndn = be->be_rootndn;
2967 ber_str2bv( dir, 0, 1, &cfdir );
2972 argv[0] = "directory";
2973 argv[1] = (char *)dir;
2977 ct = config_find_keyword( c.be->be_cf_table, &c );
2981 if ( config_add_vals( ct, &c ))
2984 if ( backend_startup_one( &cfb->cb_db ))
2987 op = (Operation *)opbuf;
2988 connection_fake_init( &conn, op, cfb );
2990 filter.f_desc = slap_schema.si_ad_objectClass;
2992 op->o_tag = LDAP_REQ_SEARCH;
2994 op->ors_filter = &filter;
2995 op->ors_filterstr = filterstr;
2996 op->ors_scope = LDAP_SCOPE_SUBTREE;
2998 op->o_dn = be->be_rootdn;
2999 op->o_ndn = be->be_rootndn;
3001 op->o_req_dn = be->be_suffix[0];
3002 op->o_req_ndn = be->be_nsuffix[0];
3004 op->ors_tlimit = SLAP_NO_LIMIT;
3005 op->ors_slimit = SLAP_NO_LIMIT;
3007 op->ors_attrs = slap_anlist_all_attributes;
3008 op->ors_attrsonly = 0;
3010 op->o_callback = &cb;
3011 cb.sc_private = cfb;
3013 op->o_bd = &cfb->cb_db;
3014 op->o_bd->be_search( op, &rs );
3016 cfb->cb_use_ldif = 1;
3022 CfOcInfo_cmp( const void *c1, const void *c2 ) {
3023 const CfOcInfo *co1 = c1;
3024 const CfOcInfo *co2 = c2;
3026 return ber_bvcmp( co1->co_name, co2->co_name );
3030 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3034 i = init_config_attrs( ct );
3037 /* set up the objectclasses */
3038 i = init_config_ocs( ocs );
3041 for (i=0; ocs[i].def; i++) {
3043 co = ch_malloc( sizeof(CfOcInfo) );
3044 co->co_oc = *ocs[i].oc;
3045 co->co_name = &co->co_oc->soc_cname;
3047 co->co_type = ocs[i].cft;
3048 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
3055 read_config(const char *fname, const char *dir) {
3059 /* Setup the config backend */
3060 be = backend_db_init( "config" );
3064 cfb = be->be_private;
3066 /* Setup the underlying back-ldif backend */
3067 if ( config_setup_ldif( be, dir ))
3070 #ifdef SLAP_USE_CONFDIR
3071 /* If we read the config from back-ldif, nothing to do here */
3072 if ( cfb->cb_got_ldif )
3075 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
3077 return read_config_file(fname, 0, NULL);
3081 config_back_bind( Operation *op, SlapReply *rs )
3083 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
3084 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3085 /* frontend sends result */
3086 return LDAP_SUCCESS;
3089 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3090 send_ldap_result( op, rs );
3096 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3100 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3102 rs->sr_attrs = op->ors_attrs;
3103 rs->sr_entry = ce->ce_entry;
3104 rc = send_search_entry( op, rs );
3106 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3107 if ( ce->ce_kids ) {
3108 rc = config_send( op, rs, ce->ce_kids, 1 );
3109 if ( rc ) return rc;
3112 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3113 rc = config_send( op, rs, ce, 0 );
3121 static ConfigTable *
3122 config_find_table( CfOcInfo **colst, int nocs, AttributeDescription *ad )
3126 for (j=0; j<nocs; j++) {
3127 for (i=0; colst[j]->co_table[i].name; i++)
3128 if ( colst[j]->co_table[i].ad == ad )
3129 return &colst[j]->co_table[i];
3134 /* Sort the attributes of the entry according to the order defined
3135 * in the objectclass, with required attributes occurring before
3136 * allowed attributes. For any attributes with sequencing dependencies
3137 * (e.g., rootDN must be defined after suffix) the objectclass must
3138 * list the attributes in the desired sequence.
3141 sort_attrs( Entry *e, CfOcInfo **colst, int nocs )
3143 Attribute *a, *head = NULL, *tail = NULL, **prev;
3146 for (i=0; i<nocs; i++) {
3147 if ( colst[i]->co_oc->soc_required ) {
3148 AttributeType **at = colst[i]->co_oc->soc_required;
3149 for (j=0; at[j]; j++) {
3150 for (a=e->e_attrs, prev=&e->e_attrs; a;
3151 prev = &(*prev)->a_next, a=a->a_next) {
3152 if ( a->a_desc == at[j]->sat_ad ) {
3166 if ( colst[i]->co_oc->soc_allowed ) {
3167 AttributeType **at = colst[i]->co_oc->soc_allowed;
3168 for (j=0; at[j]; j++) {
3169 for (a=e->e_attrs, prev=&e->e_attrs; a;
3170 prev = &(*prev)->a_next, a=a->a_next) {
3171 if ( a->a_desc == at[j]->sat_ad ) {
3187 tail->a_next = e->e_attrs;
3193 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3195 Attribute *a = NULL;
3196 AttributeDescription *ad;
3199 int i, rc = 0, sort = 0;
3206 Modifications *ml = ptr;
3208 vals = ml->sml_values;
3211 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3213 rc = ordered_value_sort( a, 1 );
3217 for ( i=0; vals[i].bv_val; i++ ) {
3218 ca->line = vals[i].bv_val;
3220 char *idx = strchr( ca->line, '}' );
3221 if ( idx ) ca->line = idx+1;
3223 rc = config_parse_vals( ct, ca, i );
3231 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3232 SlapReply *rs, int *renum )
3235 int index = -1, gotindex = 0, nsibs;
3236 int renumber = 0, tailindex = 0;
3240 if ( renum ) *renum = 0;
3242 /* These entries don't get indexed/renumbered */
3243 if ( ce_type == Cft_Global ) return 0;
3244 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3246 if ( ce_type == Cft_Include || ce_type == Cft_Module )
3249 /* See if the rdn has an index already */
3250 dnRdn( &e->e_name, &rdn );
3251 ptr1 = strchr( e->e_name.bv_val, '{' );
3252 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3253 ptr2 = strchr( ptr1, '}' );
3254 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3255 return LDAP_NAMING_VIOLATION;
3256 if ( ptr2-ptr1 == 1)
3257 return LDAP_NAMING_VIOLATION;
3259 index = atoi(ptr1+1);
3261 return LDAP_NAMING_VIOLATION;
3264 /* count related kids */
3265 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3266 if ( ce->ce_type == ce_type ) nsibs++;
3269 if ( index != nsibs ) {
3271 if ( index < nsibs ) {
3272 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3273 /* Siblings need to be renumbered */
3278 struct berval ival, newrdn, nnewrdn;
3279 struct berval rtype, rval;
3281 AttributeDescription *ad = NULL;
3285 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
3286 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
3287 rtype.bv_val = rdn.bv_val;
3288 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3291 slap_bv2ad( &rtype, &ad, &text );
3292 a = attr_find( e->e_attrs, ad );
3293 if (!a ) return LDAP_NAMING_VIOLATION;
3296 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
3298 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3299 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3302 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3303 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3310 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3312 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
3315 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3316 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3320 /* Do the equivalent of ModRDN */
3321 /* Replace DN / NDN */
3322 newrdn.bv_len = ptr1 - newrdn.bv_val;
3323 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3324 free( e->e_name.bv_val );
3325 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
3327 free( e->e_nname.bv_val );
3328 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
3332 free( a->a_vals[0].bv_val );
3333 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
3334 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
3335 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3336 strcpy( a->a_vals[0].bv_val, ptr1 );
3338 if ( a->a_nvals != a->a_vals ) {
3339 free( a->a_nvals[0].bv_val );
3340 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
3341 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
3342 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3343 strcpy( a->a_nvals[0].bv_val, ptr1 );
3345 free( nnewrdn.bv_val );
3346 free( newrdn.bv_val );
3349 if ( renum ) *renum = renumber;
3354 count_ocs( Attribute *oc_at, int *nocs )
3357 CfOcInfo co, *coptr, **colst;
3359 /* count the objectclasses */
3360 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
3362 colst = (CfOcInfo **)ch_malloc( n * sizeof(CfOcInfo *));
3364 for ( i=0, j=0; i<n; i++) {
3365 co.co_name = &oc_at->a_nvals[i];
3366 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
3368 /* ignore non-config objectclasses. probably should be
3369 * an error, general data doesn't belong here.
3371 if ( !coptr ) continue;
3373 /* Ignore the root objectclass, it has no implementation.
3375 if ( coptr->co_type == Cft_Abstract ) continue;
3382 /* Only the root can be Cft_Global, everything else must
3383 /* Parse an LDAP entry into config directives */
3385 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
3387 CfEntryInfo *ce, *last;
3389 Attribute *a, *oc_at, *type_attr;
3390 AttributeDescription *type_ad = NULL;
3392 ConfigArgs ca = {0};
3394 ConfigTable *ct, *type_ct = NULL;
3397 /* Make sure parent exists and entry does not */
3398 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3400 return LDAP_ALREADY_EXISTS;
3402 dnParent( &e->e_nname, &pdn );
3404 /* If last is NULL, the new entry is the root/suffix entry,
3405 * otherwise last should be the parent.
3407 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3409 rs->sr_matched = last->ce_entry->e_name.bv_val;
3410 return LDAP_NO_SUCH_OBJECT;
3413 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3414 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3416 colst = count_ocs( oc_at, &nocs );
3418 /* Only the root can be Cft_Global, everything else must
3419 * have a parent. Only limited nesting arrangements are allowed.
3421 switch( colst[0]->co_type ) {
3424 rc = LDAP_CONSTRAINT_VIOLATION;
3432 if ( !last || ( last->ce_type != Cft_Global &&
3433 last->ce_type != colst[0]->co_type )) {
3434 rc = LDAP_CONSTRAINT_VIOLATION;
3439 if ( !last || ( last->ce_type != Cft_Global &&
3440 last->ce_type != Cft_Database &&
3441 last->ce_type != colst[0]->co_type )) {
3442 rc = LDAP_CONSTRAINT_VIOLATION;
3446 #ifdef SLAPD_MODULES
3448 if ( !last || last->ce_type != Cft_Global ) {
3449 rc = LDAP_CONSTRAINT_VIOLATION;
3456 sort_attrs( e, colst, nocs );
3458 /* Parse all the values and check for simple syntax errors before
3459 * performing any set actions.
3461 switch (colst[0]->co_type) {
3463 /* The cn=schema entry is all hardcoded, so never reparse it */
3464 if (last->ce_type == Cft_Global )
3468 ca.be = LDAP_STAILQ_FIRST(&backendDB);
3472 if ( last->ce_type == Cft_Backend )
3473 ca.bi = last->ce_bi;
3475 type_ad = cfAd_backend;
3478 if ( last->ce_type == Cft_Database ) {
3479 ca.be = last->ce_be;
3481 type_ad = cfAd_database;
3482 /* dummy, just to get past check_attr */
3488 ca.be = last->ce_be;
3489 type_ad = cfAd_overlay;
3494 nocs = 0; /* ignored */
3497 type_ad = cfAd_include;
3499 #ifdef SLAPD_MODULES
3503 ptr = strchr( e->e_name.bv_val, '{' );
3505 rc = LDAP_NAMING_VIOLATION;
3509 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
3510 /* There is no corresponding modpath for this load? */
3512 rc = LDAP_NAMING_VIOLATION;
3515 module_path( mp->mp_path.bv_val );
3522 /* If doing an LDAPadd, check for indexed names and any necessary
3523 * renaming/renumbering. Entries that don't need indexed names are
3524 * ignored. Entries that need an indexed name and arrive without one
3525 * are assigned to the end. Entries that arrive with an index may
3526 * cause the following entries to be renumbered/bumped down.
3528 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3529 * don't allow Adding an entry with an index that's already in use.
3530 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3532 * These entries can have auto-assigned indexes (appended to the end)
3533 * but only the other types support auto-renumbering of siblings.
3535 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3539 init_config_argv( &ca );
3541 type_attr = attr_find( e->e_attrs, type_ad );
3543 rc = LDAP_OBJECT_CLASS_VIOLATION;
3546 type_ct = config_find_table( colst, nocs, type_ad );
3548 rc = LDAP_OBJECT_CLASS_VIOLATION;
3551 rc = check_vals( type_ct, &ca, type_attr, 1);
3552 if ( rc ) goto leave;
3554 for ( a=e->e_attrs; a; a=a->a_next ) {
3555 if ( a == type_attr || a == oc_at ) continue;
3556 ct = config_find_table( colst, nocs, a->a_desc );
3557 if ( !ct ) continue; /* user data? */
3558 rc = check_vals( ct, &ca, a, 1 );
3559 if ( rc ) goto leave;
3562 /* Basic syntax checks are OK. Do the actual settings. */
3564 ca.line = type_attr->a_vals[0].bv_val;
3565 if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3566 ptr = strchr( ca.line, '}' );
3567 if ( ptr ) ca.line = ptr+1;
3570 rc = config_parse_add( type_ct, &ca );
3576 for ( a=e->e_attrs; a; a=a->a_next ) {
3577 if ( a == type_attr || a == oc_at ) continue;
3578 ct = config_find_table( colst, nocs, a->a_desc );
3579 if ( !ct ) continue; /* user data? */
3580 for (i=0; a->a_vals[i].bv_val; i++) {
3581 ca.line = a->a_vals[i].bv_val;
3582 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3583 ptr = strchr( ca.line, '}' );
3584 if ( ptr ) ca.line = ptr+1;
3587 rc = config_parse_add( ct, &ca );
3595 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3596 ce->ce_parent = last;
3597 ce->ce_entry = entry_dup( e );
3598 ce->ce_entry->e_private = ce;
3599 ce->ce_type = colst[0]->co_type;
3604 } else if ( last->ce_kids ) {
3607 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3616 if ( colst ) ch_free( colst );
3620 /* Parse an LDAP entry into config directives, then store in underlying
3624 config_back_add( Operation *op, SlapReply *rs )
3627 CfEntryInfo *ce, *last;
3630 if ( !be_isroot( op ) ) {
3631 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3635 cfb = (CfBackInfo *)op->o_bd->be_private;
3637 ldap_pvt_thread_pool_pause( &connection_pool );
3640 * 1) check for existence of entry
3641 * 2) check for sibling renumbering
3642 * 3) perform internal add
3643 * 4) store entry in underlying database
3644 * 5) perform any necessary renumbering
3646 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3647 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3648 BackendDB *be = op->o_bd;
3649 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3650 op->o_bd = &cfb->cb_db;
3651 sc.sc_next = op->o_callback;
3652 op->o_callback = ≻
3653 op->o_bd->be_add( op, rs );
3655 op->o_callback = sc.sc_next;
3660 ldap_pvt_thread_pool_resume( &connection_pool );
3663 send_ldap_result( op, rs );
3667 typedef struct delrec {
3668 struct delrec *next;
3674 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3675 char *textbuf, int textsize )
3677 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3678 int rc = LDAP_UNWILLING_TO_PERFORM;
3680 Entry *e = ce->ce_entry;
3681 Attribute *save_attrs = e->e_attrs, *oc_at;
3682 ConfigArgs ca = {0};
3687 delrec *dels = NULL, *deltail = NULL;
3689 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3690 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3692 colst = count_ocs( oc_at, &nocs );
3694 e->e_attrs = attrs_dup( e->e_attrs );
3696 init_config_argv( &ca );
3700 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3701 ct = config_find_table( colst, nocs, ml->sml_desc );
3702 switch (ml->sml_op) {
3703 case LDAP_MOD_DELETE:
3704 case LDAP_MOD_REPLACE: {
3705 BerVarray vals = NULL, nvals;
3707 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3708 rc = LDAP_UNWILLING_TO_PERFORM;
3709 snprintf(textbuf, textsize, "cannot delete %s",
3711 rs->sr_text = textbuf;
3714 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3715 vals = ml->sml_values;
3716 nvals = ml->sml_nvalues;
3717 ml->sml_values = NULL;
3718 ml->sml_nvalues = NULL;
3720 /* If we're deleting by values, remember the indexes of the
3721 * values we deleted.
3723 if ( ct && ml->sml_values ) {
3725 for (i=0; ml->sml_values[i].bv_val; i++);
3726 d = ch_malloc( sizeof(delrec) + i * sizeof(int));
3737 rc = modify_delete_vindex(e, &ml->sml_mod,
3738 get_permissiveModify(op),
3739 &rs->sr_text, textbuf, textsize, idx );
3740 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3741 ml->sml_values = vals;
3742 ml->sml_nvalues = nvals;
3747 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3750 case SLAP_MOD_SOFTADD: {
3751 int mop = ml->sml_op;
3753 ml->sml_op = LDAP_MOD_ADD;
3755 if ( ct->arg_type & ARG_NO_INSERT ) {
3756 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3758 for (i = 0; a->a_vals[i].bv_val; i++ );
3762 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3763 if ( ml->sml_values[i].bv_val[0] == '{' &&
3765 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3767 rc = LDAP_UNWILLING_TO_PERFORM;
3768 snprintf(textbuf, textsize, "cannot insert %s",
3770 rs->sr_text = textbuf;
3774 rc = check_vals( ct, &ca, ml, 0 );
3778 rc = modify_add_values(e, &ml->sml_mod,
3779 get_permissiveModify(op),
3780 &rs->sr_text, textbuf, textsize );
3782 /* If value already exists, show success here
3783 * and ignore this operation down below.
3785 if ( mop == SLAP_MOD_SOFTADD ) {
3786 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3796 case LDAP_MOD_INCREMENT: /* FIXME */
3801 if(rc != LDAP_SUCCESS) break;
3804 if(rc == LDAP_SUCCESS) {
3805 /* check that the entry still obeys the schema */
3806 rc = entry_schema_check(op->o_bd, e, NULL,
3807 &rs->sr_text, textbuf, textsize );
3809 if ( rc == LDAP_SUCCESS ) {
3810 /* Basic syntax checks are OK. Do the actual settings. */
3811 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3812 ct = config_find_table( colst, nocs, ml->sml_desc );
3813 if ( !ct ) continue;
3815 switch (ml->sml_op) {
3816 case LDAP_MOD_DELETE:
3817 case LDAP_MOD_REPLACE: {
3818 BerVarray vals = NULL, nvals;
3822 a = attr_find( e->e_attrs, ml->sml_desc );
3824 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3825 vals = ml->sml_values;
3826 nvals = ml->sml_nvalues;
3827 ml->sml_values = NULL;
3828 ml->sml_nvalues = NULL;
3830 /* If we didn't delete the whole attribute */
3831 if ( ml->sml_values && a ) {
3832 struct berval *mvals;
3835 if ( ml->sml_nvalues )
3836 mvals = ml->sml_nvalues;
3838 mvals = ml->sml_values;
3840 /* use the indexes we saved up above */
3841 for (i=0; i < d->nidx; i++) {
3842 struct berval bv = *mvals++;
3843 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3844 bv.bv_val[0] == '{' ) {
3845 ptr = strchr( bv.bv_val, '}' ) + 1;
3846 bv.bv_len -= ptr - bv.bv_val;
3849 ca.line = bv.bv_val;
3850 ca.valx = d->idx[i];
3851 rc = config_del_vals( ct, &ca );
3852 if ( rc != LDAP_SUCCESS ) break;
3853 for (j=i+1; j < d->nidx; j++)
3854 if ( d->idx[j] >d->idx[i] )
3860 rc = config_del_vals( ct, &ca );
3864 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3865 ml->sml_values = vals;
3866 ml->sml_nvalues = nvals;
3868 if ( !vals || rc != LDAP_SUCCESS )
3871 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3874 for (i=0; ml->sml_values[i].bv_val; i++) {
3875 ca.line = ml->sml_values[i].bv_val;
3877 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3878 ca.line[0] == '{' ) {
3879 ptr = strchr( ca.line, '}' );
3881 ca.valx = strtol( ca.line+1, NULL, 0 );
3885 rc = config_parse_add( ct, &ca );
3900 if ( rc == LDAP_SUCCESS ) {
3901 attrs_free( save_attrs );
3903 attrs_free( e->e_attrs );
3904 e->e_attrs = save_attrs;
3907 if ( colst ) ch_free( colst );
3913 config_back_modify( Operation *op, SlapReply *rs )
3916 CfEntryInfo *ce, *last;
3918 char textbuf[SLAP_TEXT_BUFLEN];
3921 AttributeDescription *rad = NULL;
3923 if ( !be_isroot( op ) ) {
3924 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3928 cfb = (CfBackInfo *)op->o_bd->be_private;
3930 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3933 rs->sr_matched = last->ce_entry->e_name.bv_val;
3934 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3938 /* Get type of RDN */
3939 rdn = ce->ce_entry->e_nname;
3940 ptr = strchr( rdn.bv_val, '=' );
3941 rdn.bv_len = ptr - rdn.bv_val;
3942 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3944 /* Some basic validation... */
3945 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3946 /* Don't allow Modify of RDN; must use ModRdn for that. */
3947 if ( ml->sml_desc == rad ) {
3948 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3949 rs->sr_text = "Use modrdn to change the entry name";
3954 ldap_pvt_thread_pool_pause( &connection_pool );
3957 * 1) perform the Modify on the cached Entry.
3958 * 2) verify that the Entry still satisfies the schema.
3959 * 3) perform the individual config operations.
3960 * 4) store Modified entry in underlying LDIF backend.
3962 rs->sr_err = config_modify_internal( ce, op, rs, textbuf, sizeof(textbuf) );
3963 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3964 BackendDB *be = op->o_bd;
3965 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3966 op->o_bd = &cfb->cb_db;
3967 sc.sc_next = op->o_callback;
3968 op->o_callback = ≻
3969 op->o_bd->be_modify( op, rs );
3971 op->o_callback = sc.sc_next;
3974 ldap_pvt_thread_pool_resume( &connection_pool );
3976 send_ldap_result( op, rs );
3981 config_back_modrdn( Operation *op, SlapReply *rs )
3984 CfEntryInfo *ce, *last;
3986 if ( !be_isroot( op ) ) {
3987 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3991 cfb = (CfBackInfo *)op->o_bd->be_private;
3993 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3996 rs->sr_matched = last->ce_entry->e_name.bv_val;
3997 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4001 /* We don't allow moving objects to new parents.
4002 * Generally we only allow reordering a set of ordered entries.
4004 if ( op->orr_newSup ) {
4005 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4008 ldap_pvt_thread_pool_pause( &connection_pool );
4010 ldap_pvt_thread_pool_resume( &connection_pool );
4012 send_ldap_result( op, rs );
4017 config_back_search( Operation *op, SlapReply *rs )
4020 CfEntryInfo *ce, *last;
4023 if ( !be_isroot( op ) ) {
4024 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4028 cfb = (CfBackInfo *)op->o_bd->be_private;
4030 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4033 rs->sr_matched = last->ce_entry->e_name.bv_val;
4034 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4037 switch ( op->ors_scope ) {
4038 case LDAP_SCOPE_BASE:
4039 case LDAP_SCOPE_SUBTREE:
4040 config_send( op, rs, ce, 0 );
4043 case LDAP_SCOPE_ONELEVEL:
4044 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
4045 config_send( op, rs, ce, 1 );
4050 rs->sr_err = LDAP_SUCCESS;
4052 send_ldap_result( op, rs );
4057 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
4059 Entry *e = ch_calloc( 1, sizeof(Entry) );
4060 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4065 ce->ce_parent = parent;
4067 pdn = parent->ce_entry->e_nname;
4072 build_new_dn( &e->e_name, &pdn, rdn, NULL );
4073 ber_dupbv( &e->e_nname, &e->e_name );
4082 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
4083 struct berval *rdn, ConfigTable *ct, int table )
4086 struct berval ad_name;
4087 AttributeDescription *ad = NULL;
4091 char textbuf[SLAP_TEXT_BUFLEN];
4092 size_t textlen = sizeof(textbuf);
4096 val = oc->soc_cname;
4097 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass, &val, NULL );
4098 ptr = strchr(rdn->bv_val, '=');
4099 ad_name.bv_val = rdn->bv_val;
4100 ad_name.bv_len = ptr - rdn->bv_val;
4101 rc = slap_bv2ad( &ad_name, &ad, &text );
4106 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
4107 attr_merge_normalize_one(e, ad, &val, NULL );
4109 for (at=oc->soc_required; at && *at; at++) {
4110 /* Skip the naming attr */
4111 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
4113 for (i=0;ct[i].name;i++) {
4114 if (ct[i].ad == (*at)->sat_ad) {
4115 rc = config_get_vals(&ct[i], c);
4116 if (rc == LDAP_SUCCESS) {
4117 if ( c->rvalue_nvals )
4118 attr_merge(e, ct[i].ad, c->rvalue_vals,
4121 attr_merge_normalize(e, ct[i].ad,
4122 c->rvalue_vals, NULL);
4123 ber_bvarray_free( c->rvalue_nvals );
4124 ber_bvarray_free( c->rvalue_vals );
4131 for (at=oc->soc_allowed; at && *at; at++) {
4132 /* Skip the naming attr */
4133 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
4135 for (i=0;ct[i].name;i++) {
4136 if (ct[i].ad == (*at)->sat_ad) {
4137 rc = config_get_vals(&ct[i], c);
4138 if (rc == LDAP_SUCCESS) {
4139 if ( c->rvalue_nvals )
4140 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
4142 attr_merge_normalize(e, ct[i].ad, c->rvalue_vals, NULL);
4143 ber_bvarray_free( c->rvalue_nvals );
4144 ber_bvarray_free( c->rvalue_vals );
4152 if ( table == BI_TABLE )
4153 ct = c->bi->bi_cf_table;
4155 ct = c->be->be_cf_table;
4156 for (;ct && ct->name;ct++) {
4157 if (!ct->ad) continue;
4158 rc = config_get_vals(ct, c);
4159 if (rc == LDAP_SUCCESS) {
4160 if ( c->rvalue_nvals )
4161 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
4163 attr_merge_normalize(e, ct->ad, c->rvalue_vals, NULL);
4167 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4168 rc = structural_class(oc_at->a_vals, &val, NULL, &text, textbuf, textlen);
4169 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
4175 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
4176 Operation *op, SlapReply *rs )
4179 ConfigFile *cf = c->private;
4180 CfEntryInfo *ce, *ceprev;
4184 if ( ceparent->ce_kids ) {
4185 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
4186 ceprev = ceprev->ce_sibs );
4189 for (; cf; cf=cf->c_sibs, c->depth++) {
4190 c->value_dn.bv_val = c->log;
4191 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
4196 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
4198 ptr = strchr( bv.bv_val, '.' );
4200 bv.bv_len = ptr - bv.bv_val;
4201 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
4202 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
4204 c->value_dn.bv_len += bv.bv_len;
4205 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
4207 e = config_alloc_entry( ceparent, &c->value_dn );
4209 config_build_entry( c, e, cfOc_schema, &c->value_dn,
4210 c->bi->bi_cf_table, NO_TABLE );
4212 ce->ce_type = Cft_Schema;
4215 op->o_bd->be_add( op, rs );
4218 if ( !ceparent->ce_kids ) {
4219 ceparent->ce_kids = ce;
4221 ceprev->ce_sibs = ce;
4225 c->private = cf->c_kids;
4226 config_build_schema_inc( c, ceparent, op, rs );
4231 static CfEntryInfo *
4232 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
4233 Operation *op, SlapReply *rs )
4237 ConfigFile *cf = c->private;
4238 CfEntryInfo *ce, *ceprev;
4240 if ( ceparent->ce_kids ) {
4241 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
4242 ceprev = ceprev->ce_sibs );
4245 for (i=0; cf; cf=cf->c_sibs, i++) {
4246 c->value_dn.bv_val = c->log;
4247 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
4248 e = config_alloc_entry( ceparent, &c->value_dn );
4250 config_build_entry( c, e, cfOc_include, &c->value_dn,
4251 c->bi->bi_cf_table, NO_TABLE );
4254 op->o_bd->be_add( op, rs );
4257 ce->ce_type = Cft_Include;
4259 if ( !ceparent->ce_kids ) {
4260 ceparent->ce_kids = ce;
4262 ceprev->ce_sibs = ce;
4266 c->private = cf->c_kids;
4267 config_build_includes( c, ce, op, rs );
4273 #ifdef SLAPD_MODULES
4275 static CfEntryInfo *
4276 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
4277 Operation *op, SlapReply *rs )
4281 CfEntryInfo *ce, *ceprev;
4284 if ( ceparent->ce_kids ) {
4285 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
4286 ceprev = ceprev->ce_sibs );
4289 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
4290 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
4292 c->value_dn.bv_val = c->log;
4293 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
4294 e = config_alloc_entry( ceparent, &c->value_dn );
4296 ce->ce_type = Cft_Include;
4298 config_build_entry( c, e, cfOc_module, &c->value_dn,
4299 c->bi->bi_cf_table, NO_TABLE );
4302 op->o_bd->be_add( op, rs );
4305 if ( !ceparent->ce_kids ) {
4306 ceparent->ce_kids = ce;
4308 ceprev->ce_sibs = ce;
4317 config_back_db_open( BackendDB *be )
4319 CfBackInfo *cfb = be->be_private;
4322 CfEntryInfo *ce, *ceparent, *ceprev;
4328 Connection conn = {0};
4329 char opbuf[OPERATION_BUFFER_SIZE];
4331 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
4332 SlapReply rs = {REP_RESULT};
4334 /* If we read the config from back-ldif, nothing to do here */
4335 if ( cfb->cb_got_ldif )
4338 if ( cfb->cb_use_ldif ) {
4339 op = (Operation *)opbuf;
4340 connection_fake_init( &conn, op, cfb );
4342 op->o_dn = be->be_rootdn;
4343 op->o_ndn = be->be_rootndn;
4345 op->o_tag = LDAP_REQ_ADD;
4346 op->o_callback = &cb;
4347 op->o_bd = &cfb->cb_db;
4352 /* create root of tree */
4354 e = config_alloc_entry( NULL, &rdn );
4356 ce->ce_type = Cft_Global;
4360 c.private = cfb->cb_config;
4361 ct = c.bi->bi_cf_table;
4362 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
4365 op->o_bd->be_add( op, &rs );
4372 /* Create schema nodes... cn=schema will contain the hardcoded core
4373 * schema, read-only. Child objects will contain runtime loaded schema
4377 e = config_alloc_entry( ceparent, &rdn );
4379 ce->ce_type = Cft_Schema;
4381 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
4384 op->o_bd->be_add( op, &rs );
4386 if ( !ceparent->ce_kids ) {
4387 ceparent->ce_kids = ce;
4389 ceprev->ce_sibs = ce;
4393 /* Create includeFile nodes and schema nodes for included schema... */
4394 if ( cfb->cb_config->c_kids ) {
4396 c.private = cfb->cb_config->c_kids;
4397 config_build_schema_inc( &c, ce, op, &rs );
4398 c.private = cfb->cb_config->c_kids;
4399 ceprev = config_build_includes( &c, ceparent, op, &rs );
4402 #ifdef SLAPD_MODULES
4403 /* Create Module nodes... */
4404 if ( modpaths.mp_loads ) {
4405 ceprev = config_build_modules( &c, ceparent, op, &rs );
4409 /* Create backend nodes. Skip if they don't provide a cf_table.
4410 * There usually aren't any of these.
4414 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
4415 if (!bi->bi_cf_table) continue;
4416 if (!bi->bi_private) continue;
4419 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
4420 e = config_alloc_entry( ceparent, &rdn );
4422 ce->ce_type = Cft_Backend;
4425 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
4428 op->o_bd->be_add( op, &rs );
4430 if ( !ceparent->ce_kids ) {
4431 ceparent->ce_kids = ce;
4433 ceprev->ce_sibs = ce;
4438 /* Create database nodes... */
4440 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
4441 slap_overinfo *oi = NULL;
4448 if ( overlay_is_over( bptr )) {
4449 oi = bptr->bd_info->bi_private;
4455 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
4457 e = config_alloc_entry( ceparent, &rdn );
4461 ce->ce_type = Cft_Database;
4464 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
4467 op->o_bd->be_add( op, &rs );
4469 if ( !ceparent->ce_kids ) {
4470 ceparent->ce_kids = ce;
4472 ceprev->ce_sibs = ce;
4475 /* Iterate through overlays */
4479 CfEntryInfo *opar = ce, *oprev = NULL;
4482 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
4484 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
4485 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
4486 oe = config_alloc_entry( opar, &rdn );
4490 ce->ce_type = Cft_Overlay;
4493 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
4496 op->o_bd->be_add( op, &rs );
4498 if ( !opar->ce_kids ) {
4501 oprev->ce_sibs = ce;
4512 config_back_db_destroy( Backend *be )
4514 free( be->be_private );
4519 config_back_db_init( Backend *be )
4524 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4525 cfb->cb_config = &cf_prv;
4526 be->be_private = cfb;
4528 ber_dupbv( &be->be_rootdn, &config_rdn );
4529 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4530 ber_dupbv( &dn, &be->be_rootdn );
4531 ber_bvarray_add( &be->be_suffix, &dn );
4532 ber_dupbv( &dn, &be->be_rootdn );
4533 ber_bvarray_add( &be->be_nsuffix, &dn );
4535 /* Hide from namingContexts */
4536 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4542 config_back_destroy( BackendInfo *bi )
4544 ldif_must_b64_encode_release();
4550 AttributeDescription **desc;
4552 { "backend", &cfAd_backend },
4553 { "database", &cfAd_database },
4554 { "include", &cfAd_include },
4555 { "overlay", &cfAd_overlay },
4560 * add / delete: all types that may be added or deleted must use an
4561 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4562 * should automatically renumber the index of any siblings as needed,
4563 * so that no gaps in the numbering sequence exist after the add/delete
4565 * What can be added:
4567 * backend objects for backend-specific config directives
4571 * delete: probably no support this time around.
4573 * modrdn: generally not done. Will be invoked automatically by add/
4574 * delete to update numbering sequence. Perform as an explicit operation
4575 * so that the renumbering effect may be replicated. Subtree rename must
4576 * be supported, since renumbering a database will affect all its child
4579 * modify: must be fully supported.
4583 config_back_initialize( BackendInfo *bi )
4585 ConfigTable *ct = config_back_cf_table;
4588 AttributeDescription *ad = NULL;
4590 static char *controls[] = {
4591 LDAP_CONTROL_MANAGEDSAIT,
4595 bi->bi_controls = controls;
4600 bi->bi_destroy = config_back_destroy;
4602 bi->bi_db_init = config_back_db_init;
4603 bi->bi_db_config = 0;
4604 bi->bi_db_open = config_back_db_open;
4605 bi->bi_db_close = 0;
4606 bi->bi_db_destroy = config_back_db_destroy;
4608 bi->bi_op_bind = config_back_bind;
4609 bi->bi_op_unbind = 0;
4610 bi->bi_op_search = config_back_search;
4611 bi->bi_op_compare = 0;
4612 bi->bi_op_modify = config_back_modify;
4613 bi->bi_op_modrdn = config_back_modrdn;
4614 bi->bi_op_add = config_back_add;
4615 bi->bi_op_delete = 0;
4616 bi->bi_op_abandon = 0;
4618 bi->bi_extended = 0;
4620 bi->bi_chk_referrals = 0;
4622 #ifdef SLAP_OVERLAY_ACCESS
4623 bi->bi_access_allowed = slap_access_always_allowed;
4624 #endif /* SLAP_OVERLAY_ACCESS */
4626 bi->bi_connection_init = 0;
4627 bi->bi_connection_destroy = 0;
4630 for (i=0; OidMacros[i].name; i++ ) {
4631 argv[1] = OidMacros[i].name;
4632 argv[2] = OidMacros[i].oid;
4633 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4636 bi->bi_cf_table = ct;
4638 i = config_register_schema( ct, cf_ocs );
4641 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4642 * basically, we don't care if it fails */
4643 i = slap_str2ad( "olcRootPW", &ad, &text );
4645 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4646 "warning, unable to get \"olcRootPW\" "
4647 "attribute description: %d: %s\n",
4650 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4651 ad->ad_type->sat_oid );
4654 /* set up the notable AttributeDescriptions */
4656 for (;ct->name;ct++) {
4657 if (strcmp(ct->name, ads[i].name)) continue;
4658 *ads[i].desc = ct->ad;
4660 if (!ads[i].name) break;