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>
31 #include "slapi/slapi.h"
38 static struct berval config_rdn = BER_BVC("cn=config");
39 static struct berval schema_rdn = BER_BVC("cn=schema");
44 typedef struct modpath_s {
45 struct modpath_s *mp_next;
46 struct berval mp_path;
50 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
53 typedef struct ConfigFile {
54 struct ConfigFile *c_sibs;
55 struct ConfigFile *c_kids;
57 AttributeType *c_at_head, *c_at_tail;
58 ContentRule *c_cr_head, *c_cr_tail;
59 ObjectClass *c_oc_head, *c_oc_tail;
60 OidMacro *c_om_head, *c_om_tail;
64 typedef struct CfOcInfo {
65 struct berval *co_name;
66 ConfigTable *co_table;
70 typedef struct CfEntryInfo {
71 struct CfEntryInfo *ce_parent;
72 struct CfEntryInfo *ce_sibs;
73 struct CfEntryInfo *ce_kids;
81 ConfigFile *cb_config;
83 BackendDB cb_db; /* underlying database */
87 /* These do nothing in slapd, they're kept only to make them
90 static char *replica_pidFile, *replica_argsFile;
91 static int replicationInterval;
93 static char *passwd_salt;
94 static char *logfileName;
95 static BerVarray authz_rewrites;
97 static struct berval cfdir;
100 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
103 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
104 *cfOc_include, *cfOc_overlay, *cfOc_module;
106 static ConfigFile cf_prv, *cfn = &cf_prv;
108 static Avlnode *CfOcTree;
110 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
111 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
112 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
113 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs,
116 static ConfigDriver config_fname;
117 static ConfigDriver config_cfdir;
118 static ConfigDriver config_generic;
119 static ConfigDriver config_search_base;
120 static ConfigDriver config_passwd_hash;
121 static ConfigDriver config_schema_dn;
122 static ConfigDriver config_sizelimit;
123 static ConfigDriver config_timelimit;
124 static ConfigDriver config_limits;
125 static ConfigDriver config_overlay;
126 static ConfigDriver config_suffix;
127 static ConfigDriver config_deref_depth;
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_syncrepl;
138 static ConfigDriver config_replica;
139 static ConfigDriver config_updatedn;
140 static ConfigDriver config_updateref;
141 static ConfigDriver config_include;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
193 static OidRec OidMacros[] = {
194 /* OpenLDAProot:666.11.1 */
195 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
196 { "OLcfgAt", "OLcfg:3" },
197 { "OLcfgOc", "OLcfg:4" },
198 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
199 { "OMsInteger", "OMsyn:2" },
200 { "OMsBoolean", "OMsyn:7" },
201 { "OMsDN", "OMsyn:12" },
202 { "OMsDirectoryString", "OMsyn:15" },
203 { "OMsOctetString", "OMsyn:40" },
207 /* alphabetical ordering */
209 ConfigTable config_back_cf_table[] = {
210 /* This attr is read-only */
211 { "", "", 0, 0, 0, ARG_MAGIC,
212 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
213 "DESC 'File for slapd configuration directives' "
214 "EQUALITY caseIgnoreMatch "
215 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
216 { "", "", 0, 0, 0, ARG_MAGIC,
217 &config_cfdir, "( OLcfgAt:79 NAME 'olcConfigDir' "
218 "DESC 'Directory for slapd configuration backend' "
219 "EQUALITY caseIgnoreMatch "
220 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
221 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
222 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
223 "DESC 'Access Control List' "
224 "EQUALITY caseIgnoreMatch "
225 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
226 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
227 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
228 "DESC 'Allowed set of deprecated features' "
229 "EQUALITY caseIgnoreMatch "
230 "SYNTAX OMsDirectoryString )", NULL, NULL },
231 { "argsfile", "file", 2, 2, 0, ARG_STRING,
232 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
233 "DESC 'File for slapd command line options' "
234 "EQUALITY caseIgnoreMatch "
235 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
236 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
237 &config_generic, "( OLcfgAt:4 NAME 'olcAttributeTypes' "
238 "DESC 'OpenLDAP attributeTypes' "
239 "EQUALITY caseIgnoreMatch "
240 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
242 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
243 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
244 "EQUALITY caseIgnoreMatch "
245 "SYNTAX OMsDirectoryString )", NULL, NULL },
246 { "authid-rewrite", NULL, 2, 0, 0,
247 #ifdef SLAP_AUTH_REWRITE
248 ARG_MAGIC|CFG_REWRITE, &config_generic,
252 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
253 "EQUALITY caseIgnoreMatch "
254 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
255 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
256 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
259 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
260 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
261 "EQUALITY caseIgnoreMatch "
262 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
263 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
264 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
265 "DESC 'A type of backend' "
266 "EQUALITY caseIgnoreMatch "
267 "SYNTAX OMsDirectoryString X-ORDERED 'SIBLINGS' )", NULL, NULL },
268 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
269 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
270 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
271 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
272 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
273 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
274 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
275 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
276 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
277 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
278 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
279 "DESC 'The backend type for a database instance' "
280 "SUP olcBackend X-ORDERED 'SIBLINGS' )", NULL, NULL },
281 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
282 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
283 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
284 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
285 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString )", NULL, NULL },
288 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
289 &config_generic, "( OLcfgAt:16 NAME 'olcDitContentRules' "
290 "DESC 'OpenLDAP DIT content rules' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
294 { "gentlehup", "on|off", 2, 2, 0,
296 ARG_ON_OFF, &global_gentlehup,
300 "( OLcfgAt:17 NAME 'olcGentleHUP' "
301 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
302 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
303 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
304 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
305 /* XXX -- special case? */
306 { "include", "file", 2, 2, 0, ARG_MAGIC,
307 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
308 "SUP labeledURI )", NULL, NULL },
309 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
310 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
311 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
312 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
313 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
314 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
315 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
316 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
317 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
318 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
319 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
320 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
321 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
322 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
323 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
324 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
325 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
326 "SYNTAX OMsDirectoryString )", NULL, NULL },
327 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
328 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
329 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
330 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
331 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
332 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
333 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
334 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
335 "SYNTAX OMsDirectoryString )", NULL, NULL },
336 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
337 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
338 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
339 { "moduleload", "file", 2, 0, 0,
341 ARG_MAGIC|CFG_MODLOAD, &config_generic,
345 "( OLcfgAt:30 NAME 'olcModuleLoad' "
346 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
347 { "modulepath", "path", 2, 2, 0,
349 ARG_MAGIC|CFG_MODPATH, &config_generic,
353 "( OLcfgAt:31 NAME 'olcModulePath' "
354 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
355 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
356 &config_generic, "( OLcfgAt:32 NAME 'olcObjectClasses' "
357 "DESC 'OpenLDAP object classes' "
358 "EQUALITY caseIgnoreMatch "
359 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
361 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
362 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
363 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
364 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
365 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
366 "SUP olcDatabase X-ORDERED 'SIBLINGS' )", NULL, NULL },
367 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
368 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
369 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
370 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
371 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
372 "SYNTAX OMsDirectoryString )", NULL, NULL },
373 { "pidfile", "file", 2, 2, 0, ARG_STRING,
374 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
375 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
376 { "plugin", NULL, 0, 0, 0,
378 ARG_MAGIC|CFG_PLUGIN, &config_generic,
382 "( OLcfgAt:38 NAME 'olcPlugin' "
383 "SYNTAX OMsDirectoryString )", NULL, NULL },
384 { "pluginlog", "filename", 2, 2, 0,
386 ARG_STRING, &slapi_log_file,
390 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
391 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
392 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
393 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
394 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
395 { "referral", "url", 2, 2, 0, ARG_MAGIC,
396 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
397 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
398 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
399 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
400 "SUP labeledURI )", NULL, NULL },
401 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
402 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
403 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
404 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
405 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
406 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
407 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
408 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
409 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
410 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
411 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
412 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
413 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
414 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
415 "SYNTAX OMsDirectoryString )", NULL, NULL },
416 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
417 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
418 "SYNTAX OMsDirectoryString )", NULL, NULL },
419 { "reverse-lookup", "on|off", 2, 2, 0,
420 #ifdef SLAPD_RLOOKUPS
421 ARG_ON_OFF, &use_reverse_lookup,
425 "( OLcfgAt:49 NAME 'olcReverseLookup' "
426 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
427 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
428 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
429 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
430 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
431 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
432 "SYNTAX OMsDirectoryString )", NULL, NULL },
433 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
434 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
435 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
436 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
437 &config_generic, NULL, NULL, NULL },
438 { "sasl-host", "host", 2, 2, 0,
439 #ifdef HAVE_CYRUS_SASL
440 ARG_STRING|ARG_UNIQUE, &global_host,
444 "( OLcfgAt:53 NAME 'olcSaslHost' "
445 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
446 { "sasl-realm", "realm", 2, 2, 0,
447 #ifdef HAVE_CYRUS_SASL
448 ARG_STRING|ARG_UNIQUE, &global_realm,
452 "( OLcfgAt:54 NAME 'olcSaslRealm' "
453 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
454 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
455 &config_generic, NULL, NULL, NULL },
456 { "sasl-secprops", "properties", 2, 2, 0,
457 #ifdef HAVE_CYRUS_SASL
458 ARG_MAGIC|CFG_SASLSECP, &config_generic,
462 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
463 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
464 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
465 &config_generic, NULL, NULL, NULL },
466 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
467 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
468 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
469 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
470 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
471 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
472 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
473 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
474 "SYNTAX OMsDirectoryString )", NULL, NULL },
475 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
476 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
477 "SYNTAX OMsInteger )", NULL, NULL },
478 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
479 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
480 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
481 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
482 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
483 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
484 { "srvtab", "file", 2, 2, 0,
485 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
486 ARG_STRING, &ldap_srvtab,
490 "( OLcfgAt:63 NAME 'olcSrvtab' "
491 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
492 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
493 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
494 "SYNTAX OMsDN )", NULL, NULL },
495 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
496 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
497 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
498 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
499 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
500 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
501 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
502 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
503 "SYNTAX OMsInteger )", NULL, NULL },
504 { "TLSCACertificateFile", NULL, 0, 0, 0,
506 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
510 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
511 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
512 { "TLSCACertificatePath", NULL, 0, 0, 0,
514 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
518 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
519 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
520 { "TLSCertificateFile", NULL, 0, 0, 0,
522 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
526 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
527 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
528 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
530 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
534 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
535 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
536 { "TLSCipherSuite", NULL, 0, 0, 0,
538 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
542 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
543 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
544 { "TLSCRLCheck", NULL, 0, 0, 0,
545 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
546 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
550 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
551 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
552 { "TLSRandFile", NULL, 0, 0, 0,
554 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
558 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
559 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
560 { "TLSVerifyClient", NULL, 0, 0, 0,
562 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
566 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
567 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
568 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
569 NULL, NULL, NULL, NULL },
570 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
571 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
572 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
573 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
574 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
575 "SUP labeledURI )", NULL, NULL },
576 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
577 NULL, NULL, NULL, NULL }
580 static ConfigOCs cf_ocs[] = {
583 "DESC 'OpenLDAP configuration object' "
584 "ABSTRACT SUP top )", Cft_Abstract, NULL },
587 "DESC 'OpenLDAP Global configuration options' "
588 "SUP olcConfig STRUCTURAL "
589 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
590 "olcAttributeOptions $ olcAttributeTypes $ olcAuthIDRewrite $ "
591 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
592 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
593 "olcDisallows $ olcDitContentRules $ olcGentleHUP $ olcIdleTimeout $ "
594 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
595 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
596 "olcLogLevel $ olcModulePath $ olcObjectClasses $ "
597 "olcObjectIdentifier $ "
598 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
599 "olcPlugin $ olcPluginLogFile $ olcReadOnly $ olcReferral $ "
600 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
601 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
602 "olcRootDSE $ olcRootPW $ "
603 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
604 "olcSchemaCheck $ olcSchemaDN $ olcSecurity $ olcSizeLimit $ "
605 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
606 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
607 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
608 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
609 "olcTLSRandFile $ olcTLSVerifyClient ) )", Cft_Global, &cfOc_global },
611 "NAME 'olcSchemaConfig' "
612 "DESC 'OpenLDAP schema object' "
613 "SUP olcConfig STRUCTURAL "
614 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
615 "olcObjectClasses $ olcDitContentRules ) )",
616 Cft_Schema, &cfOc_schema },
618 "NAME 'olcBackendConfig' "
619 "DESC 'OpenLDAP Backend-specific options' "
620 "SUP olcConfig STRUCTURAL "
621 "MUST olcBackend )", Cft_Backend, &cfOc_backend },
623 "NAME 'olcDatabaseConfig' "
624 "DESC 'OpenLDAP Database-specific options' "
625 "SUP olcConfig STRUCTURAL "
627 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
628 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
629 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
630 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
631 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
632 Cft_Database, &cfOc_database },
634 "NAME 'olcOverlayConfig' "
635 "DESC 'OpenLDAP Overlay-specific options' "
636 "SUP olcConfig STRUCTURAL "
637 "MUST olcOverlay )", Cft_Overlay, &cfOc_overlay },
639 "NAME 'olcIncludeFile' "
640 "DESC 'OpenLDAP configuration include file' "
641 "SUP olcConfig STRUCTURAL "
643 "MAY ( cn $ olcRootDSE ) )",
644 Cft_Include, &cfOc_include },
647 "NAME 'olcModuleList' "
648 "DESC 'OpenLDAP dynamic module info' "
649 "SUP olcConfig STRUCTURAL "
650 "MUST olcModuleLoad "
651 "MAY cn )", Cft_Module, &cfOc_module },
657 config_generic(ConfigArgs *c) {
661 if ( c->op == SLAP_CONFIG_EMIT ) {
665 c->value_int = ldap_pvt_thread_get_concurrency();
668 c->value_int = connection_pool_max;
672 c->value_string = ch_strdup( passwd_salt );
677 if ( c->be->be_limits ) {
682 for ( i=0; c->be->be_limits[i]; i++ ) {
683 bv.bv_len = sprintf( buf, IFMT, i );
684 bv.bv_val = buf+bv.bv_len;
685 limits_unparse( c->be->be_limits[i], &bv );
686 bv.bv_len += bv.bv_val - buf;
688 value_add_one( &c->rvalue_vals, &bv );
691 if ( !c->rvalue_vals ) rc = 1;
694 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
697 c->value_string = ch_strdup( slap_sasl_getpolicy());
700 slap_sasl_regexp_unparse( &c->rvalue_vals );
701 if ( !c->rvalue_vals ) rc = 1;
703 #ifdef HAVE_CYRUS_SASL
705 struct berval bv = BER_BVNULL;
706 slap_sasl_secprops_unparse( &bv );
707 if ( !BER_BVISNULL( &bv )) {
708 ber_bvarray_add( &c->rvalue_vals, &bv );
716 c->value_int = c->be->be_max_deref_depth;
719 ConfigFile *cf = c->private;
721 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
722 else if ( cf->c_om_head )
723 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
725 if ( !c->rvalue_vals )
730 ConfigFile *cf = c->private;
732 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
733 else if ( cf->c_oc_head )
734 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
736 if ( !c->rvalue_vals )
741 ConfigFile *cf = c->private;
743 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
744 else if ( cf->c_at_head )
745 at_unparse( &c->rvalue_vals, cf->c_at_head,
747 if ( !c->rvalue_vals )
752 ConfigFile *cf = c->private;
754 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
755 else if ( cf->c_cr_head )
756 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
758 if ( !c->rvalue_vals )
764 c->value_int = global_schemacheck;
768 char *src, *dst, ibuf[11];
769 struct berval bv, abv;
770 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
771 abv.bv_len = sprintf( ibuf, IFMT, i );
772 acl_unparse( a, &bv );
773 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
774 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
775 /* Turn TAB / EOL into plain space */
776 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
777 if (isspace(*src)) *dst++ = ' ';
781 if (dst[-1] == ' ') {
785 abv.bv_len = dst - abv.bv_val;
786 ber_bvarray_add( &c->rvalue_vals, &abv );
792 if ( c->be->be_replogfile )
793 c->value_string = ch_strdup( c->be->be_replogfile );
796 ConfigFile *cf = c->private;
797 if ( cf->c_dseFiles ) {
798 value_add( &c->rvalue_vals, cf->c_dseFiles );
806 c->value_string = ch_strdup( logfileName );
811 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
813 case CFG_SSTR_IF_MAX:
814 c->value_int = index_substr_if_maxlen;
816 case CFG_SSTR_IF_MIN:
817 c->value_int = index_substr_if_minlen;
821 ModPaths *mp = c->private;
824 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
827 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
828 mp->mp_loads[i].bv_val );
829 value_add_one( &c->rvalue_vals, &bv );
833 rc = c->rvalue_vals ? 0 : 1;
838 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
840 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
843 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
844 mp->mp_path.bv_val );
845 value_add_one( &c->rvalue_vals, &bv );
847 rc = c->rvalue_vals ? 0 : 1;
853 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
854 if ( !c->rvalue_vals ) rc = 1;
857 #ifdef SLAP_AUTH_REWRITE
859 if ( authz_rewrites ) {
860 struct berval bv, idx;
865 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
866 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
867 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
868 bv.bv_val = ch_malloc( bv.bv_len + 1 );
869 strcpy( bv.bv_val, idx.bv_val );
870 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
871 ber_bvarray_add( &c->rvalue_vals, &bv );
874 if ( !c->rvalue_vals ) rc = 1;
883 p = strchr(c->line,'(' /*')'*/);
884 if ( c->op == LDAP_MOD_DELETE ) {
892 ldap_pvt_thread_set_concurrency(c);
899 if(!(c->bi = backend_info(c->argv[1]))) {
900 Debug(LDAP_DEBUG_ANY, "%s: "
901 "backend %s failed init!\n", c->log, c->argv[1], 0);
908 /* NOTE: config is always the first backend!
910 if ( !strcasecmp( c->argv[1], "config" )) {
911 c->be = LDAP_STAILQ_FIRST(&backendDB);
912 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
914 } else if(!(c->be = backend_db_init(c->argv[1]))) {
915 Debug(LDAP_DEBUG_ANY, "%s: "
916 "database %s failed init!\n", c->log, c->argv[1], 0);
922 ldap_pvt_thread_set_concurrency(c->value_int);
926 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
927 connection_pool_max = c->value_int; /* save for reference */
931 if ( passwd_salt ) ch_free( passwd_salt );
932 passwd_salt = c->value_string;
933 lutil_salt_format(passwd_salt);
937 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
943 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
945 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
949 ch_free(c->value_string);
950 if (slap_sasl_setpolicy( c->argv[1] )) {
951 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
952 " \"authz-policy <policy>\"\n",
953 c->log, c->argv[1], 0 );
959 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
963 #ifdef HAVE_CYRUS_SASL
966 char *txt = slap_sasl_secprops( c->argv[1] );
968 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
977 c->be->be_max_deref_depth = c->value_int;
983 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
985 if (!cfn->c_om_head) cfn->c_om_head = om;
993 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
994 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1002 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1003 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1004 cfn->c_cr_tail = cr;
1011 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1012 if (!cfn->c_at_head) cfn->c_at_head = at;
1013 cfn->c_at_tail = at;
1018 ad_define_option(NULL, NULL, 0);
1019 for(i = 1; i < c->argc; i++)
1020 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1025 global_schemacheck = c->value_int;
1026 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1027 "schema checking disabled! your mileage may vary!\n",
1032 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1036 if(SLAP_MONITOR(c->be)) {
1037 Debug(LDAP_DEBUG_ANY, "%s: "
1038 "\"replogfile\" should not be used "
1039 "inside monitor database\n",
1041 return(0); /* FIXME: should this be an error? */
1044 c->be->be_replogfile = c->value_string;
1048 if(read_root_dse_file(c->argv[1])) {
1049 Debug(LDAP_DEBUG_ANY, "%s: "
1050 "could not read \"rootDSE <filename>\" line\n",
1056 ber_str2bv( c->argv[1], 0, 1, &bv );
1057 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1063 if ( logfileName ) ch_free( logfileName );
1064 logfileName = c->value_string;
1065 logfile = fopen(logfileName, "w");
1066 if(logfile) lutil_debug_file(logfile);
1070 if(SLAP_NOLASTMODCMD(c->be)) {
1071 Debug(LDAP_DEBUG_ANY, "%s: "
1072 "lastmod not available for %s databases\n",
1073 c->log, c->be->bd_info->bi_type, 0);
1077 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1079 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1082 case CFG_SSTR_IF_MAX:
1083 if (c->value_int < index_substr_if_minlen) {
1084 Debug(LDAP_DEBUG_ANY, "%s: "
1085 "invalid max value (%d)\n",
1086 c->log, c->value_int, 0 );
1089 index_substr_if_maxlen = c->value_int;
1092 case CFG_SSTR_IF_MIN:
1093 if (c->value_int > index_substr_if_maxlen) {
1094 Debug(LDAP_DEBUG_ANY, "%s: "
1095 "invalid min value (%d)\n",
1096 c->log, c->value_int, 0 );
1099 index_substr_if_minlen = c->value_int;
1102 #ifdef SLAPD_MODULES
1104 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1106 /* Record this load on the current path */
1109 char *ptr = c->line + STRLENOF("moduleload");
1110 while (!isspace(*ptr)) ptr++;
1111 while (isspace(*ptr)) ptr++;
1112 ber_str2bv(ptr, 0, 1, &bv);
1113 ber_bvarray_add( &modcur->mp_loads, &bv );
1118 if(module_path(c->argv[1])) return(1);
1119 /* Record which path was used with each module */
1123 if (!modpaths.mp_loads) {
1126 mp = ch_malloc( sizeof( ModPaths ));
1127 modlast->mp_next = mp;
1129 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1131 mp->mp_loads = NULL;
1133 if ( c->op == SLAP_CONFIG_ADD )
1142 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1144 slapi_plugins_used++;
1148 #ifdef SLAP_AUTH_REWRITE
1151 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1153 ber_str2bv( c->line, 0, 1, &bv );
1154 ber_bvarray_add( &authz_rewrites, &bv );
1161 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1162 "(ignored)\n", c->log, c->type, 0);
1170 config_fname(ConfigArgs *c) {
1171 if(c->op == SLAP_CONFIG_EMIT) {
1173 ConfigFile *cf = c->private;
1174 value_add_one( &c->rvalue_vals, &cf->c_file );
1183 config_cfdir(ConfigArgs *c) {
1184 if(c->op == SLAP_CONFIG_EMIT) {
1185 value_add_one( &c->rvalue_vals, &cfdir );
1192 config_search_base(ConfigArgs *c) {
1195 if(c->op == SLAP_CONFIG_EMIT) {
1197 if (!BER_BVISEMPTY(&default_search_base)) {
1198 value_add_one(&c->rvalue_vals, &default_search_base);
1199 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1205 if(c->bi || c->be != frontendDB) {
1206 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1207 "prior to any backend or database definition\n",
1212 if(default_search_nbase.bv_len) {
1213 Debug(LDAP_DEBUG_ANY, "%s: "
1214 "default search base \"%s\" already defined "
1215 "(discarding old)\n",
1216 c->log, default_search_base.bv_val, 0);
1217 free(default_search_base.bv_val);
1218 free(default_search_nbase.bv_val);
1221 default_search_base = c->value_dn;
1222 default_search_nbase = c->value_ndn;
1227 config_passwd_hash(ConfigArgs *c) {
1229 if (c->op == SLAP_CONFIG_EMIT) {
1231 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1232 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1233 value_add_one(&c->rvalue_vals, &bv);
1237 if(default_passwd_hash) {
1238 Debug(LDAP_DEBUG_ANY, "%s: "
1239 "already set default password_hash\n",
1243 for(i = 1; i < c->argc; i++) {
1244 if(!lutil_passwd_scheme(c->argv[i])) {
1245 Debug(LDAP_DEBUG_ANY, "%s: "
1246 "password scheme \"%s\" not available\n",
1247 c->log, c->argv[i], 0);
1249 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1251 if(!default_passwd_hash) {
1252 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1261 config_schema_dn(ConfigArgs *c) {
1262 if ( c->op == SLAP_CONFIG_EMIT ) {
1264 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1265 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1266 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1271 c->be->be_schemadn = c->value_dn;
1272 c->be->be_schemandn = c->value_ndn;
1277 config_sizelimit(ConfigArgs *c) {
1280 struct slap_limits_set *lim = &c->be->be_def_limit;
1281 if (c->op == SLAP_CONFIG_EMIT) {
1286 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1287 if ( !BER_BVISEMPTY( &bv ))
1288 value_add_one( &c->rvalue_vals, &bv );
1293 for(i = 1; i < c->argc; i++) {
1294 if(!strncasecmp(c->argv[i], "size", 4)) {
1295 rc = limits_parse_one(c->argv[i], lim);
1297 Debug(LDAP_DEBUG_ANY, "%s: "
1298 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1299 c->log, c->argv[i], 0);
1303 if(!strcasecmp(c->argv[i], "unlimited")) {
1304 lim->lms_s_soft = -1;
1306 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1307 if(next == c->argv[i]) {
1308 Debug(LDAP_DEBUG_ANY, "%s: "
1309 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1310 c->log, c->argv[i], 0);
1312 } else if(next[0] != '\0') {
1313 Debug(LDAP_DEBUG_ANY, "%s: "
1314 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1318 lim->lms_s_hard = 0;
1325 config_timelimit(ConfigArgs *c) {
1328 struct slap_limits_set *lim = &c->be->be_def_limit;
1329 if (c->op == SLAP_CONFIG_EMIT) {
1334 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1335 if ( !BER_BVISEMPTY( &bv ))
1336 value_add_one( &c->rvalue_vals, &bv );
1341 for(i = 1; i < c->argc; i++) {
1342 if(!strncasecmp(c->argv[i], "time", 4)) {
1343 rc = limits_parse_one(c->argv[i], lim);
1345 Debug(LDAP_DEBUG_ANY, "%s: "
1346 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1347 c->log, c->argv[i], 0);
1351 if(!strcasecmp(c->argv[i], "unlimited")) {
1352 lim->lms_t_soft = -1;
1354 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1355 if(next == c->argv[i]) {
1356 Debug(LDAP_DEBUG_ANY, "%s: "
1357 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1358 c->log, c->argv[i], 0);
1360 } else if(next[0] != '\0') {
1361 Debug(LDAP_DEBUG_ANY, "%s: "
1362 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1366 lim->lms_t_hard = 0;
1373 config_overlay(ConfigArgs *c) {
1374 if (c->op == SLAP_CONFIG_EMIT) {
1377 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1379 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1380 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1381 } else if(overlay_config(c->be, c->argv[1])) {
1388 config_suffix(ConfigArgs *c) {
1390 struct berval pdn, ndn;
1393 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1394 SLAP_CONFIG(c->be)) return 1;
1396 if (c->op == SLAP_CONFIG_EMIT) {
1397 if (!BER_BVISNULL( &c->be->be_suffix[0] )) {
1398 value_add( &c->rvalue_vals, c->be->be_suffix );
1399 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1405 #ifdef SLAPD_MONITOR_DN
1406 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1407 Debug(LDAP_DEBUG_ANY, "%s: "
1408 "\"%s\" is reserved for monitoring slapd\n",
1409 c->log, SLAPD_MONITOR_DN, 0);
1416 tbe = select_backend(&ndn, 0, 0);
1418 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1423 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1424 c->log, tbe->be_suffix[0].bv_val, 0);
1428 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1429 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1430 "base provided \"%s\" (assuming okay)\n",
1431 c->log, default_search_base.bv_val, 0);
1433 ber_bvarray_add(&c->be->be_suffix, &pdn);
1434 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1439 config_rootdn(ConfigArgs *c) {
1440 if (c->op == SLAP_CONFIG_EMIT) {
1441 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1442 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1443 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1449 c->be->be_rootdn = c->value_dn;
1450 c->be->be_rootndn = c->value_ndn;
1455 config_rootpw(ConfigArgs *c) {
1457 if (c->op == SLAP_CONFIG_EMIT) {
1458 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1459 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1465 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1467 Debug(LDAP_DEBUG_ANY, "%s: "
1468 "rootpw can only be set when rootdn is under suffix\n",
1472 c->be->be_rootpw = c->value_bv;
1477 config_restrict(ConfigArgs *c) {
1478 slap_mask_t restrictops = 0;
1480 slap_verbmasks restrictable_ops[] = {
1481 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1482 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1483 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1484 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1485 { BER_BVC("modrdn"), 0 },
1486 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1487 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1488 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1489 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1490 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1491 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1492 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1493 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1494 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1495 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1499 if (c->op == SLAP_CONFIG_EMIT) {
1500 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1503 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1505 Debug(LDAP_DEBUG_ANY, "%s: "
1506 "unknown operation %s in \"restrict <features>\" line\n",
1507 c->log, c->argv[i], 0);
1510 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1511 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1512 c->be->be_restrictops |= restrictops;
1517 config_allows(ConfigArgs *c) {
1518 slap_mask_t allows = 0;
1520 slap_verbmasks allowable_ops[] = {
1521 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1522 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1523 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1524 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1527 if (c->op == SLAP_CONFIG_EMIT) {
1528 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1530 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1532 Debug(LDAP_DEBUG_ANY, "%s: "
1533 "unknown feature %s in \"allow <features>\" line\n",
1534 c->log, c->argv[i], 0);
1537 global_allows |= allows;
1542 config_disallows(ConfigArgs *c) {
1543 slap_mask_t disallows = 0;
1545 slap_verbmasks disallowable_ops[] = {
1546 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1547 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1548 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1549 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1550 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1553 if (c->op == SLAP_CONFIG_EMIT) {
1554 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1556 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1558 Debug(LDAP_DEBUG_ANY, "%s: "
1559 "unknown feature %s in \"disallow <features>\" line\n",
1560 c->log, c->argv[i], 0);
1563 global_disallows |= disallows;
1568 config_requires(ConfigArgs *c) {
1569 slap_mask_t requires = 0;
1571 slap_verbmasks requires_ops[] = {
1572 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1573 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1574 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1575 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1576 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1579 if (c->op == SLAP_CONFIG_EMIT) {
1580 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1582 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1584 Debug(LDAP_DEBUG_ANY, "%s: "
1585 "unknown feature %s in \"require <features>\" line\n",
1586 c->log, c->argv[i], 0);
1589 c->be->be_requires = requires;
1594 config_loglevel(ConfigArgs *c) {
1597 slap_verbmasks loglevel_ops[] = {
1598 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1599 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1600 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1601 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1602 { BER_BVC("BER"), LDAP_DEBUG_BER },
1603 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1604 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1605 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1606 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1607 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1608 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1609 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1610 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1611 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1612 { BER_BVC("Any"), -1 },
1616 if (c->op == SLAP_CONFIG_EMIT) {
1617 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1622 for( i=1; i < c->argc; i++ ) {
1625 if ( isdigit( c->argv[i][0] ) ) {
1626 level = strtol( c->argv[i], &next, 10 );
1627 if ( next == NULL || next[0] != '\0' ) {
1628 Debug( LDAP_DEBUG_ANY,
1629 "%s: unable to parse level \"%s\" "
1630 "in \"loglevel <level> [...]\" line.\n",
1631 c->log, c->argv[i], 0);
1635 int j = verb_to_mask(c->argv[i], loglevel_ops);
1636 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1637 Debug( LDAP_DEBUG_ANY,
1638 "%s: unknown level \"%s\" "
1639 "in \"loglevel <level> [...]\" line.\n",
1640 c->log, c->argv[i], 0);
1643 level = loglevel_ops[j].mask;
1645 ldap_syslog |= level;
1651 config_syncrepl(ConfigArgs *c) {
1652 if (c->op == SLAP_CONFIG_EMIT) {
1653 if ( c->be->be_syncinfo ) {
1655 syncrepl_unparse( c->be->be_syncinfo, &bv );
1656 ber_bvarray_add( &c->rvalue_vals, &bv );
1661 if(SLAP_SHADOW(c->be)) {
1662 Debug(LDAP_DEBUG_ANY, "%s: "
1663 "syncrepl: database already shadowed.\n",
1666 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1669 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1674 config_referral(ConfigArgs *c) {
1675 struct berval vals[2];
1676 if (c->op == SLAP_CONFIG_EMIT) {
1677 if ( default_referral ) {
1678 value_add( &c->rvalue_vals, default_referral );
1684 if(validate_global_referral(c->argv[1])) {
1685 Debug(LDAP_DEBUG_ANY, "%s: "
1686 "invalid URL (%s) in \"referral\" line.\n",
1687 c->log, c->argv[1], 0);
1691 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1692 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1693 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1701 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1702 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1703 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1704 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1705 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1706 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1707 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1708 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1709 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1714 config_security(ConfigArgs *c) {
1715 slap_ssf_set_t *set = &c->be->be_ssf_set;
1718 if (c->op == SLAP_CONFIG_EMIT) {
1724 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1725 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1728 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1729 bv.bv_len += sec_keys[i].key.bv_len;
1730 bv.bv_val = ch_malloc( bv.bv_len + 1);
1731 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1732 strcpy( next, numbuf );
1733 ber_bvarray_add( &c->rvalue_vals, &bv );
1738 for(i = 1; i < c->argc; i++) {
1739 slap_ssf_t *tgt = NULL;
1741 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1742 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1743 sec_keys[j].key.bv_len)) {
1744 src = c->argv[i] + sec_keys[j].key.bv_len;
1745 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1750 Debug(LDAP_DEBUG_ANY, "%s: "
1751 "unknown factor %s in \"security <factors>\" line\n",
1752 c->log, c->argv[i], 0);
1756 *tgt = strtol(src, &next, 10);
1757 if(next == NULL || next[0] != '\0' ) {
1758 Debug(LDAP_DEBUG_ANY, "%s: "
1759 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1760 c->log, c->argv[i], 0);
1768 anlist_unparse( AttributeName *an, char *ptr ) {
1771 for (; !BER_BVISNULL( &an->an_name ); an++) {
1772 if ( comma ) *ptr++ = ',';
1773 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1780 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1784 struct berval bc = {0};
1787 len = sprintf(numbuf, IFMT, i );
1789 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1790 if ( ri->ri_nsuffix ) {
1791 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1792 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1795 if ( ri->ri_attrs ) {
1796 len += STRLENOF("attr");
1797 if ( ri->ri_exclude ) len++;
1798 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1799 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1802 bindconf_unparse( &ri->ri_bindconf, &bc );
1805 bv->bv_val = ch_malloc(len + 1);
1808 ptr = lutil_strcopy( bv->bv_val, numbuf );
1809 ptr = lutil_strcopy( ptr, "uri=" );
1810 ptr = lutil_strcopy( ptr, ri->ri_uri );
1812 if ( ri->ri_nsuffix ) {
1813 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1814 ptr = lutil_strcopy( ptr, " suffix=\"" );
1815 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
1819 if ( ri->ri_attrs ) {
1820 ptr = lutil_strcopy( ptr, "attr" );
1821 if ( ri->ri_exclude ) *ptr++ = '!';
1823 ptr = anlist_unparse( ri->ri_attrs, ptr );
1826 strcpy( ptr, bc.bv_val );
1827 ch_free( bc.bv_val );
1832 config_replica(ConfigArgs *c) {
1833 int i, nr = -1, len;
1834 char *replicahost, *replicauri;
1837 if (c->op == SLAP_CONFIG_EMIT) {
1838 if (c->be->be_replica) {
1840 for (i=0;c->be->be_replica[i]; i++) {
1841 replica_unparse( c->be->be_replica[i], i, &bv );
1842 ber_bvarray_add( &c->rvalue_vals, &bv );
1848 if(SLAP_MONITOR(c->be)) {
1849 Debug(LDAP_DEBUG_ANY, "%s: "
1850 "\"replica\" should not be used inside monitor database\n",
1852 return(0); /* FIXME: should this be an error? */
1855 for(i = 1; i < c->argc; i++) {
1856 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
1857 replicahost = c->argv[i] + STRLENOF("host=");
1858 len = strlen( replicahost );
1859 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
1860 sprintf( replicauri, "ldap://%s", replicahost );
1861 replicahost = replicauri + STRLENOF( "ldap://");
1862 nr = add_replica_info(c->be, replicauri, replicahost);
1864 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
1865 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
1866 Debug(LDAP_DEBUG_ANY, "%s: "
1867 "replica line contains invalid "
1868 "uri definition.\n", c->log, 0, 0);
1871 if(!ludp->lud_host) {
1872 Debug(LDAP_DEBUG_ANY, "%s: "
1873 "replica line contains invalid "
1874 "uri definition - missing hostname.\n",
1878 ldap_free_urldesc(ludp);
1879 replicauri = c->argv[i] + STRLENOF("uri=");
1880 replicauri = ch_strdup( replicauri );
1881 replicahost = strchr( replicauri, '/' );
1883 nr = add_replica_info(c->be, replicauri, replicahost);
1888 Debug(LDAP_DEBUG_ANY, "%s: "
1889 "missing host or uri in \"replica\" line\n",
1892 } else if(nr == -1) {
1893 Debug(LDAP_DEBUG_ANY, "%s: "
1894 "unable to add replica \"%s\"\n",
1895 c->log, replicauri, 0);
1898 for(i = 1; i < c->argc; i++) {
1899 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
1900 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
1902 Debug(LDAP_DEBUG_ANY, "%s: "
1903 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1904 c->log, c->argv[i] + STRLENOF("suffix="), 0);
1907 Debug(LDAP_DEBUG_ANY, "%s: "
1908 "unable to normalize suffix in \"replica\" line (ignored)\n",
1913 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
1915 char *arg = c->argv[i] + STRLENOF("attr");
1923 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
1924 Debug(LDAP_DEBUG_ANY, "%s: "
1925 "attribute \"%s\" in \"replica\" line is unknown\n",
1926 c->log, arg + 1, 0);
1929 } else if ( bindconf_parse( c->argv[i],
1930 &c->be->be_replica[nr]->ri_bindconf ) ) {
1939 config_updatedn(ConfigArgs *c) {
1942 if (c->op == SLAP_CONFIG_EMIT) {
1943 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
1944 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
1945 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
1950 if(SLAP_SHADOW(c->be)) {
1951 Debug(LDAP_DEBUG_ANY, "%s: "
1952 "updatedn: database already shadowed.\n",
1957 ber_str2bv(c->argv[1], 0, 0, &dn);
1959 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
1961 if(rc != LDAP_SUCCESS) {
1962 Debug(LDAP_DEBUG_ANY, "%s: "
1963 "updatedn DN is invalid: %d (%s)\n",
1964 c->log, rc, ldap_err2string( rc ));
1968 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
1973 config_updateref(ConfigArgs *c) {
1974 struct berval vals[2];
1975 if (c->op == SLAP_CONFIG_EMIT) {
1976 if ( c->be->be_update_refs ) {
1977 value_add( &c->rvalue_vals, c->be->be_update_refs );
1983 if(!SLAP_SHADOW(c->be)) {
1984 Debug(LDAP_DEBUG_ANY, "%s: "
1985 "updateref line must come after syncrepl or updatedn.\n",
1990 if(validate_global_referral(c->argv[1])) {
1991 Debug(LDAP_DEBUG_ANY, "%s: "
1992 "invalid URL (%s) in \"updateref\" line.\n",
1993 c->log, c->argv[1], 0);
1996 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1997 vals[1].bv_val = NULL;
1998 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
2003 config_include(ConfigArgs *c) {
2004 unsigned long savelineno = c->lineno;
2007 ConfigFile *cfsave = cfn;
2008 ConfigFile *cf2 = NULL;
2009 if (c->op == SLAP_CONFIG_EMIT) {
2011 ConfigFile *cf = c->private;
2012 value_add_one( &c->rvalue_vals, &cf->c_file );
2017 cf = ch_calloc( 1, sizeof(ConfigFile));
2018 if ( cfn->c_kids ) {
2019 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2025 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2026 rc = read_config_file(c->argv[1], c->depth + 1, c);
2027 c->lineno = savelineno - 1;
2030 if ( cf2 ) cf2->c_sibs = NULL;
2031 else cfn->c_kids = NULL;
2032 ch_free( cf->c_file.bv_val );
2040 config_tls_option(ConfigArgs *c) {
2043 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2044 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2045 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2046 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2047 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2048 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2049 default: Debug(LDAP_DEBUG_ANY, "%s: "
2050 "unknown tls_option <0x%x>\n",
2051 c->log, c->type, 0);
2053 if (c->op == SLAP_CONFIG_EMIT) {
2054 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2056 ch_free(c->value_string);
2057 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2060 /* FIXME: this ought to be provided by libldap */
2062 config_tls_config(ConfigArgs *c) {
2064 slap_verbmasks crlkeys[] = {
2065 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2066 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2067 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2070 slap_verbmasks vfykeys[] = {
2071 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2072 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2073 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2074 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2078 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2079 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2081 Debug(LDAP_DEBUG_ANY, "%s: "
2082 "unknown tls_option <0x%x>\n",
2083 c->log, c->type, 0);
2085 if (c->op == SLAP_CONFIG_EMIT) {
2086 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2087 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2088 if (keys[i].mask == c->value_int) {
2089 c->value_string = ch_strdup( keys[i].word.bv_val );
2095 ch_free( c->value_string );
2096 if(isdigit((unsigned char)c->argv[1][0])) {
2097 i = atoi(c->argv[1]);
2098 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2100 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2115 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2118 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2122 si->si_bindconf.sb_tls = SB_TLS_OFF;
2123 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2124 si->si_schemachecking = 0;
2125 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2126 &si->si_filterstr );
2127 si->si_base.bv_val = NULL;
2128 si->si_scope = LDAP_SCOPE_SUBTREE;
2129 si->si_attrsonly = 0;
2130 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2131 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2132 si->si_attrs = NULL;
2133 si->si_allattrs = 0;
2134 si->si_allopattrs = 0;
2135 si->si_exattrs = NULL;
2136 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2137 si->si_interval = 86400;
2138 si->si_retryinterval = NULL;
2139 si->si_retrynum_init = NULL;
2140 si->si_retrynum = NULL;
2141 si->si_manageDSAit = 0;
2145 si->si_presentlist = NULL;
2146 LDAP_LIST_INIT( &si->si_nonpresentlist );
2147 ldap_pvt_thread_mutex_init( &si->si_mutex );
2149 rc = parse_syncrepl_line( cargv, cargc, si );
2152 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2153 syncinfo_free( si );
2156 Debug( LDAP_DEBUG_CONFIG,
2157 "Config: ** successfully added syncrepl \"%s\"\n",
2158 BER_BVISNULL( &si->si_provideruri ) ?
2159 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2160 if ( !si->si_schemachecking ) {
2161 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2164 be->be_syncinfo = si;
2169 /* NOTE: used & documented in slapd.conf(5) */
2171 #define PROVIDERSTR "provider"
2172 #define TYPESTR "type"
2173 #define INTERVALSTR "interval"
2174 #define SEARCHBASESTR "searchbase"
2175 #define FILTERSTR "filter"
2176 #define SCOPESTR "scope"
2177 #define ATTRSSTR "attrs"
2178 #define ATTRSONLYSTR "attrsonly"
2179 #define SLIMITSTR "sizelimit"
2180 #define TLIMITSTR "timelimit"
2181 #define SCHEMASTR "schemachecking"
2183 /* FIXME: undocumented */
2184 #define OLDAUTHCSTR "bindprincipal"
2185 #define EXATTRSSTR "exattrs"
2186 #define RETRYSTR "retry"
2189 #define LASTMODSTR "lastmod"
2190 #define LMGENSTR "gen"
2191 #define LMNOSTR "no"
2192 #define LMREQSTR "req"
2193 #define SRVTABSTR "srvtab"
2194 #define SUFFIXSTR "suffix"
2195 #define MANAGEDSAITSTR "manageDSAit"
2198 #define GOT_ID 0x0001
2199 #define GOT_PROVIDER 0x0002
2202 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2208 { BER_BVC("base"), LDAP_SCOPE_BASE },
2209 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2210 #ifdef LDAP_SCOPE_SUBORDINATE
2211 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2212 { BER_BVC("subordinate"), 0 },
2214 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2219 parse_syncrepl_line(
2229 for ( i = 1; i < cargc; i++ ) {
2230 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2231 STRLENOF( IDSTR "=" ) ) )
2234 /* '\0' string terminator accounts for '=' */
2235 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2237 if ( tmp >= 1000 || tmp < 0 ) {
2238 fprintf( stderr, "Error: parse_syncrepl_line: "
2239 "syncrepl id %d is out of range [0..999]\n", tmp );
2244 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2245 STRLENOF( PROVIDERSTR "=" ) ) )
2247 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2248 ber_str2bv( val, 0, 1, &si->si_provideruri );
2249 gots |= GOT_PROVIDER;
2250 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2251 STRLENOF( SCHEMASTR "=" ) ) )
2253 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2254 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2255 si->si_schemachecking = 1;
2256 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2257 si->si_schemachecking = 0;
2259 si->si_schemachecking = 1;
2261 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2262 STRLENOF( FILTERSTR "=" ) ) )
2264 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2265 ber_str2bv( val, 0, 1, &si->si_filterstr );
2266 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2267 STRLENOF( SEARCHBASESTR "=" ) ) )
2272 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2273 if ( si->si_base.bv_val ) {
2274 ch_free( si->si_base.bv_val );
2276 ber_str2bv( val, 0, 0, &bv );
2277 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2278 if ( rc != LDAP_SUCCESS ) {
2279 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2280 val, rc, ldap_err2string( rc ) );
2283 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2284 STRLENOF( SCOPESTR "=" ) ) )
2287 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2288 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2289 if (!strncasecmp( val, scopes[j].key.bv_val,
2290 scopes[j].key.bv_len )) {
2291 while (!scopes[j].val) j--;
2292 si->si_scope = scopes[j].val;
2296 if ( BER_BVISNULL(&scopes[j].key) ) {
2297 fprintf( stderr, "Error: parse_syncrepl_line: "
2298 "unknown scope \"%s\"\n", val);
2301 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2302 STRLENOF( ATTRSONLYSTR "=" ) ) )
2304 si->si_attrsonly = 1;
2305 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2306 STRLENOF( ATTRSSTR "=" ) ) )
2308 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2309 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2311 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2312 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2313 if ( si->si_anlist == NULL ) {
2314 ch_free( attr_fname );
2317 si->si_anfile = attr_fname;
2319 char *str, *s, *next;
2320 char delimstr[] = " ,\t";
2321 str = ch_strdup( val );
2322 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2324 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2326 if ( strlen(s) == 1 && *s == '*' ) {
2327 si->si_allattrs = 1;
2328 *(val + ( s - str )) = delimstr[0];
2330 if ( strlen(s) == 1 && *s == '+' ) {
2331 si->si_allopattrs = 1;
2332 *(val + ( s - str )) = delimstr[0];
2336 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2337 if ( si->si_anlist == NULL ) {
2341 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2342 STRLENOF( EXATTRSSTR "=" ) ) )
2344 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2345 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2347 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2348 si->si_exanlist = file2anlist(
2349 si->si_exanlist, attr_fname, " ,\t" );
2350 if ( si->si_exanlist == NULL ) {
2351 ch_free( attr_fname );
2354 ch_free( attr_fname );
2356 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2357 if ( si->si_exanlist == NULL ) {
2361 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2362 STRLENOF( TYPESTR "=" ) ) )
2364 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2365 if ( !strncasecmp( val, "refreshOnly",
2366 STRLENOF("refreshOnly") ))
2368 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2369 } else if ( !strncasecmp( val, "refreshAndPersist",
2370 STRLENOF("refreshAndPersist") ))
2372 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2373 si->si_interval = 60;
2375 fprintf( stderr, "Error: parse_syncrepl_line: "
2376 "unknown sync type \"%s\"\n", val);
2379 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2380 STRLENOF( INTERVALSTR "=" ) ) )
2382 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2383 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2384 si->si_interval = 0;
2392 hstr = strchr( dstr, ':' );
2393 if ( hstr == NULL ) {
2394 fprintf( stderr, "Error: parse_syncrepl_line: "
2395 "invalid interval \"%s\"\n", val );
2399 mstr = strchr( hstr, ':' );
2400 if ( mstr == NULL ) {
2401 fprintf( stderr, "Error: parse_syncrepl_line: "
2402 "invalid interval \"%s\"\n", val );
2406 sstr = strchr( mstr, ':' );
2407 if ( sstr == NULL ) {
2408 fprintf( stderr, "Error: parse_syncrepl_line: "
2409 "invalid interval \"%s\"\n", val );
2418 if (( hh > 24 ) || ( hh < 0 ) ||
2419 ( mm > 60 ) || ( mm < 0 ) ||
2420 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2421 fprintf( stderr, "Error: parse_syncrepl_line: "
2422 "invalid interval \"%s\"\n", val );
2425 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2427 if ( si->si_interval < 0 ) {
2428 fprintf( stderr, "Error: parse_syncrepl_line: "
2429 "invalid interval \"%ld\"\n",
2430 (long) si->si_interval);
2433 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2434 STRLENOF( RETRYSTR "=" ) ) )
2439 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2440 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2441 retry_list[0] = NULL;
2443 slap_str2clist( &retry_list, val, " ,\t" );
2445 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2449 "Error: incomplete syncrepl retry list\n" );
2450 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2451 ch_free( retry_list[k] );
2453 ch_free( retry_list );
2454 exit( EXIT_FAILURE );
2456 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2457 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2458 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2459 for ( j = 0; j < n; j++ ) {
2460 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2461 if ( *retry_list[j*2+1] == '+' ) {
2462 si->si_retrynum_init[j] = -1;
2463 si->si_retrynum[j] = -1;
2467 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2468 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2471 si->si_retrynum_init[j] = -2;
2472 si->si_retrynum[j] = -2;
2473 si->si_retryinterval[j] = 0;
2475 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2476 ch_free( retry_list[k] );
2478 ch_free( retry_list );
2479 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2480 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2482 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2483 si->si_manageDSAit = atoi( val );
2484 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2485 STRLENOF( SLIMITSTR "=") ) )
2487 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2488 si->si_slimit = atoi( val );
2489 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2490 STRLENOF( TLIMITSTR "=" ) ) )
2492 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2493 si->si_tlimit = atoi( val );
2494 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2495 fprintf( stderr, "Error: parse_syncrepl_line: "
2496 "unknown keyword \"%s\"\n", cargv[ i ] );
2501 if ( gots != GOT_ALL ) {
2503 "Error: Malformed \"syncrepl\" line in slapd config file" );
2511 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2514 char buf[BUFSIZ*2], *ptr;
2517 bindconf_unparse( &si->si_bindconf, &bc );
2519 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
2520 si->si_rid, si->si_provideruri.bv_val );
2521 if ( !BER_BVISNULL( &bc )) {
2522 ptr = lutil_strcopy( ptr, bc.bv_val );
2525 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2526 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2527 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2530 if ( !BER_BVISNULL( &si->si_base )) {
2531 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2532 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2535 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2536 if ( si->si_scope == scopes[i].val ) {
2537 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2538 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2542 if ( si->si_attrsonly ) {
2543 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2545 if ( si->si_anfile ) {
2546 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2547 ptr = lutil_strcopy( ptr, si->si_anfile );
2548 } else if ( si->si_allattrs || si->si_allopattrs ||
2549 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2551 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2553 ptr = anlist_unparse( si->si_anlist, ptr );
2554 if ( si->si_allattrs ) {
2555 if ( old != ptr ) *ptr++ = ',';
2558 if ( si->si_allopattrs ) {
2559 if ( old != ptr ) *ptr++ = ',';
2564 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
2565 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
2566 ptr = anlist_unparse( si->si_exanlist, ptr );
2568 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
2569 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
2571 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
2572 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
2573 "refreshAndPersist" : "refreshOnly" );
2575 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
2578 dd = si->si_interval;
2585 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
2586 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
2587 } else if ( si->si_retryinterval ) {
2589 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
2590 for (i=0; si->si_retryinterval[i]; i++) {
2591 if ( space ) *ptr++ = ' ';
2593 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
2594 if ( si->si_retrynum_init[i] == -1 )
2597 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
2602 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
2603 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
2604 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
2607 if ( si->si_slimit ) {
2608 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
2609 ptr += sprintf( ptr, "%d", si->si_slimit );
2612 if ( si->si_tlimit ) {
2613 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
2614 ptr += sprintf( ptr, "%d", si->si_tlimit );
2616 bc.bv_len = ptr - buf;
2618 ber_dupbv( bv, &bc );
2621 static CfEntryInfo *
2622 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2632 if ( dn_match( &root->ce_entry->e_nname, dn ))
2635 c = dn->bv_val+dn->bv_len;
2636 for (;*c != ',';c--);
2640 for (--c;c>dn->bv_val && *c != ',';c--);
2644 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2646 root = root->ce_kids;
2648 for (;root;root=root->ce_sibs) {
2649 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2650 if ( cdn.bv_val == dn->bv_val ) {
2661 config_ldif_resp( Operation *op, SlapReply *rs )
2663 if ( rs->sr_type == REP_SEARCH ) {
2664 CfBackInfo *cfb = op->o_callback->sc_private;
2666 cfb->cb_got_ldif = 1;
2667 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL );
2672 /* Configure and read the underlying back-ldif store */
2674 config_setup_ldif( BackendDB *be, const char *dir ) {
2675 CfBackInfo *cfb = be->be_private;
2680 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2681 Connection conn = {0};
2682 char opbuf[OPERATION_BUFFER_SIZE];
2684 SlapReply rs = {REP_RESULT};
2685 Filter filter = { LDAP_FILTER_PRESENT };
2686 struct berval filterstr = BER_BVC("(objectclass=*)");
2688 cfb->cb_db.bd_info = backend_info( "ldif" );
2689 if ( !cfb->cb_db.bd_info )
2690 return 0; /* FIXME: eventually this will be a fatal error */
2692 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2694 /* Mark that back-ldif type is in use */
2695 cfb->cb_db.bd_info->bi_nDB++;
2697 cfb->cb_db.be_suffix = be->be_suffix;
2698 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2699 cfb->cb_db.be_rootdn = be->be_rootdn;
2700 cfb->cb_db.be_rootndn = be->be_rootndn;
2702 ber_str2bv( dir, 0, 1, &cfdir );
2707 argv[0] = "directory";
2708 argv[1] = (char *)dir;
2712 ct = config_find_keyword( c.be->be_cf_table, &c );
2716 if ( config_add_vals( ct, &c ))
2719 if ( backend_startup_one( &cfb->cb_db ))
2722 op = (Operation *)opbuf;
2723 connection_fake_init( &conn, op, cfb );
2725 filter.f_desc = slap_schema.si_ad_objectClass;
2727 op->o_tag = LDAP_REQ_SEARCH;
2729 op->ors_filter = &filter;
2730 op->ors_filterstr = filterstr;
2731 op->ors_scope = LDAP_SCOPE_SUBTREE;
2733 op->o_dn = be->be_rootdn;
2734 op->o_ndn = be->be_rootndn;
2736 op->o_req_dn = be->be_suffix[0];
2737 op->o_req_ndn = be->be_nsuffix[0];
2739 op->ors_tlimit = SLAP_NO_LIMIT;
2740 op->ors_slimit = SLAP_NO_LIMIT;
2742 op->ors_attrs = slap_anlist_all_attributes;
2743 op->ors_attrsonly = 0;
2745 op->o_callback = &cb;
2746 cb.sc_private = cfb;
2748 op->o_bd = &cfb->cb_db;
2749 op->o_bd->be_search( op, &rs );
2755 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2756 const CfOcInfo *co1 = c1;
2757 const CfOcInfo *co2 = c2;
2759 return ber_bvcmp( co1->co_name, co2->co_name );
2763 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2767 i = init_config_attrs( ct );
2770 /* set up the objectclasses */
2771 i = init_config_ocs( ocs );
2774 for (i=0; ocs[i].def; i++) {
2776 co = ch_malloc( sizeof(CfOcInfo) );
2777 co->co_name = &(*ocs[i].oc)->soc_cname;
2779 co->co_type = ocs[i].cft;
2780 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2787 read_config(const char *fname, const char *dir) {
2791 /* Setup the config backend */
2792 be = backend_db_init( "config" );
2796 cfb = be->be_private;
2798 /* Setup the underlying back-ldif backend */
2799 if ( config_setup_ldif( be, dir ))
2802 #ifdef SLAP_USE_CONFDIR
2803 /* If we read the config from back-ldif, nothing to do here */
2804 if ( cfb->cb_got_ldif )
2807 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2809 return read_config_file(fname, 0, NULL);
2813 config_back_bind( Operation *op, SlapReply *rs )
2815 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2816 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2817 /* frontend sends result */
2818 return LDAP_SUCCESS;
2821 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2822 send_ldap_result( op, rs );
2828 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2832 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2834 rs->sr_attrs = op->ors_attrs;
2835 rs->sr_entry = ce->ce_entry;
2836 rc = send_search_entry( op, rs );
2838 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2839 if ( ce->ce_kids ) {
2840 rc = config_send( op, rs, ce->ce_kids, 1 );
2841 if ( rc ) return rc;
2844 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2845 rc = config_send( op, rs, ce, 0 );
2853 static ConfigTable *
2854 config_find_table( CfOcInfo *co, AttributeDescription *ad )
2858 for (i=0; co->co_table[i].name; i++)
2859 if ( co->co_table[i].ad == ad )
2860 return &co->co_table[i];
2864 /* Sort the values in an X-ORDERED VALUES attribute.
2865 * If the values have no index, leave them in their given order.
2866 * If the values have indexes, sort them.
2867 * If some are indexed and some are not, return Error.
2869 * FIXME: This function probably belongs in the frontend somewhere,
2870 * like slap_mods_check.
2873 sort_vals( Attribute *a )
2876 int index = 0, noindex = 0;
2878 /* count attrs, look for index */
2879 for (i=0; a->a_vals[i].bv_val; i++) {
2880 if ( a->a_vals[i].bv_val[0] == '{' ) {
2883 ptr = strchr( a->a_vals[i].bv_val, '}' );
2884 if ( !ptr || !ptr[1] )
2885 return LDAP_INVALID_SYNTAX;
2887 return LDAP_INVALID_SYNTAX;
2891 return LDAP_INVALID_SYNTAX;
2896 int vals = i, *indexes, j, idx;
2897 struct berval tmp, ntmp;
2901 /* Strip index from normalized values */
2902 if ( !a->a_nvals || a->a_vals == a->a_nvals ) {
2903 a->a_nvals = ch_malloc( (vals+1)*sizeof(struct berval));
2904 BER_BVZERO(a->a_nvals+vals);
2905 for ( i=0; i<vals; i++ ) {
2906 ptr = strchr(a->a_vals[i].bv_val, '}') + 1;
2907 a->a_nvals[i].bv_len = a->a_vals[i].bv_len -
2908 (ptr - a->a_vals[i].bv_val);
2909 a->a_nvals[i].bv_val = ch_malloc( a->a_nvals[i].bv_len + 1);
2910 strcpy(a->a_nvals[i].bv_val, ptr );
2913 for ( i=0; i<vals; i++ ) {
2914 ptr = strchr(a->a_nvals[i].bv_val, '}') + 1;
2915 a->a_nvals[i].bv_len -= ptr - a->a_nvals[i].bv_val;
2916 strcpy(a->a_nvals[i].bv_val, ptr);
2921 indexes = ch_malloc( vals * sizeof(int) );
2922 for ( i=0; i<vals; i++)
2923 indexes[i] = atoi(a->a_vals[i].bv_val+1);
2925 /* Insertion sort */
2926 for ( i=1; i<vals; i++ ) {
2929 ntmp = a->a_nvals[i];
2931 while ((j > 0) && (indexes[j-1] > idx)) {
2932 indexes[j] = indexes[j-1];
2933 a->a_vals[j] = a->a_vals[j-1];
2934 a->a_nvals[j] = a->a_nvals[j-1];
2939 a->a_nvals[j] = ntmp;
2946 check_attr( ConfigTable *ct, ConfigArgs *ca, Attribute *a )
2948 int i, rc = 0, sort = 0;
2950 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
2952 rc = sort_vals( a );
2956 for ( i=0; a->a_nvals[i].bv_val; i++ ) {
2957 ca->line = a->a_nvals[i].bv_val;
2958 if ( sort ) ca->line = strchr( ca->line, '}' ) + 1;
2959 rc = config_parse_vals( ct, ca, i );
2967 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2968 SlapReply *rs, int *renum )
2971 int index = -1, gotindex = 0, nsibs;
2972 int renumber = 0, tailindex = 0;
2976 if ( renum ) *renum = 0;
2978 /* These entries don't get indexed/renumbered */
2979 if ( ce_type == Cft_Global ) return 0;
2980 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2982 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2985 /* See if the rdn has an index already */
2986 dnRdn( &e->e_name, &rdn );
2987 ptr1 = strchr( e->e_name.bv_val, '{' );
2988 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2989 ptr2 = strchr( ptr1, '}' );
2990 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2991 return LDAP_NAMING_VIOLATION;
2992 if ( ptr2-ptr1 == 1)
2993 return LDAP_NAMING_VIOLATION;
2995 index = atoi(ptr1+1);
2997 return LDAP_NAMING_VIOLATION;
3000 /* count related kids */
3001 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3002 if ( ce->ce_type == ce_type ) nsibs++;
3005 if ( index != nsibs ) {
3007 if ( index < nsibs ) {
3008 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3009 /* Siblings need to be renumbered */
3014 struct berval ival, newrdn, nnewrdn;
3015 struct berval rtype, rval;
3017 AttributeDescription *ad = NULL;
3021 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
3022 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
3023 rtype.bv_val = rdn.bv_val;
3024 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3027 slap_bv2ad( &rtype, &ad, &text );
3028 a = attr_find( e->e_attrs, ad );
3029 if (!a ) return LDAP_NAMING_VIOLATION;
3032 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
3034 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3035 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3038 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3039 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3046 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3048 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
3051 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3052 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3056 /* Do the equivalent of ModRDN */
3057 /* Replace DN / NDN */
3058 newrdn.bv_len = ptr1 - newrdn.bv_val;
3059 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3060 free( e->e_name.bv_val );
3061 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
3063 free( e->e_nname.bv_val );
3064 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
3068 free( a->a_vals[0].bv_val );
3069 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
3070 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
3071 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3072 strcpy( a->a_vals[0].bv_val, ptr1 );
3074 if ( a->a_nvals != a->a_vals ) {
3075 free( a->a_nvals[0].bv_val );
3076 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
3077 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
3078 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3079 strcpy( a->a_nvals[0].bv_val, ptr1 );
3081 free( nnewrdn.bv_val );
3082 free( newrdn.bv_val );
3085 if ( renum ) *renum = renumber;
3089 /* Parse an LDAP entry into config directives */
3091 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
3093 CfEntryInfo *ce, *last;
3094 CfOcInfo co, *coptr, **colst = NULL;
3095 Attribute *a, *oc_at, *type_attr;
3096 AttributeDescription *type_ad = NULL;
3098 ConfigArgs ca = {0};
3101 ConfigTable *ct, *type_ct = NULL;
3103 /* Make sure parent exists and entry does not */
3104 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3106 return LDAP_ALREADY_EXISTS;
3108 dnParent( &e->e_nname, &pdn );
3110 /* If last is NULL, the new entry is the root/suffix entry,
3111 * otherwise last should be the parent.
3113 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3115 rs->sr_matched = last->ce_entry->e_name.bv_val;
3116 return LDAP_NO_SUCH_OBJECT;
3119 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3120 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3122 /* count the objectclasses */
3123 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
3125 colst = (CfOcInfo **)ch_malloc( nocs * sizeof(CfOcInfo *));
3127 for ( i=0, j=0; i<nocs; i++) {
3128 co.co_name = &oc_at->a_nvals[i];
3129 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
3131 /* ignore non-config objectclasses. probably should be
3132 * an error, general data doesn't belong here.
3134 if ( !coptr ) continue;
3136 /* Ignore the root objectclass, it has no implementation.
3138 if ( coptr->co_type == Cft_Abstract ) continue;
3143 /* Only the root can be Cft_Global, everything else must
3144 * have a parent. Only limited nesting arrangements are allowed.
3146 switch( colst[0]->co_type ) {
3149 rc = LDAP_CONSTRAINT_VIOLATION;
3157 if ( !last || ( last->ce_type != Cft_Global &&
3158 last->ce_type != colst[0]->co_type )) {
3159 rc = LDAP_CONSTRAINT_VIOLATION;
3164 if ( !last || ( last->ce_type != Cft_Global &&
3165 last->ce_type != Cft_Database &&
3166 last->ce_type != colst[0]->co_type )) {
3167 rc = LDAP_CONSTRAINT_VIOLATION;
3171 #ifdef SLAPD_MODULES
3173 if ( !last || last->ce_type != Cft_Global ) {
3174 rc = LDAP_CONSTRAINT_VIOLATION;
3181 /* Parse all the values and check for simple syntax errors before
3182 * performing any set actions.
3184 switch (colst[0]->co_type) {
3186 /* The cn=schema entry is all hardcoded, so never reparse it */
3187 if (last->ce_type == Cft_Global )
3191 ca.be = LDAP_STAILQ_FIRST(&backendDB);
3195 if ( last->ce_type == Cft_Backend )
3196 ca.bi = last->ce_bi;
3198 type_ad = cfAd_backend;
3201 if ( last->ce_type == Cft_Database ) {
3202 ca.be = last->ce_be;
3204 type_ad = cfAd_database;
3205 /* dummy, just to get past check_attr */
3211 ca.be = last->ce_be;
3212 type_ad = cfAd_overlay;
3216 if ( !rs ) /* ignored */
3218 type_ad = cfAd_include;
3220 #ifdef SLAPD_MODULES
3224 ptr = strchr( e->e_name.bv_val, '{' );
3226 rc = LDAP_NAMING_VIOLATION;
3230 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
3231 /* There is no corresponding modpath for this load? */
3233 rc = LDAP_NAMING_VIOLATION;
3236 module_path( mp->mp_path.bv_val );
3243 /* If doing an LDAPadd, check for indexed names and any necessary
3244 * renaming/renumbering. Entries that don't need indexed names are
3245 * ignored. Entries that need an indexed name and arrive without one
3246 * are assigned to the end. Entries that arrive with an index may
3247 * cause the following entries to be renumbered/bumped down.
3249 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3250 * don't allow Adding an entry with an index that's already in use.
3251 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3253 * These entries can have auto-assigned indexes (appended to the end)
3254 * but only the other types support auto-renumbering of siblings.
3256 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3260 init_config_argv( &ca );
3262 type_attr = attr_find( e->e_attrs, type_ad );
3264 rc = LDAP_OBJECT_CLASS_VIOLATION;
3267 for ( i=0; i<nocs; i++ ) {
3268 type_ct = config_find_table( colst[i], type_ad );
3269 if ( type_ct ) break;
3272 rc = LDAP_OBJECT_CLASS_VIOLATION;
3275 rc = check_attr( type_ct, &ca, type_attr );
3276 if ( rc ) goto leave;
3278 for ( a=e->e_attrs; a; a=a->a_next ) {
3279 if ( a == type_attr || a == oc_at ) continue;
3281 for ( i=0; i<nocs; i++ ) {
3282 ct = config_find_table( colst[i], a->a_desc );
3285 if ( !ct ) continue; /* user data? */
3286 rc = check_attr( ct, &ca, a );
3287 if ( rc ) goto leave;
3290 /* Basic syntax checks are OK. Do the actual settings. */
3292 ca.line = type_attr->a_vals[0].bv_val;
3293 if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED )
3294 ca.line = strchr( ca.line, '}' ) + 1;
3295 rc = config_parse_add( type_ct, &ca, 0 );
3301 for ( a=e->e_attrs; a; a=a->a_next ) {
3302 if ( a == type_attr || a == oc_at ) continue;
3304 for ( i=0; i<nocs; i++ ) {
3305 ct = config_find_table( colst[i], a->a_desc );
3308 if ( !ct ) continue; /* user data? */
3309 for (i=0; a->a_vals[i].bv_val; i++) {
3310 ca.line = a->a_vals[i].bv_val;
3311 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED )
3312 ca.line = strchr( ca.line, '}' ) + 1;
3313 rc = config_parse_add( ct, &ca, i );
3321 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3322 ce->ce_parent = last;
3323 ce->ce_entry = entry_dup( e );
3324 ce->ce_entry->e_private = ce;
3325 ce->ce_type = colst[0]->co_type;
3328 } else if ( last->ce_kids ) {
3331 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3340 if ( colst ) ch_free( colst );
3344 /* Parse an LDAP entry into config directives, then store in underlying
3348 config_back_add( Operation *op, SlapReply *rs )
3351 CfEntryInfo *ce, *last;
3354 if ( !be_isroot( op ) ) {
3355 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3356 send_ldap_result( op, rs );
3359 cfb = (CfBackInfo *)op->o_bd->be_private;
3361 ldap_pvt_thread_pool_pause( &connection_pool );
3364 * 1) check for existence of entry
3365 * 2) check for sibling renumbering
3366 * 3) perform internal add
3367 * 4) store entry in underlying database
3368 * 5) perform any necessary renumbering
3370 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3371 if ( rs->sr_err == LDAP_SUCCESS ) {
3372 BackendDB *be = op->o_bd;
3373 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3374 op->o_bd = &cfb->cb_db;
3375 sc.sc_next = op->o_callback;
3376 op->o_callback = ≻
3377 op->o_bd->be_add( op, rs );
3379 op->o_callback = sc.sc_next;
3384 ldap_pvt_thread_pool_resume( &connection_pool );
3387 send_ldap_result( op, rs );
3392 * for single-valued attributes, should just use REPLACE.
3393 * any received DELETE/ADD on a single-valued attr will
3394 * be checked (if a DEL value is provided) and then
3395 * rewritten as a REPLACE.
3396 * any DELETE received without a corresponding ADD will be
3397 * rejected with LDAP_CONSTRAINT_VIOLATION.
3400 config_back_modify( Operation *op, SlapReply *rs )
3403 CfEntryInfo *ce, *last;
3405 if ( !be_isroot( op ) ) {
3406 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3407 send_ldap_result( op, rs );
3410 cfb = (CfBackInfo *)op->o_bd->be_private;
3412 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3415 rs->sr_matched = last->ce_entry->e_name.bv_val;
3416 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3419 ldap_pvt_thread_pool_pause( &connection_pool );
3422 * 1) perform the Modify on the cached Entry.
3423 * 2) verify that the Entry still satisfies the schema.
3424 * 3) perform the individual config operations.
3425 * 4) store Modified entry in underlying LDIF backend.
3427 ldap_pvt_thread_pool_resume( &connection_pool );
3429 send_ldap_result( op, rs );
3434 config_back_modrdn( Operation *op, SlapReply *rs )
3437 CfEntryInfo *ce, *last;
3439 if ( !be_isroot( op ) ) {
3440 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3441 send_ldap_result( op, rs );
3444 cfb = (CfBackInfo *)op->o_bd->be_private;
3446 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3449 rs->sr_matched = last->ce_entry->e_name.bv_val;
3450 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3454 /* We don't allow moving objects to new parents.
3455 * Generally we only allow reordering a set of ordered entries.
3457 if ( op->orr_newSup ) {
3458 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3461 ldap_pvt_thread_pool_pause( &connection_pool );
3463 ldap_pvt_thread_pool_resume( &connection_pool );
3465 send_ldap_result( op, rs );
3470 config_back_search( Operation *op, SlapReply *rs )
3473 CfEntryInfo *ce, *last;
3476 if ( !be_isroot( op ) ) {
3477 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3478 send_ldap_result( op, rs );
3481 cfb = (CfBackInfo *)op->o_bd->be_private;
3483 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3486 rs->sr_matched = last->ce_entry->e_name.bv_val;
3487 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3490 switch ( op->ors_scope ) {
3491 case LDAP_SCOPE_BASE:
3492 case LDAP_SCOPE_SUBTREE:
3493 config_send( op, rs, ce, 0 );
3496 case LDAP_SCOPE_ONELEVEL:
3497 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3498 config_send( op, rs, ce, 1 );
3503 rs->sr_err = LDAP_SUCCESS;
3505 send_ldap_result( op, rs );
3510 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3512 Entry *e = ch_calloc( 1, sizeof(Entry) );
3513 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3518 ce->ce_parent = parent;
3520 pdn = parent->ce_entry->e_nname;
3525 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3526 ber_dupbv( &e->e_nname, &e->e_name );
3535 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3536 struct berval *rdn, ConfigTable *ct, int table )
3538 struct berval vals[2];
3539 struct berval ad_name;
3540 AttributeDescription *ad = NULL;
3544 char textbuf[SLAP_TEXT_BUFLEN];
3545 size_t textlen = sizeof(textbuf);
3549 BER_BVZERO( &vals[1] );
3551 vals[0] = oc->soc_cname;
3552 attr_merge(e, slap_schema.si_ad_objectClass, vals, NULL );
3553 ptr = strchr(rdn->bv_val, '=');
3554 ad_name.bv_val = rdn->bv_val;
3555 ad_name.bv_len = ptr - rdn->bv_val;
3556 rc = slap_bv2ad( &ad_name, &ad, &text );
3560 vals[0].bv_val = ptr+1;
3561 vals[0].bv_len = rdn->bv_len - (vals[0].bv_val - rdn->bv_val);
3562 attr_merge(e, ad, vals, NULL );
3564 for (at=oc->soc_required; at && *at; at++) {
3565 /* Skip the naming attr */
3566 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3568 for (i=0;ct[i].name;i++) {
3569 if (ct[i].ad == (*at)->sat_ad) {
3570 rc = config_get_vals(&ct[i], c);
3571 if (rc == LDAP_SUCCESS) {
3572 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3573 ber_bvarray_free( c->rvalue_nvals );
3574 ber_bvarray_free( c->rvalue_vals );
3581 for (at=oc->soc_allowed; at && *at; at++) {
3582 /* Skip the naming attr */
3583 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3585 for (i=0;ct[i].name;i++) {
3586 if (ct[i].ad == (*at)->sat_ad) {
3587 rc = config_get_vals(&ct[i], c);
3588 if (rc == LDAP_SUCCESS) {
3589 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3590 ber_bvarray_free( c->rvalue_nvals );
3591 ber_bvarray_free( c->rvalue_vals );
3599 if ( table == BI_TABLE )
3600 ct = c->bi->bi_cf_table;
3602 ct = c->be->be_cf_table;
3603 for (;ct && ct->name;ct++) {
3604 if (!ct->ad) continue;
3605 rc = config_get_vals(ct, c);
3606 if (rc == LDAP_SUCCESS) {
3607 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3611 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3612 rc = structural_class(oc_at->a_vals, vals, NULL, &text, textbuf, textlen);
3613 BER_BVZERO( &vals[1] );
3614 attr_merge(e, slap_schema.si_ad_structuralObjectClass, vals, NULL );
3620 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3621 Operation *op, SlapReply *rs )
3624 ConfigFile *cf = c->private;
3625 CfEntryInfo *ce, *ceprev;
3629 if ( ceparent->ce_kids ) {
3630 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3631 ceprev = ceprev->ce_sibs );
3634 for (; cf; cf=cf->c_sibs, c->depth++) {
3635 c->value_dn.bv_val = c->log;
3636 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3641 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3643 ptr = strchr( bv.bv_val, '.' );
3645 bv.bv_len = ptr - bv.bv_val;
3646 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3647 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3649 c->value_dn.bv_len += bv.bv_len;
3650 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3652 e = config_alloc_entry( ceparent, &c->value_dn );
3654 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3655 c->bi->bi_cf_table, NO_TABLE );
3657 ce->ce_type = Cft_Schema;
3659 op->o_bd->be_add( op, rs );
3661 if ( !ceparent->ce_kids ) {
3662 ceparent->ce_kids = ce;
3664 ceprev->ce_sibs = ce;
3668 c->private = cf->c_kids;
3669 config_build_schema_inc( c, ceparent, op, rs );
3674 static CfEntryInfo *
3675 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3676 Operation *op, SlapReply *rs )
3680 ConfigFile *cf = c->private;
3681 CfEntryInfo *ce, *ceprev;
3683 if ( ceparent->ce_kids ) {
3684 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3685 ceprev = ceprev->ce_sibs );
3688 for (i=0; cf; cf=cf->c_sibs, i++) {
3689 c->value_dn.bv_val = c->log;
3690 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3691 e = config_alloc_entry( ceparent, &c->value_dn );
3693 config_build_entry( c, e, cfOc_include, &c->value_dn,
3694 c->bi->bi_cf_table, NO_TABLE );
3696 op->o_bd->be_add( op, rs );
3698 ce->ce_type = Cft_Include;
3700 if ( !ceparent->ce_kids ) {
3701 ceparent->ce_kids = ce;
3703 ceprev->ce_sibs = ce;
3707 c->private = cf->c_kids;
3708 config_build_includes( c, ce, op, rs );
3714 #ifdef SLAPD_MODULES
3716 static CfEntryInfo *
3717 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3718 Operation *op, SlapReply *rs )
3722 CfEntryInfo *ce, *ceprev;
3725 if ( ceparent->ce_kids ) {
3726 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3727 ceprev = ceprev->ce_sibs );
3730 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3731 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3733 c->value_dn.bv_val = c->log;
3734 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3735 e = config_alloc_entry( ceparent, &c->value_dn );
3737 ce->ce_type = Cft_Include;
3739 config_build_entry( c, e, cfOc_module, &c->value_dn,
3740 c->bi->bi_cf_table, NO_TABLE );
3742 op->o_bd->be_add( op, rs );
3744 if ( !ceparent->ce_kids ) {
3745 ceparent->ce_kids = ce;
3747 ceprev->ce_sibs = ce;
3756 config_back_db_open( BackendDB *be )
3758 CfBackInfo *cfb = be->be_private;
3761 CfEntryInfo *ce, *ceparent, *ceprev;
3767 Connection conn = {0};
3768 char opbuf[OPERATION_BUFFER_SIZE];
3770 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3771 SlapReply rs = {REP_RESULT};
3773 /* If we read the config from back-ldif, nothing to do here */
3774 if ( cfb->cb_got_ldif )
3777 op = (Operation *)opbuf;
3778 connection_fake_init( &conn, op, cfb );
3780 op->o_dn = be->be_rootdn;
3781 op->o_ndn = be->be_rootndn;
3783 op->o_tag = LDAP_REQ_ADD;
3784 op->o_callback = &cb;
3785 op->o_bd = &cfb->cb_db;
3787 /* create root of tree */
3789 e = config_alloc_entry( NULL, &rdn );
3791 ce->ce_type = Cft_Global;
3795 c.private = cfb->cb_config;
3796 ct = c.bi->bi_cf_table;
3797 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
3799 op->o_bd->be_add( op, &rs );
3805 /* Create schema nodes... cn=schema will contain the hardcoded core
3806 * schema, read-only. Child objects will contain runtime loaded schema
3810 e = config_alloc_entry( ceparent, &rdn );
3812 ce->ce_type = Cft_Schema;
3814 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
3816 op->o_bd->be_add( op, &rs );
3817 if ( !ceparent->ce_kids ) {
3818 ceparent->ce_kids = ce;
3820 ceprev->ce_sibs = ce;
3824 /* Create includeFile nodes and schema nodes for included schema... */
3825 if ( cfb->cb_config->c_kids ) {
3827 c.private = cfb->cb_config->c_kids;
3828 config_build_schema_inc( &c, ce, op, &rs );
3829 c.private = cfb->cb_config->c_kids;
3830 ceprev = config_build_includes( &c, ceparent, op, &rs );
3833 #ifdef SLAPD_MODULES
3834 /* Create Module nodes... */
3835 if ( modpaths.mp_loads ) {
3836 ceprev = config_build_modules( &c, ceparent, op, &rs );
3840 /* Create backend nodes. Skip if they don't provide a cf_table.
3841 * There usually aren't any of these.
3845 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3846 if (!bi->bi_cf_table) continue;
3847 if (!bi->bi_private) continue;
3850 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3851 e = config_alloc_entry( ceparent, &rdn );
3853 ce->ce_type = Cft_Backend;
3856 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3858 op->o_bd->be_add( op, &rs );
3859 if ( !ceparent->ce_kids ) {
3860 ceparent->ce_kids = ce;
3862 ceprev->ce_sibs = ce;
3867 /* Create database nodes... */
3869 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3870 slap_overinfo *oi = NULL;
3877 if ( overlay_is_over( bptr )) {
3878 oi = bptr->bd_info->bi_private;
3884 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3886 e = config_alloc_entry( ceparent, &rdn );
3890 ce->ce_type = Cft_Database;
3893 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3895 op->o_bd->be_add( op, &rs );
3896 if ( !ceparent->ce_kids ) {
3897 ceparent->ce_kids = ce;
3899 ceprev->ce_sibs = ce;
3902 /* Iterate through overlays */
3906 CfEntryInfo *opar = ce, *oprev = NULL;
3909 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3911 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
3912 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3913 oe = config_alloc_entry( opar, &rdn );
3917 ce->ce_type = Cft_Overlay;
3920 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
3922 op->o_bd->be_add( op, &rs );
3923 if ( !opar->ce_kids ) {
3926 oprev->ce_sibs = ce;
3937 config_back_db_destroy( Backend *be )
3939 free( be->be_private );
3944 config_back_db_init( Backend *be )
3949 cfb = ch_calloc( 1, sizeof(CfBackInfo));
3950 cfb->cb_config = &cf_prv;
3951 be->be_private = cfb;
3953 ber_dupbv( &be->be_rootdn, &config_rdn );
3954 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
3955 ber_dupbv( &dn, &be->be_rootdn );
3956 ber_bvarray_add( &be->be_suffix, &dn );
3957 ber_dupbv( &dn, &be->be_rootdn );
3958 ber_bvarray_add( &be->be_nsuffix, &dn );
3960 /* Hide from namingContexts */
3961 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
3968 AttributeDescription **desc;
3970 { "backend", &cfAd_backend },
3971 { "database", &cfAd_database },
3972 { "include", &cfAd_include },
3973 { "overlay", &cfAd_overlay },
3978 * add / delete: all types that may be added or deleted must use an
3979 * X-ORDERED attributeType for their RDN. Adding and deleting entries
3980 * should automatically renumber the index of any siblings as needed,
3981 * so that no gaps in the numbering sequence exist after the add/delete
3983 * What can be added:
3985 * backend objects for backend-specific config directives
3989 * delete: probably no support this time around.
3991 * modrdn: generally not done. Will be invoked automatically by add/
3992 * delete to update numbering sequence. Perform as an explicit operation
3993 * so that the renumbering effect may be replicated. Subtree rename must
3994 * be supported, since renumbering a database will affect all its child
3997 * modify: must be fully supported.
4001 config_back_initialize( BackendInfo *bi )
4003 ConfigTable *ct = config_back_cf_table;
4006 static char *controls[] = {
4007 LDAP_CONTROL_MANAGEDSAIT,
4011 bi->bi_controls = controls;
4018 bi->bi_db_init = config_back_db_init;
4019 bi->bi_db_config = 0;
4020 bi->bi_db_open = config_back_db_open;
4021 bi->bi_db_close = 0;
4022 bi->bi_db_destroy = config_back_db_destroy;
4024 bi->bi_op_bind = config_back_bind;
4025 bi->bi_op_unbind = 0;
4026 bi->bi_op_search = config_back_search;
4027 bi->bi_op_compare = 0;
4028 bi->bi_op_modify = config_back_modify;
4029 bi->bi_op_modrdn = config_back_modrdn;
4030 bi->bi_op_add = config_back_add;
4031 bi->bi_op_delete = 0;
4032 bi->bi_op_abandon = 0;
4034 bi->bi_extended = 0;
4036 bi->bi_chk_referrals = 0;
4038 bi->bi_connection_init = 0;
4039 bi->bi_connection_destroy = 0;
4042 for (i=0; OidMacros[i].name; i++ ) {
4043 argv[1] = OidMacros[i].name;
4044 argv[2] = OidMacros[i].oid;
4045 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4048 bi->bi_cf_table = ct;
4050 i = config_register_schema( ct, cf_ocs );
4053 /* set up the notable AttributeDescriptions */
4055 for (;ct->name;ct++) {
4056 if (strcmp(ct->name, ads[i].name)) continue;
4057 *ads[i].desc = ct->ad;
4059 if (!ads[i].name) break;