1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 #define CONFIG_RDN "cn=config"
41 #define SCHEMA_RDN "cn=schema"
43 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
44 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
46 extern int slap_DN_strict; /* dn.c */
49 typedef struct modpath_s {
50 struct modpath_s *mp_next;
51 struct berval mp_path;
55 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 typedef struct ConfigFile {
59 struct ConfigFile *c_sibs;
60 struct ConfigFile *c_kids;
62 AttributeType *c_at_head, *c_at_tail;
63 ContentRule *c_cr_head, *c_cr_tail;
64 ObjectClass *c_oc_head, *c_oc_tail;
65 OidMacro *c_om_head, *c_om_tail;
70 ConfigFile *cb_config;
72 BackendDB cb_db; /* underlying database */
77 static CfBackInfo cfBackInfo;
79 static char *passwd_salt;
80 static char *logfileName;
81 #ifdef SLAP_AUTH_REWRITE
82 static BerVarray authz_rewrites;
85 static struct berval cfdir;
88 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
89 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om;
91 static ConfigFile *cfn;
93 static Avlnode *CfOcTree;
95 /* System schema state */
96 extern AttributeType *at_sys_tail; /* at.c */
97 extern ObjectClass *oc_sys_tail; /* oc.c */
98 extern OidMacro *om_sys_tail; /* oidm.c */
99 static AttributeType *cf_at_tail;
100 static ObjectClass *cf_oc_tail;
101 static OidMacro *cf_om_tail;
103 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
104 SlapReply *rs, int *renumber, Operation *op );
106 static int config_check_schema( Operation *op, CfBackInfo *cfb );
108 static ConfigDriver config_fname;
109 static ConfigDriver config_cfdir;
110 static ConfigDriver config_generic;
111 static ConfigDriver config_search_base;
112 static ConfigDriver config_passwd_hash;
113 static ConfigDriver config_schema_dn;
114 static ConfigDriver config_sizelimit;
115 static ConfigDriver config_timelimit;
116 static ConfigDriver config_overlay;
117 static ConfigDriver config_subordinate;
118 static ConfigDriver config_suffix;
119 static ConfigDriver config_rootdn;
120 static ConfigDriver config_rootpw;
121 static ConfigDriver config_restrict;
122 static ConfigDriver config_allows;
123 static ConfigDriver config_disallows;
124 static ConfigDriver config_requires;
125 static ConfigDriver config_security;
126 static ConfigDriver config_referral;
127 static ConfigDriver config_loglevel;
128 static ConfigDriver config_updatedn;
129 static ConfigDriver config_updateref;
130 static ConfigDriver config_include;
131 static ConfigDriver config_obsolete;
133 static ConfigDriver config_tls_option;
134 static ConfigDriver config_tls_config;
136 extern ConfigDriver syncrepl_config;
188 static OidRec OidMacros[] = {
189 /* OpenLDAProot:666.11.1 */
190 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
191 { "OLcfgAt", "OLcfg:3" },
192 { "OLcfgGlAt", "OLcfgAt:0" },
193 { "OLcfgBkAt", "OLcfgAt:1" },
194 { "OLcfgDbAt", "OLcfgAt:2" },
195 { "OLcfgOvAt", "OLcfgAt:3" },
196 { "OLcfgOc", "OLcfg:4" },
197 { "OLcfgGlOc", "OLcfgOc:0" },
198 { "OLcfgBkOc", "OLcfgOc:1" },
199 { "OLcfgDbOc", "OLcfgOc:2" },
200 { "OLcfgOvOc", "OLcfgOc:3" },
202 /* Syntaxes. We should just start using the standard names and
203 * document that they are predefined and available for users
204 * to reference in their own schema. Defining schema without
205 * OID macros is for masochists...
207 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
208 { "OMsBoolean", "OMsyn:7" },
209 { "OMsDN", "OMsyn:12" },
210 { "OMsDirectoryString", "OMsyn:15" },
211 { "OMsInteger", "OMsyn:27" },
212 { "OMsOID", "OMsyn:38" },
213 { "OMsOctetString", "OMsyn:40" },
218 * Backend/Database registry
220 * OLcfg{Bk|Db}{Oc|At}:0 -> common
221 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
222 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
223 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
224 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
230 * OLcfgOv{Oc|At}:1 -> syncprov
231 * OLcfgOv{Oc|At}:2 -> pcache
232 * OLcfgOv{Oc|At}:3 -> chain
233 * OLcfgOv{Oc|At}:4 -> accesslog
234 * OLcfgOv{Oc|At}:5 -> valsort
235 * (FIXME: separate arc for contribware?)
236 * OLcfgOv{Oc|At}:6 -> smbk5pwd
237 * OLcfgOv{Oc|At}:7 -> distproc
238 * OLcfgOv{Oc|At}:8 -> dynlist
239 * OLcfgOv{Oc|At}:9 -> dds
240 * OLcfgOv{Oc|At}:10 -> unique
241 * OLcfgOv{Oc|At}:11 -> refint
242 * OLcfgOv{Oc|At}:12 -> ppolicy
243 * OLcfgOv{Oc|At}:13 -> constraint
244 * OLcfgOv{Oc|At}:14 -> translucent
245 * OLcfgOv{Oc|At}:15 -> auditlog
248 /* alphabetical ordering */
250 static ConfigTable config_back_cf_table[] = {
251 /* This attr is read-only */
252 { "", "", 0, 0, 0, ARG_MAGIC,
253 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
254 "DESC 'File for slapd configuration directives' "
255 "EQUALITY caseIgnoreMatch "
256 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
257 { "", "", 0, 0, 0, ARG_MAGIC,
258 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
259 "DESC 'Directory for slapd configuration backend' "
260 "EQUALITY caseIgnoreMatch "
261 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
262 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
263 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
264 "DESC 'Access Control List' "
265 "EQUALITY caseIgnoreMatch "
266 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
267 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
268 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
269 "DESC 'Allowed set of deprecated features' "
270 "EQUALITY caseIgnoreMatch "
271 "SYNTAX OMsDirectoryString )", NULL, NULL },
272 { "argsfile", "file", 2, 2, 0, ARG_STRING,
273 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
274 "DESC 'File for slapd command line options' "
275 "EQUALITY caseIgnoreMatch "
276 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
277 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
278 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
279 "EQUALITY caseIgnoreMatch "
280 "SYNTAX OMsDirectoryString )", NULL, NULL },
281 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
282 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
283 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
284 "DESC 'OpenLDAP attributeTypes' "
285 "EQUALITY caseIgnoreMatch "
286 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
288 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
289 #ifdef SLAP_AUTH_REWRITE
290 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
294 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
295 "EQUALITY caseIgnoreMatch "
296 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
297 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
298 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
299 "EQUALITY caseIgnoreMatch "
300 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
301 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
302 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
303 "EQUALITY caseIgnoreMatch "
304 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
305 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
306 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
307 "DESC 'A type of backend' "
308 "EQUALITY caseIgnoreMatch "
309 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
311 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
312 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
313 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
314 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
315 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
316 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
317 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
318 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
319 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
320 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
321 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
322 "DESC 'The backend type for a database instance' "
323 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
324 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
325 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
326 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
327 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
328 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
329 "EQUALITY caseIgnoreMatch "
330 "SYNTAX OMsDirectoryString )", NULL, NULL },
331 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
332 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
333 "DESC 'OpenLDAP DIT content rules' "
334 "EQUALITY caseIgnoreMatch "
335 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
337 { "gentlehup", "on|off", 2, 2, 0,
339 ARG_ON_OFF, &global_gentlehup,
343 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
344 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
345 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
346 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
347 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
348 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
349 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
350 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
351 { "include", "file", 2, 2, 0, ARG_MAGIC,
352 &config_include, NULL, NULL, NULL },
353 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
354 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
355 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
356 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
357 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
358 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
359 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
360 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
361 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
362 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
363 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
364 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
365 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
366 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
367 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
368 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
369 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
370 "EQUALITY caseIgnoreMatch "
371 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
372 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
373 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
374 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
375 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
376 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
377 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
378 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
379 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
380 "EQUALITY caseIgnoreMatch "
381 "SYNTAX OMsDirectoryString )", NULL, NULL },
382 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
383 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
384 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
385 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
386 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
387 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
388 { "moduleload", "file", 2, 0, 0,
390 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
394 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
395 "EQUALITY caseIgnoreMatch "
396 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
397 { "modulepath", "path", 2, 2, 0,
399 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
403 "( OLcfgGlAt:31 NAME 'olcModulePath' "
404 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
405 { "monitoring", "TRUE|FALSE", 2, 2, 0,
406 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
407 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
408 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
409 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
410 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
411 "DESC 'OpenLDAP object classes' "
412 "EQUALITY caseIgnoreMatch "
413 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
415 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
416 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
417 "EQUALITY caseIgnoreMatch "
418 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
419 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
420 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
421 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
422 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
423 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
424 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
425 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
426 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
427 "EQUALITY caseIgnoreMatch "
428 "SYNTAX OMsDirectoryString )", NULL, NULL },
429 { "pidfile", "file", 2, 2, 0, ARG_STRING,
430 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
431 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
432 { "plugin", NULL, 0, 0, 0,
434 ARG_MAGIC|CFG_PLUGIN, &config_generic,
438 "( OLcfgGlAt:38 NAME 'olcPlugin' "
439 "EQUALITY caseIgnoreMatch "
440 "SYNTAX OMsDirectoryString )", NULL, NULL },
441 { "pluginlog", "filename", 2, 2, 0,
443 ARG_STRING, &slapi_log_file,
447 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
448 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
449 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
450 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
451 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
452 { "referral", "url", 2, 2, 0, ARG_MAGIC,
453 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
454 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
455 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
456 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
457 "EQUALITY caseIgnoreMatch "
458 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
459 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
460 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
461 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
462 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
463 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
464 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
465 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
466 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
467 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
468 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
469 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
470 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
471 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
472 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
473 "EQUALITY caseIgnoreMatch "
474 "SYNTAX OMsDirectoryString )", NULL, NULL },
475 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
476 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
477 "EQUALITY caseIgnoreMatch "
478 "SYNTAX OMsDirectoryString )", NULL, NULL },
479 { "reverse-lookup", "on|off", 2, 2, 0,
480 #ifdef SLAPD_RLOOKUPS
481 ARG_ON_OFF, &use_reverse_lookup,
485 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
486 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
487 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
488 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
489 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
490 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
491 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
492 "EQUALITY caseIgnoreMatch "
493 "SYNTAX OMsDirectoryString )", NULL, NULL },
494 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
495 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
496 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
497 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
498 &config_generic, NULL, NULL, NULL },
499 { "sasl-host", "host", 2, 2, 0,
500 #ifdef HAVE_CYRUS_SASL
501 ARG_STRING|ARG_UNIQUE, &global_host,
505 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
506 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
507 { "sasl-realm", "realm", 2, 2, 0,
508 #ifdef HAVE_CYRUS_SASL
509 ARG_STRING|ARG_UNIQUE, &global_realm,
513 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
514 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
515 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
516 &config_generic, NULL, NULL, NULL },
517 { "sasl-secprops", "properties", 2, 2, 0,
518 #ifdef HAVE_CYRUS_SASL
519 ARG_MAGIC|CFG_SASLSECP, &config_generic,
523 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
526 &config_generic, NULL, NULL, NULL },
527 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
528 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
529 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
530 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
531 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
532 "EQUALITY caseIgnoreMatch "
533 "SYNTAX OMsDirectoryString )", NULL, NULL },
534 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
535 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
536 "EQUALITY caseIgnoreMatch "
537 "SYNTAX OMsDirectoryString )", NULL, NULL },
538 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
539 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
542 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
543 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
544 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
545 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
546 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
547 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
548 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
549 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
550 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
551 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
552 "EQUALITY distinguishedNameMatch "
553 "SYNTAX OMsDN )", NULL, NULL },
554 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
555 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
556 "EQUALITY caseIgnoreMatch "
557 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
558 { "threads", "count", 2, 2, 0,
562 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
564 "( OLcfgGlAt:66 NAME 'olcThreads' "
565 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
566 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
567 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
568 "SYNTAX OMsDirectoryString )", NULL, NULL },
569 { "TLSCACertificateFile", NULL, 0, 0, 0,
571 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
575 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
576 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
577 { "TLSCACertificatePath", NULL, 0, 0, 0,
579 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
583 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
584 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
585 { "TLSCertificateFile", NULL, 0, 0, 0,
587 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
591 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
592 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
593 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
595 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
599 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
600 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
601 { "TLSCipherSuite", NULL, 0, 0, 0,
603 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
607 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
608 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
609 { "TLSCRLCheck", NULL, 0, 0, 0,
610 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
611 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
615 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
616 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
617 { "TLSCRLFile", NULL, 0, 0, 0,
618 #if defined(HAVE_GNUTLS)
619 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
623 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
624 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
625 { "TLSRandFile", NULL, 0, 0, 0,
627 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
631 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
632 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
633 { "TLSVerifyClient", NULL, 0, 0, 0,
635 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
639 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
640 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
641 { "TLSDHParamFile", NULL, 0, 0, 0,
643 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
647 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
648 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
649 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
650 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
651 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
652 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
653 NULL, NULL, NULL, NULL },
654 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
655 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
656 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
657 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
658 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
659 "EQUALITY caseIgnoreMatch "
660 "SUP labeledURI )", NULL, NULL },
661 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
662 NULL, NULL, NULL, NULL }
665 /* Routines to check if a child can be added to this type */
666 static ConfigLDAPadd cfAddSchema, cfAddDatabase,
667 cfAddBackend, cfAddModule, cfAddOverlay;
669 /* NOTE: be careful when defining array members
670 * that can be conditionally compiled */
671 #define CFOC_GLOBAL cf_ocs[1]
672 #define CFOC_SCHEMA cf_ocs[2]
673 #define CFOC_BACKEND cf_ocs[3]
674 #define CFOC_DATABASE cf_ocs[4]
675 #define CFOC_OVERLAY cf_ocs[5]
676 #define CFOC_FRONTEND cf_ocs[6]
678 #define CFOC_MODULE cf_ocs[7]
679 #endif /* SLAPD_MODULES */
681 static ConfigOCs cf_ocs[] = {
684 "DESC 'OpenLDAP configuration object' "
685 "ABSTRACT SUP top )", Cft_Abstract, NULL },
688 "DESC 'OpenLDAP Global configuration options' "
689 "SUP olcConfig STRUCTURAL "
690 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
691 "olcAttributeOptions $ olcAuthIDRewrite $ "
692 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
693 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
694 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
695 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
696 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
698 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
699 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
700 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
702 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
703 "olcSecurity $ olcServerID $ olcSizeLimit $ "
704 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
705 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
706 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
707 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
708 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
709 "olcTLSCRLFile $ olcToolThreads $ "
710 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
711 "olcDitContentRules ) )", Cft_Global },
713 "NAME 'olcSchemaConfig' "
714 "DESC 'OpenLDAP schema object' "
715 "SUP olcConfig STRUCTURAL "
716 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
717 "olcObjectClasses $ olcDitContentRules ) )",
718 Cft_Schema, NULL, cfAddSchema },
720 "NAME 'olcBackendConfig' "
721 "DESC 'OpenLDAP Backend-specific options' "
722 "SUP olcConfig STRUCTURAL "
723 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
725 "NAME 'olcDatabaseConfig' "
726 "DESC 'OpenLDAP Database-specific options' "
727 "SUP olcConfig STRUCTURAL "
729 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
730 "olcLastMod $ olcLimits $ "
731 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
732 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
733 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
734 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
735 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
737 Cft_Database, NULL, cfAddDatabase },
739 "NAME 'olcOverlayConfig' "
740 "DESC 'OpenLDAP Overlay-specific options' "
741 "SUP olcConfig STRUCTURAL "
742 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
743 /* This should be STRUCTURAL like all the other database classes, but
744 * that would mean inheriting all of the olcDatabaseConfig attributes,
745 * which causes them to be merged twice in config_build_entry.
748 "NAME 'olcFrontendConfig' "
749 "DESC 'OpenLDAP frontend configuration' "
751 "MAY olcDefaultSearchBase )",
752 Cft_Database, NULL, NULL },
755 "NAME 'olcModuleList' "
756 "DESC 'OpenLDAP dynamic module info' "
757 "SUP olcConfig STRUCTURAL "
758 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
759 Cft_Module, NULL, cfAddModule },
764 typedef struct ServerID {
765 struct ServerID *si_next;
766 struct berval si_url;
770 static ServerID *sid_list;
773 config_generic(ConfigArgs *c) {
776 if ( c->op == SLAP_CONFIG_EMIT ) {
780 c->value_int = ldap_pvt_thread_get_concurrency();
783 c->value_int = connection_pool_max;
786 c->value_int = slap_tool_thread_max;
790 c->value_string = ch_strdup( passwd_salt );
795 if ( c->be->be_limits ) {
800 for ( i=0; c->be->be_limits[i]; i++ ) {
801 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
802 if ( bv.bv_len >= sizeof( buf ) ) {
803 ber_bvarray_free_x( c->rvalue_vals, NULL );
804 c->rvalue_vals = NULL;
808 bv.bv_val = buf + bv.bv_len;
809 limits_unparse( c->be->be_limits[i], &bv,
810 sizeof( buf ) - ( bv.bv_val - buf ) );
811 bv.bv_len += bv.bv_val - buf;
813 value_add_one( &c->rvalue_vals, &bv );
816 if ( !c->rvalue_vals ) rc = 1;
819 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
820 SLAP_RESTRICT_OP_WRITES;
823 c->value_string = ch_strdup( slap_sasl_getpolicy());
826 slap_sasl_regexp_unparse( &c->rvalue_vals );
827 if ( !c->rvalue_vals ) rc = 1;
829 #ifdef HAVE_CYRUS_SASL
831 struct berval bv = BER_BVNULL;
832 slap_sasl_secprops_unparse( &bv );
833 if ( !BER_BVISNULL( &bv )) {
834 ber_bvarray_add( &c->rvalue_vals, &bv );
842 c->value_int = c->be->be_max_deref_depth;
845 if ( SLAP_DBHIDDEN( c->be )) {
852 ConfigFile *cf = c->private;
854 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
855 else if ( cf->c_om_head )
856 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
858 if ( !c->rvalue_vals )
863 ad_unparse_options( &c->rvalue_vals );
866 ConfigFile *cf = c->private;
868 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
869 else if ( cf->c_oc_head )
870 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
872 if ( !c->rvalue_vals )
877 ConfigFile *cf = c->private;
879 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
880 else if ( cf->c_at_head )
881 at_unparse( &c->rvalue_vals, cf->c_at_head,
883 if ( !c->rvalue_vals )
888 ConfigFile *cf = c->private;
890 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
891 else if ( cf->c_cr_head )
892 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
894 if ( !c->rvalue_vals )
901 char *src, *dst, ibuf[11];
902 struct berval bv, abv;
903 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
904 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
905 if ( abv.bv_len >= sizeof( ibuf ) ) {
906 ber_bvarray_free_x( c->rvalue_vals, NULL );
907 c->rvalue_vals = NULL;
911 acl_unparse( a, &bv );
912 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
913 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
914 /* Turn TAB / EOL into plain space */
915 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
916 if (isspace((unsigned char)*src)) *dst++ = ' ';
920 if (dst[-1] == ' ') {
924 abv.bv_len = dst - abv.bv_val;
925 ber_bvarray_add( &c->rvalue_vals, &abv );
931 ConfigFile *cf = c->private;
932 if ( cf->c_dseFiles ) {
933 value_add( &c->rvalue_vals, cf->c_dseFiles );
944 for ( si = sid_list; si; si=si->si_next ) {
945 if ( !BER_BVISEMPTY( &si->si_url )) {
946 bv.bv_len = si->si_url.bv_len + 6;
947 bv.bv_val = ch_malloc( bv.bv_len );
948 sprintf( bv.bv_val, "%d %s", si->si_num,
950 ber_bvarray_add( &c->rvalue_vals, &bv );
954 bv.bv_len = sprintf( buf, "%d", si->si_num );
955 value_add_one( &c->rvalue_vals, &bv );
964 c->value_string = ch_strdup( logfileName );
969 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
972 if ( SLAP_SHADOW(c->be))
973 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
978 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
980 case CFG_SSTR_IF_MAX:
981 c->value_int = index_substr_if_maxlen;
983 case CFG_SSTR_IF_MIN:
984 c->value_int = index_substr_if_minlen;
988 ModPaths *mp = c->private;
991 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
994 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
995 SLAP_X_ORDERED_FMT "%s", i,
996 mp->mp_loads[i].bv_val );
997 if ( bv.bv_len >= sizeof( c->log ) ) {
998 ber_bvarray_free_x( c->rvalue_vals, NULL );
999 c->rvalue_vals = NULL;
1002 value_add_one( &c->rvalue_vals, &bv );
1006 rc = c->rvalue_vals ? 0 : 1;
1010 ModPaths *mp = c->private;
1011 if ( !BER_BVISNULL( &mp->mp_path ))
1012 value_add_one( &c->rvalue_vals, &mp->mp_path );
1014 rc = c->rvalue_vals ? 0 : 1;
1020 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1021 if ( !c->rvalue_vals ) rc = 1;
1024 #ifdef SLAP_AUTH_REWRITE
1026 if ( authz_rewrites ) {
1027 struct berval bv, idx;
1032 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1033 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1034 if ( idx.bv_len >= sizeof( ibuf ) ) {
1035 ber_bvarray_free_x( c->rvalue_vals, NULL );
1036 c->rvalue_vals = NULL;
1039 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1040 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1041 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1042 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1043 authz_rewrites[i].bv_val,
1044 authz_rewrites[i].bv_len + 1 );
1045 ber_bvarray_add( &c->rvalue_vals, &bv );
1048 if ( !c->rvalue_vals ) rc = 1;
1055 } else if ( c->op == LDAP_MOD_DELETE ) {
1058 /* single-valued attrs, no-ops */
1066 case CFG_MIRRORMODE:
1067 case CFG_MONITORING:
1069 case CFG_SSTR_IF_MAX:
1070 case CFG_SSTR_IF_MIN:
1073 /* no-ops, requires slapd restart */
1078 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1082 ch_free( passwd_salt );
1087 ch_free( logfileName );
1091 case CFG_SERVERID: {
1093 ServerID *si, **sip;
1095 for ( i=0, si = sid_list, sip = &sid_list;
1096 si; si = *sip, i++ ) {
1097 if ( c->valx == -1 || i == c->valx ) {
1109 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1113 if ( c->valx < 0 ) {
1115 if ( c->be == frontendDB )
1118 end = frontendDB->be_acl;
1119 acl_destroy( c->be->be_acl, end );
1120 c->be->be_acl = end;
1123 AccessControl **prev, *a;
1125 for (i=0, prev = &c->be->be_acl; i < c->valx;
1128 prev = &a->acl_next;
1131 *prev = a->acl_next;
1137 CfEntryInfo *ce = c->ca_entry->e_private;
1138 /* can't modify the hardcoded schema */
1139 if ( ce->ce_parent->ce_type == Cft_Global )
1143 if ( c->valx < 0 ) {
1146 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1148 if ( oc == cfn->c_oc_tail )
1151 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1153 ObjectClass *oc, *prev = NULL;
1156 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1161 if ( cfn->c_oc_tail == oc ) {
1162 cfn->c_oc_tail = prev;
1164 if ( cfn->c_oc_head == oc ) {
1166 cfn->c_oc_head = oc;
1172 CfEntryInfo *ce = c->ca_entry->e_private;
1173 /* can't modify the hardcoded schema */
1174 if ( ce->ce_parent->ce_type == Cft_Global )
1178 if ( c->valx < 0 ) {
1181 for( at = cfn->c_at_head; at; at_next( &at )) {
1183 if ( at == cfn->c_at_tail )
1186 cfn->c_at_head = cfn->c_at_tail = NULL;
1188 AttributeType *at, *prev = NULL;
1191 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1196 if ( cfn->c_at_tail == at ) {
1197 cfn->c_at_tail = prev;
1199 if ( cfn->c_at_head == at ) {
1201 cfn->c_at_head = at;
1207 /* FIXME: there is no limits_free function */
1209 /* FIXME: there is no ad_option_free function */
1211 /* FIXME: there is no way to remove attributes added by
1225 if(!(c->bi = backend_info(c->argv[1]))) {
1226 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1227 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1228 c->log, c->msg, c->argv[1] );
1235 /* NOTE: config is always the first backend!
1237 if ( !strcasecmp( c->argv[1], "config" )) {
1238 c->be = LDAP_STAILQ_FIRST(&backendDB);
1239 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1242 c->be = backend_db_init(c->argv[1], NULL, c->valx);
1244 snprintf( c->msg, sizeof( c->msg ), "<%s> failed init", c->argv[0] );
1245 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1246 c->log, c->msg, c->argv[1] );
1253 ldap_pvt_thread_set_concurrency(c->value_int);
1257 if ( c->value_int < 2 ) {
1258 snprintf( c->msg, sizeof( c->msg ),
1259 "threads=%d smaller than minimum value 2",
1261 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1262 c->log, c->msg, 0 );
1265 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1266 snprintf( c->msg, sizeof( c->msg ),
1267 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1268 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1269 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1270 c->log, c->msg, 0 );
1272 if ( slapMode & SLAP_SERVER_MODE )
1273 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1274 connection_pool_max = c->value_int; /* save for reference */
1278 if ( slapMode & SLAP_TOOL_MODE )
1279 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1280 slap_tool_thread_max = c->value_int; /* save for reference */
1284 if ( passwd_salt ) ch_free( passwd_salt );
1285 passwd_salt = c->value_string;
1286 lutil_salt_format(passwd_salt);
1290 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1296 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1298 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1302 ch_free(c->value_string);
1303 if (slap_sasl_setpolicy( c->argv[1] )) {
1304 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1305 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1306 c->log, c->msg, c->argv[1] );
1312 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1316 #ifdef HAVE_CYRUS_SASL
1319 char *txt = slap_sasl_secprops( c->argv[1] );
1321 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1323 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1331 c->be->be_max_deref_depth = c->value_int;
1337 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1339 if(parse_oidm(c, 1, &om))
1341 if (!cfn->c_om_head) cfn->c_om_head = om;
1342 cfn->c_om_tail = om;
1347 ObjectClass *oc, *prev;
1349 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1351 if ( c->valx < 0 ) {
1352 prev = cfn->c_oc_tail;
1355 /* If adding anything after the first, prev is easy */
1358 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1363 /* If adding the first, and head exists, find its prev */
1364 if (cfn->c_oc_head) {
1365 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1370 /* else prev is NULL, append to end of global list */
1372 if(parse_oc(c, &oc, prev)) return(1);
1373 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1374 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1379 AttributeType *at, *prev;
1381 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1383 if ( c->valx < 0 ) {
1384 prev = cfn->c_at_tail;
1387 /* If adding anything after the first, prev is easy */
1390 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1395 /* If adding the first, and head exists, find its prev */
1396 if (cfn->c_at_head) {
1397 for ( at_start( &at ); at != cfn->c_at_head; ) {
1402 /* else prev is NULL, append to end of global list */
1404 if(parse_at(c, &at, prev)) return(1);
1405 if (!cfn->c_at_head) cfn->c_at_head = at;
1406 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1413 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1415 if(parse_cr(c, &cr)) return(1);
1416 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1417 cfn->c_cr_tail = cr;
1422 ad_define_option(NULL, NULL, 0);
1423 for(i = 1; i < c->argc; i++)
1424 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1429 /* Don't append to the global ACL if we're on a specific DB */
1431 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1434 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1438 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1444 if(root_dse_read_file(c->argv[1])) {
1445 snprintf( c->msg, sizeof( c->msg ), "<%s> could not read file", c->argv[0] );
1446 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1447 c->log, c->msg, c->argv[1] );
1452 ber_str2bv( c->argv[1], 0, 1, &bv );
1453 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1455 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1461 ServerID *si, **sip;
1463 int num = atoi( c->argv[1] );
1464 if ( num < 0 || num > SLAP_SYNC_SID_MAX ) {
1465 snprintf( c->msg, sizeof( c->msg ),
1466 "<%s> illegal server ID", c->argv[0] );
1467 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1468 c->log, c->msg, c->argv[1] );
1471 /* only one value allowed if no URL is given */
1472 if ( c->argc > 2 ) {
1475 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1476 snprintf( c->msg, sizeof( c->msg ),
1477 "<%s> only one server ID allowed now", c->argv[0] );
1478 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1479 c->log, c->msg, c->argv[1] );
1483 if ( ldap_url_parse( c->argv[2], &lud )) {
1484 snprintf( c->msg, sizeof( c->msg ),
1485 "<%s> invalid URL", c->argv[0] );
1486 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1487 c->log, c->msg, c->argv[2] );
1490 len = strlen( c->argv[2] );
1491 si = ch_malloc( sizeof(ServerID) + len + 1 );
1492 si->si_url.bv_val = (char *)(si+1);
1493 si->si_url.bv_len = len;
1494 strcpy( si->si_url.bv_val, c->argv[2] );
1497 snprintf( c->msg, sizeof( c->msg ),
1498 "<%s> unqualified server ID not allowed now", c->argv[0] );
1499 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1500 c->log, c->msg, c->argv[1] );
1503 si = ch_malloc( sizeof(ServerID) );
1504 BER_BVZERO( &si->si_url );
1505 slap_serverID = num;
1509 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1512 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1513 /* If hostname is empty, or is localhost, or matches
1514 * our hostname, this serverID refers to this host.
1515 * Compare it against listeners and ports.
1517 if ( !lud->lud_host || !lud->lud_host[0] ||
1518 !strncasecmp("localhost", lud->lud_host,
1519 STRLENOF("localhost")) ||
1520 !strcasecmp( global_host, lud->lud_host )) {
1521 Listener **l = slapd_get_listeners();
1524 for ( i=0; l[i]; i++ ) {
1527 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1529 if ( strcasecmp( lud->lud_scheme,
1532 if ( lud->lud_port != lu2->lud_port )
1534 /* Listener on ANY address */
1535 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1539 /* URL on ANY address */
1540 if ( !lud->lud_host || !lud->lud_host[0] ) {
1544 /* Listener has specific host, must
1547 if ( !strcasecmp( lud->lud_host,
1553 ldap_free_urldesc( lu2 );
1555 slap_serverID = si->si_num;
1562 ldap_free_urldesc( lud );
1567 if ( logfileName ) ch_free( logfileName );
1568 logfileName = c->value_string;
1569 logfile = fopen(logfileName, "w");
1570 if(logfile) lutil_debug_file(logfile);
1574 if(SLAP_NOLASTMODCMD(c->be)) {
1575 snprintf( c->msg, sizeof( c->msg ), "<%s> not available for %s database",
1576 c->argv[0], c->be->bd_info->bi_type );
1577 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1578 c->log, c->msg, 0 );
1582 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1584 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1587 case CFG_MIRRORMODE:
1588 if(!SLAP_SHADOW(c->be)) {
1589 snprintf( c->msg, sizeof( c->msg ), "<%s> database is not a shadow",
1591 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1592 c->log, c->msg, 0 );
1596 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1598 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1601 case CFG_MONITORING:
1603 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1605 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1610 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1612 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1615 case CFG_SSTR_IF_MAX:
1616 if (c->value_int < index_substr_if_minlen) {
1617 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1618 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1619 c->log, c->msg, c->value_int );
1622 index_substr_if_maxlen = c->value_int;
1625 case CFG_SSTR_IF_MIN:
1626 if (c->value_int > index_substr_if_maxlen) {
1627 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value", c->argv[0] );
1628 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1629 c->log, c->msg, c->value_int );
1632 index_substr_if_minlen = c->value_int;
1635 #ifdef SLAPD_MODULES
1637 /* If we're just adding a module on an existing modpath,
1638 * make sure we've selected the current path.
1640 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1641 modcur = c->private;
1642 /* This should never fail */
1643 if ( module_path( modcur->mp_path.bv_val )) {
1644 snprintf( c->msg, sizeof( c->msg ), "<%s> module path no longer valid",
1646 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1647 c->log, c->msg, modcur->mp_path.bv_val );
1651 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1653 /* Record this load on the current path */
1657 if ( c->op == SLAP_CONFIG_ADD ) {
1658 ptr = c->line + STRLENOF("moduleload");
1659 while (!isspace((unsigned char) *ptr)) ptr++;
1660 while (isspace((unsigned char) *ptr)) ptr++;
1664 ber_str2bv(ptr, 0, 1, &bv);
1665 ber_bvarray_add( &modcur->mp_loads, &bv );
1667 /* Check for any new hardcoded schema */
1668 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1669 config_check_schema( NULL, &cfBackInfo );
1674 if(module_path(c->argv[1])) return(1);
1675 /* Record which path was used with each module */
1679 if (!modpaths.mp_loads) {
1682 mp = ch_malloc( sizeof( ModPaths ));
1683 modlast->mp_next = mp;
1685 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1687 mp->mp_loads = NULL;
1698 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1700 slapi_plugins_used++;
1704 #ifdef SLAP_AUTH_REWRITE
1709 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1712 if ( c->argc > 1 ) {
1715 /* quote all args but the first */
1716 line = ldap_charray2str( c->argv, "\" \"" );
1717 ber_str2bv( line, 0, 0, &bv );
1718 s = ber_bvchr( &bv, '"' );
1719 assert( s != NULL );
1720 /* move the trailing quote of argv[0] to the end */
1721 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1722 bv.bv_val[ bv.bv_len - 1 ] = '"';
1725 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1728 ber_bvarray_add( &authz_rewrites, &bv );
1735 Debug( LDAP_DEBUG_ANY,
1736 "%s: unknown CFG_TYPE %d.\n",
1737 c->log, c->type, 0 );
1746 config_fname(ConfigArgs *c) {
1747 if(c->op == SLAP_CONFIG_EMIT) {
1749 ConfigFile *cf = c->private;
1750 value_add_one( &c->rvalue_vals, &cf->c_file );
1759 config_cfdir(ConfigArgs *c) {
1760 if(c->op == SLAP_CONFIG_EMIT) {
1761 if ( !BER_BVISEMPTY( &cfdir )) {
1762 value_add_one( &c->rvalue_vals, &cfdir );
1771 config_search_base(ConfigArgs *c) {
1772 if(c->op == SLAP_CONFIG_EMIT) {
1774 if (!BER_BVISEMPTY(&default_search_base)) {
1775 value_add_one(&c->rvalue_vals, &default_search_base);
1776 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1780 } else if( c->op == LDAP_MOD_DELETE ) {
1781 ch_free( default_search_base.bv_val );
1782 ch_free( default_search_nbase.bv_val );
1783 BER_BVZERO( &default_search_base );
1784 BER_BVZERO( &default_search_nbase );
1788 if(c->bi || c->be != frontendDB) {
1789 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1790 "prior to any backend or database definition\n",
1795 if(default_search_nbase.bv_len) {
1796 free(default_search_base.bv_val);
1797 free(default_search_nbase.bv_val);
1800 default_search_base = c->value_dn;
1801 default_search_nbase = c->value_ndn;
1806 config_passwd_hash(ConfigArgs *c) {
1808 if (c->op == SLAP_CONFIG_EMIT) {
1810 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1811 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1812 value_add_one(&c->rvalue_vals, &bv);
1815 } else if ( c->op == LDAP_MOD_DELETE ) {
1816 if ( c->valx < 0 ) {
1817 ldap_charray_free( default_passwd_hash );
1818 default_passwd_hash = NULL;
1821 ch_free( default_passwd_hash[i] );
1822 for (; default_passwd_hash[i]; i++ )
1823 default_passwd_hash[i] = default_passwd_hash[i+1];
1827 if(default_passwd_hash) {
1828 Debug(LDAP_DEBUG_ANY, "%s: "
1829 "already set default password_hash\n",
1833 for(i = 1; i < c->argc; i++) {
1834 if(!lutil_passwd_scheme(c->argv[i])) {
1835 snprintf( c->msg, sizeof( c->msg ), "<%s> scheme not available", c->argv[0] );
1836 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1837 c->log, c->msg, c->argv[i]);
1839 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1841 if(!default_passwd_hash) {
1842 snprintf( c->msg, sizeof( c->msg ), "<%s> no valid hashes found", c->argv[0] );
1843 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1844 c->log, c->msg, 0 );
1852 config_schema_dn(ConfigArgs *c) {
1853 if ( c->op == SLAP_CONFIG_EMIT ) {
1855 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1856 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1857 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1861 } else if ( c->op == LDAP_MOD_DELETE ) {
1862 ch_free( c->be->be_schemadn.bv_val );
1863 ch_free( c->be->be_schemandn.bv_val );
1864 BER_BVZERO( &c->be->be_schemadn );
1865 BER_BVZERO( &c->be->be_schemandn );
1868 ch_free( c->be->be_schemadn.bv_val );
1869 ch_free( c->be->be_schemandn.bv_val );
1870 c->be->be_schemadn = c->value_dn;
1871 c->be->be_schemandn = c->value_ndn;
1876 config_sizelimit(ConfigArgs *c) {
1878 struct slap_limits_set *lim = &c->be->be_def_limit;
1879 if (c->op == SLAP_CONFIG_EMIT) {
1884 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
1885 if ( !BER_BVISEMPTY( &bv ))
1886 value_add_one( &c->rvalue_vals, &bv );
1890 } else if ( c->op == LDAP_MOD_DELETE ) {
1891 /* Reset to defaults */
1892 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1893 lim->lms_s_hard = 0;
1894 lim->lms_s_unchecked = -1;
1896 lim->lms_s_pr_hide = 0;
1897 lim->lms_s_pr_total = 0;
1900 for(i = 1; i < c->argc; i++) {
1901 if(!strncasecmp(c->argv[i], "size", 4)) {
1902 rc = limits_parse_one(c->argv[i], lim);
1904 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1905 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1906 c->log, c->msg, c->argv[i]);
1910 if(!strcasecmp(c->argv[i], "unlimited")) {
1911 lim->lms_s_soft = -1;
1913 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
1914 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
1915 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1916 c->log, c->msg, c->argv[i]);
1920 lim->lms_s_hard = 0;
1927 config_timelimit(ConfigArgs *c) {
1929 struct slap_limits_set *lim = &c->be->be_def_limit;
1930 if (c->op == SLAP_CONFIG_EMIT) {
1935 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
1936 if ( !BER_BVISEMPTY( &bv ))
1937 value_add_one( &c->rvalue_vals, &bv );
1941 } else if ( c->op == LDAP_MOD_DELETE ) {
1942 /* Reset to defaults */
1943 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1944 lim->lms_t_hard = 0;
1947 for(i = 1; i < c->argc; i++) {
1948 if(!strncasecmp(c->argv[i], "time", 4)) {
1949 rc = limits_parse_one(c->argv[i], lim);
1951 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse value", c->argv[0] );
1952 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1953 c->log, c->msg, c->argv[i]);
1957 if(!strcasecmp(c->argv[i], "unlimited")) {
1958 lim->lms_t_soft = -1;
1960 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
1961 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse limit", c->argv[0]);
1962 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1963 c->log, c->msg, c->argv[i]);
1967 lim->lms_t_hard = 0;
1974 config_overlay(ConfigArgs *c) {
1975 if (c->op == SLAP_CONFIG_EMIT) {
1977 } else if ( c->op == LDAP_MOD_DELETE ) {
1980 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
1983 Debug( LDAP_DEBUG_ANY,
1984 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
1985 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
1987 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
1994 config_subordinate(ConfigArgs *c)
2000 case SLAP_CONFIG_EMIT:
2001 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2004 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2005 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2008 value_add_one( &c->rvalue_vals, &bv );
2012 case LDAP_MOD_DELETE:
2013 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2014 glue_sub_del( c->be );
2016 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2021 case SLAP_CONFIG_ADD:
2022 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2023 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2030 config_suffix(ConfigArgs *c)
2033 struct berval pdn, ndn;
2034 char *notallowed = NULL;
2036 if ( c->be == frontendDB ) {
2037 notallowed = "frontend";
2039 } else if ( SLAP_MONITOR(c->be) ) {
2040 notallowed = "monitor";
2042 } else if ( SLAP_CONFIG(c->be) ) {
2043 notallowed = "config";
2046 if ( notallowed != NULL ) {
2047 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2051 case LDAP_MOD_DELETE:
2052 case LDAP_MOD_REPLACE:
2053 case LDAP_MOD_INCREMENT:
2054 case SLAP_CONFIG_ADD:
2055 if ( !BER_BVISNULL( &c->value_dn ) ) {
2056 snprintf( buf, sizeof( buf ), "<%s> ",
2057 c->value_dn.bv_val );
2060 Debug(LDAP_DEBUG_ANY,
2061 "%s: suffix %snot allowed in %s database.\n",
2062 c->log, buf, notallowed );
2065 case SLAP_CONFIG_EMIT:
2066 /* don't complain when emitting... */
2070 /* FIXME: don't know what values may be valid;
2071 * please remove assertion, or add legal values
2072 * to either block */
2080 if (c->op == SLAP_CONFIG_EMIT) {
2081 if ( c->be->be_suffix == NULL
2082 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2086 value_add( &c->rvalue_vals, c->be->be_suffix );
2087 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2090 } else if ( c->op == LDAP_MOD_DELETE ) {
2091 if ( c->valx < 0 ) {
2092 ber_bvarray_free( c->be->be_suffix );
2093 ber_bvarray_free( c->be->be_nsuffix );
2094 c->be->be_suffix = NULL;
2095 c->be->be_nsuffix = NULL;
2098 ch_free( c->be->be_suffix[i].bv_val );
2099 ch_free( c->be->be_nsuffix[i].bv_val );
2101 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2102 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2104 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2109 #ifdef SLAPD_MONITOR_DN
2110 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2111 snprintf( c->msg, sizeof( c->msg ), "<%s> DN is reserved for monitoring slapd",
2113 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2114 c->log, c->msg, SLAPD_MONITOR_DN);
2121 if (SLAP_DBHIDDEN( c->be ))
2124 tbe = select_backend(&ndn, 0, 0);
2126 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2132 BackendDB *b2 = tbe;
2134 /* Does tbe precede be? */
2135 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2138 char *type = tbe->bd_info->bi_type;
2140 if ( overlay_is_over( tbe ) ) {
2141 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2142 type = oi->oi_orig->bi_type;
2145 snprintf( c->msg, sizeof( c->msg ), "<%s> namingContext \"%s\" "
2146 "already served by a preceding %s database",
2147 c->argv[0], pdn.bv_val, type );
2148 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2149 c->log, c->msg, tbe->be_suffix[0].bv_val);
2155 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2156 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2157 "base provided \"%s\" (assuming okay)\n",
2158 c->log, default_search_base.bv_val, 0);
2160 ber_bvarray_add(&c->be->be_suffix, &pdn);
2161 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2166 config_rootdn(ConfigArgs *c) {
2167 if (c->op == SLAP_CONFIG_EMIT) {
2168 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2169 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2170 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2175 } else if ( c->op == LDAP_MOD_DELETE ) {
2176 ch_free( c->be->be_rootdn.bv_val );
2177 ch_free( c->be->be_rootndn.bv_val );
2178 BER_BVZERO( &c->be->be_rootdn );
2179 BER_BVZERO( &c->be->be_rootndn );
2182 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2183 ch_free( c->be->be_rootdn.bv_val );
2184 ch_free( c->be->be_rootndn.bv_val );
2186 c->be->be_rootdn = c->value_dn;
2187 c->be->be_rootndn = c->value_ndn;
2192 config_rootpw(ConfigArgs *c) {
2195 if (c->op == SLAP_CONFIG_EMIT) {
2196 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2197 /* don't copy, because "rootpw" is marked
2199 c->value_bv = c->be->be_rootpw;
2203 } else if ( c->op == LDAP_MOD_DELETE ) {
2204 ch_free( c->be->be_rootpw.bv_val );
2205 BER_BVZERO( &c->be->be_rootpw );
2209 tbe = select_backend(&c->be->be_rootndn, 0, 0);
2211 snprintf( c->msg, sizeof( c->msg ), "<%s> can only be set when rootdn is under suffix",
2213 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2217 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2218 ch_free( c->be->be_rootpw.bv_val );
2219 c->be->be_rootpw = c->value_bv;
2224 config_restrict(ConfigArgs *c) {
2225 slap_mask_t restrictops = 0;
2227 slap_verbmasks restrictable_ops[] = {
2228 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2229 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2230 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2231 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2232 { BER_BVC("modrdn"), 0 },
2233 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2234 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2235 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2236 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2237 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2238 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2239 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2240 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2241 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2242 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2243 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2247 if (c->op == SLAP_CONFIG_EMIT) {
2248 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2250 } else if ( c->op == LDAP_MOD_DELETE ) {
2252 c->be->be_restrictops = 0;
2254 restrictops = verb_to_mask( c->line, restrictable_ops );
2255 c->be->be_restrictops ^= restrictops;
2259 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2261 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown operation", c->argv[0] );
2262 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2263 c->log, c->msg, c->argv[i]);
2266 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2267 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2268 c->be->be_restrictops |= restrictops;
2273 config_allows(ConfigArgs *c) {
2274 slap_mask_t allows = 0;
2276 slap_verbmasks allowable_ops[] = {
2277 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2278 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2279 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2280 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2281 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2284 if (c->op == SLAP_CONFIG_EMIT) {
2285 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2286 } else if ( c->op == LDAP_MOD_DELETE ) {
2290 allows = verb_to_mask( c->line, allowable_ops );
2291 global_allows ^= allows;
2295 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2297 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2298 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2299 c->log, c->msg, c->argv[i]);
2302 global_allows |= allows;
2307 config_disallows(ConfigArgs *c) {
2308 slap_mask_t disallows = 0;
2310 slap_verbmasks disallowable_ops[] = {
2311 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2312 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2313 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2314 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2317 if (c->op == SLAP_CONFIG_EMIT) {
2318 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2319 } else if ( c->op == LDAP_MOD_DELETE ) {
2321 global_disallows = 0;
2323 disallows = verb_to_mask( c->line, disallowable_ops );
2324 global_disallows ^= disallows;
2328 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2330 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature", c->argv[0] );
2331 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2332 c->log, c->msg, c->argv[i]);
2335 global_disallows |= disallows;
2340 config_requires(ConfigArgs *c) {
2341 slap_mask_t requires = frontendDB->be_requires;
2342 int i, argc = c->argc;
2343 char **argv = c->argv;
2345 slap_verbmasks requires_ops[] = {
2346 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2347 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2348 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2349 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2350 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2353 if (c->op == SLAP_CONFIG_EMIT) {
2354 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2355 } else if ( c->op == LDAP_MOD_DELETE ) {
2357 c->be->be_requires = 0;
2359 requires = verb_to_mask( c->line, requires_ops );
2360 c->be->be_requires ^= requires;
2364 /* "none" can only be first, to wipe out default/global values */
2365 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2370 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2372 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2373 snprintf( c->msg, sizeof( c->msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2374 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2377 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2378 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2379 c->log, c->msg, c->argv[i]);
2383 c->be->be_requires = requires;
2387 static slap_verbmasks *loglevel_ops;
2390 loglevel_init( void )
2392 slap_verbmasks lo[] = {
2393 { BER_BVC("Any"), -1 },
2394 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2395 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2396 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2397 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2398 { BER_BVC("BER"), LDAP_DEBUG_BER },
2399 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2400 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2401 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2402 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2403 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2404 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2405 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2406 #if 0 /* no longer used (nor supported) */
2407 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2408 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2410 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2411 { BER_BVC("None"), LDAP_DEBUG_NONE },
2415 return slap_verbmasks_init( &loglevel_ops, lo );
2419 loglevel_destroy( void )
2421 if ( loglevel_ops ) {
2422 (void)slap_verbmasks_destroy( loglevel_ops );
2424 loglevel_ops = NULL;
2427 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2430 slap_loglevel_register( slap_mask_t m, struct berval *s )
2434 if ( loglevel_ops == NULL ) {
2438 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2441 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2449 slap_loglevel_get( struct berval *s, int *l )
2455 if ( loglevel_ops == NULL ) {
2459 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2460 m |= loglevel_ops[ i ].mask;
2465 for ( i = 1; i <= ( 1 << ( sizeof( int ) * 8 - 1 ) ) && !( m & i ); i <<= 1 )
2472 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2475 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2486 str2loglevel( const char *s, int *l )
2490 if ( loglevel_ops == NULL ) {
2494 i = verb_to_mask( s, loglevel_ops );
2496 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2500 *l = loglevel_ops[ i ].mask;
2506 loglevel2str( int l )
2508 struct berval bv = BER_BVNULL;
2510 loglevel2bv( l, &bv );
2516 loglevel2bv( int l, struct berval *bv )
2518 if ( loglevel_ops == NULL ) {
2524 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2528 loglevel2bvarray( int l, BerVarray *bva )
2530 if ( loglevel_ops == NULL ) {
2534 return mask_to_verbs( loglevel_ops, l, bva );
2538 loglevel_print( FILE *out )
2542 if ( loglevel_ops == NULL ) {
2546 fprintf( out, "Installed log subsystems:\n\n" );
2547 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2548 fprintf( out, "\t%-30s (%lu)\n",
2549 loglevel_ops[ i ].word.bv_val,
2550 loglevel_ops[ i ].mask );
2553 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2554 "by specific code\n\n" );
2559 static int config_syslog;
2562 config_loglevel(ConfigArgs *c) {
2565 if ( loglevel_ops == NULL ) {
2569 if (c->op == SLAP_CONFIG_EMIT) {
2570 /* Get default or commandline slapd setting */
2571 if ( ldap_syslog && !config_syslog )
2572 config_syslog = ldap_syslog;
2573 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2575 } else if ( c->op == LDAP_MOD_DELETE ) {
2579 int level = verb_to_mask( c->line, loglevel_ops );
2580 config_syslog ^= level;
2582 if ( slapMode & SLAP_SERVER_MODE ) {
2583 ldap_syslog = config_syslog;
2588 for( i=1; i < c->argc; i++ ) {
2591 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2592 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2593 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse level", c->argv[0] );
2594 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2595 c->log, c->msg, c->argv[i]);
2599 if ( str2loglevel( c->argv[i], &level ) ) {
2600 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown level", c->argv[0] );
2601 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2602 c->log, c->msg, c->argv[i]);
2606 /* Explicitly setting a zero clears all the levels */
2608 config_syslog |= level;
2612 if ( slapMode & SLAP_SERVER_MODE ) {
2613 ldap_syslog = config_syslog;
2619 config_referral(ConfigArgs *c) {
2621 if (c->op == SLAP_CONFIG_EMIT) {
2622 if ( default_referral ) {
2623 value_add( &c->rvalue_vals, default_referral );
2628 } else if ( c->op == LDAP_MOD_DELETE ) {
2629 if ( c->valx < 0 ) {
2630 ber_bvarray_free( default_referral );
2631 default_referral = NULL;
2634 ch_free( default_referral[i].bv_val );
2635 for (; default_referral[i].bv_val; i++ )
2636 default_referral[i] = default_referral[i+1];
2640 if(validate_global_referral(c->argv[1])) {
2641 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
2642 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2643 c->log, c->msg, c->argv[1]);
2647 ber_str2bv(c->argv[1], 0, 0, &val);
2648 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2656 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2657 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2658 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2659 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2660 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2661 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2662 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2663 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2664 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2669 config_security(ConfigArgs *c) {
2670 slap_ssf_set_t *set = &c->be->be_ssf_set;
2673 if (c->op == SLAP_CONFIG_EMIT) {
2679 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2680 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2683 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2684 if ( bv.bv_len >= sizeof( numbuf ) ) {
2685 ber_bvarray_free_x( c->rvalue_vals, NULL );
2686 c->rvalue_vals = NULL;
2690 bv.bv_len += sec_keys[i].key.bv_len;
2691 bv.bv_val = ch_malloc( bv.bv_len + 1);
2692 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2693 strcpy( next, numbuf );
2694 ber_bvarray_add( &c->rvalue_vals, &bv );
2699 for(i = 1; i < c->argc; i++) {
2700 slap_ssf_t *tgt = NULL;
2702 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2703 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2704 sec_keys[j].key.bv_len)) {
2705 src = c->argv[i] + sec_keys[j].key.bv_len;
2706 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2711 snprintf( c->msg, sizeof( c->msg ), "<%s> unknown factor", c->argv[0] );
2712 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2713 c->log, c->msg, c->argv[i]);
2717 if ( lutil_atou( tgt, src ) != 0 ) {
2718 snprintf( c->msg, sizeof( c->msg ), "<%s> unable to parse factor", c->argv[0] );
2719 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2720 c->log, c->msg, c->argv[i]);
2728 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2732 for (; !BER_BVISNULL( &an->an_name ); an++) {
2733 /* if buflen == 0, assume the buffer size has been
2734 * already checked otherwise */
2735 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2736 if ( comma ) *ptr++ = ',';
2737 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2744 config_updatedn(ConfigArgs *c) {
2745 if (c->op == SLAP_CONFIG_EMIT) {
2746 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2747 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2748 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2752 } else if ( c->op == LDAP_MOD_DELETE ) {
2753 ch_free( c->be->be_update_ndn.bv_val );
2754 BER_BVZERO( &c->be->be_update_ndn );
2755 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2758 if(SLAP_SHADOW(c->be)) {
2759 snprintf( c->msg, sizeof( c->msg ), "<%s> database already shadowed", c->argv[0] );
2760 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2765 ber_memfree_x( c->value_dn.bv_val, NULL );
2766 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2767 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2769 c->be->be_update_ndn = c->value_ndn;
2770 BER_BVZERO( &c->value_dn );
2771 BER_BVZERO( &c->value_ndn );
2773 return config_slurp_shadow( c );
2777 config_shadow( ConfigArgs *c, int flag )
2779 char *notallowed = NULL;
2781 if ( c->be == frontendDB ) {
2782 notallowed = "frontend";
2784 } else if ( SLAP_MONITOR(c->be) ) {
2785 notallowed = "monitor";
2788 if ( notallowed != NULL ) {
2789 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2793 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2799 config_updateref(ConfigArgs *c) {
2801 if (c->op == SLAP_CONFIG_EMIT) {
2802 if ( c->be->be_update_refs ) {
2803 value_add( &c->rvalue_vals, c->be->be_update_refs );
2808 } else if ( c->op == LDAP_MOD_DELETE ) {
2809 if ( c->valx < 0 ) {
2810 ber_bvarray_free( c->be->be_update_refs );
2811 c->be->be_update_refs = NULL;
2814 ch_free( c->be->be_update_refs[i].bv_val );
2815 for (; c->be->be_update_refs[i].bv_val; i++)
2816 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2820 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2821 snprintf( c->msg, sizeof( c->msg ), "<%s> must appear after syncrepl or updatedn",
2823 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2828 if(validate_global_referral(c->argv[1])) {
2829 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid URL", c->argv[0] );
2830 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2831 c->log, c->msg, c->argv[1]);
2834 ber_str2bv(c->argv[1], 0, 0, &val);
2835 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2840 config_obsolete(ConfigArgs *c) {
2841 if (c->op == SLAP_CONFIG_EMIT)
2844 snprintf( c->msg, sizeof( c->msg ), "<%s> keyword is obsolete (ignored)",
2846 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0);
2851 config_include(ConfigArgs *c) {
2852 int savelineno = c->lineno;
2855 ConfigFile *cfsave = cfn;
2856 ConfigFile *cf2 = NULL;
2858 /* No dynamic config for include files */
2859 cf = ch_calloc( 1, sizeof(ConfigFile));
2860 if ( cfn->c_kids ) {
2861 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2867 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2868 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2869 c->lineno = savelineno - 1;
2872 if ( cf2 ) cf2->c_sibs = NULL;
2873 else cfn->c_kids = NULL;
2874 ch_free( cf->c_file.bv_val );
2884 config_tls_option(ConfigArgs *c) {
2886 LDAP *ld = slap_tls_ld;
2888 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
2889 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2890 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2891 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2892 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2893 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2894 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
2896 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
2898 default: Debug(LDAP_DEBUG_ANY, "%s: "
2899 "unknown tls_option <0x%x>\n",
2900 c->log, c->type, 0);
2903 if (c->op == SLAP_CONFIG_EMIT) {
2904 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
2905 } else if ( c->op == LDAP_MOD_DELETE ) {
2906 return ldap_pvt_tls_set_option( ld, flag, NULL );
2908 ch_free(c->value_string);
2909 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
2912 /* FIXME: this ought to be provided by libldap */
2914 config_tls_config(ConfigArgs *c) {
2917 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
2918 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
2920 Debug(LDAP_DEBUG_ANY, "%s: "
2921 "unknown tls_option <0x%x>\n",
2922 c->log, c->type, 0);
2925 if (c->op == SLAP_CONFIG_EMIT) {
2926 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
2927 } else if ( c->op == LDAP_MOD_DELETE ) {
2929 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
2931 ch_free( c->value_string );
2932 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
2933 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
2934 Debug(LDAP_DEBUG_ANY, "%s: "
2935 "unable to parse %s \"%s\"\n",
2936 c->log, c->argv[0], c->argv[1] );
2939 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
2941 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
2946 static CfEntryInfo *
2947 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2957 if ( dn_match( &root->ce_entry->e_nname, dn ))
2960 c = dn->bv_val+dn->bv_len;
2961 for (;*c != ',';c--);
2965 for (--c;c>dn->bv_val && *c != ',';c--);
2969 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2971 root = root->ce_kids;
2973 for (;root;root=root->ce_sibs) {
2974 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2975 if ( cdn.bv_val == dn->bv_val ) {
2985 typedef struct setup_cookie {
2995 config_ldif_resp( Operation *op, SlapReply *rs )
2997 if ( rs->sr_type == REP_SEARCH ) {
2998 setup_cookie *sc = op->o_callback->sc_private;
3000 sc->cfb->cb_got_ldif = 1;
3001 /* Does the frontend exist? */
3002 if ( !sc->got_frontend ) {
3003 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3004 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3005 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3006 STRLENOF( "olcDatabase" ), "={-1}frontend",
3007 STRLENOF( "={-1}frontend" ))) {
3010 sc->ca->be = frontendDB;
3011 sc->ca->bi = frontendDB->bd_info;
3012 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3013 rdn.bv_val = sc->ca->log;
3014 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3015 "%s=" SLAP_X_ORDERED_FMT "%s",
3016 cfAd_database->ad_cname.bv_val, -1,
3017 sc->ca->bi->bi_type);
3019 sc->frontend = config_build_entry( op, rs,
3020 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3021 sc->ca->be->be_cf_ocs );
3030 /* Does the configDB exist? */
3031 if ( sc->got_frontend && !sc->got_config &&
3032 !strncmp( rs->sr_entry->e_nname.bv_val,
3033 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3034 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3035 STRLENOF( "olcDatabase" ), "={0}config",
3036 STRLENOF( "={0}config" ))) {
3039 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3040 sc->ca->bi = sc->ca->be->bd_info;
3041 rdn.bv_val = sc->ca->log;
3042 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3043 "%s=" SLAP_X_ORDERED_FMT "%s",
3044 cfAd_database->ad_cname.bv_val, 0,
3045 sc->ca->bi->bi_type);
3047 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3048 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3055 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3056 if ( rs->sr_err != LDAP_SUCCESS ) {
3057 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3058 rs->sr_entry->e_name.bv_val, sc->ca->msg, 0 );
3064 /* Configure and read the underlying back-ldif store */
3066 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3067 CfBackInfo *cfb = be->be_private;
3073 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3074 Connection conn = {0};
3075 OperationBuffer opbuf;
3077 SlapReply rs = {REP_RESULT};
3078 Filter filter = { LDAP_FILTER_PRESENT };
3079 struct berval filterstr = BER_BVC("(objectclass=*)");
3082 /* Is the config directory available? */
3083 if ( stat( dir, &st ) < 0 ) {
3084 /* No, so don't bother using the backing store.
3085 * All changes will be in-memory only.
3090 cfb->cb_db.bd_info = backend_info( "ldif" );
3091 if ( !cfb->cb_db.bd_info )
3092 return 0; /* FIXME: eventually this will be a fatal error */
3094 if ( backend_db_init( "ldif", &cfb->cb_db, -1 ) == NULL )
3097 cfb->cb_db.be_suffix = be->be_suffix;
3098 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3100 /* The suffix is always "cn=config". The underlying DB's rootdn
3101 * is always the same as the suffix.
3103 cfb->cb_db.be_rootdn = be->be_suffix[0];
3104 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3106 ber_str2bv( dir, 0, 1, &cfdir );
3111 argv[0] = "directory";
3112 argv[1] = (char *)dir;
3115 c.table = Cft_Database;
3117 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3121 if ( config_add_vals( ct, &c ))
3124 if ( backend_startup_one( &cfb->cb_db ))
3128 void *thrctx = ldap_pvt_thread_pool_context();
3131 connection_fake_init( &conn, &opbuf, thrctx );
3134 filter.f_desc = slap_schema.si_ad_objectClass;
3136 op->o_tag = LDAP_REQ_SEARCH;
3138 op->ors_filter = &filter;
3139 op->ors_filterstr = filterstr;
3140 op->ors_scope = LDAP_SCOPE_SUBTREE;
3142 op->o_dn = c.be->be_rootdn;
3143 op->o_ndn = c.be->be_rootndn;
3145 op->o_req_dn = be->be_suffix[0];
3146 op->o_req_ndn = be->be_nsuffix[0];
3148 op->ors_tlimit = SLAP_NO_LIMIT;
3149 op->ors_slimit = SLAP_NO_LIMIT;
3151 op->ors_attrs = slap_anlist_all_attributes;
3152 op->ors_attrsonly = 0;
3154 op->o_callback = &cb;
3157 cb.sc_private = ≻
3158 sc.got_frontend = 0;
3163 op->o_bd = &cfb->cb_db;
3165 /* Allow unknown attrs in DNs */
3166 prev_DN_strict = slap_DN_strict;
3169 rc = op->o_bd->be_search( op, &rs );
3171 /* Restore normal DN validation */
3172 slap_DN_strict = prev_DN_strict;
3174 op->o_tag = LDAP_REQ_ADD;
3175 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3176 op->ora_e = sc.frontend;
3177 rc = op->o_bd->be_add( op, &rs );
3179 if ( rc == LDAP_SUCCESS && sc.config ) {
3180 op->ora_e = sc.config;
3181 rc = op->o_bd->be_add( op, &rs );
3183 ldap_pvt_thread_pool_context_reset( thrctx );
3186 /* ITS#4194 - only use if it's present, or we're converting. */
3187 if ( !readit || rc == LDAP_SUCCESS )
3188 cfb->cb_use_ldif = 1;
3194 CfOc_cmp( const void *c1, const void *c2 ) {
3195 const ConfigOCs *co1 = c1;
3196 const ConfigOCs *co2 = c2;
3198 return ber_bvcmp( co1->co_name, co2->co_name );
3202 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3205 i = init_config_attrs( ct );
3208 /* set up the objectclasses */
3209 i = init_config_ocs( ocs );
3212 for (i=0; ocs[i].co_def; i++) {
3213 if ( ocs[i].co_oc ) {
3214 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3215 if ( !ocs[i].co_table )
3216 ocs[i].co_table = ct;
3217 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3224 read_config(const char *fname, const char *dir) {
3227 const char *cfdir, *cfname;
3230 /* Setup the config backend */
3231 be = backend_db_init( "config", NULL, 0 );
3235 cfb = be->be_private;
3236 be->be_dfltaccess = ACL_NONE;
3238 /* If no .conf, or a dir was specified, setup the dir */
3239 if ( !fname || dir ) {
3241 /* If explicitly given, check for existence */
3244 if ( stat( dir, &st ) < 0 ) {
3245 Debug( LDAP_DEBUG_ANY,
3246 "invalid config directory %s, error %d\n",
3252 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3254 /* if fname is defaulted, try reading .d */
3255 rc = config_setup_ldif( be, cfdir, !fname );
3258 /* It may be OK if the base object doesn't exist yet. */
3259 if ( rc != LDAP_NO_SUCH_OBJECT )
3261 /* ITS#4194: But if dir was specified and no fname,
3262 * then we were supposed to read the dir. Unless we're
3263 * trying to slapadd the dir...
3265 if ( dir && !fname ) {
3266 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3268 /* Assume it's slapadd with a config dir, let it continue */
3270 cfb->cb_got_ldif = 1;
3271 cfb->cb_use_ldif = 1;
3276 /* If we read the config from back-ldif, nothing to do here */
3277 if ( cfb->cb_got_ldif ) {
3286 cfname = SLAPD_DEFAULT_CONFIGFILE;
3288 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3291 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3294 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3295 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3296 &frontendDB->be_schemadn );
3297 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3298 if ( rc != LDAP_SUCCESS ) {
3299 Debug(LDAP_DEBUG_ANY, "read_config: "
3300 "unable to normalize default schema DN \"%s\"\n",
3301 frontendDB->be_schemadn.bv_val, 0, 0 );
3302 /* must not happen */
3310 config_back_bind( Operation *op, SlapReply *rs )
3312 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
3313 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3314 /* frontend sends result */
3315 return LDAP_SUCCESS;
3318 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3319 send_ldap_result( op, rs );
3325 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3329 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3331 rs->sr_attrs = op->ors_attrs;
3332 rs->sr_entry = ce->ce_entry;
3334 rc = send_search_entry( op, rs );
3336 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3337 if ( ce->ce_kids ) {
3338 rc = config_send( op, rs, ce->ce_kids, 1 );
3339 if ( rc ) return rc;
3342 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3343 rc = config_send( op, rs, ce, 0 );
3351 static ConfigTable *
3352 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3357 for (j=0; j<nocs; j++) {
3358 for (i=0; colst[j]->co_table[i].name; i++)
3359 if ( colst[j]->co_table[i].ad == ad ) {
3360 ca->table = colst[j]->co_type;
3361 return &colst[j]->co_table[i];
3367 /* Sort the attributes of the entry according to the order defined
3368 * in the objectclass, with required attributes occurring before
3369 * allowed attributes. For any attributes with sequencing dependencies
3370 * (e.g., rootDN must be defined after suffix) the objectclass must
3371 * list the attributes in the desired sequence.
3374 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3376 Attribute *a, *head = NULL, *tail = NULL, **prev;
3379 for (i=0; i<nocs; i++) {
3380 if ( colst[i]->co_oc->soc_required ) {
3381 AttributeType **at = colst[i]->co_oc->soc_required;
3382 for (j=0; at[j]; j++) {
3383 for (a=e->e_attrs, prev=&e->e_attrs; a;
3384 prev = &(*prev)->a_next, a=a->a_next) {
3385 if ( a->a_desc == at[j]->sat_ad ) {
3399 if ( colst[i]->co_oc->soc_allowed ) {
3400 AttributeType **at = colst[i]->co_oc->soc_allowed;
3401 for (j=0; at[j]; j++) {
3402 for (a=e->e_attrs, prev=&e->e_attrs; a;
3403 prev = &(*prev)->a_next, a=a->a_next) {
3404 if ( a->a_desc == at[j]->sat_ad ) {
3420 tail->a_next = e->e_attrs;
3426 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3428 Attribute *a = NULL;
3429 AttributeDescription *ad;
3439 Modifications *ml = ptr;
3441 vals = ml->sml_values;
3444 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3445 rc = ordered_value_sort( a, 1 );
3447 snprintf(ca->msg, sizeof( ca->msg ), "ordered_value_sort failed on attr %s\n",
3448 ad->ad_cname.bv_val );
3452 for ( i=0; vals[i].bv_val; i++ ) {
3453 ca->line = vals[i].bv_val;
3454 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3455 ca->line[0] == '{' ) {
3456 char *idx = strchr( ca->line, '}' );
3457 if ( idx ) ca->line = idx+1;
3459 rc = config_parse_vals( ct, ca, i );
3468 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3471 struct berval rtype, rval;
3473 AttributeDescription *ad = NULL;
3475 dnRdn( &e->e_name, rdn );
3476 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3477 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3478 rtype.bv_val = rdn->bv_val;
3479 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3482 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3483 a = attr_find( e->e_attrs, ad );
3484 if (!a ) return LDAP_NAMING_VIOLATION;
3491 config_rename_kids( CfEntryInfo *ce )
3494 struct berval rdn, nrdn;
3496 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3497 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3498 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3499 free( ce2->ce_entry->e_name.bv_val );
3500 free( ce2->ce_entry->e_nname.bv_val );
3501 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3503 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3505 config_rename_kids( ce2 );
3510 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3511 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3512 struct berval *nnewrdn, int use_ldif )
3516 struct berval odn, ondn;
3520 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3521 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3524 free( a->a_vals[0].bv_val );
3525 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3526 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3527 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3528 strcpy( a->a_vals[0].bv_val, ptr1 );
3530 if ( a->a_nvals != a->a_vals ) {
3531 free( a->a_nvals[0].bv_val );
3532 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3533 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3534 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3535 strcpy( a->a_nvals[0].bv_val, ptr1 );
3538 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3539 BackendDB *be = op->o_bd;
3540 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3541 struct berval dn, ndn, xdn, xndn;
3543 op->o_bd = &cfb->cb_db;
3545 /* Save current rootdn; use the underlying DB's rootdn */
3549 xndn = op->o_req_ndn;
3550 op->o_dn = op->o_bd->be_rootdn;
3551 op->o_ndn = op->o_bd->be_rootndn;
3553 op->o_req_ndn = ondn;
3555 scp = op->o_callback;
3556 op->o_callback = ≻
3557 op->orr_newrdn = *newrdn;
3558 op->orr_nnewrdn = *nnewrdn;
3559 op->orr_newSup = NULL;
3560 op->orr_nnewSup = NULL;
3561 op->orr_deleteoldrdn = 1;
3562 op->orr_modlist = NULL;
3563 slap_modrdn2mods( op, rs );
3564 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3565 rc = op->o_bd->be_modrdn( op, rs );
3566 slap_mods_free( op->orr_modlist, 1 );
3569 op->o_callback = scp;
3573 op->o_req_ndn = xndn;
3576 free( ondn.bv_val );
3578 config_rename_kids( e->e_private );
3583 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3584 Entry *e, int idx, int tailindex, int use_ldif )
3586 struct berval ival, newrdn, nnewrdn;
3589 char ibuf[32], *ptr1, *ptr2 = NULL;
3592 rc = config_rename_attr( rs, e, &rdn, &a );
3593 if ( rc ) return rc;
3596 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3597 if ( ival.bv_len >= sizeof( ibuf ) ) {
3598 return LDAP_NAMING_VIOLATION;
3601 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3602 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3605 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3606 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3609 ptr2 = ber_bvchr( &rdn, '}' );
3613 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3615 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3616 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3617 a->a_desc->ad_cname.bv_len );
3619 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3620 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3624 /* Do the equivalent of ModRDN */
3625 /* Replace DN / NDN */
3626 newrdn.bv_len = ptr1 - newrdn.bv_val;
3627 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3628 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3630 free( nnewrdn.bv_val );
3631 free( newrdn.bv_val );
3636 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3637 SlapReply *rs, int *renum, int *ibase )
3640 int index = -1, gotindex = 0, nsibs, rc = 0;
3641 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3642 char *ptr1, *ptr2 = NULL;
3645 if ( renum ) *renum = 0;
3647 /* These entries don't get indexed/renumbered */
3648 if ( ce_type == Cft_Global ) return 0;
3649 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3651 if ( ce_type == Cft_Module )
3654 /* See if the rdn has an index already */
3655 dnRdn( &e->e_name, &rdn );
3656 if ( ce_type == Cft_Database ) {
3657 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3658 "frontend", STRLENOF("frontend") ))
3660 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3661 "config", STRLENOF("config") ))
3664 ptr1 = ber_bvchr( &e->e_name, '{' );
3665 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3667 ptr2 = strchr( ptr1, '}' );
3668 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3669 return LDAP_NAMING_VIOLATION;
3670 if ( ptr2-ptr1 == 1)
3671 return LDAP_NAMING_VIOLATION;
3673 index = strtol( ptr1 + 1, &next, 10 );
3674 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3675 return LDAP_NAMING_VIOLATION;
3678 /* Special case, we allow -1 for the frontendDB */
3679 if ( index != -1 || !isfrontend )
3680 return LDAP_NAMING_VIOLATION;
3682 if ( isconfig && index != 0 ){
3683 return LDAP_NAMING_VIOLATION;
3687 /* count related kids */
3688 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3689 if ( ce->ce_type == ce_type ) nsibs++;
3692 /* account for -1 frontend */
3693 if ( ce_type == Cft_Database )
3696 if ( index != nsibs ) {
3698 if ( index < nsibs ) {
3699 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3700 /* Siblings need to be renumbered */
3701 if ( index != -1 || !isfrontend )
3705 /* config DB is always "0" */
3706 if ( isconfig && index == -1 ) {
3709 if ( !isfrontend && index == -1 ) {
3713 /* just make index = nsibs */
3715 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3718 if ( ibase ) *ibase = index;
3719 if ( renum ) *renum = renumber;
3724 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3729 co.co_name = &oc->soc_cname;
3730 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3734 /* check for duplicates */
3735 for ( i = 0; i < *nocs; i++ ) {
3736 if ( *copp && (*copp)[i] == cop ) {
3742 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3743 if ( tmp == NULL ) {
3747 (*copp)[*nocs] = cop;
3752 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3753 if ( count_oc( *sups, copp, nocs ) ) {
3762 count_ocs( Attribute *oc_at, int *nocs )
3765 ConfigOCs **colst = NULL;
3769 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3773 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3775 assert( oc != NULL );
3776 if ( count_oc( oc, &colst, nocs ) ) {
3786 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3790 /* This entry is hardcoded, don't re-parse it */
3791 if ( p->ce_type == Cft_Global ) {
3792 cfn = p->ce_private;
3794 return LDAP_COMPARE_TRUE;
3796 if ( p->ce_type != Cft_Schema )
3797 return LDAP_CONSTRAINT_VIOLATION;
3799 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3801 cfo = p->ce_private;
3802 cfn->c_sibs = cfo->c_kids;
3804 return LDAP_SUCCESS;
3808 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3810 if ( p->ce_type != Cft_Global ) {
3811 return LDAP_CONSTRAINT_VIOLATION;
3813 ca->be = frontendDB; /* just to get past check_vals */
3814 return LDAP_SUCCESS;
3818 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3820 if ( p->ce_type != Cft_Global ) {
3821 return LDAP_CONSTRAINT_VIOLATION;
3823 return LDAP_SUCCESS;
3827 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3829 if ( p->ce_type != Cft_Global ) {
3830 return LDAP_CONSTRAINT_VIOLATION;
3832 return LDAP_SUCCESS;
3836 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3838 if ( p->ce_type != Cft_Database ) {
3839 return LDAP_CONSTRAINT_VIOLATION;
3842 return LDAP_SUCCESS;
3846 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
3851 AttributeDescription *ad;
3856 if ( cfn->c_cr_head ) {
3857 struct berval bv = BER_BVC("olcDitContentRules");
3859 slap_bv2ad( &bv, &ad, &text );
3860 ct = config_find_table( colst, nocs, ad, ca );
3861 config_del_vals( ct, ca );
3863 if ( cfn->c_oc_head ) {
3864 struct berval bv = BER_BVC("olcObjectClasses");
3866 slap_bv2ad( &bv, &ad, &text );
3867 ct = config_find_table( colst, nocs, ad, ca );
3868 config_del_vals( ct, ca );
3870 if ( cfn->c_at_head ) {
3871 struct berval bv = BER_BVC("olcAttributeTypes");
3873 slap_bv2ad( &bv, &ad, &text );
3874 ct = config_find_table( colst, nocs, ad, ca );
3875 config_del_vals( ct, ca );
3877 if ( cfn->c_om_head ) {
3878 struct berval bv = BER_BVC("olcObjectIdentifier");
3880 slap_bv2ad( &bv, &ad, &text );
3881 ct = config_find_table( colst, nocs, ad, ca );
3882 config_del_vals( ct, ca );
3884 cfo = p->ce_private;
3885 cfo->c_kids = cfn->c_sibs;
3890 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
3892 int rc = LDAP_CONSTRAINT_VIOLATION;
3895 if ( (*cop)->co_ldadd ) {
3896 rc = (*cop)->co_ldadd( last, e, ca );
3897 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
3902 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
3903 ConfigOCs co = { 0 };
3905 co.co_name = &(*ocp)->soc_cname;
3906 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
3907 if ( *cop == NULL ) {
3911 rc = config_add_oc( cop, last, e, ca );
3912 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
3920 /* Parse an LDAP entry into config directives */
3922 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
3923 int *renum, Operation *op )
3925 CfEntryInfo *ce, *last = NULL;
3926 ConfigOCs co, *coptr, **colst;
3927 Attribute *a, *oc_at, *soc_at;
3928 int i, ibase = -1, nocs, rc = 0;
3933 memset( ca, 0, sizeof(ConfigArgs));
3935 /* Make sure parent exists and entry does not. But allow
3936 * Databases and Overlays to be inserted. Don't do any
3937 * auto-renumbering if manageDSAit control is present.
3939 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3941 if ( ( op && op->o_managedsait ) ||
3942 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
3943 ce->ce_type != Cft_Module ) )
3945 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
3946 "DN=\"%s\" already exists\n",
3947 op->o_log_prefix, e->e_name.bv_val, 0 );
3948 return LDAP_ALREADY_EXISTS;
3952 dnParent( &e->e_nname, &pdn );
3954 /* If last is NULL, the new entry is the root/suffix entry,
3955 * otherwise last should be the parent.
3957 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
3959 rs->sr_matched = last->ce_entry->e_name.bv_val;
3961 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
3962 "DN=\"%s\" not child of DN=\"%s\"\n",
3963 op ? op->o_log_prefix : "", e->e_name.bv_val,
3964 last->ce_entry->e_name.bv_val );
3965 return LDAP_NO_SUCH_OBJECT;
3969 /* No parent, must be root. This will never happen... */
3970 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
3971 return LDAP_NO_SUCH_OBJECT;
3974 if ( last && !access_allowed( op, last->ce_entry,
3975 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
3977 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
3978 "DN=\"%s\" no write access to \"children\" of parent\n",
3979 op->o_log_prefix, e->e_name.bv_val, 0 );
3980 return LDAP_INSUFFICIENT_ACCESS;
3984 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3986 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
3987 "DN=\"%s\" no objectClass\n",
3988 op ? op->o_log_prefix : "", e->e_name.bv_val, 0 );
3989 return LDAP_OBJECT_CLASS_VIOLATION;
3992 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
3994 ObjectClass *soc = NULL;
3995 char textbuf[ SLAP_TEXT_BUFLEN ];
3996 const char *text = textbuf;
3998 /* FIXME: check result */
3999 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4000 &text, textbuf, sizeof(textbuf), NULL );
4001 if ( rc != LDAP_SUCCESS ) {
4002 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4003 "DN=\"%s\" no structural objectClass (%s)\n",
4004 op ? op->o_log_prefix : "", e->e_name.bv_val, text );
4007 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4008 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4009 if ( soc_at == NULL ) {
4010 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4011 "DN=\"%s\" no structural objectClass; "
4012 "unable to merge computed class %s\n",
4013 op ? op->o_log_prefix : "", e->e_name.bv_val,
4014 soc->soc_cname.bv_val );
4015 return LDAP_OBJECT_CLASS_VIOLATION;
4018 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4019 "DN=\"%s\" no structural objectClass; "
4020 "computed objectClass %s merged\n",
4021 op ? op->o_log_prefix : "", e->e_name.bv_val,
4022 soc->soc_cname.bv_val );
4025 /* Fake the coordinates based on whether we're part of an
4026 * LDAP Add or if reading the config dir
4029 ca->fname = "slapd";
4032 ca->fname = cfdir.bv_val;
4037 co.co_name = &soc_at->a_nvals[0];
4038 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4039 if ( coptr == NULL ) {
4040 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4041 "DN=\"%s\" no structural objectClass in configuration table\n",
4042 op ? op->o_log_prefix : "", e->e_name.bv_val, 0 );
4043 return LDAP_OBJECT_CLASS_VIOLATION;
4046 /* Only the root can be Cft_Global, everything else must
4047 * have a parent. Only limited nesting arrangements are allowed.
4049 rc = LDAP_CONSTRAINT_VIOLATION;
4050 if ( coptr->co_type == Cft_Global && !last ) {
4051 cfn = cfb->cb_config;
4053 ca->be = frontendDB; /* just to get past check_vals */
4057 /* Check whether the Add is allowed by its parent, and do
4058 * any necessary arg setup
4061 rc = config_add_oc( &coptr, last, e, ca );
4062 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4063 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4064 "DN=\"%s\" no structural objectClass add function\n",
4065 op ? op->o_log_prefix : "", e->e_name.bv_val, 0 );
4066 return LDAP_OBJECT_CLASS_VIOLATION;
4070 colst = count_ocs( oc_at, &nocs );
4072 /* Add the entry but don't parse it, we already have its contents */
4073 if ( rc == LDAP_COMPARE_TRUE ) {
4078 if ( rc != LDAP_SUCCESS )
4081 /* Parse all the values and check for simple syntax errors before
4082 * performing any set actions.
4084 * If doing an LDAPadd, check for indexed names and any necessary
4085 * renaming/renumbering. Entries that don't need indexed names are
4086 * ignored. Entries that need an indexed name and arrive without one
4087 * are assigned to the end. Entries that arrive with an index may
4088 * cause the following entries to be renumbered/bumped down.
4090 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4091 * don't allow Adding an entry with an index that's already in use.
4092 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4094 * These entries can have auto-assigned indexes (appended to the end)
4095 * but only the other types support auto-renumbering of siblings.
4098 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4103 if ( renum && *renum && coptr->co_type != Cft_Database &&
4104 coptr->co_type != Cft_Overlay )
4106 snprintf( ca->msg, sizeof( ca->msg ),
4107 "operation requires sibling renumbering" );
4108 rc = LDAP_UNWILLING_TO_PERFORM;
4113 init_config_argv( ca );
4115 /* Make sure we process attrs in the required order */
4116 sort_attrs( e, colst, nocs );
4118 for ( a = e->e_attrs; a; a = a->a_next ) {
4119 if ( a == oc_at ) continue;
4120 ct = config_find_table( colst, nocs, a->a_desc, ca );
4121 if ( !ct ) continue; /* user data? */
4122 rc = check_vals( ct, ca, a, 1 );
4123 if ( rc ) goto done_noop;
4126 /* Basic syntax checks are OK. Do the actual settings. */
4127 for ( a=e->e_attrs; a; a=a->a_next ) {
4128 if ( a == oc_at ) continue;
4129 ct = config_find_table( colst, nocs, a->a_desc, ca );
4130 if ( !ct ) continue; /* user data? */
4131 for (i=0; a->a_vals[i].bv_val; i++) {
4133 ca->line = a->a_vals[i].bv_val;
4134 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4135 ptr = strchr( ca->line, '}' );
4137 iptr = strchr( ca->line, '{' );
4141 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4143 ca->valx = strtol( iptr+1, NULL, 0 );
4150 rc = config_parse_add( ct, ca, i );
4158 /* Newly added databases and overlays need to be started up */
4159 if ( CONFIG_ONLINE_ADD( ca )) {
4160 if ( colst[0]->co_type == Cft_Database ) {
4161 rc = backend_startup_one( ca->be );
4163 } else if ( colst[0]->co_type == Cft_Overlay ) {
4164 if ( ca->bi->bi_db_open ) {
4165 BackendInfo *bi_orig = ca->be->bd_info;
4166 ca->be->bd_info = ca->bi;
4167 rc = ca->bi->bi_db_open( ca->be );
4168 ca->be->bd_info = bi_orig;
4172 snprintf( ca->msg, sizeof( ca->msg ), "<%s> failed startup", ca->argv[0] );
4173 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4174 ca->log, ca->msg, ca->argv[1] );
4181 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4182 ce->ce_parent = last;
4183 ce->ce_entry = entry_dup( e );
4184 ce->ce_entry->e_private = ce;
4185 ce->ce_type = colst[0]->co_type;
4188 ce->ce_private = ca->private;
4189 ca->ca_entry = ce->ce_entry;
4192 } else if ( last->ce_kids ) {
4193 CfEntryInfo *c2, **cprev;
4195 /* Advance to first of this type */
4196 cprev = &last->ce_kids;
4197 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4198 cprev = &c2->ce_sibs;
4201 /* Account for the (-1) frontendDB entry */
4202 if ( ce->ce_type == Cft_Database ) {
4203 if ( ca->be == frontendDB )
4205 else if ( ibase != -1 )
4210 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4211 cprev = &c2->ce_sibs;
4217 for ( i=0; i<ibase; i++ ) {
4219 cprev = &c2->ce_sibs;
4222 ce->ce_sibs = *cprev;
4230 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4231 if ( ca->be != frontendDB )
4232 backend_destroy_one( ca->be, 1 );
4233 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4234 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4235 } else if ( colst[0]->co_type == Cft_Schema ) {
4236 schema_destroy_one( ca, colst, nocs, last );
4241 ch_free( ca->argv );
4242 if ( colst ) ch_free( colst );
4246 #define BIGTMP 10000
4248 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4249 int base, int rebase, int max, int use_ldif )
4251 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4252 ConfigType etype = ce->ce_type;
4253 int count = 0, rc = 0;
4255 /* Reverse ce list */
4256 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4257 if (ce2->ce_type != etype) {
4262 ce2->ce_sibs = cetmp;
4265 if ( max && count >= max ) {
4271 /* Move original to a temp name until increments are done */
4273 ce->ce_entry->e_private = NULL;
4274 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4275 base+BIGTMP, 0, use_ldif );
4276 ce->ce_entry->e_private = ce;
4278 /* start incrementing */
4279 for (ce2=cetmp; ce2; ce2=ce3) {
4281 ce2->ce_sibs = cerem;
4284 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4285 count+base, 0, use_ldif );
4289 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4290 base, 0, use_ldif );
4295 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4296 CfEntryInfo *ce2, int old, int use_ldif )
4300 /* Renumber original to a temp value */
4301 ce->ce_entry->e_private = NULL;
4302 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4303 old+BIGTMP, 0, use_ldif );
4304 ce->ce_entry->e_private = ce;
4306 /* start decrementing */
4307 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4308 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4309 count+old, 0, use_ldif );
4312 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4313 count+old, 0, use_ldif );
4316 /* Parse an LDAP entry into config directives, then store in underlying
4320 config_back_add( Operation *op, SlapReply *rs )
4326 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4327 NULL, ACL_WADD, NULL )) {
4328 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4332 cfb = (CfBackInfo *)op->o_bd->be_private;
4334 /* add opattrs for syncprov */
4336 char textbuf[SLAP_TEXT_BUFLEN];
4337 size_t textlen = sizeof textbuf;
4338 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4339 &rs->sr_text, textbuf, sizeof( textbuf ) );
4340 if ( rs->sr_err != LDAP_SUCCESS )
4342 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4343 if ( rs->sr_err != LDAP_SUCCESS ) {
4344 Debug( LDAP_DEBUG_TRACE,
4345 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4346 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4351 ldap_pvt_thread_pool_pause( &connection_pool );
4354 * 1) check for existence of entry
4355 * 2) check for sibling renumbering
4356 * 3) perform internal add
4357 * 4) perform any necessary renumbering
4358 * 5) store entry in underlying database
4360 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4361 if ( rs->sr_err != LDAP_SUCCESS ) {
4362 rs->sr_text = ca.msg;
4367 CfEntryInfo *ce = ca.ca_entry->e_private;
4368 req_add_s addr = op->oq_add;
4369 op->o_tag = LDAP_REQ_MODRDN;
4370 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4371 op->o_tag = LDAP_REQ_ADD;
4373 if ( rs->sr_err != LDAP_SUCCESS ) {
4378 if ( cfb->cb_use_ldif ) {
4379 BackendDB *be = op->o_bd;
4380 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4381 struct berval dn, ndn;
4383 op->o_bd = &cfb->cb_db;
4385 /* Save current rootdn; use the underlying DB's rootdn */
4388 op->o_dn = op->o_bd->be_rootdn;
4389 op->o_ndn = op->o_bd->be_rootndn;
4391 scp = op->o_callback;
4392 op->o_callback = ≻
4393 op->o_bd->be_add( op, rs );
4395 op->o_callback = scp;
4401 ldap_pvt_thread_pool_resume( &connection_pool );
4404 send_ldap_result( op, rs );
4405 slap_graduate_commit_csn( op );
4409 typedef struct delrec {
4410 struct delrec *next;
4416 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4421 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4422 ca->line[0] == '{' )
4424 char *ptr = strchr( ca->line + 1, '}' );
4428 ca->valx = strtol( ca->line + 1, &next, 0 );
4429 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4435 rc = config_parse_add( ct, ca, i );
4443 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4446 int rc = LDAP_UNWILLING_TO_PERFORM;
4448 Entry *e = ce->ce_entry;
4449 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4454 delrec *dels = NULL, *deltail = NULL;
4456 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4457 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4459 colst = count_ocs( oc_at, &nocs );
4461 /* make sure add/del flags are clear; should always be true */
4462 for ( s = save_attrs; s; s = s->a_next ) {
4463 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4466 e->e_attrs = attrs_dup( e->e_attrs );
4468 init_config_argv( ca );
4471 ca->private = ce->ce_private;
4473 ca->fname = "slapd";
4475 strcpy( ca->log, "back-config" );
4477 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4478 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4479 switch (ml->sml_op) {
4480 case LDAP_MOD_DELETE:
4481 case LDAP_MOD_REPLACE: {
4482 BerVarray vals = NULL, nvals = NULL;
4484 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4486 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
4487 ml->sml_desc->ad_cname.bv_val );
4490 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4491 vals = ml->sml_values;
4492 nvals = ml->sml_nvalues;
4493 ml->sml_values = NULL;
4494 ml->sml_nvalues = NULL;
4496 /* If we're deleting by values, remember the indexes of the
4497 * values we deleted.
4499 if ( ct && ml->sml_values ) {
4501 for (i=0; ml->sml_values[i].bv_val; i++);
4502 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4513 rc = modify_delete_vindex(e, &ml->sml_mod,
4514 get_permissiveModify(op),
4515 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
4516 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4517 ml->sml_values = vals;
4518 ml->sml_nvalues = nvals;
4523 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4526 case SLAP_MOD_SOFTADD: {
4527 int mop = ml->sml_op;
4529 ml->sml_op = LDAP_MOD_ADD;
4531 if ( ct->arg_type & ARG_NO_INSERT ) {
4532 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4534 for (i = 0; a->a_vals[i].bv_val; i++ );
4538 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4539 if ( ml->sml_values[i].bv_val[0] == '{' &&
4542 char *next, *val = ml->sml_values[i].bv_val + 1;
4545 j = strtol( val, &next, 0 );
4546 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4548 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
4549 ml->sml_desc->ad_cname.bv_val );
4553 rc = check_vals( ct, ca, ml, 0 );
4554 if ( rc ) goto out_noop;
4557 rc = modify_add_values(e, &ml->sml_mod,
4558 get_permissiveModify(op),
4559 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4561 /* If value already exists, show success here
4562 * and ignore this operation down below.
4564 if ( mop == SLAP_MOD_SOFTADD ) {
4565 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4575 case LDAP_MOD_INCREMENT: /* FIXME */
4580 if(rc != LDAP_SUCCESS) break;
4583 if ( rc == LDAP_SUCCESS) {
4584 /* check that the entry still obeys the schema */
4585 rc = entry_schema_check(op, e, NULL, 0, 0,
4586 &rs->sr_text, ca->msg, sizeof(ca->msg) );
4587 if ( rc ) goto out_noop;
4589 /* Basic syntax checks are OK. Do the actual settings. */
4590 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4591 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4592 if ( !ct ) continue;
4594 s = attr_find( save_attrs, ml->sml_desc );
4595 a = attr_find( e->e_attrs, ml->sml_desc );
4597 switch (ml->sml_op) {
4598 case LDAP_MOD_DELETE:
4599 case LDAP_MOD_REPLACE: {
4600 BerVarray vals = NULL, nvals = NULL;
4603 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4604 vals = ml->sml_values;
4605 nvals = ml->sml_nvalues;
4606 ml->sml_values = NULL;
4607 ml->sml_nvalues = NULL;
4610 if ( ml->sml_values )
4613 /* If we didn't delete the whole attribute */
4614 if ( ml->sml_values && a ) {
4615 struct berval *mvals;
4618 if ( ml->sml_nvalues )
4619 mvals = ml->sml_nvalues;
4621 mvals = ml->sml_values;
4623 /* use the indexes we saved up above */
4624 for (i=0; i < d->nidx; i++) {
4625 struct berval bv = *mvals++;
4626 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4627 bv.bv_val[0] == '{' ) {
4628 ptr = strchr( bv.bv_val, '}' ) + 1;
4629 bv.bv_len -= ptr - bv.bv_val;
4632 ca->line = bv.bv_val;
4633 ca->valx = d->idx[i];
4634 rc = config_del_vals( ct, ca );
4635 if ( rc != LDAP_SUCCESS ) break;
4637 s->a_flags |= SLAP_ATTR_IXDEL;
4638 for (j=i+1; j < d->nidx; j++)
4639 if ( d->idx[j] >d->idx[i] )
4645 rc = config_del_vals( ct, ca );
4646 if ( rc ) rc = LDAP_OTHER;
4648 s->a_flags |= SLAP_ATTR_IXDEL;
4650 if ( ml->sml_values ) {
4655 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4656 ml->sml_values = vals;
4657 ml->sml_nvalues = nvals;
4659 if ( !vals || rc != LDAP_SUCCESS )
4662 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4665 for (i=0; ml->sml_values[i].bv_val; i++) {
4666 ca->line = ml->sml_values[i].bv_val;
4668 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4671 a->a_flags |= SLAP_ATTR_IXADD;
4678 /* Undo for a failed operation */
4679 if ( rc != LDAP_SUCCESS ) {
4680 for ( s = save_attrs; s; s = s->a_next ) {
4681 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4682 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4683 ct = config_find_table( colst, nocs, s->a_desc, ca );
4684 a = attr_find( e->e_attrs, s->a_desc );
4686 /* clear the flag so the add check below will skip it */
4687 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4690 config_del_vals( ct, ca );
4692 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4693 ca->line = s->a_vals[i].bv_val;
4695 config_modify_add( ct, ca, s->a_desc, i );
4699 for ( a = e->e_attrs; a; a = a->a_next ) {
4700 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4701 ct = config_find_table( colst, nocs, a->a_desc, ca );
4704 config_del_vals( ct, ca );
4705 s = attr_find( save_attrs, a->a_desc );
4707 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4708 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4709 ca->line = s->a_vals[i].bv_val;
4711 config_modify_add( ct, ca, s->a_desc, i );
4721 if ( rc == LDAP_SUCCESS ) {
4722 attrs_free( save_attrs );
4724 attrs_free( e->e_attrs );
4725 e->e_attrs = save_attrs;
4727 ch_free( ca->argv );
4728 if ( colst ) ch_free( colst );
4730 deltail = dels->next;
4739 config_back_modify( Operation *op, SlapReply *rs )
4742 CfEntryInfo *ce, *last;
4744 ConfigArgs ca = {0};
4747 AttributeDescription *rad = NULL;
4749 cfb = (CfBackInfo *)op->o_bd->be_private;
4751 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4754 rs->sr_matched = last->ce_entry->e_name.bv_val;
4755 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4759 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4760 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4764 /* Get type of RDN */
4765 rdn = ce->ce_entry->e_nname;
4766 ptr = strchr( rdn.bv_val, '=' );
4767 rdn.bv_len = ptr - rdn.bv_val;
4768 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4770 /* Some basic validation... */
4771 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4772 /* Don't allow Modify of RDN; must use ModRdn for that. */
4773 if ( ml->sml_desc == rad ) {
4774 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4775 rs->sr_text = "Use modrdn to change the entry name";
4780 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4782 if ( !slapd_shutdown )
4783 ldap_pvt_thread_pool_pause( &connection_pool );
4786 * 1) perform the Modify on the cached Entry.
4787 * 2) verify that the Entry still satisfies the schema.
4788 * 3) perform the individual config operations.
4789 * 4) store Modified entry in underlying LDIF backend.
4791 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4793 rs->sr_text = ca.msg;
4794 } else if ( cfb->cb_use_ldif ) {
4795 BackendDB *be = op->o_bd;
4796 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4797 struct berval dn, ndn;
4799 op->o_bd = &cfb->cb_db;
4803 op->o_dn = op->o_bd->be_rootdn;
4804 op->o_ndn = op->o_bd->be_rootndn;
4806 scp = op->o_callback;
4807 op->o_callback = ≻
4808 op->o_bd->be_modify( op, rs );
4810 op->o_callback = scp;
4815 if ( !slapd_shutdown )
4816 ldap_pvt_thread_pool_resume( &connection_pool );
4818 send_ldap_result( op, rs );
4819 slap_graduate_commit_csn( op );
4824 config_back_modrdn( Operation *op, SlapReply *rs )
4827 CfEntryInfo *ce, *last;
4831 cfb = (CfBackInfo *)op->o_bd->be_private;
4833 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4836 rs->sr_matched = last->ce_entry->e_name.bv_val;
4837 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4840 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4841 NULL, ACL_WRITE, NULL )) {
4842 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4846 if ( ce->ce_parent )
4847 parent = ce->ce_parent->ce_entry;
4849 parent = (Entry *)&slap_entry_root;
4850 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
4851 NULL, ACL_WRITE, NULL )) {
4852 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4857 /* We don't allow moving objects to new parents.
4858 * Generally we only allow reordering a set of ordered entries.
4860 if ( op->orr_newSup ) {
4861 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4865 /* If newRDN == oldRDN, quietly succeed */
4866 dnRdn( &op->o_req_ndn, &rdn );
4867 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
4868 rs->sr_err = LDAP_SUCCESS;
4872 /* Current behavior, subject to change as needed:
4874 * For backends and overlays, we only allow renumbering.
4875 * For schema, we allow renaming with the same number.
4876 * Otherwise, the op is not allowed.
4879 if ( ce->ce_type == Cft_Schema ) {
4883 /* Can't alter the main cn=schema entry */
4884 if ( ce->ce_parent->ce_type == Cft_Global ) {
4885 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4886 rs->sr_text = "renaming not allowed for this entry";
4890 /* We could support this later if desired */
4891 ptr1 = ber_bvchr( &rdn, '}' );
4892 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4893 len = ptr1 - rdn.bv_val;
4894 if ( len != ptr2 - op->orr_newrdn.bv_val ||
4895 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
4896 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4897 rs->sr_text = "schema reordering not supported";
4900 } else if ( ce->ce_type == Cft_Database ||
4901 ce->ce_type == Cft_Overlay ) {
4902 char *ptr1, *ptr2, *iptr1, *iptr2;
4905 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
4906 if ( *iptr2 != '{' ) {
4907 rs->sr_err = LDAP_NAMING_VIOLATION;
4908 rs->sr_text = "new ordering index is required";
4912 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
4913 ptr1 = ber_bvchr( &rdn, '}' );
4914 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4916 rs->sr_err = LDAP_NAMING_VIOLATION;
4917 rs->sr_text = "new ordering index is required";
4921 len1 = ptr1 - rdn.bv_val;
4922 len2 = ptr2 - op->orr_newrdn.bv_val;
4924 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
4925 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
4926 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4927 rs->sr_text = "changing database/overlay type not allowed";
4930 ixold = strtol( iptr1, NULL, 0 );
4931 ixnew = strtol( iptr2, &ptr1, 0 );
4932 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
4933 rs->sr_err = LDAP_NAMING_VIOLATION;
4936 /* config DB is always 0, cannot be changed */
4937 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
4938 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
4942 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4943 rs->sr_text = "renaming not supported for this entry";
4947 ldap_pvt_thread_pool_pause( &connection_pool );
4949 if ( ce->ce_type == Cft_Schema ) {
4950 req_modrdn_s modr = op->oq_modrdn;
4953 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
4954 if ( rs->sr_err == LDAP_SUCCESS ) {
4955 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
4956 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
4959 op->oq_modrdn = modr;
4961 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
4962 req_modrdn_s modr = op->oq_modrdn;
4965 /* Advance to first of this type */
4966 cprev = &ce->ce_parent->ce_kids;
4967 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
4968 cprev = &ce2->ce_sibs;
4971 /* Skip the -1 entry */
4972 if ( ce->ce_type == Cft_Database ) {
4973 cprev = &ce2->ce_sibs;
4979 /* Remove from old slot */
4980 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
4981 cprev = &ce2->ce_sibs;
4982 *cprev = ce->ce_sibs;
4983 ceold = ce->ce_sibs;
4985 /* Insert into new slot */
4987 for ( i=0; i<ixnew; i++ ) {
4991 cprev = &ce2->ce_sibs;
4993 ce->ce_sibs = *cprev;
4998 /* NOTE: These should be encoded in the OC tables, not inline here */
4999 if ( ce->ce_type == Cft_Database )
5000 backend_db_move( ce->ce_be, ixnew );
5001 else if ( ce->ce_type == Cft_Overlay )
5002 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5004 if ( ixold < ixnew ) {
5005 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5008 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5009 ixold - ixnew, cfb->cb_use_ldif );
5011 op->oq_modrdn = modr;
5014 ldap_pvt_thread_pool_resume( &connection_pool );
5016 send_ldap_result( op, rs );
5021 config_back_delete( Operation *op, SlapReply *rs )
5023 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5028 config_back_search( Operation *op, SlapReply *rs )
5031 CfEntryInfo *ce, *last;
5034 cfb = (CfBackInfo *)op->o_bd->be_private;
5036 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5039 rs->sr_matched = last->ce_entry->e_name.bv_val;
5040 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5043 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5044 ACL_SEARCH, NULL, &mask ))
5046 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5047 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5049 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5053 switch ( op->ors_scope ) {
5054 case LDAP_SCOPE_BASE:
5055 case LDAP_SCOPE_SUBTREE:
5056 config_send( op, rs, ce, 0 );
5059 case LDAP_SCOPE_ONELEVEL:
5060 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5061 config_send( op, rs, ce, 1 );
5066 rs->sr_err = LDAP_SUCCESS;
5068 send_ldap_result( op, rs );
5072 /* no-op, we never free entries */
5073 int config_entry_release(
5078 if ( !e->e_private ) {
5081 return LDAP_SUCCESS;
5084 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5086 int config_back_entry_get(
5090 AttributeDescription *at,
5095 CfEntryInfo *ce, *last;
5097 cfb = (CfBackInfo *)op->o_bd->be_private;
5099 ce = config_find_base( cfb->cb_root, ndn, &last );
5101 *ent = ce->ce_entry;
5102 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5107 return ( *ent == NULL ? 1 : 0 );
5111 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5112 ConfigTable *ct, ConfigArgs *c )
5116 for (; at && *at; at++) {
5117 /* Skip the naming attr */
5118 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5120 for (i=0;ct[i].name;i++) {
5121 if (ct[i].ad == (*at)->sat_ad) {
5122 rc = config_get_vals(&ct[i], c);
5123 /* NOTE: tolerate that config_get_vals()
5124 * returns success with no values */
5125 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5126 if ( c->rvalue_nvals )
5127 attr_merge(e, ct[i].ad, c->rvalue_vals,
5130 attr_merge_normalize(e, ct[i].ad,
5131 c->rvalue_vals, NULL);
5132 ber_bvarray_free( c->rvalue_nvals );
5133 ber_bvarray_free( c->rvalue_vals );
5142 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5143 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5145 Entry *e = entry_alloc();
5146 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5148 struct berval ad_name;
5149 AttributeDescription *ad = NULL;
5156 CfEntryInfo *ceprev = NULL;
5158 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5161 ce->ce_type = main->co_type;
5162 ce->ce_parent = parent;
5164 pdn = parent->ce_entry->e_nname;
5165 if ( parent->ce_kids )
5166 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5167 ceprev->ce_type <= ce->ce_type;
5168 ceprev = ceprev->ce_sibs );
5173 ce->ce_private = c->private;
5177 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5178 ber_dupbv( &e->e_nname, &e->e_name );
5180 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5181 main->co_name, NULL );
5183 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5184 extra->co_name, NULL );
5185 ptr = strchr(rdn->bv_val, '=');
5186 ad_name.bv_val = rdn->bv_val;
5187 ad_name.bv_len = ptr - rdn->bv_val;
5188 rc = slap_bv2ad( &ad_name, &ad, &text );
5193 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5194 attr_merge_normalize_one(e, ad, &val, NULL );
5197 c->table = main->co_type;
5198 if ( oc->soc_required )
5199 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5201 if ( oc->soc_allowed )
5202 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5206 c->table = extra->co_type;
5207 if ( oc->soc_required )
5208 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5210 if ( oc->soc_allowed )
5211 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5214 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5215 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->msg,
5216 sizeof(c->msg), op ? op->o_tmpmemctx : NULL );
5217 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5218 if ( op && !op->o_noop ) {
5220 op->ora_modlist = NULL;
5221 op->o_bd->be_add( op, rs );
5222 if ( ( rs->sr_err != LDAP_SUCCESS )
5223 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5228 ce->ce_sibs = ceprev->ce_sibs;
5229 ceprev->ce_sibs = ce;
5230 } else if ( parent ) {
5231 ce->ce_sibs = parent->ce_kids;
5232 parent->ce_kids = ce;
5239 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5240 Operation *op, SlapReply *rs )
5243 ConfigFile *cf = c->private;
5247 for (; cf; cf=cf->c_sibs, c->depth++) {
5248 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5249 !cf->c_om_head ) continue;
5250 c->value_dn.bv_val = c->log;
5251 LUTIL_SLASHPATH( cf->c_file.bv_val );
5252 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5257 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5259 ptr = strchr( bv.bv_val, '.' );
5261 bv.bv_len = ptr - bv.bv_val;
5262 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5263 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5264 /* FIXME: how can indicate error? */
5267 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5269 c->value_dn.bv_len += bv.bv_len;
5270 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5273 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5274 &CFOC_SCHEMA, NULL );
5277 } else if ( e && cf->c_kids ) {
5278 c->private = cf->c_kids;
5279 config_build_schema_inc( c, e->e_private, op, rs );
5285 #ifdef SLAPD_MODULES
5288 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5289 Operation *op, SlapReply *rs )
5294 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5295 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5297 c->value_dn.bv_val = c->log;
5298 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5299 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5300 /* FIXME: how can indicate error? */
5304 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5313 config_check_schema(Operation *op, CfBackInfo *cfb)
5315 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5317 CfEntryInfo *ce, *last;
5320 /* If there's no root entry, we must be in the midst of converting */
5321 if ( !cfb->cb_root )
5324 /* Make sure the main schema entry exists */
5325 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5332 /* Make sure it's up to date */
5333 if ( cf_om_tail != om_sys_tail ) {
5334 a = attr_find( e->e_attrs, cfAd_om );
5336 if ( a->a_nvals != a->a_vals )
5337 ber_bvarray_free( a->a_nvals );
5338 ber_bvarray_free( a->a_vals );
5342 oidm_unparse( &bv, NULL, NULL, 1 );
5343 attr_merge_normalize( e, cfAd_om, bv, NULL );
5344 ber_bvarray_free( bv );
5345 cf_om_tail = om_sys_tail;
5347 if ( cf_at_tail != at_sys_tail ) {
5348 a = attr_find( e->e_attrs, cfAd_attr );
5350 if ( a->a_nvals != a->a_vals )
5351 ber_bvarray_free( a->a_nvals );
5352 ber_bvarray_free( a->a_vals );
5356 at_unparse( &bv, NULL, NULL, 1 );
5357 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5358 ber_bvarray_free( bv );
5359 cf_at_tail = at_sys_tail;
5361 if ( cf_oc_tail != oc_sys_tail ) {
5362 a = attr_find( e->e_attrs, cfAd_oc );
5364 if ( a->a_nvals != a->a_vals )
5365 ber_bvarray_free( a->a_nvals );
5366 ber_bvarray_free( a->a_vals );
5370 oc_unparse( &bv, NULL, NULL, 1 );
5371 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5372 ber_bvarray_free( bv );
5373 cf_oc_tail = oc_sys_tail;
5376 SlapReply rs = {REP_RESULT};
5378 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5379 &CFOC_SCHEMA, NULL );
5384 ce->ce_private = cfb->cb_config;
5385 cf_at_tail = at_sys_tail;
5386 cf_oc_tail = oc_sys_tail;
5387 cf_om_tail = om_sys_tail;
5392 static const char *defacl[] = {
5393 NULL, "to", "*", "by", "*", "none", NULL
5397 config_back_db_open( BackendDB *be )
5399 CfBackInfo *cfb = be->be_private;
5402 CfEntryInfo *ce, *ceparent;
5406 Connection conn = {0};
5407 OperationBuffer opbuf;
5409 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5410 SlapReply rs = {REP_RESULT};
5411 void *thrctx = NULL;
5413 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5415 /* If we have no explicitly configured ACLs, don't just use
5416 * the global ACLs. Explicitly deny access to everything.
5418 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5419 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5422 thrctx = ldap_pvt_thread_pool_context();
5423 connection_fake_init( &conn, &opbuf, thrctx );
5426 op->o_tag = LDAP_REQ_ADD;
5427 op->o_callback = &cb;
5428 op->o_bd = &cfb->cb_db;
5429 op->o_dn = op->o_bd->be_rootdn;
5430 op->o_ndn = op->o_bd->be_rootndn;
5432 if ( !cfb->cb_use_ldif ) {
5436 /* If we read the config from back-ldif, do some quick sanity checks */
5437 if ( cfb->cb_got_ldif ) {
5438 return config_check_schema( op, cfb );
5441 /* create root of tree */
5443 c.private = cfb->cb_config;
5445 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5455 #ifdef SLAPD_MODULES
5456 /* Create Module nodes... */
5457 if ( modpaths.mp_loads ) {
5458 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5464 /* Create schema nodes... cn=schema will contain the hardcoded core
5465 * schema, read-only. Child objects will contain runtime loaded schema
5470 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5475 ce->ce_private = cfb->cb_config;
5476 cf_at_tail = at_sys_tail;
5477 cf_oc_tail = oc_sys_tail;
5478 cf_om_tail = om_sys_tail;
5480 /* Create schema nodes for included schema... */
5481 if ( cfb->cb_config->c_kids ) {
5483 c.private = cfb->cb_config->c_kids;
5484 if (config_build_schema_inc( &c, ce, op, &rs )) {
5489 /* Create backend nodes. Skip if they don't provide a cf_table.
5490 * There usually aren't any of these.
5494 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5495 if (!bi->bi_cf_ocs) {
5496 /* If it only supports the old config mech, complain. */
5497 if ( bi->bi_config ) {
5498 Debug( LDAP_DEBUG_ANY,
5499 "WARNING: No dynamic config support for backend %s.\n",
5500 bi->bi_type, 0, 0 );
5505 if (!bi->bi_private) continue;
5508 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5509 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5510 if ( rdn.bv_len >= sizeof( c.log ) ) {
5511 /* FIXME: holler ... */ ;
5514 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5521 /* Create database nodes... */
5522 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5523 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5524 for ( i = -1, be = frontendDB ; be;
5525 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5526 slap_overinfo *oi = NULL;
5528 if ( overlay_is_over( be )) {
5529 oi = be->bd_info->bi_private;
5535 /* If this backend supports the old config mechanism, but not
5536 * the new mech, complain.
5538 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5539 Debug( LDAP_DEBUG_ANY,
5540 "WARNING: No dynamic config support for database %s.\n",
5541 bi->bi_type, 0, 0 );
5545 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5546 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5548 if ( rdn.bv_len >= sizeof( c.log ) ) {
5549 /* FIXME: holler ... */ ;
5553 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5559 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5560 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5561 /* Iterate through overlays */
5567 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5568 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5569 Debug( LDAP_DEBUG_ANY,
5570 "WARNING: No dynamic config support for overlay %s.\n",
5571 on->on_bi.bi_type, 0, 0 );
5575 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5576 "%s=" SLAP_X_ORDERED_FMT "%s",
5577 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5578 if ( rdn.bv_len >= sizeof( c.log ) ) {
5579 /* FIXME: holler ... */ ;
5583 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5584 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5588 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5589 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5594 ldap_pvt_thread_pool_context_reset( thrctx );
5596 if ( unsupp && cfb->cb_use_ldif ) {
5597 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5598 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5605 cfb_free_cffile( ConfigFile *cf )
5609 for (; cf; cf=next) {
5612 cfb_free_cffile( cf->c_kids );
5613 ch_free( cf->c_file.bv_val );
5614 ber_bvarray_free( cf->c_dseFiles );
5620 cfb_free_entries( CfEntryInfo *ce )
5624 for (; ce; ce=next) {
5627 cfb_free_entries( ce->ce_kids );
5628 ce->ce_entry->e_private = NULL;
5629 entry_free( ce->ce_entry );
5635 config_back_db_close( BackendDB *be )
5637 CfBackInfo *cfb = be->be_private;
5639 cfb_free_entries( cfb->cb_root );
5640 cfb->cb_root = NULL;
5642 if ( cfb->cb_db.bd_info ) {
5643 backend_shutdown( &cfb->cb_db );
5650 config_back_db_destroy( BackendDB *be )
5652 CfBackInfo *cfb = be->be_private;
5654 cfb_free_cffile( cfb->cb_config );
5656 ch_free( cfdir.bv_val );
5658 avl_free( CfOcTree, NULL );
5660 if ( cfb->cb_db.bd_info ) {
5661 cfb->cb_db.be_suffix = NULL;
5662 cfb->cb_db.be_nsuffix = NULL;
5663 BER_BVZERO( &cfb->cb_db.be_rootdn );
5664 BER_BVZERO( &cfb->cb_db.be_rootndn );
5666 backend_destroy_one( &cfb->cb_db, 0 );
5675 config_back_db_init( BackendDB *be )
5681 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5682 cfn = cfb->cb_config;
5683 be->be_private = cfb;
5685 ber_dupbv( &be->be_rootdn, &config_rdn );
5686 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5687 ber_dupbv( &dn, &be->be_rootdn );
5688 ber_bvarray_add( &be->be_suffix, &dn );
5689 ber_dupbv( &dn, &be->be_rootdn );
5690 ber_bvarray_add( &be->be_nsuffix, &dn );
5692 /* Hide from namingContexts */
5693 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5699 config_back_destroy( BackendInfo *bi )
5701 ldif_must_b64_encode_release();
5706 config_tool_entry_open( BackendDB *be, int mode )
5708 CfBackInfo *cfb = be->be_private;
5709 BackendInfo *bi = cfb->cb_db.bd_info;
5711 if ( bi && bi->bi_tool_entry_open )
5712 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5719 config_tool_entry_close( BackendDB *be )
5721 CfBackInfo *cfb = be->be_private;
5722 BackendInfo *bi = cfb->cb_db.bd_info;
5724 if ( bi && bi->bi_tool_entry_close )
5725 return bi->bi_tool_entry_close( &cfb->cb_db );
5731 config_tool_entry_first( BackendDB *be )
5733 CfBackInfo *cfb = be->be_private;
5734 BackendInfo *bi = cfb->cb_db.bd_info;
5736 if ( bi && bi->bi_tool_entry_first )
5737 return bi->bi_tool_entry_first( &cfb->cb_db );
5743 config_tool_entry_next( BackendDB *be )
5745 CfBackInfo *cfb = be->be_private;
5746 BackendInfo *bi = cfb->cb_db.bd_info;
5748 if ( bi && bi->bi_tool_entry_next )
5749 return bi->bi_tool_entry_next( &cfb->cb_db );
5755 config_tool_entry_get( BackendDB *be, ID id )
5757 CfBackInfo *cfb = be->be_private;
5758 BackendInfo *bi = cfb->cb_db.bd_info;
5760 if ( bi && bi->bi_tool_entry_get )
5761 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5766 static int entry_put_got_frontend=0;
5767 static int entry_put_got_config=0;
5769 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5771 CfBackInfo *cfb = be->be_private;
5772 BackendInfo *bi = cfb->cb_db.bd_info;
5774 struct berval rdn, vals[ 2 ];
5776 OperationBuffer opbuf;
5778 Connection conn = {0};
5779 Operation *op = NULL;
5782 /* Create entry for frontend database if it does not exist already */
5783 if ( !entry_put_got_frontend ) {
5784 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5785 STRLENOF( "olcDatabase" ))) {
5786 if ( strncmp( e->e_nname.bv_val +
5787 STRLENOF( "olcDatabase" ), "={-1}frontend",
5788 STRLENOF( "={-1}frontend" )) &&
5789 strncmp( e->e_nname.bv_val +
5790 STRLENOF( "olcDatabase" ), "=frontend",
5791 STRLENOF( "=frontend" ))) {
5793 vals[1].bv_val = NULL;
5794 memset( &ca, 0, sizeof(ConfigArgs));
5796 ca.bi = frontendDB->bd_info;
5797 ca.be->be_cf_ocs = &CFOC_FRONTEND;
5798 rdn.bv_val = ca.log;
5799 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5800 "%s=" SLAP_X_ORDERED_FMT "%s",
5801 cfAd_database->ad_cname.bv_val, -1,
5803 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
5804 &CFOC_DATABASE, ca.be->be_cf_ocs );
5805 thrctx = ldap_pvt_thread_pool_context();
5806 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5808 op->o_bd = &cfb->cb_db;
5809 op->o_tag = LDAP_REQ_ADD;
5811 op->o_dn = be->be_rootdn;
5812 op->o_ndn = be->be_rootndn;
5813 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5814 if ( rc != LDAP_SUCCESS ) {
5815 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5816 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5820 if ( ce && bi && bi->bi_tool_entry_put &&
5821 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5822 entry_put_got_frontend++;
5824 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5825 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5829 entry_put_got_frontend++;
5833 /* Create entry for config database if it does not exist already */
5834 if ( !entry_put_got_config ) {
5835 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5836 STRLENOF( "olcDatabase" ))) {
5837 if ( strncmp( e->e_nname.bv_val +
5838 STRLENOF( "olcDatabase" ), "={0}config",
5839 STRLENOF( "={0}config" )) &&
5840 strncmp( e->e_nname.bv_val +
5841 STRLENOF( "olcDatabase" ), "=config",
5842 STRLENOF( "=config" )) ) {
5844 vals[1].bv_val = NULL;
5845 memset( &ca, 0, sizeof(ConfigArgs));
5846 ca.be = LDAP_STAILQ_FIRST( &backendDB );
5847 ca.bi = ca.be->bd_info;
5848 rdn.bv_val = ca.log;
5849 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5850 "%s=" SLAP_X_ORDERED_FMT "%s",
5851 cfAd_database->ad_cname.bv_val, 0,
5853 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
5856 thrctx = ldap_pvt_thread_pool_context();
5857 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5859 op->o_bd = &cfb->cb_db;
5860 op->o_tag = LDAP_REQ_ADD;
5861 op->o_dn = be->be_rootdn;
5862 op->o_ndn = be->be_rootndn;
5865 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5866 if ( rc != LDAP_SUCCESS ) {
5867 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
5868 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
5871 if (ce && bi && bi->bi_tool_entry_put &&
5872 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5873 entry_put_got_config++;
5875 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
5876 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
5880 entry_put_got_config++;
5884 if ( bi && bi->bi_tool_entry_put &&
5885 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
5886 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
5893 AttributeDescription **desc;
5895 { "attribute", &cfAd_attr },
5896 { "backend", &cfAd_backend },
5897 { "database", &cfAd_database },
5898 { "include", &cfAd_include },
5899 { "objectclass", &cfAd_oc },
5900 { "objectidentifier", &cfAd_om },
5901 { "overlay", &cfAd_overlay },
5906 * add / delete: all types that may be added or deleted must use an
5907 * X-ORDERED attributeType for their RDN. Adding and deleting entries
5908 * should automatically renumber the index of any siblings as needed,
5909 * so that no gaps in the numbering sequence exist after the add/delete
5911 * What can be added:
5913 * backend objects for backend-specific config directives
5917 * delete: probably no support this time around.
5919 * modrdn: generally not done. Will be invoked automatically by add/
5920 * delete to update numbering sequence. Perform as an explicit operation
5921 * so that the renumbering effect may be replicated. Subtree rename must
5922 * be supported, since renumbering a database will affect all its child
5925 * modify: must be fully supported.
5929 config_back_initialize( BackendInfo *bi )
5931 ConfigTable *ct = config_back_cf_table;
5935 AttributeDescription *ad = NULL;
5937 static char *controls[] = {
5938 LDAP_CONTROL_MANAGEDSAIT,
5942 /* Make sure we don't exceed the bits reserved for userland */
5943 config_check_userland( CFG_LAST );
5945 bi->bi_controls = controls;
5950 bi->bi_destroy = config_back_destroy;
5952 bi->bi_db_init = config_back_db_init;
5953 bi->bi_db_config = 0;
5954 bi->bi_db_open = config_back_db_open;
5955 bi->bi_db_close = config_back_db_close;
5956 bi->bi_db_destroy = config_back_db_destroy;
5958 bi->bi_op_bind = config_back_bind;
5959 bi->bi_op_unbind = 0;
5960 bi->bi_op_search = config_back_search;
5961 bi->bi_op_compare = 0;
5962 bi->bi_op_modify = config_back_modify;
5963 bi->bi_op_modrdn = config_back_modrdn;
5964 bi->bi_op_add = config_back_add;
5965 bi->bi_op_delete = config_back_delete;
5966 bi->bi_op_abandon = 0;
5968 bi->bi_extended = 0;
5970 bi->bi_chk_referrals = 0;
5972 bi->bi_access_allowed = slap_access_allowed;
5974 bi->bi_connection_init = 0;
5975 bi->bi_connection_destroy = 0;
5977 bi->bi_entry_release_rw = config_entry_release;
5978 bi->bi_entry_get_rw = config_back_entry_get;
5980 bi->bi_tool_entry_open = config_tool_entry_open;
5981 bi->bi_tool_entry_close = config_tool_entry_close;
5982 bi->bi_tool_entry_first = config_tool_entry_first;
5983 bi->bi_tool_entry_next = config_tool_entry_next;
5984 bi->bi_tool_entry_get = config_tool_entry_get;
5985 bi->bi_tool_entry_put = config_tool_entry_put;
5988 argv[ 0 ] = "slapd";
5994 for (i=0; OidMacros[i].name; i++ ) {
5995 argv[1] = OidMacros[i].name;
5996 argv[2] = OidMacros[i].oid;
5997 parse_oidm( &ca, 0, NULL );
6000 bi->bi_cf_ocs = cf_ocs;
6002 i = config_register_schema( ct, cf_ocs );
6005 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6006 * basically, we don't care if it fails */
6007 i = slap_str2ad( "olcRootPW", &ad, &text );
6009 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6010 "warning, unable to get \"olcRootPW\" "
6011 "attribute description: %d: %s\n",
6014 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6015 ad->ad_type->sat_oid );
6018 /* set up the notable AttributeDescriptions */
6020 for (;ct->name;ct++) {
6021 if (strcmp(ct->name, ads[i].name)) continue;
6022 *ads[i].desc = ct->ad;
6024 if (!ads[i].name) break;