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;
71 typedef struct CfEntryInfo {
72 struct CfEntryInfo *ce_parent;
73 struct CfEntryInfo *ce_sibs;
74 struct CfEntryInfo *ce_kids;
82 ConfigFile *cb_config;
84 BackendDB cb_db; /* underlying database */
88 /* These do nothing in slapd, they're kept only to make them
91 static char *replica_pidFile, *replica_argsFile;
92 static int replicationInterval;
94 static char *passwd_salt;
95 static char *logfileName;
96 static BerVarray authz_rewrites;
98 static struct berval cfdir;
101 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
104 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
105 *cfOc_include, *cfOc_overlay, *cfOc_module;
107 static ConfigFile cf_prv, *cfn = &cf_prv;
109 static Avlnode *CfOcTree;
111 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
112 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
113 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
114 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs,
117 static ConfigDriver config_fname;
118 static ConfigDriver config_cfdir;
119 static ConfigDriver config_generic;
120 static ConfigDriver config_search_base;
121 static ConfigDriver config_passwd_hash;
122 static ConfigDriver config_schema_dn;
123 static ConfigDriver config_sizelimit;
124 static ConfigDriver config_timelimit;
125 static ConfigDriver config_limits;
126 static ConfigDriver config_overlay;
127 static ConfigDriver config_suffix;
128 static ConfigDriver config_deref_depth;
129 static ConfigDriver config_rootdn;
130 static ConfigDriver config_rootpw;
131 static ConfigDriver config_restrict;
132 static ConfigDriver config_allows;
133 static ConfigDriver config_disallows;
134 static ConfigDriver config_requires;
135 static ConfigDriver config_security;
136 static ConfigDriver config_referral;
137 static ConfigDriver config_loglevel;
138 static ConfigDriver config_syncrepl;
139 static ConfigDriver config_replica;
140 static ConfigDriver config_updatedn;
141 static ConfigDriver config_updateref;
142 static ConfigDriver config_include;
144 static ConfigDriver config_tls_option;
145 static ConfigDriver config_tls_config;
194 static OidRec OidMacros[] = {
195 /* OpenLDAProot:666.11.1 */
196 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
197 { "OLcfgAt", "OLcfg:3" },
198 { "OLcfgOc", "OLcfg:4" },
199 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
200 { "OMsInteger", "OMsyn:2" },
201 { "OMsBoolean", "OMsyn:7" },
202 { "OMsDN", "OMsyn:12" },
203 { "OMsDirectoryString", "OMsyn:15" },
204 { "OMsOctetString", "OMsyn:40" },
208 /* alphabetical ordering */
210 ConfigTable config_back_cf_table[] = {
211 /* This attr is read-only */
212 { "", "", 0, 0, 0, ARG_MAGIC,
213 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
214 "DESC 'File for slapd configuration directives' "
215 "EQUALITY caseIgnoreMatch "
216 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
217 { "", "", 0, 0, 0, ARG_MAGIC,
218 &config_cfdir, "( OLcfgAt:79 NAME 'olcConfigDir' "
219 "DESC 'Directory for slapd configuration backend' "
220 "EQUALITY caseIgnoreMatch "
221 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
222 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
223 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
224 "DESC 'Access Control List' "
225 "EQUALITY caseIgnoreMatch "
226 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
227 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
228 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
229 "DESC 'Allowed set of deprecated features' "
230 "EQUALITY caseIgnoreMatch "
231 "SYNTAX OMsDirectoryString )", NULL, NULL },
232 { "argsfile", "file", 2, 2, 0, ARG_STRING,
233 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
234 "DESC 'File for slapd command line options' "
235 "EQUALITY caseIgnoreMatch "
236 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
237 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
238 &config_generic, "( OLcfgAt:4 NAME 'olcAttributeTypes' "
239 "DESC 'OpenLDAP attributeTypes' "
240 "EQUALITY caseIgnoreMatch "
241 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
243 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
244 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
245 "EQUALITY caseIgnoreMatch "
246 "SYNTAX OMsDirectoryString )", NULL, NULL },
247 { "authid-rewrite", NULL, 2, 0, 0,
248 #ifdef SLAP_AUTH_REWRITE
249 ARG_MAGIC|CFG_REWRITE, &config_generic,
253 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
254 "EQUALITY caseIgnoreMatch "
255 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
256 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
257 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
258 "EQUALITY caseIgnoreMatch "
259 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
260 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
261 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
262 "EQUALITY caseIgnoreMatch "
263 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
264 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
265 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
266 "DESC 'A type of backend' "
267 "EQUALITY caseIgnoreMatch "
268 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
270 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
271 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
272 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
273 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
274 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
275 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
276 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
277 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
278 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
279 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
280 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
281 "DESC 'The backend type for a database instance' "
282 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
283 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
284 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
285 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
286 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
287 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
288 "EQUALITY caseIgnoreMatch "
289 "SYNTAX OMsDirectoryString )", NULL, NULL },
290 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
291 &config_generic, "( OLcfgAt:16 NAME 'olcDitContentRules' "
292 "DESC 'OpenLDAP DIT content rules' "
293 "EQUALITY caseIgnoreMatch "
294 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
296 { "gentlehup", "on|off", 2, 2, 0,
298 ARG_ON_OFF, &global_gentlehup,
302 "( OLcfgAt:17 NAME 'olcGentleHUP' "
303 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
304 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
305 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
306 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
307 /* XXX -- special case? */
308 { "include", "file", 2, 2, 0, ARG_MAGIC,
309 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
310 "SUP labeledURI )", NULL, NULL },
311 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
312 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
313 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
314 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
315 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
316 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
317 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
318 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
319 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
320 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
321 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
322 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
323 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
324 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
325 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
326 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
327 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
328 "SYNTAX OMsDirectoryString )", NULL, NULL },
329 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
330 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
331 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
332 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
333 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
334 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
335 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
336 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
337 "SYNTAX OMsDirectoryString )", NULL, NULL },
338 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
339 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
340 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
341 { "moduleload", "file", 2, 0, 0,
343 ARG_MAGIC|CFG_MODLOAD, &config_generic,
347 "( OLcfgAt:30 NAME 'olcModuleLoad' "
348 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
349 { "modulepath", "path", 2, 2, 0,
351 ARG_MAGIC|CFG_MODPATH, &config_generic,
355 "( OLcfgAt:31 NAME 'olcModulePath' "
356 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
357 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
358 &config_generic, "( OLcfgAt:32 NAME 'olcObjectClasses' "
359 "DESC 'OpenLDAP object classes' "
360 "EQUALITY caseIgnoreMatch "
361 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
363 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
364 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
365 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
366 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
367 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
368 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
369 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
370 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
371 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
372 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
373 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
374 "SYNTAX OMsDirectoryString )", NULL, NULL },
375 { "pidfile", "file", 2, 2, 0, ARG_STRING,
376 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
377 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
378 { "plugin", NULL, 0, 0, 0,
380 ARG_MAGIC|CFG_PLUGIN, &config_generic,
384 "( OLcfgAt:38 NAME 'olcPlugin' "
385 "SYNTAX OMsDirectoryString )", NULL, NULL },
386 { "pluginlog", "filename", 2, 2, 0,
388 ARG_STRING, &slapi_log_file,
392 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
393 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
394 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
395 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
396 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
397 { "referral", "url", 2, 2, 0, ARG_MAGIC,
398 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
399 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
400 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
401 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
402 "SUP labeledURI )", NULL, NULL },
403 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
404 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
405 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
406 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
407 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
408 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
409 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
410 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
411 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
412 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
413 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
414 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
415 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
416 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
417 "SYNTAX OMsDirectoryString )", NULL, NULL },
418 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
419 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
420 "SYNTAX OMsDirectoryString )", NULL, NULL },
421 { "reverse-lookup", "on|off", 2, 2, 0,
422 #ifdef SLAPD_RLOOKUPS
423 ARG_ON_OFF, &use_reverse_lookup,
427 "( OLcfgAt:49 NAME 'olcReverseLookup' "
428 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
429 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
430 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
431 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
432 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
433 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
434 "SYNTAX OMsDirectoryString )", NULL, NULL },
435 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
436 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
437 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
438 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
439 &config_generic, NULL, NULL, NULL },
440 { "sasl-host", "host", 2, 2, 0,
441 #ifdef HAVE_CYRUS_SASL
442 ARG_STRING|ARG_UNIQUE, &global_host,
446 "( OLcfgAt:53 NAME 'olcSaslHost' "
447 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
448 { "sasl-realm", "realm", 2, 2, 0,
449 #ifdef HAVE_CYRUS_SASL
450 ARG_STRING|ARG_UNIQUE, &global_realm,
454 "( OLcfgAt:54 NAME 'olcSaslRealm' "
455 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
456 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
457 &config_generic, NULL, NULL, NULL },
458 { "sasl-secprops", "properties", 2, 2, 0,
459 #ifdef HAVE_CYRUS_SASL
460 ARG_MAGIC|CFG_SASLSECP, &config_generic,
464 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
465 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
466 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
467 &config_generic, NULL, NULL, NULL },
468 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
469 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
470 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
471 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
472 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
473 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
474 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
475 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
476 "SYNTAX OMsDirectoryString )", NULL, NULL },
477 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
478 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
479 "SYNTAX OMsInteger )", NULL, NULL },
480 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
481 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
482 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
483 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
484 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
485 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
486 { "srvtab", "file", 2, 2, 0,
487 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
488 ARG_STRING, &ldap_srvtab,
492 "( OLcfgAt:63 NAME 'olcSrvtab' "
493 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
494 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
495 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
496 "SYNTAX OMsDN )", NULL, NULL },
497 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
498 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
499 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
500 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
501 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
502 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
503 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
504 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
505 "SYNTAX OMsInteger )", NULL, NULL },
506 { "TLSCACertificateFile", NULL, 0, 0, 0,
508 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
512 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
513 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
514 { "TLSCACertificatePath", NULL, 0, 0, 0,
516 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
520 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
521 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
522 { "TLSCertificateFile", NULL, 0, 0, 0,
524 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
528 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
529 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
530 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
532 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
536 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
537 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
538 { "TLSCipherSuite", NULL, 0, 0, 0,
540 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
544 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
545 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
546 { "TLSCRLCheck", NULL, 0, 0, 0,
547 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
548 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
552 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
553 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
554 { "TLSRandFile", NULL, 0, 0, 0,
556 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
560 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
561 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
562 { "TLSVerifyClient", NULL, 0, 0, 0,
564 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
568 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
569 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
570 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
571 NULL, NULL, NULL, NULL },
572 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
573 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
574 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
575 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
576 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
577 "SUP labeledURI )", NULL, NULL },
578 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
579 NULL, NULL, NULL, NULL }
582 static ConfigOCs cf_ocs[] = {
585 "DESC 'OpenLDAP configuration object' "
586 "ABSTRACT SUP top )", Cft_Abstract, NULL },
589 "DESC 'OpenLDAP Global configuration options' "
590 "SUP olcConfig STRUCTURAL "
591 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
592 "olcAttributeOptions $ olcAuthIDRewrite $ "
593 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
594 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
595 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
596 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
597 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
598 "olcLogLevel $ olcModulePath $ "
599 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
600 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
601 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
602 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
603 "olcRootDSE $ olcRootPW $ "
604 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
605 "olcSchemaCheck $ olcSecurity $ olcSizeLimit $ "
606 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
607 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
608 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
609 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
610 "olcTLSRandFile $ olcTLSVerifyClient $ "
611 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
612 "olcDitContentRules ) )", Cft_Global, &cfOc_global },
614 "NAME 'olcSchemaConfig' "
615 "DESC 'OpenLDAP schema object' "
616 "SUP olcConfig STRUCTURAL "
617 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
618 "olcObjectClasses $ olcDitContentRules ) )",
619 Cft_Schema, &cfOc_schema },
621 "NAME 'olcBackendConfig' "
622 "DESC 'OpenLDAP Backend-specific options' "
623 "SUP olcConfig STRUCTURAL "
624 "MUST olcBackend )", Cft_Backend, &cfOc_backend },
626 "NAME 'olcDatabaseConfig' "
627 "DESC 'OpenLDAP Database-specific options' "
628 "SUP olcConfig STRUCTURAL "
630 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
631 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
632 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
633 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
634 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
635 Cft_Database, &cfOc_database },
637 "NAME 'olcOverlayConfig' "
638 "DESC 'OpenLDAP Overlay-specific options' "
639 "SUP olcConfig STRUCTURAL "
640 "MUST olcOverlay )", Cft_Overlay, &cfOc_overlay },
642 "NAME 'olcIncludeFile' "
643 "DESC 'OpenLDAP configuration include file' "
644 "SUP olcConfig STRUCTURAL "
646 "MAY ( cn $ olcRootDSE ) )",
647 Cft_Include, &cfOc_include },
650 "NAME 'olcModuleList' "
651 "DESC 'OpenLDAP dynamic module info' "
652 "SUP olcConfig STRUCTURAL "
653 "MUST olcModuleLoad "
654 "MAY cn )", Cft_Module, &cfOc_module },
660 config_generic(ConfigArgs *c) {
664 if ( c->op == SLAP_CONFIG_EMIT ) {
668 c->value_int = ldap_pvt_thread_get_concurrency();
671 c->value_int = connection_pool_max;
675 c->value_string = ch_strdup( passwd_salt );
680 if ( c->be->be_limits ) {
685 for ( i=0; c->be->be_limits[i]; i++ ) {
686 bv.bv_len = sprintf( buf, IFMT, i );
687 bv.bv_val = buf+bv.bv_len;
688 limits_unparse( c->be->be_limits[i], &bv );
689 bv.bv_len += bv.bv_val - buf;
691 value_add_one( &c->rvalue_vals, &bv );
694 if ( !c->rvalue_vals ) rc = 1;
697 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
700 c->value_string = ch_strdup( slap_sasl_getpolicy());
703 slap_sasl_regexp_unparse( &c->rvalue_vals );
704 if ( !c->rvalue_vals ) rc = 1;
706 #ifdef HAVE_CYRUS_SASL
708 struct berval bv = BER_BVNULL;
709 slap_sasl_secprops_unparse( &bv );
710 if ( !BER_BVISNULL( &bv )) {
711 ber_bvarray_add( &c->rvalue_vals, &bv );
719 c->value_int = c->be->be_max_deref_depth;
722 ConfigFile *cf = c->private;
724 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
725 else if ( cf->c_om_head )
726 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
728 if ( !c->rvalue_vals )
733 ConfigFile *cf = c->private;
735 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
736 else if ( cf->c_oc_head )
737 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
739 if ( !c->rvalue_vals )
744 ConfigFile *cf = c->private;
746 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
747 else if ( cf->c_at_head )
748 at_unparse( &c->rvalue_vals, cf->c_at_head,
750 if ( !c->rvalue_vals )
755 ConfigFile *cf = c->private;
757 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
758 else if ( cf->c_cr_head )
759 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
761 if ( !c->rvalue_vals )
767 c->value_int = global_schemacheck;
771 char *src, *dst, ibuf[11];
772 struct berval bv, abv;
773 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
774 abv.bv_len = sprintf( ibuf, IFMT, i );
775 acl_unparse( a, &bv );
776 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
777 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
778 /* Turn TAB / EOL into plain space */
779 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
780 if (isspace(*src)) *dst++ = ' ';
784 if (dst[-1] == ' ') {
788 abv.bv_len = dst - abv.bv_val;
789 ber_bvarray_add( &c->rvalue_vals, &abv );
795 if ( c->be->be_replogfile )
796 c->value_string = ch_strdup( c->be->be_replogfile );
799 ConfigFile *cf = c->private;
800 if ( cf->c_dseFiles ) {
801 value_add( &c->rvalue_vals, cf->c_dseFiles );
809 c->value_string = ch_strdup( logfileName );
814 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
816 case CFG_SSTR_IF_MAX:
817 c->value_int = index_substr_if_maxlen;
819 case CFG_SSTR_IF_MIN:
820 c->value_int = index_substr_if_minlen;
824 ModPaths *mp = c->private;
827 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
830 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
831 mp->mp_loads[i].bv_val );
832 value_add_one( &c->rvalue_vals, &bv );
836 rc = c->rvalue_vals ? 0 : 1;
841 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
843 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
846 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
847 mp->mp_path.bv_val );
848 value_add_one( &c->rvalue_vals, &bv );
850 rc = c->rvalue_vals ? 0 : 1;
856 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
857 if ( !c->rvalue_vals ) rc = 1;
860 #ifdef SLAP_AUTH_REWRITE
862 if ( authz_rewrites ) {
863 struct berval bv, idx;
868 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
869 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
870 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
871 bv.bv_val = ch_malloc( bv.bv_len + 1 );
872 strcpy( bv.bv_val, idx.bv_val );
873 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
874 ber_bvarray_add( &c->rvalue_vals, &bv );
877 if ( !c->rvalue_vals ) rc = 1;
886 p = strchr(c->line,'(' /*')'*/);
887 if ( c->op == LDAP_MOD_DELETE ) {
895 ldap_pvt_thread_set_concurrency(c->value_int);
902 if(!(c->bi = backend_info(c->argv[1]))) {
903 Debug(LDAP_DEBUG_ANY, "%s: "
904 "backend %s failed init!\n", c->log, c->argv[1], 0);
911 /* NOTE: config is always the first backend!
913 if ( !strcasecmp( c->argv[1], "config" )) {
914 c->be = LDAP_STAILQ_FIRST(&backendDB);
915 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
917 } else if(!(c->be = backend_db_init(c->argv[1]))) {
918 Debug(LDAP_DEBUG_ANY, "%s: "
919 "database %s failed init!\n", c->log, c->argv[1], 0);
925 ldap_pvt_thread_set_concurrency(c->value_int);
929 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
930 connection_pool_max = c->value_int; /* save for reference */
934 if ( passwd_salt ) ch_free( passwd_salt );
935 passwd_salt = c->value_string;
936 lutil_salt_format(passwd_salt);
940 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
946 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
948 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
952 ch_free(c->value_string);
953 if (slap_sasl_setpolicy( c->argv[1] )) {
954 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
955 " \"authz-policy <policy>\"\n",
956 c->log, c->argv[1], 0 );
962 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
966 #ifdef HAVE_CYRUS_SASL
969 char *txt = slap_sasl_secprops( c->argv[1] );
971 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
980 c->be->be_max_deref_depth = c->value_int;
986 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
988 if (!cfn->c_om_head) cfn->c_om_head = om;
996 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
997 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1005 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1006 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1007 cfn->c_cr_tail = cr;
1014 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1015 if (!cfn->c_at_head) cfn->c_at_head = at;
1016 cfn->c_at_tail = at;
1021 ad_define_option(NULL, NULL, 0);
1022 for(i = 1; i < c->argc; i++)
1023 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1028 global_schemacheck = c->value_int;
1029 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1030 "schema checking disabled! your mileage may vary!\n",
1035 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1039 if(SLAP_MONITOR(c->be)) {
1040 Debug(LDAP_DEBUG_ANY, "%s: "
1041 "\"replogfile\" should not be used "
1042 "inside monitor database\n",
1044 return(0); /* FIXME: should this be an error? */
1047 c->be->be_replogfile = c->value_string;
1051 if(read_root_dse_file(c->argv[1])) {
1052 Debug(LDAP_DEBUG_ANY, "%s: "
1053 "could not read \"rootDSE <filename>\" line\n",
1059 ber_str2bv( c->argv[1], 0, 1, &bv );
1060 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1066 if ( logfileName ) ch_free( logfileName );
1067 logfileName = c->value_string;
1068 logfile = fopen(logfileName, "w");
1069 if(logfile) lutil_debug_file(logfile);
1073 if(SLAP_NOLASTMODCMD(c->be)) {
1074 Debug(LDAP_DEBUG_ANY, "%s: "
1075 "lastmod not available for %s databases\n",
1076 c->log, c->be->bd_info->bi_type, 0);
1080 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1082 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1085 case CFG_SSTR_IF_MAX:
1086 if (c->value_int < index_substr_if_minlen) {
1087 Debug(LDAP_DEBUG_ANY, "%s: "
1088 "invalid max value (%d)\n",
1089 c->log, c->value_int, 0 );
1092 index_substr_if_maxlen = c->value_int;
1095 case CFG_SSTR_IF_MIN:
1096 if (c->value_int > index_substr_if_maxlen) {
1097 Debug(LDAP_DEBUG_ANY, "%s: "
1098 "invalid min value (%d)\n",
1099 c->log, c->value_int, 0 );
1102 index_substr_if_minlen = c->value_int;
1105 #ifdef SLAPD_MODULES
1107 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1109 /* Record this load on the current path */
1112 char *ptr = c->line + STRLENOF("moduleload");
1113 while (!isspace(*ptr)) ptr++;
1114 while (isspace(*ptr)) ptr++;
1115 ber_str2bv(ptr, 0, 1, &bv);
1116 ber_bvarray_add( &modcur->mp_loads, &bv );
1121 if(module_path(c->argv[1])) return(1);
1122 /* Record which path was used with each module */
1126 if (!modpaths.mp_loads) {
1129 mp = ch_malloc( sizeof( ModPaths ));
1130 modlast->mp_next = mp;
1132 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1134 mp->mp_loads = NULL;
1136 if ( c->op == SLAP_CONFIG_ADD )
1145 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1147 slapi_plugins_used++;
1151 #ifdef SLAP_AUTH_REWRITE
1154 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1156 ber_str2bv( c->line, 0, 1, &bv );
1157 ber_bvarray_add( &authz_rewrites, &bv );
1164 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1165 "(ignored)\n", c->log, c->type, 0);
1173 config_fname(ConfigArgs *c) {
1174 if(c->op == SLAP_CONFIG_EMIT) {
1176 ConfigFile *cf = c->private;
1177 value_add_one( &c->rvalue_vals, &cf->c_file );
1186 config_cfdir(ConfigArgs *c) {
1187 if(c->op == SLAP_CONFIG_EMIT) {
1188 value_add_one( &c->rvalue_vals, &cfdir );
1195 config_search_base(ConfigArgs *c) {
1198 if(c->op == SLAP_CONFIG_EMIT) {
1200 if (!BER_BVISEMPTY(&default_search_base)) {
1201 value_add_one(&c->rvalue_vals, &default_search_base);
1202 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1208 if(c->bi || c->be != frontendDB) {
1209 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1210 "prior to any backend or database definition\n",
1215 if(default_search_nbase.bv_len) {
1216 Debug(LDAP_DEBUG_ANY, "%s: "
1217 "default search base \"%s\" already defined "
1218 "(discarding old)\n",
1219 c->log, default_search_base.bv_val, 0);
1220 free(default_search_base.bv_val);
1221 free(default_search_nbase.bv_val);
1224 default_search_base = c->value_dn;
1225 default_search_nbase = c->value_ndn;
1230 config_passwd_hash(ConfigArgs *c) {
1232 if (c->op == SLAP_CONFIG_EMIT) {
1234 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1235 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1236 value_add_one(&c->rvalue_vals, &bv);
1240 if(default_passwd_hash) {
1241 Debug(LDAP_DEBUG_ANY, "%s: "
1242 "already set default password_hash\n",
1246 for(i = 1; i < c->argc; i++) {
1247 if(!lutil_passwd_scheme(c->argv[i])) {
1248 Debug(LDAP_DEBUG_ANY, "%s: "
1249 "password scheme \"%s\" not available\n",
1250 c->log, c->argv[i], 0);
1252 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1254 if(!default_passwd_hash) {
1255 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1264 config_schema_dn(ConfigArgs *c) {
1265 if ( c->op == SLAP_CONFIG_EMIT ) {
1267 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1268 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1269 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1274 c->be->be_schemadn = c->value_dn;
1275 c->be->be_schemandn = c->value_ndn;
1280 config_sizelimit(ConfigArgs *c) {
1283 struct slap_limits_set *lim = &c->be->be_def_limit;
1284 if (c->op == SLAP_CONFIG_EMIT) {
1289 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1290 if ( !BER_BVISEMPTY( &bv ))
1291 value_add_one( &c->rvalue_vals, &bv );
1296 for(i = 1; i < c->argc; i++) {
1297 if(!strncasecmp(c->argv[i], "size", 4)) {
1298 rc = limits_parse_one(c->argv[i], lim);
1300 Debug(LDAP_DEBUG_ANY, "%s: "
1301 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1302 c->log, c->argv[i], 0);
1306 if(!strcasecmp(c->argv[i], "unlimited")) {
1307 lim->lms_s_soft = -1;
1309 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1310 if(next == c->argv[i]) {
1311 Debug(LDAP_DEBUG_ANY, "%s: "
1312 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1313 c->log, c->argv[i], 0);
1315 } else if(next[0] != '\0') {
1316 Debug(LDAP_DEBUG_ANY, "%s: "
1317 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1321 lim->lms_s_hard = 0;
1328 config_timelimit(ConfigArgs *c) {
1331 struct slap_limits_set *lim = &c->be->be_def_limit;
1332 if (c->op == SLAP_CONFIG_EMIT) {
1337 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1338 if ( !BER_BVISEMPTY( &bv ))
1339 value_add_one( &c->rvalue_vals, &bv );
1344 for(i = 1; i < c->argc; i++) {
1345 if(!strncasecmp(c->argv[i], "time", 4)) {
1346 rc = limits_parse_one(c->argv[i], lim);
1348 Debug(LDAP_DEBUG_ANY, "%s: "
1349 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1350 c->log, c->argv[i], 0);
1354 if(!strcasecmp(c->argv[i], "unlimited")) {
1355 lim->lms_t_soft = -1;
1357 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1358 if(next == c->argv[i]) {
1359 Debug(LDAP_DEBUG_ANY, "%s: "
1360 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1361 c->log, c->argv[i], 0);
1363 } else if(next[0] != '\0') {
1364 Debug(LDAP_DEBUG_ANY, "%s: "
1365 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1369 lim->lms_t_hard = 0;
1376 config_overlay(ConfigArgs *c) {
1377 if (c->op == SLAP_CONFIG_EMIT) {
1380 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1382 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1383 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1384 } else if(overlay_config(c->be, c->argv[1])) {
1391 config_suffix(ConfigArgs *c) {
1393 struct berval pdn, ndn;
1396 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1397 SLAP_CONFIG(c->be)) return 1;
1399 if (c->op == SLAP_CONFIG_EMIT) {
1400 if (!BER_BVISNULL( &c->be->be_suffix[0] )) {
1401 value_add( &c->rvalue_vals, c->be->be_suffix );
1402 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1408 #ifdef SLAPD_MONITOR_DN
1409 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1410 Debug(LDAP_DEBUG_ANY, "%s: "
1411 "\"%s\" is reserved for monitoring slapd\n",
1412 c->log, SLAPD_MONITOR_DN, 0);
1419 tbe = select_backend(&ndn, 0, 0);
1421 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1426 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1427 c->log, tbe->be_suffix[0].bv_val, 0);
1431 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1432 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1433 "base provided \"%s\" (assuming okay)\n",
1434 c->log, default_search_base.bv_val, 0);
1436 ber_bvarray_add(&c->be->be_suffix, &pdn);
1437 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1442 config_rootdn(ConfigArgs *c) {
1443 if (c->op == SLAP_CONFIG_EMIT) {
1444 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1445 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1446 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1452 c->be->be_rootdn = c->value_dn;
1453 c->be->be_rootndn = c->value_ndn;
1458 config_rootpw(ConfigArgs *c) {
1460 if (c->op == SLAP_CONFIG_EMIT) {
1461 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1462 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1468 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1470 Debug(LDAP_DEBUG_ANY, "%s: "
1471 "rootpw can only be set when rootdn is under suffix\n",
1475 c->be->be_rootpw = c->value_bv;
1480 config_restrict(ConfigArgs *c) {
1481 slap_mask_t restrictops = 0;
1483 slap_verbmasks restrictable_ops[] = {
1484 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1485 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1486 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1487 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1488 { BER_BVC("modrdn"), 0 },
1489 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1490 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1491 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1492 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1493 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1494 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1495 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1496 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1497 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1498 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1502 if (c->op == SLAP_CONFIG_EMIT) {
1503 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1506 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1508 Debug(LDAP_DEBUG_ANY, "%s: "
1509 "unknown operation %s in \"restrict <features>\" line\n",
1510 c->log, c->argv[i], 0);
1513 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1514 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1515 c->be->be_restrictops |= restrictops;
1520 config_allows(ConfigArgs *c) {
1521 slap_mask_t allows = 0;
1523 slap_verbmasks allowable_ops[] = {
1524 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1525 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1526 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1527 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1530 if (c->op == SLAP_CONFIG_EMIT) {
1531 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1533 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1535 Debug(LDAP_DEBUG_ANY, "%s: "
1536 "unknown feature %s in \"allow <features>\" line\n",
1537 c->log, c->argv[i], 0);
1540 global_allows |= allows;
1545 config_disallows(ConfigArgs *c) {
1546 slap_mask_t disallows = 0;
1548 slap_verbmasks disallowable_ops[] = {
1549 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1550 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1551 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1552 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1553 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1556 if (c->op == SLAP_CONFIG_EMIT) {
1557 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1559 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1561 Debug(LDAP_DEBUG_ANY, "%s: "
1562 "unknown feature %s in \"disallow <features>\" line\n",
1563 c->log, c->argv[i], 0);
1566 global_disallows |= disallows;
1571 config_requires(ConfigArgs *c) {
1572 slap_mask_t requires = 0;
1574 slap_verbmasks requires_ops[] = {
1575 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1576 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1577 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1578 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1579 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1582 if (c->op == SLAP_CONFIG_EMIT) {
1583 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1585 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1587 Debug(LDAP_DEBUG_ANY, "%s: "
1588 "unknown feature %s in \"require <features>\" line\n",
1589 c->log, c->argv[i], 0);
1592 c->be->be_requires = requires;
1597 config_loglevel(ConfigArgs *c) {
1600 slap_verbmasks loglevel_ops[] = {
1601 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1602 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1603 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1604 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1605 { BER_BVC("BER"), LDAP_DEBUG_BER },
1606 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1607 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1608 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1609 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1610 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1611 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1612 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1613 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1614 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1615 { BER_BVC("Any"), -1 },
1619 if (c->op == SLAP_CONFIG_EMIT) {
1620 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1625 for( i=1; i < c->argc; i++ ) {
1628 if ( isdigit( c->argv[i][0] ) ) {
1629 level = strtol( c->argv[i], &next, 10 );
1630 if ( next == NULL || next[0] != '\0' ) {
1631 Debug( LDAP_DEBUG_ANY,
1632 "%s: unable to parse level \"%s\" "
1633 "in \"loglevel <level> [...]\" line.\n",
1634 c->log, c->argv[i], 0);
1638 int j = verb_to_mask(c->argv[i], loglevel_ops);
1639 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1640 Debug( LDAP_DEBUG_ANY,
1641 "%s: unknown level \"%s\" "
1642 "in \"loglevel <level> [...]\" line.\n",
1643 c->log, c->argv[i], 0);
1646 level = loglevel_ops[j].mask;
1648 ldap_syslog |= level;
1654 config_syncrepl(ConfigArgs *c) {
1655 if (c->op == SLAP_CONFIG_EMIT) {
1656 if ( c->be->be_syncinfo ) {
1658 syncrepl_unparse( c->be->be_syncinfo, &bv );
1659 ber_bvarray_add( &c->rvalue_vals, &bv );
1664 if(SLAP_SHADOW(c->be)) {
1665 Debug(LDAP_DEBUG_ANY, "%s: "
1666 "syncrepl: database already shadowed.\n",
1669 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1672 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1677 config_referral(ConfigArgs *c) {
1678 struct berval vals[2];
1679 if (c->op == SLAP_CONFIG_EMIT) {
1680 if ( default_referral ) {
1681 value_add( &c->rvalue_vals, default_referral );
1687 if(validate_global_referral(c->argv[1])) {
1688 Debug(LDAP_DEBUG_ANY, "%s: "
1689 "invalid URL (%s) in \"referral\" line.\n",
1690 c->log, c->argv[1], 0);
1694 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1695 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1696 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1704 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1705 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1706 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1707 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1708 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1709 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1710 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1711 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1712 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1717 config_security(ConfigArgs *c) {
1718 slap_ssf_set_t *set = &c->be->be_ssf_set;
1721 if (c->op == SLAP_CONFIG_EMIT) {
1727 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1728 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1731 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1732 bv.bv_len += sec_keys[i].key.bv_len;
1733 bv.bv_val = ch_malloc( bv.bv_len + 1);
1734 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1735 strcpy( next, numbuf );
1736 ber_bvarray_add( &c->rvalue_vals, &bv );
1741 for(i = 1; i < c->argc; i++) {
1742 slap_ssf_t *tgt = NULL;
1744 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1745 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1746 sec_keys[j].key.bv_len)) {
1747 src = c->argv[i] + sec_keys[j].key.bv_len;
1748 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1753 Debug(LDAP_DEBUG_ANY, "%s: "
1754 "unknown factor %s in \"security <factors>\" line\n",
1755 c->log, c->argv[i], 0);
1759 *tgt = strtol(src, &next, 10);
1760 if(next == NULL || next[0] != '\0' ) {
1761 Debug(LDAP_DEBUG_ANY, "%s: "
1762 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1763 c->log, c->argv[i], 0);
1771 anlist_unparse( AttributeName *an, char *ptr ) {
1774 for (; !BER_BVISNULL( &an->an_name ); an++) {
1775 if ( comma ) *ptr++ = ',';
1776 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1783 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1787 struct berval bc = {0};
1790 len = sprintf(numbuf, IFMT, i );
1792 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1793 if ( ri->ri_nsuffix ) {
1794 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1795 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1798 if ( ri->ri_attrs ) {
1799 len += STRLENOF("attr");
1800 if ( ri->ri_exclude ) len++;
1801 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1802 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1805 bindconf_unparse( &ri->ri_bindconf, &bc );
1808 bv->bv_val = ch_malloc(len + 1);
1811 ptr = lutil_strcopy( bv->bv_val, numbuf );
1812 ptr = lutil_strcopy( ptr, "uri=" );
1813 ptr = lutil_strcopy( ptr, ri->ri_uri );
1815 if ( ri->ri_nsuffix ) {
1816 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1817 ptr = lutil_strcopy( ptr, " suffix=\"" );
1818 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
1822 if ( ri->ri_attrs ) {
1823 ptr = lutil_strcopy( ptr, "attr" );
1824 if ( ri->ri_exclude ) *ptr++ = '!';
1826 ptr = anlist_unparse( ri->ri_attrs, ptr );
1829 strcpy( ptr, bc.bv_val );
1830 ch_free( bc.bv_val );
1835 config_replica(ConfigArgs *c) {
1836 int i, nr = -1, len;
1837 char *replicahost, *replicauri;
1840 if (c->op == SLAP_CONFIG_EMIT) {
1841 if (c->be->be_replica) {
1843 for (i=0;c->be->be_replica[i]; i++) {
1844 replica_unparse( c->be->be_replica[i], i, &bv );
1845 ber_bvarray_add( &c->rvalue_vals, &bv );
1851 if(SLAP_MONITOR(c->be)) {
1852 Debug(LDAP_DEBUG_ANY, "%s: "
1853 "\"replica\" should not be used inside monitor database\n",
1855 return(0); /* FIXME: should this be an error? */
1858 for(i = 1; i < c->argc; i++) {
1859 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
1860 replicahost = c->argv[i] + STRLENOF("host=");
1861 len = strlen( replicahost );
1862 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
1863 sprintf( replicauri, "ldap://%s", replicahost );
1864 replicahost = replicauri + STRLENOF( "ldap://");
1865 nr = add_replica_info(c->be, replicauri, replicahost);
1867 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
1868 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
1869 Debug(LDAP_DEBUG_ANY, "%s: "
1870 "replica line contains invalid "
1871 "uri definition.\n", c->log, 0, 0);
1874 if(!ludp->lud_host) {
1875 Debug(LDAP_DEBUG_ANY, "%s: "
1876 "replica line contains invalid "
1877 "uri definition - missing hostname.\n",
1881 ldap_free_urldesc(ludp);
1882 replicauri = c->argv[i] + STRLENOF("uri=");
1883 replicauri = ch_strdup( replicauri );
1884 replicahost = strchr( replicauri, '/' );
1886 nr = add_replica_info(c->be, replicauri, replicahost);
1891 Debug(LDAP_DEBUG_ANY, "%s: "
1892 "missing host or uri in \"replica\" line\n",
1895 } else if(nr == -1) {
1896 Debug(LDAP_DEBUG_ANY, "%s: "
1897 "unable to add replica \"%s\"\n",
1898 c->log, replicauri, 0);
1901 for(i = 1; i < c->argc; i++) {
1902 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
1903 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
1905 Debug(LDAP_DEBUG_ANY, "%s: "
1906 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1907 c->log, c->argv[i] + STRLENOF("suffix="), 0);
1910 Debug(LDAP_DEBUG_ANY, "%s: "
1911 "unable to normalize suffix in \"replica\" line (ignored)\n",
1916 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
1918 char *arg = c->argv[i] + STRLENOF("attr");
1926 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
1927 Debug(LDAP_DEBUG_ANY, "%s: "
1928 "attribute \"%s\" in \"replica\" line is unknown\n",
1929 c->log, arg + 1, 0);
1932 } else if ( bindconf_parse( c->argv[i],
1933 &c->be->be_replica[nr]->ri_bindconf ) ) {
1942 config_updatedn(ConfigArgs *c) {
1945 if (c->op == SLAP_CONFIG_EMIT) {
1946 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
1947 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
1948 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
1953 if(SLAP_SHADOW(c->be)) {
1954 Debug(LDAP_DEBUG_ANY, "%s: "
1955 "updatedn: database already shadowed.\n",
1960 ber_str2bv(c->argv[1], 0, 0, &dn);
1962 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
1964 if(rc != LDAP_SUCCESS) {
1965 Debug(LDAP_DEBUG_ANY, "%s: "
1966 "updatedn DN is invalid: %d (%s)\n",
1967 c->log, rc, ldap_err2string( rc ));
1971 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
1976 config_updateref(ConfigArgs *c) {
1977 struct berval vals[2];
1978 if (c->op == SLAP_CONFIG_EMIT) {
1979 if ( c->be->be_update_refs ) {
1980 value_add( &c->rvalue_vals, c->be->be_update_refs );
1986 if(!SLAP_SHADOW(c->be)) {
1987 Debug(LDAP_DEBUG_ANY, "%s: "
1988 "updateref line must come after syncrepl or updatedn.\n",
1993 if(validate_global_referral(c->argv[1])) {
1994 Debug(LDAP_DEBUG_ANY, "%s: "
1995 "invalid URL (%s) in \"updateref\" line.\n",
1996 c->log, c->argv[1], 0);
1999 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
2000 vals[1].bv_val = NULL;
2001 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
2006 config_include(ConfigArgs *c) {
2007 unsigned long savelineno = c->lineno;
2010 ConfigFile *cfsave = cfn;
2011 ConfigFile *cf2 = NULL;
2012 if (c->op == SLAP_CONFIG_EMIT) {
2014 ConfigFile *cf = c->private;
2015 value_add_one( &c->rvalue_vals, &cf->c_file );
2020 cf = ch_calloc( 1, sizeof(ConfigFile));
2021 if ( cfn->c_kids ) {
2022 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2028 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2029 rc = read_config_file(c->argv[1], c->depth + 1, c);
2030 c->lineno = savelineno - 1;
2033 if ( cf2 ) cf2->c_sibs = NULL;
2034 else cfn->c_kids = NULL;
2035 ch_free( cf->c_file.bv_val );
2043 config_tls_option(ConfigArgs *c) {
2046 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2047 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2048 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2049 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2050 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2051 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2052 default: Debug(LDAP_DEBUG_ANY, "%s: "
2053 "unknown tls_option <0x%x>\n",
2054 c->log, c->type, 0);
2056 if (c->op == SLAP_CONFIG_EMIT) {
2057 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2059 ch_free(c->value_string);
2060 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2063 /* FIXME: this ought to be provided by libldap */
2065 config_tls_config(ConfigArgs *c) {
2067 slap_verbmasks crlkeys[] = {
2068 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2069 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2070 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2073 slap_verbmasks vfykeys[] = {
2074 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2075 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2076 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2077 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2081 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2082 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2084 Debug(LDAP_DEBUG_ANY, "%s: "
2085 "unknown tls_option <0x%x>\n",
2086 c->log, c->type, 0);
2088 if (c->op == SLAP_CONFIG_EMIT) {
2089 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2090 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2091 if (keys[i].mask == c->value_int) {
2092 c->value_string = ch_strdup( keys[i].word.bv_val );
2098 ch_free( c->value_string );
2099 if(isdigit((unsigned char)c->argv[1][0])) {
2100 i = atoi(c->argv[1]);
2101 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2103 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2118 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2121 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2125 si->si_bindconf.sb_tls = SB_TLS_OFF;
2126 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2127 si->si_schemachecking = 0;
2128 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2129 &si->si_filterstr );
2130 si->si_base.bv_val = NULL;
2131 si->si_scope = LDAP_SCOPE_SUBTREE;
2132 si->si_attrsonly = 0;
2133 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2134 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2135 si->si_attrs = NULL;
2136 si->si_allattrs = 0;
2137 si->si_allopattrs = 0;
2138 si->si_exattrs = NULL;
2139 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2140 si->si_interval = 86400;
2141 si->si_retryinterval = NULL;
2142 si->si_retrynum_init = NULL;
2143 si->si_retrynum = NULL;
2144 si->si_manageDSAit = 0;
2148 si->si_presentlist = NULL;
2149 LDAP_LIST_INIT( &si->si_nonpresentlist );
2150 ldap_pvt_thread_mutex_init( &si->si_mutex );
2152 rc = parse_syncrepl_line( cargv, cargc, si );
2155 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2156 syncinfo_free( si );
2159 Debug( LDAP_DEBUG_CONFIG,
2160 "Config: ** successfully added syncrepl \"%s\"\n",
2161 BER_BVISNULL( &si->si_provideruri ) ?
2162 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2163 if ( !si->si_schemachecking ) {
2164 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2167 be->be_syncinfo = si;
2172 /* NOTE: used & documented in slapd.conf(5) */
2174 #define PROVIDERSTR "provider"
2175 #define TYPESTR "type"
2176 #define INTERVALSTR "interval"
2177 #define SEARCHBASESTR "searchbase"
2178 #define FILTERSTR "filter"
2179 #define SCOPESTR "scope"
2180 #define ATTRSSTR "attrs"
2181 #define ATTRSONLYSTR "attrsonly"
2182 #define SLIMITSTR "sizelimit"
2183 #define TLIMITSTR "timelimit"
2184 #define SCHEMASTR "schemachecking"
2186 /* FIXME: undocumented */
2187 #define OLDAUTHCSTR "bindprincipal"
2188 #define EXATTRSSTR "exattrs"
2189 #define RETRYSTR "retry"
2192 #define LASTMODSTR "lastmod"
2193 #define LMGENSTR "gen"
2194 #define LMNOSTR "no"
2195 #define LMREQSTR "req"
2196 #define SRVTABSTR "srvtab"
2197 #define SUFFIXSTR "suffix"
2198 #define MANAGEDSAITSTR "manageDSAit"
2201 #define GOT_ID 0x0001
2202 #define GOT_PROVIDER 0x0002
2205 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2211 { BER_BVC("base"), LDAP_SCOPE_BASE },
2212 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2213 #ifdef LDAP_SCOPE_SUBORDINATE
2214 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2215 { BER_BVC("subordinate"), 0 },
2217 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2222 parse_syncrepl_line(
2232 for ( i = 1; i < cargc; i++ ) {
2233 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2234 STRLENOF( IDSTR "=" ) ) )
2237 /* '\0' string terminator accounts for '=' */
2238 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2240 if ( tmp >= 1000 || tmp < 0 ) {
2241 fprintf( stderr, "Error: parse_syncrepl_line: "
2242 "syncrepl id %d is out of range [0..999]\n", tmp );
2247 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2248 STRLENOF( PROVIDERSTR "=" ) ) )
2250 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2251 ber_str2bv( val, 0, 1, &si->si_provideruri );
2252 gots |= GOT_PROVIDER;
2253 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2254 STRLENOF( SCHEMASTR "=" ) ) )
2256 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2257 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2258 si->si_schemachecking = 1;
2259 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2260 si->si_schemachecking = 0;
2262 si->si_schemachecking = 1;
2264 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2265 STRLENOF( FILTERSTR "=" ) ) )
2267 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2268 ber_str2bv( val, 0, 1, &si->si_filterstr );
2269 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2270 STRLENOF( SEARCHBASESTR "=" ) ) )
2275 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2276 if ( si->si_base.bv_val ) {
2277 ch_free( si->si_base.bv_val );
2279 ber_str2bv( val, 0, 0, &bv );
2280 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2281 if ( rc != LDAP_SUCCESS ) {
2282 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2283 val, rc, ldap_err2string( rc ) );
2286 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2287 STRLENOF( SCOPESTR "=" ) ) )
2290 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2291 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2292 if (!strncasecmp( val, scopes[j].key.bv_val,
2293 scopes[j].key.bv_len )) {
2294 while (!scopes[j].val) j--;
2295 si->si_scope = scopes[j].val;
2299 if ( BER_BVISNULL(&scopes[j].key) ) {
2300 fprintf( stderr, "Error: parse_syncrepl_line: "
2301 "unknown scope \"%s\"\n", val);
2304 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2305 STRLENOF( ATTRSONLYSTR "=" ) ) )
2307 si->si_attrsonly = 1;
2308 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2309 STRLENOF( ATTRSSTR "=" ) ) )
2311 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2312 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2314 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2315 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2316 if ( si->si_anlist == NULL ) {
2317 ch_free( attr_fname );
2320 si->si_anfile = attr_fname;
2322 char *str, *s, *next;
2323 char delimstr[] = " ,\t";
2324 str = ch_strdup( val );
2325 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2327 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2329 if ( strlen(s) == 1 && *s == '*' ) {
2330 si->si_allattrs = 1;
2331 *(val + ( s - str )) = delimstr[0];
2333 if ( strlen(s) == 1 && *s == '+' ) {
2334 si->si_allopattrs = 1;
2335 *(val + ( s - str )) = delimstr[0];
2339 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2340 if ( si->si_anlist == NULL ) {
2344 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2345 STRLENOF( EXATTRSSTR "=" ) ) )
2347 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2348 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2350 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2351 si->si_exanlist = file2anlist(
2352 si->si_exanlist, attr_fname, " ,\t" );
2353 if ( si->si_exanlist == NULL ) {
2354 ch_free( attr_fname );
2357 ch_free( attr_fname );
2359 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2360 if ( si->si_exanlist == NULL ) {
2364 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2365 STRLENOF( TYPESTR "=" ) ) )
2367 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2368 if ( !strncasecmp( val, "refreshOnly",
2369 STRLENOF("refreshOnly") ))
2371 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2372 } else if ( !strncasecmp( val, "refreshAndPersist",
2373 STRLENOF("refreshAndPersist") ))
2375 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2376 si->si_interval = 60;
2378 fprintf( stderr, "Error: parse_syncrepl_line: "
2379 "unknown sync type \"%s\"\n", val);
2382 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2383 STRLENOF( INTERVALSTR "=" ) ) )
2385 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2386 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2387 si->si_interval = 0;
2395 hstr = strchr( dstr, ':' );
2396 if ( hstr == NULL ) {
2397 fprintf( stderr, "Error: parse_syncrepl_line: "
2398 "invalid interval \"%s\"\n", val );
2402 mstr = strchr( hstr, ':' );
2403 if ( mstr == NULL ) {
2404 fprintf( stderr, "Error: parse_syncrepl_line: "
2405 "invalid interval \"%s\"\n", val );
2409 sstr = strchr( mstr, ':' );
2410 if ( sstr == NULL ) {
2411 fprintf( stderr, "Error: parse_syncrepl_line: "
2412 "invalid interval \"%s\"\n", val );
2421 if (( hh > 24 ) || ( hh < 0 ) ||
2422 ( mm > 60 ) || ( mm < 0 ) ||
2423 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2424 fprintf( stderr, "Error: parse_syncrepl_line: "
2425 "invalid interval \"%s\"\n", val );
2428 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2430 if ( si->si_interval < 0 ) {
2431 fprintf( stderr, "Error: parse_syncrepl_line: "
2432 "invalid interval \"%ld\"\n",
2433 (long) si->si_interval);
2436 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2437 STRLENOF( RETRYSTR "=" ) ) )
2442 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2443 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2444 retry_list[0] = NULL;
2446 slap_str2clist( &retry_list, val, " ,\t" );
2448 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2452 "Error: incomplete syncrepl retry list\n" );
2453 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2454 ch_free( retry_list[k] );
2456 ch_free( retry_list );
2457 exit( EXIT_FAILURE );
2459 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2460 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2461 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2462 for ( j = 0; j < n; j++ ) {
2463 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2464 if ( *retry_list[j*2+1] == '+' ) {
2465 si->si_retrynum_init[j] = -1;
2466 si->si_retrynum[j] = -1;
2470 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2471 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2474 si->si_retrynum_init[j] = -2;
2475 si->si_retrynum[j] = -2;
2476 si->si_retryinterval[j] = 0;
2478 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2479 ch_free( retry_list[k] );
2481 ch_free( retry_list );
2482 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2483 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2485 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2486 si->si_manageDSAit = atoi( val );
2487 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2488 STRLENOF( SLIMITSTR "=") ) )
2490 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2491 si->si_slimit = atoi( val );
2492 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2493 STRLENOF( TLIMITSTR "=" ) ) )
2495 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2496 si->si_tlimit = atoi( val );
2497 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2498 fprintf( stderr, "Error: parse_syncrepl_line: "
2499 "unknown keyword \"%s\"\n", cargv[ i ] );
2504 if ( gots != GOT_ALL ) {
2506 "Error: Malformed \"syncrepl\" line in slapd config file" );
2514 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2517 char buf[BUFSIZ*2], *ptr;
2520 bindconf_unparse( &si->si_bindconf, &bc );
2522 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
2523 si->si_rid, si->si_provideruri.bv_val );
2524 if ( !BER_BVISNULL( &bc )) {
2525 ptr = lutil_strcopy( ptr, bc.bv_val );
2528 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2529 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2530 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2533 if ( !BER_BVISNULL( &si->si_base )) {
2534 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2535 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2538 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2539 if ( si->si_scope == scopes[i].val ) {
2540 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2541 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2545 if ( si->si_attrsonly ) {
2546 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2548 if ( si->si_anfile ) {
2549 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2550 ptr = lutil_strcopy( ptr, si->si_anfile );
2551 } else if ( si->si_allattrs || si->si_allopattrs ||
2552 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2554 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2556 ptr = anlist_unparse( si->si_anlist, ptr );
2557 if ( si->si_allattrs ) {
2558 if ( old != ptr ) *ptr++ = ',';
2561 if ( si->si_allopattrs ) {
2562 if ( old != ptr ) *ptr++ = ',';
2567 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
2568 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
2569 ptr = anlist_unparse( si->si_exanlist, ptr );
2571 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
2572 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
2574 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
2575 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
2576 "refreshAndPersist" : "refreshOnly" );
2578 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
2581 dd = si->si_interval;
2588 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
2589 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
2590 } else if ( si->si_retryinterval ) {
2592 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
2593 for (i=0; si->si_retryinterval[i]; i++) {
2594 if ( space ) *ptr++ = ' ';
2596 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
2597 if ( si->si_retrynum_init[i] == -1 )
2600 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
2605 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
2606 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
2607 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
2610 if ( si->si_slimit ) {
2611 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
2612 ptr += sprintf( ptr, "%d", si->si_slimit );
2615 if ( si->si_tlimit ) {
2616 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
2617 ptr += sprintf( ptr, "%d", si->si_tlimit );
2619 bc.bv_len = ptr - buf;
2621 ber_dupbv( bv, &bc );
2624 static CfEntryInfo *
2625 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2635 if ( dn_match( &root->ce_entry->e_nname, dn ))
2638 c = dn->bv_val+dn->bv_len;
2639 for (;*c != ',';c--);
2643 for (--c;c>dn->bv_val && *c != ',';c--);
2647 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2649 root = root->ce_kids;
2651 for (;root;root=root->ce_sibs) {
2652 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2653 if ( cdn.bv_val == dn->bv_val ) {
2664 config_ldif_resp( Operation *op, SlapReply *rs )
2666 if ( rs->sr_type == REP_SEARCH ) {
2667 CfBackInfo *cfb = op->o_callback->sc_private;
2669 cfb->cb_got_ldif = 1;
2670 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL );
2675 /* Configure and read the underlying back-ldif store */
2677 config_setup_ldif( BackendDB *be, const char *dir ) {
2678 CfBackInfo *cfb = be->be_private;
2683 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2684 Connection conn = {0};
2685 char opbuf[OPERATION_BUFFER_SIZE];
2687 SlapReply rs = {REP_RESULT};
2688 Filter filter = { LDAP_FILTER_PRESENT };
2689 struct berval filterstr = BER_BVC("(objectclass=*)");
2691 cfb->cb_db.bd_info = backend_info( "ldif" );
2692 if ( !cfb->cb_db.bd_info )
2693 return 0; /* FIXME: eventually this will be a fatal error */
2695 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2697 /* Mark that back-ldif type is in use */
2698 cfb->cb_db.bd_info->bi_nDB++;
2700 cfb->cb_db.be_suffix = be->be_suffix;
2701 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2702 cfb->cb_db.be_rootdn = be->be_rootdn;
2703 cfb->cb_db.be_rootndn = be->be_rootndn;
2705 ber_str2bv( dir, 0, 1, &cfdir );
2710 argv[0] = "directory";
2711 argv[1] = (char *)dir;
2715 ct = config_find_keyword( c.be->be_cf_table, &c );
2719 if ( config_add_vals( ct, &c ))
2722 if ( backend_startup_one( &cfb->cb_db ))
2725 op = (Operation *)opbuf;
2726 connection_fake_init( &conn, op, cfb );
2728 filter.f_desc = slap_schema.si_ad_objectClass;
2730 op->o_tag = LDAP_REQ_SEARCH;
2732 op->ors_filter = &filter;
2733 op->ors_filterstr = filterstr;
2734 op->ors_scope = LDAP_SCOPE_SUBTREE;
2736 op->o_dn = be->be_rootdn;
2737 op->o_ndn = be->be_rootndn;
2739 op->o_req_dn = be->be_suffix[0];
2740 op->o_req_ndn = be->be_nsuffix[0];
2742 op->ors_tlimit = SLAP_NO_LIMIT;
2743 op->ors_slimit = SLAP_NO_LIMIT;
2745 op->ors_attrs = slap_anlist_all_attributes;
2746 op->ors_attrsonly = 0;
2748 op->o_callback = &cb;
2749 cb.sc_private = cfb;
2751 op->o_bd = &cfb->cb_db;
2752 op->o_bd->be_search( op, &rs );
2758 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2759 const CfOcInfo *co1 = c1;
2760 const CfOcInfo *co2 = c2;
2762 return ber_bvcmp( co1->co_name, co2->co_name );
2766 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2770 i = init_config_attrs( ct );
2773 /* set up the objectclasses */
2774 i = init_config_ocs( ocs );
2777 for (i=0; ocs[i].def; i++) {
2779 co = ch_malloc( sizeof(CfOcInfo) );
2780 co->co_oc = *ocs[i].oc;
2781 co->co_name = &co->co_oc->soc_cname;
2783 co->co_type = ocs[i].cft;
2784 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2791 read_config(const char *fname, const char *dir) {
2795 /* Setup the config backend */
2796 be = backend_db_init( "config" );
2800 cfb = be->be_private;
2802 /* Setup the underlying back-ldif backend */
2803 if ( config_setup_ldif( be, dir ))
2806 #ifdef SLAP_USE_CONFDIR
2807 /* If we read the config from back-ldif, nothing to do here */
2808 if ( cfb->cb_got_ldif )
2811 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2813 return read_config_file(fname, 0, NULL);
2817 config_back_bind( Operation *op, SlapReply *rs )
2819 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2820 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2821 /* frontend sends result */
2822 return LDAP_SUCCESS;
2825 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2826 send_ldap_result( op, rs );
2832 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2836 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2838 rs->sr_attrs = op->ors_attrs;
2839 rs->sr_entry = ce->ce_entry;
2840 rc = send_search_entry( op, rs );
2842 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2843 if ( ce->ce_kids ) {
2844 rc = config_send( op, rs, ce->ce_kids, 1 );
2845 if ( rc ) return rc;
2848 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2849 rc = config_send( op, rs, ce, 0 );
2857 static ConfigTable *
2858 config_find_table( CfOcInfo *co, AttributeDescription *ad )
2862 for (i=0; co->co_table[i].name; i++)
2863 if ( co->co_table[i].ad == ad )
2864 return &co->co_table[i];
2868 /* Sort the values in an X-ORDERED VALUES attribute.
2869 * If the values have no index, leave them in their given order.
2870 * If the values have indexes, sort them.
2871 * If some are indexed and some are not, return Error.
2873 * FIXME: This function probably belongs in the frontend somewhere,
2874 * like slap_mods_check.
2877 sort_vals( Attribute *a )
2880 int index = 0, noindex = 0;
2882 /* count attrs, look for index */
2883 for (i=0; a->a_vals[i].bv_val; i++) {
2884 if ( a->a_vals[i].bv_val[0] == '{' ) {
2887 ptr = strchr( a->a_vals[i].bv_val, '}' );
2888 if ( !ptr || !ptr[1] )
2889 return LDAP_INVALID_SYNTAX;
2891 return LDAP_INVALID_SYNTAX;
2895 return LDAP_INVALID_SYNTAX;
2900 int vals = i, *indexes, j, idx;
2901 struct berval tmp, ntmp;
2905 /* Strip index from normalized values */
2906 if ( !a->a_nvals || a->a_vals == a->a_nvals ) {
2907 a->a_nvals = ch_malloc( (vals+1)*sizeof(struct berval));
2908 BER_BVZERO(a->a_nvals+vals);
2909 for ( i=0; i<vals; i++ ) {
2910 ptr = strchr(a->a_vals[i].bv_val, '}') + 1;
2911 a->a_nvals[i].bv_len = a->a_vals[i].bv_len -
2912 (ptr - a->a_vals[i].bv_val);
2913 a->a_nvals[i].bv_val = ch_malloc( a->a_nvals[i].bv_len + 1);
2914 strcpy(a->a_nvals[i].bv_val, ptr );
2917 for ( i=0; i<vals; i++ ) {
2918 ptr = strchr(a->a_nvals[i].bv_val, '}') + 1;
2919 a->a_nvals[i].bv_len -= ptr - a->a_nvals[i].bv_val;
2920 strcpy(a->a_nvals[i].bv_val, ptr);
2925 indexes = ch_malloc( vals * sizeof(int) );
2926 for ( i=0; i<vals; i++)
2927 indexes[i] = atoi(a->a_vals[i].bv_val+1);
2929 /* Insertion sort */
2930 for ( i=1; i<vals; i++ ) {
2933 ntmp = a->a_nvals[i];
2935 while ((j > 0) && (indexes[j-1] > idx)) {
2936 indexes[j] = indexes[j-1];
2937 a->a_vals[j] = a->a_vals[j-1];
2938 a->a_nvals[j] = a->a_nvals[j-1];
2943 a->a_nvals[j] = ntmp;
2949 /* Sort the attributes of the entry according to the order defined
2950 * in the objectclass, with required attributes occurring before
2951 * allowed attributes. For any attributes with sequencing dependencies
2952 * (e.g., rootDN must be defined after suffix) the objectclass must
2953 * list the attributes in the desired sequence.
2956 sort_attrs( Entry *e, CfOcInfo **colst, int nocs )
2958 Attribute *a, *head = NULL, *tail = NULL, **prev;
2961 for (i=0; i<nocs; i++) {
2962 if ( colst[i]->co_oc->soc_required ) {
2963 AttributeType **at = colst[i]->co_oc->soc_required;
2964 for (j=0; at[j]; j++) {
2965 for (a=e->e_attrs, prev=&e->e_attrs; a;
2966 prev = &(*prev)->a_next, a=a->a_next) {
2967 if ( a->a_desc == at[j]->sat_ad ) {
2981 if ( colst[i]->co_oc->soc_allowed ) {
2982 AttributeType **at = colst[i]->co_oc->soc_allowed;
2983 for (j=0; at[j]; j++) {
2984 for (a=e->e_attrs, prev=&e->e_attrs; a;
2985 prev = &(*prev)->a_next, a=a->a_next) {
2986 if ( a->a_desc == at[j]->sat_ad ) {
3002 tail->a_next = e->e_attrs;
3008 check_attr( ConfigTable *ct, ConfigArgs *ca, Attribute *a )
3010 int i, rc = 0, sort = 0;
3012 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3014 rc = sort_vals( a );
3018 for ( i=0; a->a_nvals[i].bv_val; i++ ) {
3019 ca->line = a->a_nvals[i].bv_val;
3020 if ( sort ) ca->line = strchr( ca->line, '}' ) + 1;
3021 rc = config_parse_vals( ct, ca, i );
3029 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3030 SlapReply *rs, int *renum )
3033 int index = -1, gotindex = 0, nsibs;
3034 int renumber = 0, tailindex = 0;
3038 if ( renum ) *renum = 0;
3040 /* These entries don't get indexed/renumbered */
3041 if ( ce_type == Cft_Global ) return 0;
3042 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3044 if ( ce_type == Cft_Include || ce_type == Cft_Module )
3047 /* See if the rdn has an index already */
3048 dnRdn( &e->e_name, &rdn );
3049 ptr1 = strchr( e->e_name.bv_val, '{' );
3050 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3051 ptr2 = strchr( ptr1, '}' );
3052 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3053 return LDAP_NAMING_VIOLATION;
3054 if ( ptr2-ptr1 == 1)
3055 return LDAP_NAMING_VIOLATION;
3057 index = atoi(ptr1+1);
3059 return LDAP_NAMING_VIOLATION;
3062 /* count related kids */
3063 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3064 if ( ce->ce_type == ce_type ) nsibs++;
3067 if ( index != nsibs ) {
3069 if ( index < nsibs ) {
3070 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3071 /* Siblings need to be renumbered */
3076 struct berval ival, newrdn, nnewrdn;
3077 struct berval rtype, rval;
3079 AttributeDescription *ad = NULL;
3083 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
3084 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
3085 rtype.bv_val = rdn.bv_val;
3086 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3089 slap_bv2ad( &rtype, &ad, &text );
3090 a = attr_find( e->e_attrs, ad );
3091 if (!a ) return LDAP_NAMING_VIOLATION;
3094 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
3096 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3097 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3100 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3101 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3108 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3110 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
3113 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3114 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3118 /* Do the equivalent of ModRDN */
3119 /* Replace DN / NDN */
3120 newrdn.bv_len = ptr1 - newrdn.bv_val;
3121 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3122 free( e->e_name.bv_val );
3123 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
3125 free( e->e_nname.bv_val );
3126 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
3130 free( a->a_vals[0].bv_val );
3131 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
3132 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
3133 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3134 strcpy( a->a_vals[0].bv_val, ptr1 );
3136 if ( a->a_nvals != a->a_vals ) {
3137 free( a->a_nvals[0].bv_val );
3138 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
3139 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
3140 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3141 strcpy( a->a_nvals[0].bv_val, ptr1 );
3143 free( nnewrdn.bv_val );
3144 free( newrdn.bv_val );
3147 if ( renum ) *renum = renumber;
3151 /* Parse an LDAP entry into config directives */
3153 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
3155 CfEntryInfo *ce, *last;
3156 CfOcInfo co, *coptr, **colst = NULL;
3157 Attribute *a, *oc_at, *type_attr;
3158 AttributeDescription *type_ad = NULL;
3160 ConfigArgs ca = {0};
3163 ConfigTable *ct, *type_ct = NULL;
3165 /* Make sure parent exists and entry does not */
3166 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3168 return LDAP_ALREADY_EXISTS;
3170 dnParent( &e->e_nname, &pdn );
3172 /* If last is NULL, the new entry is the root/suffix entry,
3173 * otherwise last should be the parent.
3175 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
3177 rs->sr_matched = last->ce_entry->e_name.bv_val;
3178 return LDAP_NO_SUCH_OBJECT;
3181 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3182 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3184 /* count the objectclasses */
3185 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
3187 colst = (CfOcInfo **)ch_malloc( nocs * sizeof(CfOcInfo *));
3189 for ( i=0, j=0; i<nocs; i++) {
3190 co.co_name = &oc_at->a_nvals[i];
3191 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
3193 /* ignore non-config objectclasses. probably should be
3194 * an error, general data doesn't belong here.
3196 if ( !coptr ) continue;
3198 /* Ignore the root objectclass, it has no implementation.
3200 if ( coptr->co_type == Cft_Abstract ) continue;
3205 /* Only the root can be Cft_Global, everything else must
3206 * have a parent. Only limited nesting arrangements are allowed.
3208 switch( colst[0]->co_type ) {
3211 rc = LDAP_CONSTRAINT_VIOLATION;
3219 if ( !last || ( last->ce_type != Cft_Global &&
3220 last->ce_type != colst[0]->co_type )) {
3221 rc = LDAP_CONSTRAINT_VIOLATION;
3226 if ( !last || ( last->ce_type != Cft_Global &&
3227 last->ce_type != Cft_Database &&
3228 last->ce_type != colst[0]->co_type )) {
3229 rc = LDAP_CONSTRAINT_VIOLATION;
3233 #ifdef SLAPD_MODULES
3235 if ( !last || last->ce_type != Cft_Global ) {
3236 rc = LDAP_CONSTRAINT_VIOLATION;
3243 sort_attrs( e, colst, nocs );
3245 /* Parse all the values and check for simple syntax errors before
3246 * performing any set actions.
3248 switch (colst[0]->co_type) {
3250 /* The cn=schema entry is all hardcoded, so never reparse it */
3251 if (last->ce_type == Cft_Global )
3255 ca.be = LDAP_STAILQ_FIRST(&backendDB);
3259 if ( last->ce_type == Cft_Backend )
3260 ca.bi = last->ce_bi;
3262 type_ad = cfAd_backend;
3265 if ( last->ce_type == Cft_Database ) {
3266 ca.be = last->ce_be;
3268 type_ad = cfAd_database;
3269 /* dummy, just to get past check_attr */
3275 ca.be = last->ce_be;
3276 type_ad = cfAd_overlay;
3280 if ( !rs ) /* ignored */
3282 type_ad = cfAd_include;
3284 #ifdef SLAPD_MODULES
3288 ptr = strchr( e->e_name.bv_val, '{' );
3290 rc = LDAP_NAMING_VIOLATION;
3294 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
3295 /* There is no corresponding modpath for this load? */
3297 rc = LDAP_NAMING_VIOLATION;
3300 module_path( mp->mp_path.bv_val );
3307 /* If doing an LDAPadd, check for indexed names and any necessary
3308 * renaming/renumbering. Entries that don't need indexed names are
3309 * ignored. Entries that need an indexed name and arrive without one
3310 * are assigned to the end. Entries that arrive with an index may
3311 * cause the following entries to be renumbered/bumped down.
3313 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
3314 * don't allow Adding an entry with an index that's already in use.
3315 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3317 * These entries can have auto-assigned indexes (appended to the end)
3318 * but only the other types support auto-renumbering of siblings.
3320 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3324 init_config_argv( &ca );
3326 type_attr = attr_find( e->e_attrs, type_ad );
3328 rc = LDAP_OBJECT_CLASS_VIOLATION;
3331 for ( i=0; i<nocs; i++ ) {
3332 type_ct = config_find_table( colst[i], type_ad );
3333 if ( type_ct ) break;
3336 rc = LDAP_OBJECT_CLASS_VIOLATION;
3339 rc = check_attr( type_ct, &ca, type_attr );
3340 if ( rc ) goto leave;
3342 for ( a=e->e_attrs; a; a=a->a_next ) {
3343 if ( a == type_attr || a == oc_at ) continue;
3345 for ( i=0; i<nocs; i++ ) {
3346 ct = config_find_table( colst[i], a->a_desc );
3349 if ( !ct ) continue; /* user data? */
3350 rc = check_attr( ct, &ca, a );
3351 if ( rc ) goto leave;
3354 /* Basic syntax checks are OK. Do the actual settings. */
3356 ca.line = type_attr->a_vals[0].bv_val;
3357 if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED )
3358 ca.line = strchr( ca.line, '}' ) + 1;
3359 rc = config_parse_add( type_ct, &ca, 0 );
3365 for ( a=e->e_attrs; a; a=a->a_next ) {
3366 if ( a == type_attr || a == oc_at ) continue;
3368 for ( i=0; i<nocs; i++ ) {
3369 ct = config_find_table( colst[i], a->a_desc );
3372 if ( !ct ) continue; /* user data? */
3373 for (i=0; a->a_vals[i].bv_val; i++) {
3374 ca.line = a->a_vals[i].bv_val;
3375 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED )
3376 ca.line = strchr( ca.line, '}' ) + 1;
3377 rc = config_parse_add( ct, &ca, i );
3385 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3386 ce->ce_parent = last;
3387 ce->ce_entry = entry_dup( e );
3388 ce->ce_entry->e_private = ce;
3389 ce->ce_type = colst[0]->co_type;
3392 } else if ( last->ce_kids ) {
3395 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3404 if ( colst ) ch_free( colst );
3408 /* Parse an LDAP entry into config directives, then store in underlying
3412 config_back_add( Operation *op, SlapReply *rs )
3415 CfEntryInfo *ce, *last;
3418 if ( !be_isroot( op ) ) {
3419 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3420 send_ldap_result( op, rs );
3423 cfb = (CfBackInfo *)op->o_bd->be_private;
3425 ldap_pvt_thread_pool_pause( &connection_pool );
3428 * 1) check for existence of entry
3429 * 2) check for sibling renumbering
3430 * 3) perform internal add
3431 * 4) store entry in underlying database
3432 * 5) perform any necessary renumbering
3434 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3435 if ( rs->sr_err == LDAP_SUCCESS ) {
3436 BackendDB *be = op->o_bd;
3437 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3438 op->o_bd = &cfb->cb_db;
3439 sc.sc_next = op->o_callback;
3440 op->o_callback = ≻
3441 op->o_bd->be_add( op, rs );
3443 op->o_callback = sc.sc_next;
3448 ldap_pvt_thread_pool_resume( &connection_pool );
3451 send_ldap_result( op, rs );
3456 * for single-valued attributes, should just use REPLACE.
3457 * any received DELETE/ADD on a single-valued attr will
3458 * be checked (if a DEL value is provided) and then
3459 * rewritten as a REPLACE.
3460 * any DELETE received without a corresponding ADD will be
3461 * rejected with LDAP_CONSTRAINT_VIOLATION.
3464 config_back_modify( Operation *op, SlapReply *rs )
3467 CfEntryInfo *ce, *last;
3469 if ( !be_isroot( op ) ) {
3470 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3471 send_ldap_result( op, rs );
3474 cfb = (CfBackInfo *)op->o_bd->be_private;
3476 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3479 rs->sr_matched = last->ce_entry->e_name.bv_val;
3480 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3483 ldap_pvt_thread_pool_pause( &connection_pool );
3486 * 1) perform the Modify on the cached Entry.
3487 * 2) verify that the Entry still satisfies the schema.
3488 * 3) perform the individual config operations.
3489 * 4) store Modified entry in underlying LDIF backend.
3491 ldap_pvt_thread_pool_resume( &connection_pool );
3493 send_ldap_result( op, rs );
3498 config_back_modrdn( Operation *op, SlapReply *rs )
3501 CfEntryInfo *ce, *last;
3503 if ( !be_isroot( op ) ) {
3504 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3505 send_ldap_result( op, rs );
3508 cfb = (CfBackInfo *)op->o_bd->be_private;
3510 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3513 rs->sr_matched = last->ce_entry->e_name.bv_val;
3514 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3518 /* We don't allow moving objects to new parents.
3519 * Generally we only allow reordering a set of ordered entries.
3521 if ( op->orr_newSup ) {
3522 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3525 ldap_pvt_thread_pool_pause( &connection_pool );
3527 ldap_pvt_thread_pool_resume( &connection_pool );
3529 send_ldap_result( op, rs );
3534 config_back_search( Operation *op, SlapReply *rs )
3537 CfEntryInfo *ce, *last;
3540 if ( !be_isroot( op ) ) {
3541 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3542 send_ldap_result( op, rs );
3545 cfb = (CfBackInfo *)op->o_bd->be_private;
3547 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3550 rs->sr_matched = last->ce_entry->e_name.bv_val;
3551 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3554 switch ( op->ors_scope ) {
3555 case LDAP_SCOPE_BASE:
3556 case LDAP_SCOPE_SUBTREE:
3557 config_send( op, rs, ce, 0 );
3560 case LDAP_SCOPE_ONELEVEL:
3561 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3562 config_send( op, rs, ce, 1 );
3567 rs->sr_err = LDAP_SUCCESS;
3569 send_ldap_result( op, rs );
3574 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3576 Entry *e = ch_calloc( 1, sizeof(Entry) );
3577 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3582 ce->ce_parent = parent;
3584 pdn = parent->ce_entry->e_nname;
3589 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3590 ber_dupbv( &e->e_nname, &e->e_name );
3599 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3600 struct berval *rdn, ConfigTable *ct, int table )
3602 struct berval vals[2];
3603 struct berval ad_name;
3604 AttributeDescription *ad = NULL;
3608 char textbuf[SLAP_TEXT_BUFLEN];
3609 size_t textlen = sizeof(textbuf);
3613 BER_BVZERO( &vals[1] );
3615 vals[0] = oc->soc_cname;
3616 attr_merge(e, slap_schema.si_ad_objectClass, vals, NULL );
3617 ptr = strchr(rdn->bv_val, '=');
3618 ad_name.bv_val = rdn->bv_val;
3619 ad_name.bv_len = ptr - rdn->bv_val;
3620 rc = slap_bv2ad( &ad_name, &ad, &text );
3624 vals[0].bv_val = ptr+1;
3625 vals[0].bv_len = rdn->bv_len - (vals[0].bv_val - rdn->bv_val);
3626 attr_merge(e, ad, vals, NULL );
3628 for (at=oc->soc_required; at && *at; at++) {
3629 /* Skip the naming attr */
3630 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3632 for (i=0;ct[i].name;i++) {
3633 if (ct[i].ad == (*at)->sat_ad) {
3634 rc = config_get_vals(&ct[i], c);
3635 if (rc == LDAP_SUCCESS) {
3636 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3637 ber_bvarray_free( c->rvalue_nvals );
3638 ber_bvarray_free( c->rvalue_vals );
3645 for (at=oc->soc_allowed; at && *at; at++) {
3646 /* Skip the naming attr */
3647 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3649 for (i=0;ct[i].name;i++) {
3650 if (ct[i].ad == (*at)->sat_ad) {
3651 rc = config_get_vals(&ct[i], c);
3652 if (rc == LDAP_SUCCESS) {
3653 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3654 ber_bvarray_free( c->rvalue_nvals );
3655 ber_bvarray_free( c->rvalue_vals );
3663 if ( table == BI_TABLE )
3664 ct = c->bi->bi_cf_table;
3666 ct = c->be->be_cf_table;
3667 for (;ct && ct->name;ct++) {
3668 if (!ct->ad) continue;
3669 rc = config_get_vals(ct, c);
3670 if (rc == LDAP_SUCCESS) {
3671 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3675 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3676 rc = structural_class(oc_at->a_vals, vals, NULL, &text, textbuf, textlen);
3677 BER_BVZERO( &vals[1] );
3678 attr_merge(e, slap_schema.si_ad_structuralObjectClass, vals, NULL );
3684 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3685 Operation *op, SlapReply *rs )
3688 ConfigFile *cf = c->private;
3689 CfEntryInfo *ce, *ceprev;
3693 if ( ceparent->ce_kids ) {
3694 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3695 ceprev = ceprev->ce_sibs );
3698 for (; cf; cf=cf->c_sibs, c->depth++) {
3699 c->value_dn.bv_val = c->log;
3700 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3705 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3707 ptr = strchr( bv.bv_val, '.' );
3709 bv.bv_len = ptr - bv.bv_val;
3710 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3711 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3713 c->value_dn.bv_len += bv.bv_len;
3714 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3716 e = config_alloc_entry( ceparent, &c->value_dn );
3718 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3719 c->bi->bi_cf_table, NO_TABLE );
3721 ce->ce_type = Cft_Schema;
3723 op->o_bd->be_add( op, rs );
3725 if ( !ceparent->ce_kids ) {
3726 ceparent->ce_kids = ce;
3728 ceprev->ce_sibs = ce;
3732 c->private = cf->c_kids;
3733 config_build_schema_inc( c, ceparent, op, rs );
3738 static CfEntryInfo *
3739 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3740 Operation *op, SlapReply *rs )
3744 ConfigFile *cf = c->private;
3745 CfEntryInfo *ce, *ceprev;
3747 if ( ceparent->ce_kids ) {
3748 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3749 ceprev = ceprev->ce_sibs );
3752 for (i=0; cf; cf=cf->c_sibs, i++) {
3753 c->value_dn.bv_val = c->log;
3754 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3755 e = config_alloc_entry( ceparent, &c->value_dn );
3757 config_build_entry( c, e, cfOc_include, &c->value_dn,
3758 c->bi->bi_cf_table, NO_TABLE );
3760 op->o_bd->be_add( op, rs );
3762 ce->ce_type = Cft_Include;
3764 if ( !ceparent->ce_kids ) {
3765 ceparent->ce_kids = ce;
3767 ceprev->ce_sibs = ce;
3771 c->private = cf->c_kids;
3772 config_build_includes( c, ce, op, rs );
3778 #ifdef SLAPD_MODULES
3780 static CfEntryInfo *
3781 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3782 Operation *op, SlapReply *rs )
3786 CfEntryInfo *ce, *ceprev;
3789 if ( ceparent->ce_kids ) {
3790 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3791 ceprev = ceprev->ce_sibs );
3794 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3795 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3797 c->value_dn.bv_val = c->log;
3798 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3799 e = config_alloc_entry( ceparent, &c->value_dn );
3801 ce->ce_type = Cft_Include;
3803 config_build_entry( c, e, cfOc_module, &c->value_dn,
3804 c->bi->bi_cf_table, NO_TABLE );
3806 op->o_bd->be_add( op, rs );
3808 if ( !ceparent->ce_kids ) {
3809 ceparent->ce_kids = ce;
3811 ceprev->ce_sibs = ce;
3820 config_back_db_open( BackendDB *be )
3822 CfBackInfo *cfb = be->be_private;
3825 CfEntryInfo *ce, *ceparent, *ceprev;
3831 Connection conn = {0};
3832 char opbuf[OPERATION_BUFFER_SIZE];
3834 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3835 SlapReply rs = {REP_RESULT};
3837 /* If we read the config from back-ldif, nothing to do here */
3838 if ( cfb->cb_got_ldif )
3841 op = (Operation *)opbuf;
3842 connection_fake_init( &conn, op, cfb );
3844 op->o_dn = be->be_rootdn;
3845 op->o_ndn = be->be_rootndn;
3847 op->o_tag = LDAP_REQ_ADD;
3848 op->o_callback = &cb;
3849 op->o_bd = &cfb->cb_db;
3851 /* create root of tree */
3853 e = config_alloc_entry( NULL, &rdn );
3855 ce->ce_type = Cft_Global;
3859 c.private = cfb->cb_config;
3860 ct = c.bi->bi_cf_table;
3861 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
3863 op->o_bd->be_add( op, &rs );
3869 /* Create schema nodes... cn=schema will contain the hardcoded core
3870 * schema, read-only. Child objects will contain runtime loaded schema
3874 e = config_alloc_entry( ceparent, &rdn );
3876 ce->ce_type = Cft_Schema;
3878 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
3880 op->o_bd->be_add( op, &rs );
3881 if ( !ceparent->ce_kids ) {
3882 ceparent->ce_kids = ce;
3884 ceprev->ce_sibs = ce;
3888 /* Create includeFile nodes and schema nodes for included schema... */
3889 if ( cfb->cb_config->c_kids ) {
3891 c.private = cfb->cb_config->c_kids;
3892 config_build_schema_inc( &c, ce, op, &rs );
3893 c.private = cfb->cb_config->c_kids;
3894 ceprev = config_build_includes( &c, ceparent, op, &rs );
3897 #ifdef SLAPD_MODULES
3898 /* Create Module nodes... */
3899 if ( modpaths.mp_loads ) {
3900 ceprev = config_build_modules( &c, ceparent, op, &rs );
3904 /* Create backend nodes. Skip if they don't provide a cf_table.
3905 * There usually aren't any of these.
3909 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3910 if (!bi->bi_cf_table) continue;
3911 if (!bi->bi_private) continue;
3914 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3915 e = config_alloc_entry( ceparent, &rdn );
3917 ce->ce_type = Cft_Backend;
3920 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3922 op->o_bd->be_add( op, &rs );
3923 if ( !ceparent->ce_kids ) {
3924 ceparent->ce_kids = ce;
3926 ceprev->ce_sibs = ce;
3931 /* Create database nodes... */
3933 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3934 slap_overinfo *oi = NULL;
3941 if ( overlay_is_over( bptr )) {
3942 oi = bptr->bd_info->bi_private;
3948 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3950 e = config_alloc_entry( ceparent, &rdn );
3954 ce->ce_type = Cft_Database;
3957 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3959 op->o_bd->be_add( op, &rs );
3960 if ( !ceparent->ce_kids ) {
3961 ceparent->ce_kids = ce;
3963 ceprev->ce_sibs = ce;
3966 /* Iterate through overlays */
3970 CfEntryInfo *opar = ce, *oprev = NULL;
3973 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3975 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
3976 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3977 oe = config_alloc_entry( opar, &rdn );
3981 ce->ce_type = Cft_Overlay;
3984 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
3986 op->o_bd->be_add( op, &rs );
3987 if ( !opar->ce_kids ) {
3990 oprev->ce_sibs = ce;
4001 config_back_db_destroy( Backend *be )
4003 free( be->be_private );
4008 config_back_db_init( Backend *be )
4013 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4014 cfb->cb_config = &cf_prv;
4015 be->be_private = cfb;
4017 ber_dupbv( &be->be_rootdn, &config_rdn );
4018 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4019 ber_dupbv( &dn, &be->be_rootdn );
4020 ber_bvarray_add( &be->be_suffix, &dn );
4021 ber_dupbv( &dn, &be->be_rootdn );
4022 ber_bvarray_add( &be->be_nsuffix, &dn );
4024 /* Hide from namingContexts */
4025 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4032 AttributeDescription **desc;
4034 { "backend", &cfAd_backend },
4035 { "database", &cfAd_database },
4036 { "include", &cfAd_include },
4037 { "overlay", &cfAd_overlay },
4042 * add / delete: all types that may be added or deleted must use an
4043 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4044 * should automatically renumber the index of any siblings as needed,
4045 * so that no gaps in the numbering sequence exist after the add/delete
4047 * What can be added:
4049 * backend objects for backend-specific config directives
4053 * delete: probably no support this time around.
4055 * modrdn: generally not done. Will be invoked automatically by add/
4056 * delete to update numbering sequence. Perform as an explicit operation
4057 * so that the renumbering effect may be replicated. Subtree rename must
4058 * be supported, since renumbering a database will affect all its child
4061 * modify: must be fully supported.
4065 config_back_initialize( BackendInfo *bi )
4067 ConfigTable *ct = config_back_cf_table;
4070 static char *controls[] = {
4071 LDAP_CONTROL_MANAGEDSAIT,
4075 bi->bi_controls = controls;
4082 bi->bi_db_init = config_back_db_init;
4083 bi->bi_db_config = 0;
4084 bi->bi_db_open = config_back_db_open;
4085 bi->bi_db_close = 0;
4086 bi->bi_db_destroy = config_back_db_destroy;
4088 bi->bi_op_bind = config_back_bind;
4089 bi->bi_op_unbind = 0;
4090 bi->bi_op_search = config_back_search;
4091 bi->bi_op_compare = 0;
4092 bi->bi_op_modify = config_back_modify;
4093 bi->bi_op_modrdn = config_back_modrdn;
4094 bi->bi_op_add = config_back_add;
4095 bi->bi_op_delete = 0;
4096 bi->bi_op_abandon = 0;
4098 bi->bi_extended = 0;
4100 bi->bi_chk_referrals = 0;
4102 bi->bi_connection_init = 0;
4103 bi->bi_connection_destroy = 0;
4106 for (i=0; OidMacros[i].name; i++ ) {
4107 argv[1] = OidMacros[i].name;
4108 argv[2] = OidMacros[i].oid;
4109 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4112 bi->bi_cf_table = ct;
4114 i = config_register_schema( ct, cf_ocs );
4117 /* set up the notable AttributeDescriptions */
4119 for (;ct->name;ct++) {
4120 if (strcmp(ct->name, ads[i].name)) continue;
4121 *ads[i].desc = ct->ad;
4123 if (!ads[i].name) break;