1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2011 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>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
87 static AccessControl *defacl_parsed = NULL;
89 static struct berval cfdir;
92 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
93 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
95 static ConfigFile *cfn;
97 static Avlnode *CfOcTree;
99 /* System schema state */
100 extern AttributeType *at_sys_tail; /* at.c */
101 extern ObjectClass *oc_sys_tail; /* oc.c */
102 extern OidMacro *om_sys_tail; /* oidm.c */
103 extern Syntax *syn_sys_tail; /* syntax.c */
104 static AttributeType *cf_at_tail;
105 static ObjectClass *cf_oc_tail;
106 static OidMacro *cf_om_tail;
107 static Syntax *cf_syn_tail;
109 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
110 SlapReply *rs, int *renumber, Operation *op );
112 static int config_check_schema( Operation *op, CfBackInfo *cfb );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_subordinate;
124 static ConfigDriver config_suffix;
125 #ifdef LDAP_TCP_BUFFER
126 static ConfigDriver config_tcp_buffer;
127 #endif /* LDAP_TCP_BUFFER */
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_extra_attrs;
140 static ConfigDriver config_include;
141 static ConfigDriver config_obsolete;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_config;
154 CFG_TLS_PROTOCOL_MIN,
205 static OidRec OidMacros[] = {
206 /* OpenLDAProot:1.12.2 */
207 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
208 { "OLcfgAt", "OLcfg:3" },
209 { "OLcfgGlAt", "OLcfgAt:0" },
210 { "OLcfgBkAt", "OLcfgAt:1" },
211 { "OLcfgDbAt", "OLcfgAt:2" },
212 { "OLcfgOvAt", "OLcfgAt:3" },
213 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
214 { "OLcfgOc", "OLcfg:4" },
215 { "OLcfgGlOc", "OLcfgOc:0" },
216 { "OLcfgBkOc", "OLcfgOc:1" },
217 { "OLcfgDbOc", "OLcfgOc:2" },
218 { "OLcfgOvOc", "OLcfgOc:3" },
219 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
221 /* Syntaxes. We should just start using the standard names and
222 * document that they are predefined and available for users
223 * to reference in their own schema. Defining schema without
224 * OID macros is for masochists...
226 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
227 { "OMsBoolean", "OMsyn:7" },
228 { "OMsDN", "OMsyn:12" },
229 { "OMsDirectoryString", "OMsyn:15" },
230 { "OMsIA5String", "OMsyn:26" },
231 { "OMsInteger", "OMsyn:27" },
232 { "OMsOID", "OMsyn:38" },
233 { "OMsOctetString", "OMsyn:40" },
238 * Backend/Database registry
240 * OLcfg{Bk|Db}{Oc|At}:0 -> common
241 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
242 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
243 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
244 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
245 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
246 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
247 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
248 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
254 * OLcfgOv{Oc|At}:1 -> syncprov
255 * OLcfgOv{Oc|At}:2 -> pcache
256 * OLcfgOv{Oc|At}:3 -> chain
257 * OLcfgOv{Oc|At}:4 -> accesslog
258 * OLcfgOv{Oc|At}:5 -> valsort
259 * OLcfgOv{Oc|At}:7 -> distproc
260 * OLcfgOv{Oc|At}:8 -> dynlist
261 * OLcfgOv{Oc|At}:9 -> dds
262 * OLcfgOv{Oc|At}:10 -> unique
263 * OLcfgOv{Oc|At}:11 -> refint
264 * OLcfgOv{Oc|At}:12 -> ppolicy
265 * OLcfgOv{Oc|At}:13 -> constraint
266 * OLcfgOv{Oc|At}:14 -> translucent
267 * OLcfgOv{Oc|At}:15 -> auditlog
268 * OLcfgOv{Oc|At}:16 -> rwm
269 * OLcfgOv{Oc|At}:17 -> dyngroup
270 * OLcfgOv{Oc|At}:18 -> memberof
271 * OLcfgOv{Oc|At}:19 -> collect
272 * OLcfgOv{Oc|At}:20 -> retcode
273 * OLcfgOv{Oc|At}:21 -> sssvlv
276 /* alphabetical ordering */
278 static ConfigTable config_back_cf_table[] = {
279 /* This attr is read-only */
280 { "", "", 0, 0, 0, ARG_MAGIC,
281 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
282 "DESC 'File for slapd configuration directives' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
285 { "", "", 0, 0, 0, ARG_MAGIC,
286 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
287 "DESC 'Directory for slapd configuration backend' "
288 "EQUALITY caseIgnoreMatch "
289 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
290 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
291 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
292 "DESC 'Access Control List' "
293 "EQUALITY caseIgnoreMatch "
294 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
295 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
296 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
297 "DESC 'Check ACLs against content of Add ops' "
298 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
299 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
300 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
301 "DESC 'Allowed set of deprecated features' "
302 "EQUALITY caseIgnoreMatch "
303 "SYNTAX OMsDirectoryString )", NULL, NULL },
304 { "argsfile", "file", 2, 2, 0, ARG_STRING,
305 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
306 "DESC 'File for slapd command line options' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
309 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
310 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString )", NULL, NULL },
313 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
314 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
315 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
316 "DESC 'OpenLDAP attributeTypes' "
317 "EQUALITY caseIgnoreMatch "
318 "SUBSTR caseIgnoreSubstringsMatch "
319 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
321 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
322 #ifdef SLAP_AUTH_REWRITE
323 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
327 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
328 "EQUALITY caseIgnoreMatch "
329 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
330 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
331 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
332 "EQUALITY caseIgnoreMatch "
333 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
334 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
335 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
338 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
339 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
340 "DESC 'A type of backend' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
344 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
345 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
346 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
347 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
348 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
349 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
350 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
351 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
352 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
353 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
354 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
355 "DESC 'The backend type for a database instance' "
356 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
357 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
358 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
359 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
360 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
361 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
362 "EQUALITY caseIgnoreMatch "
363 "SYNTAX OMsDirectoryString )", NULL, NULL },
364 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
365 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
366 "DESC 'OpenLDAP DIT content rules' "
367 "EQUALITY caseIgnoreMatch "
368 "SUBSTR caseIgnoreSubstringsMatch "
369 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
371 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
372 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
373 "EQUALITY caseIgnoreMatch "
374 "SYNTAX OMsDirectoryString )", NULL, NULL },
375 { "gentlehup", "on|off", 2, 2, 0,
377 ARG_ON_OFF, &global_gentlehup,
381 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
382 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
383 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
384 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
385 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
386 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
387 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
388 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
389 { "include", "file", 2, 2, 0, ARG_MAGIC,
390 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
391 "SUP labeledURI )", NULL, NULL },
392 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
393 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
394 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
395 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
396 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
397 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
398 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
399 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
402 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
403 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
404 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
405 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
406 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
407 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
408 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
409 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
410 { "ldapsyntax", "syntax", 2, 0, 0,
411 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
412 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
413 "DESC 'OpenLDAP ldapSyntax' "
414 "EQUALITY caseIgnoreMatch "
415 "SUBSTR caseIgnoreSubstringsMatch "
416 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
418 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
419 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
420 "EQUALITY caseIgnoreMatch "
421 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
422 { "listener-threads", "count", 2, 0, 0,
426 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
428 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
429 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
430 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
431 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
432 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
433 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
434 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
435 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
436 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
437 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
438 "EQUALITY caseIgnoreMatch "
439 "SYNTAX OMsDirectoryString )", NULL, NULL },
440 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
441 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
442 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
443 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
444 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
445 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
446 { "moduleload", "file", 2, 0, 0,
448 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
452 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
453 "EQUALITY caseIgnoreMatch "
454 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
455 { "modulepath", "path", 2, 2, 0,
457 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
461 "( OLcfgGlAt:31 NAME 'olcModulePath' "
462 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
463 { "monitoring", "TRUE|FALSE", 2, 2, 0,
464 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
465 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
466 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
467 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
468 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
469 "DESC 'OpenLDAP object classes' "
470 "EQUALITY caseIgnoreMatch "
471 "SUBSTR caseIgnoreSubstringsMatch "
472 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
474 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
475 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
476 "EQUALITY caseIgnoreMatch "
477 "SUBSTR caseIgnoreSubstringsMatch "
478 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
479 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
480 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
481 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
482 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
483 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
484 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
485 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
486 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
487 "EQUALITY caseIgnoreMatch "
488 "SYNTAX OMsDirectoryString )", NULL, NULL },
489 { "pidfile", "file", 2, 2, 0, ARG_STRING,
490 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
491 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
492 { "plugin", NULL, 0, 0, 0,
494 ARG_MAGIC|CFG_PLUGIN, &config_generic,
498 "( OLcfgGlAt:38 NAME 'olcPlugin' "
499 "EQUALITY caseIgnoreMatch "
500 "SYNTAX OMsDirectoryString )", NULL, NULL },
501 { "pluginlog", "filename", 2, 2, 0,
503 ARG_STRING, &slapi_log_file,
507 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
508 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
509 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
510 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
511 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
512 { "referral", "url", 2, 2, 0, ARG_MAGIC,
513 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
514 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
515 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
516 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
517 "EQUALITY caseIgnoreMatch "
518 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
519 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
520 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
521 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
522 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
523 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
526 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
527 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
528 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
529 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
530 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
531 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
532 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
533 "EQUALITY caseIgnoreMatch "
534 "SYNTAX OMsDirectoryString )", NULL, NULL },
535 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
536 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
537 "EQUALITY caseIgnoreMatch "
538 "SYNTAX OMsDirectoryString )", NULL, NULL },
539 { "reverse-lookup", "on|off", 2, 2, 0,
540 #ifdef SLAPD_RLOOKUPS
541 ARG_ON_OFF, &use_reverse_lookup,
545 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
546 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
547 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
548 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
549 "EQUALITY distinguishedNameMatch "
550 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
551 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
552 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
553 "EQUALITY caseIgnoreMatch "
554 "SYNTAX OMsDirectoryString )", NULL, NULL },
555 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
556 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
557 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
558 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
559 &config_generic, NULL, NULL, NULL },
560 { "sasl-auxprops", NULL, 2, 0, 0,
561 #ifdef HAVE_CYRUS_SASL
562 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
566 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
567 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
568 { "sasl-host", "host", 2, 2, 0,
569 #ifdef HAVE_CYRUS_SASL
570 ARG_STRING|ARG_UNIQUE, &sasl_host,
574 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
575 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
576 { "sasl-realm", "realm", 2, 2, 0,
577 #ifdef HAVE_CYRUS_SASL
578 ARG_STRING|ARG_UNIQUE, &global_realm,
582 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
583 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
584 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
585 &config_generic, NULL, NULL, NULL },
586 { "sasl-secprops", "properties", 2, 2, 0,
587 #ifdef HAVE_CYRUS_SASL
588 ARG_MAGIC|CFG_SASLSECP, &config_generic,
592 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
593 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
594 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
595 &config_generic, NULL, NULL, NULL },
596 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
597 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
598 "EQUALITY distinguishedNameMatch "
599 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
600 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
601 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
602 "EQUALITY caseIgnoreMatch "
603 "SYNTAX OMsDirectoryString )", NULL, NULL },
604 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
605 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
606 "EQUALITY caseIgnoreMatch "
607 "SYNTAX OMsDirectoryString )", NULL, NULL },
608 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
609 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
610 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
611 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
612 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
613 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
614 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
615 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
616 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
617 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
618 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
619 "DESC 'Attributes whose values will always be sorted' "
620 "EQUALITY caseIgnoreMatch "
621 "SYNTAX OMsDirectoryString )", NULL, NULL },
622 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
623 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
624 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
625 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
626 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
627 "EQUALITY distinguishedNameMatch "
628 "SYNTAX OMsDN )", NULL, NULL },
629 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
630 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
631 "DESC 'Store sync context in a subentry' "
632 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
633 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
634 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
635 "EQUALITY caseIgnoreMatch "
636 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
637 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
638 #ifndef LDAP_TCP_BUFFER
640 #else /* LDAP_TCP_BUFFER */
641 ARG_MAGIC, &config_tcp_buffer,
642 #endif /* LDAP_TCP_BUFFER */
643 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
644 "DESC 'Custom TCP buffer size' "
645 "SYNTAX OMsDirectoryString )", NULL, NULL },
646 { "threads", "count", 2, 2, 0,
650 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
652 "( OLcfgGlAt:66 NAME 'olcThreads' "
653 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
654 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
655 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
656 "SYNTAX OMsDirectoryString )", NULL, NULL },
657 { "TLSCACertificateFile", NULL, 2, 2, 0,
659 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
663 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
664 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
665 { "TLSCACertificatePath", NULL, 2, 2, 0,
667 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
671 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
672 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
673 { "TLSCertificateFile", NULL, 2, 2, 0,
675 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
679 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
680 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
681 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
683 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
687 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
688 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
689 { "TLSCipherSuite", NULL, 2, 2, 0,
691 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
695 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
696 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
697 { "TLSCRLCheck", NULL, 2, 2, 0,
698 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
699 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
703 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
704 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
705 { "TLSCRLFile", NULL, 2, 2, 0,
706 #if defined(HAVE_GNUTLS)
707 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
711 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
712 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
713 { "TLSRandFile", NULL, 2, 2, 0,
715 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
719 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
720 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
721 { "TLSVerifyClient", NULL, 2, 2, 0,
723 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
727 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
728 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
729 { "TLSDHParamFile", NULL, 2, 2, 0,
731 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
735 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
736 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
737 { "TLSProtocolMin", NULL, 2, 2, 0,
739 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
743 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
744 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
745 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
746 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
747 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
748 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
749 NULL, NULL, NULL, NULL },
750 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
751 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
752 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
753 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
754 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
755 "EQUALITY caseIgnoreMatch "
756 "SUP labeledURI )", NULL, NULL },
757 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
758 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
759 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
760 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
761 NULL, NULL, NULL, NULL }
764 /* Need to no-op this keyword for dynamic config */
765 ConfigTable olcDatabaseDummy[] = {
766 { "", "", 0, 0, 0, ARG_IGNORED,
767 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
768 "DESC 'The backend type for a database instance' "
769 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
770 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
773 /* Routines to check if a child can be added to this type */
774 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
775 cfAddBackend, cfAddModule, cfAddOverlay;
777 /* NOTE: be careful when defining array members
778 * that can be conditionally compiled */
779 #define CFOC_GLOBAL cf_ocs[1]
780 #define CFOC_SCHEMA cf_ocs[2]
781 #define CFOC_BACKEND cf_ocs[3]
782 #define CFOC_DATABASE cf_ocs[4]
783 #define CFOC_OVERLAY cf_ocs[5]
784 #define CFOC_INCLUDE cf_ocs[6]
785 #define CFOC_FRONTEND cf_ocs[7]
787 #define CFOC_MODULE cf_ocs[8]
788 #endif /* SLAPD_MODULES */
790 static ConfigOCs cf_ocs[] = {
793 "DESC 'OpenLDAP configuration object' "
794 "ABSTRACT SUP top )", Cft_Abstract, NULL },
797 "DESC 'OpenLDAP Global configuration options' "
798 "SUP olcConfig STRUCTURAL "
799 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
800 "olcAttributeOptions $ olcAuthIDRewrite $ "
801 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
802 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
803 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
804 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
805 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
806 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
807 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
808 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
809 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
811 "olcSaslAuxprops $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
812 "olcSecurity $ olcServerID $ olcSizeLimit $ "
813 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
815 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
816 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
817 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
818 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
819 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
820 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
821 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
823 "NAME 'olcSchemaConfig' "
824 "DESC 'OpenLDAP schema object' "
825 "SUP olcConfig STRUCTURAL "
826 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
827 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
828 Cft_Schema, NULL, cfAddSchema },
830 "NAME 'olcBackendConfig' "
831 "DESC 'OpenLDAP Backend-specific options' "
832 "SUP olcConfig STRUCTURAL "
833 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
835 "NAME 'olcDatabaseConfig' "
836 "DESC 'OpenLDAP Database-specific options' "
837 "SUP olcConfig STRUCTURAL "
839 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
840 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
841 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
842 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
843 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
844 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
845 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
846 "olcMonitoring $ olcExtraAttrs ) )",
847 Cft_Database, NULL, cfAddDatabase },
849 "NAME 'olcOverlayConfig' "
850 "DESC 'OpenLDAP Overlay-specific options' "
851 "SUP olcConfig STRUCTURAL "
852 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
854 "NAME 'olcIncludeFile' "
855 "DESC 'OpenLDAP configuration include file' "
856 "SUP olcConfig STRUCTURAL "
858 "MAY ( cn $ olcRootDSE ) )",
859 /* Used to be Cft_Include, that def has been removed */
860 Cft_Abstract, NULL, cfAddInclude },
861 /* This should be STRUCTURAL like all the other database classes, but
862 * that would mean inheriting all of the olcDatabaseConfig attributes,
863 * which causes them to be merged twice in config_build_entry.
866 "NAME 'olcFrontendConfig' "
867 "DESC 'OpenLDAP frontend configuration' "
869 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
870 Cft_Database, NULL, NULL },
873 "NAME 'olcModuleList' "
874 "DESC 'OpenLDAP dynamic module info' "
875 "SUP olcConfig STRUCTURAL "
876 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
877 Cft_Module, NULL, cfAddModule },
882 typedef struct ServerID {
883 struct ServerID *si_next;
884 struct berval si_url;
888 static ServerID *sid_list;
890 typedef struct voidList {
891 struct voidList *vl_next;
895 typedef struct ADlist {
896 struct ADlist *al_next;
897 AttributeDescription *al_desc;
900 static ADlist *sortVals;
903 config_generic(ConfigArgs *c) {
906 if ( c->op == SLAP_CONFIG_EMIT ) {
910 c->value_int = ldap_pvt_thread_get_concurrency();
913 c->value_int = connection_pool_max;
916 c->value_int = slap_tool_thread_max;
919 c->value_uint = slapd_daemon_threads;
923 c->value_string = ch_strdup( passwd_salt );
928 if ( c->be->be_limits ) {
932 for ( i=0; c->be->be_limits[i]; i++ ) {
933 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
934 if ( bv.bv_len >= sizeof( buf ) ) {
935 ber_bvarray_free_x( c->rvalue_vals, NULL );
936 c->rvalue_vals = NULL;
940 bv.bv_val = buf + bv.bv_len;
941 limits_unparse( c->be->be_limits[i], &bv,
942 sizeof( buf ) - ( bv.bv_val - buf ) );
943 bv.bv_len += bv.bv_val - buf;
945 value_add_one( &c->rvalue_vals, &bv );
948 if ( !c->rvalue_vals ) rc = 1;
951 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
954 c->value_string = ch_strdup( slap_sasl_getpolicy());
957 slap_sasl_regexp_unparse( &c->rvalue_vals );
958 if ( !c->rvalue_vals ) rc = 1;
960 #ifdef HAVE_CYRUS_SASL
962 struct berval bv = BER_BVNULL;
963 slap_sasl_secprops_unparse( &bv );
964 if ( !BER_BVISNULL( &bv )) {
965 ber_bvarray_add( &c->rvalue_vals, &bv );
973 c->value_int = c->be->be_max_deref_depth;
976 if ( SLAP_DBHIDDEN( c->be )) {
983 ConfigFile *cf = c->ca_private;
985 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
986 else if ( cf->c_om_head )
987 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
989 if ( !c->rvalue_vals )
994 ad_unparse_options( &c->rvalue_vals );
997 ConfigFile *cf = c->ca_private;
999 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1000 else if ( cf->c_oc_head )
1001 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1003 if ( !c->rvalue_vals )
1008 ConfigFile *cf = c->ca_private;
1010 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1011 else if ( cf->c_at_head )
1012 at_unparse( &c->rvalue_vals, cf->c_at_head,
1014 if ( !c->rvalue_vals )
1019 ConfigFile *cf = c->ca_private;
1021 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1022 else if ( cf->c_syn_head )
1023 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1024 cf->c_syn_tail, 0 );
1025 if ( !c->rvalue_vals )
1030 ConfigFile *cf = c->ca_private;
1032 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1033 else if ( cf->c_cr_head )
1034 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1036 if ( !c->rvalue_vals )
1043 char *src, *dst, ibuf[11];
1044 struct berval bv, abv;
1045 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1046 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1047 if ( abv.bv_len >= sizeof( ibuf ) ) {
1048 ber_bvarray_free_x( c->rvalue_vals, NULL );
1049 c->rvalue_vals = NULL;
1053 acl_unparse( a, &bv );
1054 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1055 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1056 /* Turn TAB / EOL into plain space */
1057 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1058 if (isspace((unsigned char)*src)) *dst++ = ' ';
1062 if (dst[-1] == ' ') {
1066 abv.bv_len = dst - abv.bv_val;
1067 ber_bvarray_add( &c->rvalue_vals, &abv );
1073 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1076 ConfigFile *cf = c->ca_private;
1077 if ( cf->c_dseFiles ) {
1078 value_add( &c->rvalue_vals, cf->c_dseFiles );
1089 for ( si = sid_list; si; si=si->si_next ) {
1090 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1091 if ( !BER_BVISEMPTY( &si->si_url )) {
1092 bv.bv_len = si->si_url.bv_len + 6;
1093 bv.bv_val = ch_malloc( bv.bv_len );
1094 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1095 si->si_url.bv_val );
1096 ber_bvarray_add( &c->rvalue_vals, &bv );
1100 bv.bv_len = sprintf( buf, "%d", si->si_num );
1101 value_add_one( &c->rvalue_vals, &bv );
1110 c->value_string = ch_strdup( logfileName );
1115 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1117 case CFG_SYNC_SUBENTRY:
1118 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1120 case CFG_MIRRORMODE:
1121 if ( SLAP_SHADOW(c->be))
1122 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1126 case CFG_MONITORING:
1127 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1129 case CFG_SSTR_IF_MAX:
1130 c->value_uint = index_substr_if_maxlen;
1132 case CFG_SSTR_IF_MIN:
1133 c->value_uint = index_substr_if_minlen;
1136 c->value_int = index_intlen;
1138 case CFG_SORTVALS: {
1141 for ( sv = sortVals; sv; sv = sv->al_next ) {
1142 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1146 #ifdef SLAPD_MODULES
1148 ModPaths *mp = c->ca_private;
1151 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1154 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1155 SLAP_X_ORDERED_FMT "%s", i,
1156 mp->mp_loads[i].bv_val );
1157 if ( bv.bv_len >= sizeof( c->log ) ) {
1158 ber_bvarray_free_x( c->rvalue_vals, NULL );
1159 c->rvalue_vals = NULL;
1162 value_add_one( &c->rvalue_vals, &bv );
1166 rc = c->rvalue_vals ? 0 : 1;
1170 ModPaths *mp = c->ca_private;
1171 if ( !BER_BVISNULL( &mp->mp_path ))
1172 value_add_one( &c->rvalue_vals, &mp->mp_path );
1174 rc = c->rvalue_vals ? 0 : 1;
1180 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1181 if ( !c->rvalue_vals ) rc = 1;
1184 #ifdef SLAP_AUTH_REWRITE
1186 if ( authz_rewrites ) {
1187 struct berval bv, idx;
1192 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1193 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1194 if ( idx.bv_len >= sizeof( ibuf ) ) {
1195 ber_bvarray_free_x( c->rvalue_vals, NULL );
1196 c->rvalue_vals = NULL;
1199 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1200 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1201 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1202 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1203 authz_rewrites[i].bv_val,
1204 authz_rewrites[i].bv_len + 1 );
1205 ber_bvarray_add( &c->rvalue_vals, &bv );
1208 if ( !c->rvalue_vals ) rc = 1;
1215 } else if ( c->op == LDAP_MOD_DELETE ) {
1218 /* single-valued attrs, no-ops */
1227 case CFG_MIRRORMODE:
1228 case CFG_MONITORING:
1230 case CFG_SSTR_IF_MAX:
1231 case CFG_SSTR_IF_MIN:
1233 case CFG_SYNC_SUBENTRY:
1236 /* no-ops, requires slapd restart */
1241 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1245 ch_free( passwd_salt );
1250 ch_free( logfileName );
1258 case CFG_SERVERID: {
1259 ServerID *si, **sip;
1261 for ( i=0, si = sid_list, sip = &sid_list;
1262 si; si = *sip, i++ ) {
1263 if ( c->valx == -1 || i == c->valx ) {
1275 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1279 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1280 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1281 SLAP_INDEX_INTLEN_DEFAULT );
1285 if ( c->valx < 0 ) {
1286 acl_destroy( c->be->be_acl );
1287 c->be->be_acl = NULL;
1290 AccessControl **prev, *a;
1292 for (i=0, prev = &c->be->be_acl; i < c->valx;
1295 prev = &a->acl_next;
1298 *prev = a->acl_next;
1301 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1302 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1303 "Last explicit ACL for back-config removed. "
1304 "Using hardcoded default\n", 0, 0, 0 );
1305 c->be->be_acl = defacl_parsed;
1311 /* Can be NULL when undoing a failed add */
1312 if ( c->ca_entry ) {
1313 ce = c->ca_entry->e_private;
1314 /* can't modify the hardcoded schema */
1315 if ( ce->ce_parent->ce_type == Cft_Global )
1319 cfn = c->ca_private;
1320 if ( c->valx < 0 ) {
1323 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1325 if ( oc == cfn->c_oc_tail )
1328 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1330 ObjectClass *oc, *prev = NULL;
1332 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1337 if ( cfn->c_oc_tail == oc ) {
1338 cfn->c_oc_tail = prev;
1340 if ( cfn->c_oc_head == oc ) {
1342 cfn->c_oc_head = oc;
1349 /* Can be NULL when undoing a failed add */
1350 if ( c->ca_entry ) {
1351 ce = c->ca_entry->e_private;
1352 /* can't modify the hardcoded schema */
1353 if ( ce->ce_parent->ce_type == Cft_Global )
1357 cfn = c->ca_private;
1358 if ( c->valx < 0 ) {
1361 for( at = cfn->c_at_head; at; at_next( &at )) {
1363 if ( at == cfn->c_at_tail )
1366 cfn->c_at_head = cfn->c_at_tail = NULL;
1368 AttributeType *at, *prev = NULL;
1370 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1375 if ( cfn->c_at_tail == at ) {
1376 cfn->c_at_tail = prev;
1378 if ( cfn->c_at_head == at ) {
1380 cfn->c_at_head = at;
1387 /* Can be NULL when undoing a failed add */
1388 if ( c->ca_entry ) {
1389 ce = c->ca_entry->e_private;
1390 /* can't modify the hardcoded schema */
1391 if ( ce->ce_parent->ce_type == Cft_Global )
1395 cfn = c->ca_private;
1396 if ( c->valx < 0 ) {
1399 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1401 if ( syn == cfn->c_syn_tail )
1404 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1406 Syntax *syn, *prev = NULL;
1408 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1413 if ( cfn->c_syn_tail == syn ) {
1414 cfn->c_syn_tail = prev;
1416 if ( cfn->c_syn_head == syn ) {
1418 cfn->c_syn_head = syn;
1423 if ( c->valx < 0 ) {
1425 for ( sv = sortVals; sv; sv = sortVals ) {
1426 sortVals = sv->al_next;
1427 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1434 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1435 prev = &sv->al_next;
1438 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1439 *prev = sv->al_next;
1445 /* FIXME: there is no limits_free function */
1446 if ( c->valx < 0 ) {
1447 limits_destroy( c->be->be_limits );
1448 c->be->be_limits = NULL;
1453 if ( c->be->be_limits ) {
1454 for ( num = 0; c->be->be_limits[ num ]; num++ )
1458 if ( c->valx >= num ) {
1463 limits_destroy( c->be->be_limits );
1464 c->be->be_limits = NULL;
1467 limits_free_one( c->be->be_limits[ c->valx ] );
1469 for ( cnt = c->valx; cnt < num; cnt++ ) {
1470 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1477 /* FIXME: there is no ad_option_free function */
1479 /* FIXME: there is no way to remove attributes added by
1493 if(!(c->bi = backend_info(c->argv[1]))) {
1494 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1495 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1496 c->log, c->cr_msg, c->argv[1] );
1503 /* NOTE: config is always the first backend!
1505 if ( !strcasecmp( c->argv[1], "config" )) {
1506 c->be = LDAP_STAILQ_FIRST(&backendDB);
1507 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1510 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1512 if ( c->cr_msg[0] == 0 )
1513 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1514 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1521 ldap_pvt_thread_set_concurrency(c->value_int);
1525 if ( c->value_int < 2 ) {
1526 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1527 "threads=%d smaller than minimum value 2",
1529 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1530 c->log, c->cr_msg, 0 );
1533 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1534 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1535 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1536 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1537 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1538 c->log, c->cr_msg, 0 );
1540 if ( slapMode & SLAP_SERVER_MODE )
1541 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1542 connection_pool_max = c->value_int; /* save for reference */
1546 if ( slapMode & SLAP_TOOL_MODE )
1547 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1548 slap_tool_thread_max = c->value_int; /* save for reference */
1553 /* use a power of two */
1554 while (c->value_uint > 1) {
1555 c->value_uint >>= 1;
1559 slapd_daemon_mask = mask;
1560 slapd_daemon_threads = mask+1;
1565 if ( passwd_salt ) ch_free( passwd_salt );
1566 passwd_salt = c->value_string;
1567 lutil_salt_format(passwd_salt);
1571 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1577 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1579 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1583 ch_free(c->value_string);
1584 if (slap_sasl_setpolicy( c->argv[1] )) {
1585 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1586 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1587 c->log, c->cr_msg, c->argv[1] );
1593 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1597 #ifdef HAVE_CYRUS_SASL
1600 char *txt = slap_sasl_secprops( c->argv[1] );
1602 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1604 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1612 c->be->be_max_deref_depth = c->value_int;
1618 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1619 cfn = c->ca_private;
1620 if(parse_oidm(c, 1, &om))
1622 if (!cfn->c_om_head) cfn->c_om_head = om;
1623 cfn->c_om_tail = om;
1628 ObjectClass *oc, *prev;
1630 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1631 cfn = c->ca_private;
1632 if ( c->valx < 0 ) {
1633 prev = cfn->c_oc_tail;
1636 /* If adding anything after the first, prev is easy */
1639 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1641 if ( !oc_next( &oc ))
1645 /* If adding the first, and head exists, find its prev */
1646 if (cfn->c_oc_head) {
1647 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1652 /* else prev is NULL, append to end of global list */
1654 if(parse_oc(c, &oc, prev)) return(1);
1655 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1656 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1661 AttributeType *at, *prev;
1663 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1664 cfn = c->ca_private;
1665 if ( c->valx < 0 ) {
1666 prev = cfn->c_at_tail;
1669 /* If adding anything after the first, prev is easy */
1672 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1674 if ( !at_next( &at ))
1678 /* If adding the first, and head exists, find its prev */
1679 if (cfn->c_at_head) {
1680 for ( at_start( &at ); at != cfn->c_at_head; ) {
1685 /* else prev is NULL, append to end of global list */
1687 if(parse_at(c, &at, prev)) return(1);
1688 if (!cfn->c_at_head) cfn->c_at_head = at;
1689 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1696 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1697 cfn = c->ca_private;
1698 if ( c->valx < 0 ) {
1699 prev = cfn->c_syn_tail;
1702 /* If adding anything after the first, prev is easy */
1705 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1707 if ( !syn_next( &syn ))
1711 /* If adding the first, and head exists, find its prev */
1712 if (cfn->c_syn_head) {
1713 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1718 /* else prev is NULL, append to end of global list */
1720 if ( parse_syn( c, &syn, prev ) ) return(1);
1721 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1722 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1729 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1730 cfn = c->ca_private;
1731 if(parse_cr(c, &cr)) return(1);
1732 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1733 cfn->c_cr_tail = cr;
1738 ad_define_option(NULL, NULL, 0);
1739 for(i = 1; i < c->argc; i++)
1740 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1745 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1746 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1747 else if ( c->value_int > 255 )
1749 index_intlen = c->value_int;
1750 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1754 case CFG_SORTVALS: {
1755 ADlist *svnew = NULL, *svtail, *sv;
1757 for ( i = 1; i < c->argc; i++ ) {
1758 AttributeDescription *ad = NULL;
1762 rc = slap_str2ad( c->argv[i], &ad, &text );
1764 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1767 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1768 c->log, c->cr_msg, c->argv[i] );
1769 for ( sv = svnew; sv; sv = svnew ) {
1770 svnew = sv->al_next;
1775 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1776 ad->ad_type->sat_single_value ) {
1777 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1779 goto sortval_reject;
1781 sv = ch_malloc( sizeof( ADlist ));
1786 svtail->al_next = sv;
1791 for ( sv = svnew; sv; sv = sv->al_next )
1792 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1793 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1795 sv->al_next = svnew;
1802 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
1803 c->be->be_acl = NULL;
1805 /* Don't append to the global ACL if we're on a specific DB */
1807 if ( c->valx == -1 ) {
1810 for ( a=c->be->be_acl; a; a = a->acl_next )
1813 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1814 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
1815 c->be->be_acl = defacl_parsed;
1823 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1825 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1829 if(root_dse_read_file(c->argv[1])) {
1830 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1831 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1832 c->log, c->cr_msg, c->argv[1] );
1837 ber_str2bv( c->argv[1], 0, 1, &bv );
1838 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1839 cfn = c->ca_private;
1840 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1846 ServerID *si, **sip;
1849 if (( lutil_atoi( &num, c->argv[1] ) &&
1850 lutil_atoix( &num, c->argv[1], 16 )) ||
1851 num < 0 || num > SLAP_SYNC_SID_MAX )
1853 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1854 "<%s> illegal server ID", c->argv[0] );
1855 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1856 c->log, c->cr_msg, c->argv[1] );
1859 /* only one value allowed if no URL is given */
1860 if ( c->argc > 2 ) {
1863 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1864 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1865 "<%s> only one server ID allowed now", c->argv[0] );
1866 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1867 c->log, c->cr_msg, c->argv[1] );
1871 if ( ldap_url_parse( c->argv[2], &lud )) {
1872 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1873 "<%s> invalid URL", c->argv[0] );
1874 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1875 c->log, c->cr_msg, c->argv[2] );
1878 len = strlen( c->argv[2] );
1879 si = ch_malloc( sizeof(ServerID) + len + 1 );
1880 si->si_url.bv_val = (char *)(si+1);
1881 si->si_url.bv_len = len;
1882 strcpy( si->si_url.bv_val, c->argv[2] );
1885 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1886 "<%s> unqualified server ID not allowed now", c->argv[0] );
1887 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1888 c->log, c->cr_msg, c->argv[1] );
1891 si = ch_malloc( sizeof(ServerID) );
1892 BER_BVZERO( &si->si_url );
1893 slap_serverID = num;
1894 Debug( LDAP_DEBUG_CONFIG,
1896 c->log, slap_serverID, 0 );
1900 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1903 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1904 Listener *l = config_check_my_url( c->argv[2], lud );
1906 slap_serverID = si->si_num;
1907 Debug( LDAP_DEBUG_CONFIG,
1908 "%s: SID=0x%03x (listener=%s)\n",
1909 c->log, slap_serverID,
1914 ldap_free_urldesc( lud );
1918 if ( logfileName ) ch_free( logfileName );
1919 logfileName = c->value_string;
1920 logfile = fopen(logfileName, "w");
1921 if(logfile) lutil_debug_file(logfile);
1925 if(SLAP_NOLASTMODCMD(c->be)) {
1926 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1927 c->argv[0], c->be->bd_info->bi_type );
1928 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1929 c->log, c->cr_msg, 0 );
1933 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1935 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1938 case CFG_MIRRORMODE:
1939 if(c->value_int && !SLAP_SHADOW(c->be)) {
1940 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1942 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1943 c->log, c->cr_msg, 0 );
1947 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1949 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1952 case CFG_MONITORING:
1954 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1956 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1961 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1963 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1966 case CFG_SYNC_SUBENTRY:
1968 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
1970 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1973 case CFG_SSTR_IF_MAX:
1974 if (c->value_uint < index_substr_if_minlen) {
1975 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1976 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1977 c->log, c->cr_msg, c->value_int );
1980 index_substr_if_maxlen = c->value_uint;
1983 case CFG_SSTR_IF_MIN:
1984 if (c->value_uint > index_substr_if_maxlen) {
1985 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1986 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1987 c->log, c->cr_msg, c->value_int );
1990 index_substr_if_minlen = c->value_uint;
1993 #ifdef SLAPD_MODULES
1995 /* If we're just adding a module on an existing modpath,
1996 * make sure we've selected the current path.
1998 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1999 modcur = c->ca_private;
2000 /* This should never fail */
2001 if ( module_path( modcur->mp_path.bv_val )) {
2002 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2004 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2005 c->log, c->cr_msg, modcur->mp_path.bv_val );
2009 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2011 /* Record this load on the current path */
2015 if ( c->op == SLAP_CONFIG_ADD ) {
2016 ptr = c->line + STRLENOF("moduleload");
2017 while (!isspace((unsigned char) *ptr)) ptr++;
2018 while (isspace((unsigned char) *ptr)) ptr++;
2022 ber_str2bv(ptr, 0, 1, &bv);
2023 ber_bvarray_add( &modcur->mp_loads, &bv );
2025 /* Check for any new hardcoded schema */
2026 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2027 config_check_schema( NULL, &cfBackInfo );
2032 if(module_path(c->argv[1])) return(1);
2033 /* Record which path was used with each module */
2037 if (!modpaths.mp_loads) {
2040 mp = ch_malloc( sizeof( ModPaths ));
2041 modlast->mp_next = mp;
2043 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2045 mp->mp_loads = NULL;
2056 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2058 slapi_plugins_used++;
2062 #ifdef SLAP_AUTH_REWRITE
2068 if ( c->op == LDAP_MOD_ADD ) {
2072 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2076 if ( c->argc > 1 ) {
2079 /* quote all args but the first */
2080 line = ldap_charray2str( c->argv, "\" \"" );
2081 ber_str2bv( line, 0, 0, &bv );
2082 s = ber_bvchr( &bv, '"' );
2083 assert( s != NULL );
2084 /* move the trailing quote of argv[0] to the end */
2085 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2086 bv.bv_val[ bv.bv_len - 1 ] = '"';
2089 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2092 ber_bvarray_add( &authz_rewrites, &bv );
2094 if ( c->op == LDAP_MOD_ADD ) {
2104 Debug( LDAP_DEBUG_ANY,
2105 "%s: unknown CFG_TYPE %d.\n",
2106 c->log, c->type, 0 );
2115 config_fname(ConfigArgs *c) {
2116 if(c->op == SLAP_CONFIG_EMIT) {
2117 if (c->ca_private) {
2118 ConfigFile *cf = c->ca_private;
2119 value_add_one( &c->rvalue_vals, &cf->c_file );
2128 config_cfdir(ConfigArgs *c) {
2129 if(c->op == SLAP_CONFIG_EMIT) {
2130 if ( !BER_BVISEMPTY( &cfdir )) {
2131 value_add_one( &c->rvalue_vals, &cfdir );
2140 config_search_base(ConfigArgs *c) {
2141 if(c->op == SLAP_CONFIG_EMIT) {
2143 if (!BER_BVISEMPTY(&default_search_base)) {
2144 value_add_one(&c->rvalue_vals, &default_search_base);
2145 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2149 } else if( c->op == LDAP_MOD_DELETE ) {
2150 ch_free( default_search_base.bv_val );
2151 ch_free( default_search_nbase.bv_val );
2152 BER_BVZERO( &default_search_base );
2153 BER_BVZERO( &default_search_nbase );
2157 if(c->bi || c->be != frontendDB) {
2158 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2159 "prior to any backend or database definition\n",
2164 if(default_search_nbase.bv_len) {
2165 free(default_search_base.bv_val);
2166 free(default_search_nbase.bv_val);
2169 default_search_base = c->value_dn;
2170 default_search_nbase = c->value_ndn;
2174 /* For RE23 compatibility we allow this in the global entry
2175 * but we now defer it to the frontend entry to allow modules
2176 * to load new hash types.
2179 config_passwd_hash(ConfigArgs *c) {
2181 if (c->op == SLAP_CONFIG_EMIT) {
2183 /* Don't generate it in the global entry */
2184 if ( c->table == Cft_Global )
2186 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2187 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2188 value_add_one(&c->rvalue_vals, &bv);
2191 } else if ( c->op == LDAP_MOD_DELETE ) {
2192 /* Deleting from global is a no-op, only the frontendDB entry matters */
2193 if ( c->table == Cft_Global )
2195 if ( c->valx < 0 ) {
2196 ldap_charray_free( default_passwd_hash );
2197 default_passwd_hash = NULL;
2200 ch_free( default_passwd_hash[i] );
2201 for (; default_passwd_hash[i]; i++ )
2202 default_passwd_hash[i] = default_passwd_hash[i+1];
2206 for(i = 1; i < c->argc; i++) {
2207 if(!lutil_passwd_scheme(c->argv[i])) {
2208 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2209 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2210 c->log, c->cr_msg, c->argv[i]);
2212 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2215 if(!default_passwd_hash) {
2216 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2217 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2218 c->log, c->cr_msg, 0 );
2225 config_schema_dn(ConfigArgs *c) {
2226 if ( c->op == SLAP_CONFIG_EMIT ) {
2228 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2229 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2230 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2234 } else if ( c->op == LDAP_MOD_DELETE ) {
2235 ch_free( c->be->be_schemadn.bv_val );
2236 ch_free( c->be->be_schemandn.bv_val );
2237 BER_BVZERO( &c->be->be_schemadn );
2238 BER_BVZERO( &c->be->be_schemandn );
2241 ch_free( c->be->be_schemadn.bv_val );
2242 ch_free( c->be->be_schemandn.bv_val );
2243 c->be->be_schemadn = c->value_dn;
2244 c->be->be_schemandn = c->value_ndn;
2249 config_sizelimit(ConfigArgs *c) {
2251 struct slap_limits_set *lim = &c->be->be_def_limit;
2252 if (c->op == SLAP_CONFIG_EMIT) {
2257 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2258 if ( !BER_BVISEMPTY( &bv ))
2259 value_add_one( &c->rvalue_vals, &bv );
2263 } else if ( c->op == LDAP_MOD_DELETE ) {
2264 /* Reset to defaults or values from frontend */
2265 if ( c->be == frontendDB ) {
2266 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2267 lim->lms_s_hard = 0;
2268 lim->lms_s_unchecked = -1;
2270 lim->lms_s_pr_hide = 0;
2271 lim->lms_s_pr_total = 0;
2273 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2274 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2275 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2276 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2277 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2278 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2282 for(i = 1; i < c->argc; i++) {
2283 if(!strncasecmp(c->argv[i], "size", 4)) {
2284 rc = limits_parse_one(c->argv[i], lim);
2286 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2287 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2288 c->log, c->cr_msg, c->argv[i]);
2292 if(!strcasecmp(c->argv[i], "unlimited")) {
2293 lim->lms_s_soft = -1;
2295 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2296 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2297 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2298 c->log, c->cr_msg, c->argv[i]);
2302 lim->lms_s_hard = 0;
2307 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2308 /* This is a modification to the global limits apply it to
2309 * the other databases as needed */
2310 AttributeDescription *ad=NULL;
2311 const char *text = NULL;
2312 CfEntryInfo *ce = c->ca_entry->e_private;
2314 slap_str2ad(c->argv[0], &ad, &text);
2315 /* if we got here... */
2316 assert( ad != NULL );
2318 if ( ce->ce_type == Cft_Global ){
2321 for (; ce; ce=ce->ce_sibs) {
2322 Entry *dbe = ce->ce_entry;
2323 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2324 && (!attr_find(dbe->e_attrs, ad)) ) {
2325 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2326 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2327 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2328 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2329 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2330 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2338 config_timelimit(ConfigArgs *c) {
2340 struct slap_limits_set *lim = &c->be->be_def_limit;
2341 if (c->op == SLAP_CONFIG_EMIT) {
2346 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2347 if ( !BER_BVISEMPTY( &bv ))
2348 value_add_one( &c->rvalue_vals, &bv );
2352 } else if ( c->op == LDAP_MOD_DELETE ) {
2353 /* Reset to defaults or values from frontend */
2354 if ( c->be == frontendDB ) {
2355 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2356 lim->lms_t_hard = 0;
2358 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2359 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2363 for(i = 1; i < c->argc; i++) {
2364 if(!strncasecmp(c->argv[i], "time", 4)) {
2365 rc = limits_parse_one(c->argv[i], lim);
2367 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2368 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2369 c->log, c->cr_msg, c->argv[i]);
2373 if(!strcasecmp(c->argv[i], "unlimited")) {
2374 lim->lms_t_soft = -1;
2376 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2377 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2378 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2379 c->log, c->cr_msg, c->argv[i]);
2383 lim->lms_t_hard = 0;
2388 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2389 /* This is a modification to the global limits apply it to
2390 * the other databases as needed */
2391 AttributeDescription *ad=NULL;
2392 const char *text = NULL;
2393 CfEntryInfo *ce = c->ca_entry->e_private;
2395 slap_str2ad(c->argv[0], &ad, &text);
2396 /* if we got here... */
2397 assert( ad != NULL );
2399 if ( ce->ce_type == Cft_Global ){
2402 for (; ce; ce=ce->ce_sibs) {
2403 Entry *dbe = ce->ce_entry;
2404 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2405 && (!attr_find(dbe->e_attrs, ad)) ) {
2406 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2407 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2415 config_overlay(ConfigArgs *c) {
2416 if (c->op == SLAP_CONFIG_EMIT) {
2418 } else if ( c->op == LDAP_MOD_DELETE ) {
2421 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2422 c->valx, &c->bi, &c->reply)) {
2424 Debug( LDAP_DEBUG_ANY,
2425 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2426 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2428 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2435 config_subordinate(ConfigArgs *c)
2441 case SLAP_CONFIG_EMIT:
2442 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2445 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2446 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2449 value_add_one( &c->rvalue_vals, &bv );
2453 case LDAP_MOD_DELETE:
2454 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2455 glue_sub_del( c->be );
2457 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2462 case SLAP_CONFIG_ADD:
2463 if ( c->be->be_nsuffix == NULL ) {
2465 snprintf( c->cr_msg, sizeof( c->cr_msg),
2466 "subordinate configuration needs a suffix" );
2467 Debug( LDAP_DEBUG_ANY,
2469 c->log, c->cr_msg, 0 );
2474 if ( c->argc == 2 ) {
2475 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2478 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2480 snprintf( c->cr_msg, sizeof( c->cr_msg),
2481 "subordinate must be \"TRUE\" or \"advertise\"" );
2482 Debug( LDAP_DEBUG_ANY,
2483 "%s: suffix \"%s\": %s.\n",
2484 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2490 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2498 * [listener=<listener>] [{read|write}=]<size>
2501 #ifdef LDAP_TCP_BUFFER
2502 static BerVarray tcp_buffer;
2505 #define SLAP_TCP_RMEM (0x1U)
2506 #define SLAP_TCP_WMEM (0x2U)
2509 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2510 int *size, int *rw, Listener **l )
2512 int i, rc = LDAP_SUCCESS;
2513 LDAPURLDesc *lud = NULL;
2516 if ( val != NULL && argv == NULL ) {
2517 char *s = val->bv_val;
2519 argv = ldap_str2charray( s, " \t" );
2520 if ( argv == NULL ) {
2526 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2529 char *url = argv[ i ] + STRLENOF( "listener=" );
2531 if ( ldap_url_parse( url, &lud ) ) {
2532 rc = LDAP_INVALID_SYNTAX;
2536 *l = config_check_my_url( url, lud );
2538 rc = LDAP_NO_SUCH_ATTRIBUTE;
2546 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2547 *rw |= SLAP_TCP_RMEM;
2548 ptr += STRLENOF( "read=" );
2550 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2551 *rw |= SLAP_TCP_WMEM;
2552 ptr += STRLENOF( "write=" );
2555 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2558 /* accept any base */
2559 if ( lutil_atoix( size, ptr, 0 ) ) {
2560 rc = LDAP_INVALID_SYNTAX;
2565 if ( val != NULL && argv != NULL ) {
2566 ldap_charray_free( argv );
2569 if ( lud != NULL ) {
2570 ldap_free_urldesc( lud );
2577 tcp_buffer_delete_one( struct berval *val )
2580 int size = -1, rw = 0;
2583 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2590 Listener **ll = slapd_get_listeners();
2592 for ( i = 0; ll[ i ] != NULL; i++ ) {
2593 if ( ll[ i ] == l ) break;
2596 if ( ll[ i ] == NULL ) {
2597 return LDAP_NO_SUCH_ATTRIBUTE;
2600 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2601 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2603 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2604 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2605 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2609 /* NOTE: this affects listeners without a specific setting,
2610 * does not reset all listeners. If a listener without
2611 * specific settings was assigned a buffer because of
2612 * a global setting, it will not be reset. In any case,
2613 * buffer changes will only take place at restart. */
2614 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2615 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2622 tcp_buffer_delete( BerVarray vals )
2626 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2627 tcp_buffer_delete_one( &vals[ i ] );
2634 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2636 char buf[sizeof("2147483648")], *ptr;
2638 /* unparse for later use */
2639 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2641 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2644 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2645 if ( rw & SLAP_TCP_RMEM ) {
2646 val->bv_len += STRLENOF( "read=" );
2647 } else if ( rw & SLAP_TCP_WMEM ) {
2648 val->bv_len += STRLENOF( "write=" );
2652 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2657 ptr = lutil_strcopy( ptr, "listener=" );
2658 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2662 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2663 if ( rw & SLAP_TCP_RMEM ) {
2664 ptr = lutil_strcopy( ptr, "read=" );
2665 } else if ( rw & SLAP_TCP_WMEM ) {
2666 ptr = lutil_strcopy( ptr, "write=" );
2670 ptr = lutil_strcopy( ptr, buf );
2673 assert( val->bv_val + val->bv_len == ptr );
2675 return LDAP_SUCCESS;
2679 tcp_buffer_add_one( int argc, char **argv )
2682 int size = -1, rw = 0;
2688 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2693 /* unparse for later use */
2694 rc = tcp_buffer_unparse( size, rw, l, &val );
2695 if ( rc != LDAP_SUCCESS ) {
2699 /* use parsed values */
2702 Listener **ll = slapd_get_listeners();
2704 for ( i = 0; ll[ i ] != NULL; i++ ) {
2705 if ( ll[ i ] == l ) break;
2708 if ( ll[ i ] == NULL ) {
2709 return LDAP_NO_SUCH_ATTRIBUTE;
2712 /* buffer only applies to TCP listeners;
2713 * we do not do any check here, and delegate them
2714 * to setsockopt(2) */
2715 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2716 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2718 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2719 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2720 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2724 /* NOTE: this affects listeners without a specific setting,
2725 * does not set all listeners */
2726 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2727 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2730 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2732 tcp_buffer[ tcp_buffer_num ] = val;
2735 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2741 config_tcp_buffer( ConfigArgs *c )
2743 if ( c->op == SLAP_CONFIG_EMIT ) {
2744 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2747 value_add( &c->rvalue_vals, tcp_buffer );
2748 value_add( &c->rvalue_nvals, tcp_buffer );
2750 } else if ( c->op == LDAP_MOD_DELETE ) {
2752 tcp_buffer_delete( tcp_buffer );
2753 ber_bvarray_free( tcp_buffer );
2759 int size = -1, rw = 0;
2762 struct berval val = BER_BVNULL;
2766 if ( tcp_buffer_num == 0 ) {
2771 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2776 /* unparse for later use */
2777 rc = tcp_buffer_unparse( size, rw, l, &val );
2778 if ( rc != LDAP_SUCCESS ) {
2782 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2783 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2788 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2794 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2795 ber_memfree( tcp_buffer[ i ].bv_val );
2796 for ( ; i < tcp_buffer_num; i++ ) {
2797 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2802 if ( !BER_BVISNULL( &val ) ) {
2803 SLAP_FREE( val.bv_val );
2811 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2813 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2814 "<%s> unable to add value #%d",
2815 c->argv[0], tcp_buffer_num );
2816 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2817 c->log, c->cr_msg, 0 );
2824 #endif /* LDAP_TCP_BUFFER */
2827 config_suffix(ConfigArgs *c)
2830 struct berval pdn, ndn;
2831 char *notallowed = NULL;
2833 if ( c->be == frontendDB ) {
2834 notallowed = "frontend";
2836 } else if ( SLAP_MONITOR(c->be) ) {
2837 notallowed = "monitor";
2839 } else if ( SLAP_CONFIG(c->be) ) {
2840 notallowed = "config";
2843 if ( notallowed != NULL ) {
2844 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2848 case LDAP_MOD_DELETE:
2849 case LDAP_MOD_REPLACE:
2850 case LDAP_MOD_INCREMENT:
2851 case SLAP_CONFIG_ADD:
2852 if ( !BER_BVISNULL( &c->value_dn ) ) {
2853 snprintf( buf, sizeof( buf ), "<%s> ",
2854 c->value_dn.bv_val );
2857 Debug(LDAP_DEBUG_ANY,
2858 "%s: suffix %snot allowed in %s database.\n",
2859 c->log, buf, notallowed );
2862 case SLAP_CONFIG_EMIT:
2863 /* don't complain when emitting... */
2867 /* FIXME: don't know what values may be valid;
2868 * please remove assertion, or add legal values
2869 * to either block */
2877 if (c->op == SLAP_CONFIG_EMIT) {
2878 if ( c->be->be_suffix == NULL
2879 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2883 value_add( &c->rvalue_vals, c->be->be_suffix );
2884 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2887 } else if ( c->op == LDAP_MOD_DELETE ) {
2888 if ( c->valx < 0 ) {
2889 ber_bvarray_free( c->be->be_suffix );
2890 ber_bvarray_free( c->be->be_nsuffix );
2891 c->be->be_suffix = NULL;
2892 c->be->be_nsuffix = NULL;
2895 ch_free( c->be->be_suffix[i].bv_val );
2896 ch_free( c->be->be_nsuffix[i].bv_val );
2898 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2899 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2901 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2906 #ifdef SLAPD_MONITOR_DN
2907 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2908 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2910 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2911 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2916 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2917 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2918 c->argv[0], c->be->bd_info->bi_type );
2919 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2920 c->log, c->cr_msg, 0);
2927 if (SLAP_DBHIDDEN( c->be ))
2930 tbe = select_backend(&ndn, 0);
2932 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2938 BackendDB *b2 = tbe;
2940 /* Does tbe precede be? */
2941 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2944 char *type = tbe->bd_info->bi_type;
2946 if ( overlay_is_over( tbe ) ) {
2947 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2948 type = oi->oi_orig->bi_type;
2951 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2952 "already served by a preceding %s database",
2953 c->argv[0], pdn.bv_val, type );
2954 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2955 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2961 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2962 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2963 "base provided \"%s\" (assuming okay)\n",
2964 c->log, default_search_base.bv_val, 0);
2966 ber_bvarray_add(&c->be->be_suffix, &pdn);
2967 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2972 config_rootdn(ConfigArgs *c) {
2973 if (c->op == SLAP_CONFIG_EMIT) {
2974 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2975 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2976 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2981 } else if ( c->op == LDAP_MOD_DELETE ) {
2982 ch_free( c->be->be_rootdn.bv_val );
2983 ch_free( c->be->be_rootndn.bv_val );
2984 BER_BVZERO( &c->be->be_rootdn );
2985 BER_BVZERO( &c->be->be_rootndn );
2988 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2989 ch_free( c->be->be_rootdn.bv_val );
2990 ch_free( c->be->be_rootndn.bv_val );
2992 c->be->be_rootdn = c->value_dn;
2993 c->be->be_rootndn = c->value_ndn;
2998 config_rootpw(ConfigArgs *c) {
3001 if (c->op == SLAP_CONFIG_EMIT) {
3002 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3003 /* don't copy, because "rootpw" is marked
3005 c->value_bv = c->be->be_rootpw;
3009 } else if ( c->op == LDAP_MOD_DELETE ) {
3010 ch_free( c->be->be_rootpw.bv_val );
3011 BER_BVZERO( &c->be->be_rootpw );
3015 tbe = select_backend(&c->be->be_rootndn, 0);
3017 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3019 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3020 c->log, c->cr_msg, 0);
3023 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3024 ch_free( c->be->be_rootpw.bv_val );
3025 c->be->be_rootpw = c->value_bv;
3030 config_restrict(ConfigArgs *c) {
3031 slap_mask_t restrictops = 0;
3033 slap_verbmasks restrictable_ops[] = {
3034 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3035 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3036 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3037 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3038 { BER_BVC("modrdn"), 0 },
3039 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3040 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3041 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3042 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3043 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3044 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3045 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3046 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3047 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3048 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3049 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3053 if (c->op == SLAP_CONFIG_EMIT) {
3054 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3056 } else if ( c->op == LDAP_MOD_DELETE ) {
3058 c->be->be_restrictops = 0;
3060 restrictops = verb_to_mask( c->line, restrictable_ops );
3061 c->be->be_restrictops ^= restrictops;
3065 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3067 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3068 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3069 c->log, c->cr_msg, c->argv[i]);
3072 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3073 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3074 c->be->be_restrictops |= restrictops;
3079 config_allows(ConfigArgs *c) {
3080 slap_mask_t allows = 0;
3082 slap_verbmasks allowable_ops[] = {
3083 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3084 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3085 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3086 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3087 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3090 if (c->op == SLAP_CONFIG_EMIT) {
3091 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3092 } else if ( c->op == LDAP_MOD_DELETE ) {
3096 allows = verb_to_mask( c->line, allowable_ops );
3097 global_allows ^= allows;
3101 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3103 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3104 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3105 c->log, c->cr_msg, c->argv[i]);
3108 global_allows |= allows;
3113 config_disallows(ConfigArgs *c) {
3114 slap_mask_t disallows = 0;
3116 slap_verbmasks disallowable_ops[] = {
3117 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3118 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3119 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3120 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3121 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3122 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3125 if (c->op == SLAP_CONFIG_EMIT) {
3126 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3127 } else if ( c->op == LDAP_MOD_DELETE ) {
3129 global_disallows = 0;
3131 disallows = verb_to_mask( c->line, disallowable_ops );
3132 global_disallows ^= disallows;
3136 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3138 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3139 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3140 c->log, c->cr_msg, c->argv[i]);
3143 global_disallows |= disallows;
3148 config_requires(ConfigArgs *c) {
3149 slap_mask_t requires = frontendDB->be_requires;
3150 int i, argc = c->argc;
3151 char **argv = c->argv;
3153 slap_verbmasks requires_ops[] = {
3154 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3155 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3156 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3157 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3158 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3161 if (c->op == SLAP_CONFIG_EMIT) {
3162 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3163 } else if ( c->op == LDAP_MOD_DELETE ) {
3165 c->be->be_requires = 0;
3167 requires = verb_to_mask( c->line, requires_ops );
3168 c->be->be_requires ^= requires;
3172 /* "none" can only be first, to wipe out default/global values */
3173 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3178 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3180 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3181 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3182 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3183 c->log, c->cr_msg, 0);
3185 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3186 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3187 c->log, c->cr_msg, c->argv[i]);
3191 c->be->be_requires = requires;
3196 config_extra_attrs(ConfigArgs *c)
3198 assert( c->be != NULL );
3200 if ( c->op == SLAP_CONFIG_EMIT ) {
3203 if ( c->be->be_extra_anlist == NULL ) {
3207 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3208 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3211 } else if ( c->op == LDAP_MOD_DELETE ) {
3212 if ( c->be->be_extra_anlist == NULL ) {
3216 if ( c->valx < 0 ) {
3217 anlist_free( c->be->be_extra_anlist, 1, NULL );
3218 c->be->be_extra_anlist = NULL;
3223 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3226 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3230 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3232 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3233 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3238 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3239 if ( c->be->be_extra_anlist == NULL ) {
3247 static slap_verbmasks *loglevel_ops;
3250 loglevel_init( void )
3252 slap_verbmasks lo[] = {
3253 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3254 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3255 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3256 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3257 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3258 { BER_BVC("BER"), LDAP_DEBUG_BER },
3259 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3260 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3261 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3262 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3263 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3264 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3265 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3266 #if 0 /* no longer used (nor supported) */
3267 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3268 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3270 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3271 { BER_BVC("None"), LDAP_DEBUG_NONE },
3275 return slap_verbmasks_init( &loglevel_ops, lo );
3279 loglevel_destroy( void )
3281 if ( loglevel_ops ) {
3282 (void)slap_verbmasks_destroy( loglevel_ops );
3284 loglevel_ops = NULL;
3287 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3290 slap_loglevel_register( slap_mask_t m, struct berval *s )
3294 if ( loglevel_ops == NULL ) {
3298 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3301 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3309 slap_loglevel_get( struct berval *s, int *l )
3314 if ( loglevel_ops == NULL ) {
3318 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3319 m |= loglevel_ops[ i ].mask;
3322 for ( i = 1; m & i; i <<= 1 )
3329 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3332 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3343 str2loglevel( const char *s, int *l )
3347 if ( loglevel_ops == NULL ) {
3351 i = verb_to_mask( s, loglevel_ops );
3353 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3357 *l = loglevel_ops[ i ].mask;
3363 loglevel2str( int l )
3365 struct berval bv = BER_BVNULL;
3367 loglevel2bv( l, &bv );
3373 loglevel2bv( int l, struct berval *bv )
3375 if ( loglevel_ops == NULL ) {
3381 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3385 loglevel2bvarray( int l, BerVarray *bva )
3387 if ( loglevel_ops == NULL ) {
3391 return mask_to_verbs( loglevel_ops, l, bva );
3395 loglevel_print( FILE *out )
3399 if ( loglevel_ops == NULL ) {
3403 fprintf( out, "Installed log subsystems:\n\n" );
3404 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3405 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3407 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3408 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3409 loglevel_ops[ i ].word.bv_val, mask, mask );
3412 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3413 "by specific code\n\n" );
3418 static int config_syslog;
3421 config_loglevel(ConfigArgs *c) {
3424 if ( loglevel_ops == NULL ) {
3428 if (c->op == SLAP_CONFIG_EMIT) {
3429 /* Get default or commandline slapd setting */
3430 if ( ldap_syslog && !config_syslog )
3431 config_syslog = ldap_syslog;
3432 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3434 } else if ( c->op == LDAP_MOD_DELETE ) {
3438 int level = verb_to_mask( c->line, loglevel_ops );
3439 config_syslog ^= level;
3441 if ( slapMode & SLAP_SERVER_MODE ) {
3442 ldap_syslog = config_syslog;
3447 for( i=1; i < c->argc; i++ ) {
3450 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3451 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3452 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3453 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3454 c->log, c->cr_msg, c->argv[i]);
3458 if ( str2loglevel( c->argv[i], &level ) ) {
3459 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3460 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3461 c->log, c->cr_msg, c->argv[i]);
3465 /* Explicitly setting a zero clears all the levels */
3467 config_syslog |= level;
3471 if ( slapMode & SLAP_SERVER_MODE ) {
3472 ldap_syslog = config_syslog;
3478 config_referral(ConfigArgs *c) {
3480 if (c->op == SLAP_CONFIG_EMIT) {
3481 if ( default_referral ) {
3482 value_add( &c->rvalue_vals, default_referral );
3487 } else if ( c->op == LDAP_MOD_DELETE ) {
3488 if ( c->valx < 0 ) {
3489 ber_bvarray_free( default_referral );
3490 default_referral = NULL;
3493 ch_free( default_referral[i].bv_val );
3494 for (; default_referral[i].bv_val; i++ )
3495 default_referral[i] = default_referral[i+1];
3499 if(validate_global_referral(c->argv[1])) {
3500 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3501 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3502 c->log, c->cr_msg, c->argv[1]);
3506 ber_str2bv(c->argv[1], 0, 0, &val);
3507 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3515 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3516 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3517 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3518 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3519 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3520 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3521 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3522 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3523 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3528 config_security(ConfigArgs *c) {
3529 slap_ssf_set_t *set = &c->be->be_ssf_set;
3532 if (c->op == SLAP_CONFIG_EMIT) {
3538 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3539 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3542 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3543 if ( bv.bv_len >= sizeof( numbuf ) ) {
3544 ber_bvarray_free_x( c->rvalue_vals, NULL );
3545 c->rvalue_vals = NULL;
3549 bv.bv_len += sec_keys[i].key.bv_len;
3550 bv.bv_val = ch_malloc( bv.bv_len + 1);
3551 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3552 strcpy( next, numbuf );
3553 ber_bvarray_add( &c->rvalue_vals, &bv );
3558 for(i = 1; i < c->argc; i++) {
3559 slap_ssf_t *tgt = NULL;
3561 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3562 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3563 sec_keys[j].key.bv_len)) {
3564 src = c->argv[i] + sec_keys[j].key.bv_len;
3565 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3570 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3571 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3572 c->log, c->cr_msg, c->argv[i]);
3576 if ( lutil_atou( tgt, src ) != 0 ) {
3577 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3578 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3579 c->log, c->cr_msg, c->argv[i]);
3587 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3591 for (; !BER_BVISNULL( &an->an_name ); an++) {
3592 /* if buflen == 0, assume the buffer size has been
3593 * already checked otherwise */
3594 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3595 if ( comma ) *ptr++ = ',';
3596 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3603 config_updatedn(ConfigArgs *c) {
3604 if (c->op == SLAP_CONFIG_EMIT) {
3605 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3606 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3607 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3611 } else if ( c->op == LDAP_MOD_DELETE ) {
3612 ch_free( c->be->be_update_ndn.bv_val );
3613 BER_BVZERO( &c->be->be_update_ndn );
3614 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3617 if(SLAP_SHADOW(c->be)) {
3618 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3619 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3620 c->log, c->cr_msg, 0);
3624 ber_memfree_x( c->value_dn.bv_val, NULL );
3625 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3626 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3628 c->be->be_update_ndn = c->value_ndn;
3629 BER_BVZERO( &c->value_dn );
3630 BER_BVZERO( &c->value_ndn );
3632 return config_slurp_shadow( c );
3636 config_shadow( ConfigArgs *c, slap_mask_t flag )
3638 char *notallowed = NULL;
3640 if ( c->be == frontendDB ) {
3641 notallowed = "frontend";
3643 } else if ( SLAP_MONITOR(c->be) ) {
3644 notallowed = "monitor";
3647 if ( notallowed != NULL ) {
3648 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3652 if ( SLAP_SHADOW(c->be) ) {
3653 /* if already shadow, only check consistency */
3654 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3655 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3661 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3668 config_updateref(ConfigArgs *c) {
3670 if (c->op == SLAP_CONFIG_EMIT) {
3671 if ( c->be->be_update_refs ) {
3672 value_add( &c->rvalue_vals, c->be->be_update_refs );
3677 } else if ( c->op == LDAP_MOD_DELETE ) {
3678 if ( c->valx < 0 ) {
3679 ber_bvarray_free( c->be->be_update_refs );
3680 c->be->be_update_refs = NULL;
3683 ch_free( c->be->be_update_refs[i].bv_val );
3684 for (; c->be->be_update_refs[i].bv_val; i++)
3685 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3689 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3690 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3692 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3693 c->log, c->cr_msg, 0);
3697 if(validate_global_referral(c->argv[1])) {
3698 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3699 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3700 c->log, c->cr_msg, c->argv[1]);
3703 ber_str2bv(c->argv[1], 0, 0, &val);
3704 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3709 config_obsolete(ConfigArgs *c) {
3710 if (c->op == SLAP_CONFIG_EMIT)
3713 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3715 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3720 config_include(ConfigArgs *c) {
3721 int savelineno = c->lineno;
3724 ConfigFile *cfsave = cfn;
3725 ConfigFile *cf2 = NULL;
3727 /* Leftover from RE23. No dynamic config for include files */
3728 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3731 cf = ch_calloc( 1, sizeof(ConfigFile));
3732 if ( cfn->c_kids ) {
3733 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3739 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3740 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3741 c->lineno = savelineno - 1;
3744 if ( cf2 ) cf2->c_sibs = NULL;
3745 else cfn->c_kids = NULL;
3746 ch_free( cf->c_file.bv_val );
3756 config_tls_cleanup(ConfigArgs *c) {
3759 if ( slap_tls_ld ) {
3762 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3764 /* Force new ctx to be created */
3765 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3767 /* The ctx's refcount is bumped up here */
3768 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3769 /* This is a no-op if it's already loaded */
3770 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3777 config_tls_option(ConfigArgs *c) {
3779 LDAP *ld = slap_tls_ld;
3781 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3782 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3783 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3784 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3785 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3786 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3787 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3789 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3791 default: Debug(LDAP_DEBUG_ANY, "%s: "
3792 "unknown tls_option <0x%x>\n",
3793 c->log, c->type, 0);
3796 if (c->op == SLAP_CONFIG_EMIT) {
3797 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3798 } else if ( c->op == LDAP_MOD_DELETE ) {
3799 c->cleanup = config_tls_cleanup;
3800 return ldap_pvt_tls_set_option( ld, flag, NULL );
3802 ch_free(c->value_string);
3803 c->cleanup = config_tls_cleanup;
3804 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3807 /* FIXME: this ought to be provided by libldap */
3809 config_tls_config(ConfigArgs *c) {
3812 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3813 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3814 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3816 Debug(LDAP_DEBUG_ANY, "%s: "
3817 "unknown tls_option <0x%x>\n",
3818 c->log, c->type, 0);
3821 if (c->op == SLAP_CONFIG_EMIT) {
3822 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3823 } else if ( c->op == LDAP_MOD_DELETE ) {
3825 c->cleanup = config_tls_cleanup;
3826 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3828 ch_free( c->value_string );
3829 c->cleanup = config_tls_cleanup;
3830 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3831 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3832 Debug(LDAP_DEBUG_ANY, "%s: "
3833 "unable to parse %s \"%s\"\n",
3834 c->log, c->argv[0], c->argv[1] );
3837 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3839 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3844 static CfEntryInfo *
3845 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3855 if ( dn_match( &root->ce_entry->e_nname, dn ))
3858 c = dn->bv_val+dn->bv_len;
3859 for (;*c != ',';c--);
3863 for (--c;c>dn->bv_val && *c != ',';c--);
3867 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3869 root = root->ce_kids;
3871 for (;root;root=root->ce_sibs) {
3872 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3873 if ( cdn.bv_val == dn->bv_val ) {
3883 typedef struct setup_cookie {
3893 config_ldif_resp( Operation *op, SlapReply *rs )
3895 if ( rs->sr_type == REP_SEARCH ) {
3896 setup_cookie *sc = op->o_callback->sc_private;
3899 sc->cfb->cb_got_ldif = 1;
3900 /* Does the frontend exist? */
3901 if ( !sc->got_frontend ) {
3902 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3903 "olcDatabase", STRLENOF( "olcDatabase" )))
3905 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3906 STRLENOF( "olcDatabase" ), "={-1}frontend",
3907 STRLENOF( "={-1}frontend" )))
3911 sc->ca->be = frontendDB;
3912 sc->ca->bi = frontendDB->bd_info;
3913 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3914 rdn.bv_val = sc->ca->log;
3915 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3916 "%s=" SLAP_X_ORDERED_FMT "%s",
3917 cfAd_database->ad_cname.bv_val, -1,
3918 sc->ca->bi->bi_type);
3920 sc->frontend = config_build_entry( op, rs,
3921 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3922 sc->ca->be->be_cf_ocs );
3932 dnParent( &rs->sr_entry->e_nname, &pdn );
3934 /* Does the configDB exist? */
3935 if ( sc->got_frontend && !sc->got_config &&
3936 !strncmp( rs->sr_entry->e_nname.bv_val,
3937 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3938 dn_match( &config_rdn, &pdn ) )
3940 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3941 STRLENOF( "olcDatabase" ), "={0}config",
3942 STRLENOF( "={0}config" )))
3946 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3947 sc->ca->bi = sc->ca->be->bd_info;
3948 rdn.bv_val = sc->ca->log;
3949 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3950 "%s=" SLAP_X_ORDERED_FMT "%s",
3951 cfAd_database->ad_cname.bv_val, 0,
3952 sc->ca->bi->bi_type);
3954 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3955 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3962 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3963 if ( rs->sr_err != LDAP_SUCCESS ) {
3964 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3965 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3971 /* Configure and read the underlying back-ldif store */
3973 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3974 CfBackInfo *cfb = be->be_private;
3980 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3981 Connection conn = {0};
3982 OperationBuffer opbuf;
3984 SlapReply rs = {REP_RESULT};
3985 Filter filter = { LDAP_FILTER_PRESENT };
3986 struct berval filterstr = BER_BVC("(objectclass=*)");
3989 /* Is the config directory available? */
3990 if ( stat( dir, &st ) < 0 ) {
3991 /* No, so don't bother using the backing store.
3992 * All changes will be in-memory only.
3997 cfb->cb_db.bd_info = backend_info( "ldif" );
3998 if ( !cfb->cb_db.bd_info )
3999 return 0; /* FIXME: eventually this will be a fatal error */
4001 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4004 cfb->cb_db.be_suffix = be->be_suffix;
4005 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4007 /* The suffix is always "cn=config". The underlying DB's rootdn
4008 * is always the same as the suffix.
4010 cfb->cb_db.be_rootdn = be->be_suffix[0];
4011 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4013 ber_str2bv( dir, 0, 1, &cfdir );
4018 argv[0] = "directory";
4019 argv[1] = (char *)dir;
4024 c.table = Cft_Database;
4026 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4030 if ( config_add_vals( ct, &c ))
4033 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4037 void *thrctx = ldap_pvt_thread_pool_context();
4040 connection_fake_init( &conn, &opbuf, thrctx );
4043 filter.f_desc = slap_schema.si_ad_objectClass;
4045 op->o_tag = LDAP_REQ_SEARCH;
4047 op->ors_filter = &filter;
4048 op->ors_filterstr = filterstr;
4049 op->ors_scope = LDAP_SCOPE_SUBTREE;
4051 op->o_dn = c.be->be_rootdn;
4052 op->o_ndn = c.be->be_rootndn;
4054 op->o_req_dn = be->be_suffix[0];
4055 op->o_req_ndn = be->be_nsuffix[0];
4057 op->ors_tlimit = SLAP_NO_LIMIT;
4058 op->ors_slimit = SLAP_NO_LIMIT;
4060 op->ors_attrs = slap_anlist_all_attributes;
4061 op->ors_attrsonly = 0;
4063 op->o_callback = &cb;
4066 cb.sc_private = ≻
4067 sc.got_frontend = 0;
4072 op->o_bd = &cfb->cb_db;
4074 /* Allow unknown attrs in DNs */
4075 prev_DN_strict = slap_DN_strict;
4078 rc = op->o_bd->be_search( op, &rs );
4080 /* Restore normal DN validation */
4081 slap_DN_strict = prev_DN_strict;
4083 op->o_tag = LDAP_REQ_ADD;
4084 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4085 rs_reinit( &rs, REP_RESULT );
4086 op->ora_e = sc.frontend;
4087 rc = op->o_bd->be_add( op, &rs );
4089 if ( rc == LDAP_SUCCESS && sc.config ) {
4090 rs_reinit( &rs, REP_RESULT );
4091 op->ora_e = sc.config;
4092 rc = op->o_bd->be_add( op, &rs );
4094 ldap_pvt_thread_pool_context_reset( thrctx );
4097 /* ITS#4194 - only use if it's present, or we're converting. */
4098 if ( !readit || rc == LDAP_SUCCESS )
4099 cfb->cb_use_ldif = 1;
4105 CfOc_cmp( const void *c1, const void *c2 ) {
4106 const ConfigOCs *co1 = c1;
4107 const ConfigOCs *co2 = c2;
4109 return ber_bvcmp( co1->co_name, co2->co_name );
4113 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4116 i = init_config_attrs( ct );
4119 /* set up the objectclasses */
4120 i = init_config_ocs( ocs );
4123 for (i=0; ocs[i].co_def; i++) {
4124 if ( ocs[i].co_oc ) {
4125 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4126 if ( !ocs[i].co_table )
4127 ocs[i].co_table = ct;
4128 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4135 read_config(const char *fname, const char *dir) {
4138 const char *cfdir, *cfname;
4141 /* Setup the config backend */
4142 be = backend_db_init( "config", NULL, 0, NULL );
4146 cfb = be->be_private;
4147 be->be_dfltaccess = ACL_NONE;
4149 /* If no .conf, or a dir was specified, setup the dir */
4150 if ( !fname || dir ) {
4152 /* If explicitly given, check for existence */
4155 if ( stat( dir, &st ) < 0 ) {
4156 Debug( LDAP_DEBUG_ANY,
4157 "invalid config directory %s, error %d\n",
4163 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4165 /* if fname is defaulted, try reading .d */
4166 rc = config_setup_ldif( be, cfdir, !fname );
4169 /* It may be OK if the base object doesn't exist yet. */
4170 if ( rc != LDAP_NO_SUCH_OBJECT )
4172 /* ITS#4194: But if dir was specified and no fname,
4173 * then we were supposed to read the dir. Unless we're
4174 * trying to slapadd the dir...
4176 if ( dir && !fname ) {
4177 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4179 /* Assume it's slapadd with a config dir, let it continue */
4181 cfb->cb_got_ldif = 1;
4182 cfb->cb_use_ldif = 1;
4187 /* If we read the config from back-ldif, nothing to do here */
4188 if ( cfb->cb_got_ldif ) {
4197 cfname = SLAPD_DEFAULT_CONFIGFILE;
4199 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4202 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4205 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4206 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4207 &frontendDB->be_schemadn );
4208 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4209 if ( rc != LDAP_SUCCESS ) {
4210 Debug(LDAP_DEBUG_ANY, "read_config: "
4211 "unable to normalize default schema DN \"%s\"\n",
4212 frontendDB->be_schemadn.bv_val, 0, 0 );
4213 /* must not happen */
4221 config_back_bind( Operation *op, SlapReply *rs )
4223 if ( be_isroot_pw( op ) ) {
4224 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4225 /* frontend sends result */
4226 return LDAP_SUCCESS;
4229 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4230 send_ldap_result( op, rs );
4236 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4240 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4242 rs->sr_attrs = op->ors_attrs;
4243 rs->sr_entry = ce->ce_entry;
4245 rc = send_search_entry( op, rs );
4246 if ( rc != LDAP_SUCCESS ) {
4250 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4251 if ( ce->ce_kids ) {
4252 rc = config_send( op, rs, ce->ce_kids, 1 );
4253 if ( rc ) return rc;
4256 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4257 rc = config_send( op, rs, ce, 0 );
4265 static ConfigTable *
4266 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4271 for (j=0; j<nocs; j++) {
4272 for (i=0; colst[j]->co_table[i].name; i++)
4273 if ( colst[j]->co_table[i].ad == ad ) {
4274 ca->table = colst[j]->co_type;
4275 return &colst[j]->co_table[i];
4281 /* Sort the attributes of the entry according to the order defined
4282 * in the objectclass, with required attributes occurring before
4283 * allowed attributes. For any attributes with sequencing dependencies
4284 * (e.g., rootDN must be defined after suffix) the objectclass must
4285 * list the attributes in the desired sequence.
4288 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4290 Attribute *a, *head = NULL, *tail = NULL, **prev;
4293 for (i=0; i<nocs; i++) {
4294 if ( colst[i]->co_oc->soc_required ) {
4295 AttributeType **at = colst[i]->co_oc->soc_required;
4296 for (j=0; at[j]; j++) {
4297 for (a=e->e_attrs, prev=&e->e_attrs; a;
4298 prev = &(*prev)->a_next, a=a->a_next) {
4299 if ( a->a_desc == at[j]->sat_ad ) {
4313 if ( colst[i]->co_oc->soc_allowed ) {
4314 AttributeType **at = colst[i]->co_oc->soc_allowed;
4315 for (j=0; at[j]; j++) {
4316 for (a=e->e_attrs, prev=&e->e_attrs; a;
4317 prev = &(*prev)->a_next, a=a->a_next) {
4318 if ( a->a_desc == at[j]->sat_ad ) {
4334 tail->a_next = e->e_attrs;
4340 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4342 Attribute *a = NULL;
4343 AttributeDescription *ad;
4353 Modifications *ml = ptr;
4355 vals = ml->sml_values;
4358 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4359 rc = ordered_value_sort( a, 1 );
4361 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4362 ad->ad_cname.bv_val );
4366 for ( i=0; vals[i].bv_val; i++ ) {
4367 ca->line = vals[i].bv_val;
4368 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4369 ca->line[0] == '{' ) {
4370 char *idx = strchr( ca->line, '}' );
4371 if ( idx ) ca->line = idx+1;
4373 rc = config_parse_vals( ct, ca, i );
4382 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4385 struct berval rtype, rval;
4387 AttributeDescription *ad = NULL;
4389 dnRdn( &e->e_name, rdn );
4390 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4391 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4392 rtype.bv_val = rdn->bv_val;
4393 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4396 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4397 a = attr_find( e->e_attrs, ad );
4398 if (!a ) return LDAP_NAMING_VIOLATION;
4405 config_rename_kids( CfEntryInfo *ce )
4408 struct berval rdn, nrdn;
4410 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4411 struct berval newdn, newndn;
4412 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4413 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4414 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4415 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4416 free( ce2->ce_entry->e_name.bv_val );
4417 free( ce2->ce_entry->e_nname.bv_val );
4418 ce2->ce_entry->e_name = newdn;
4419 ce2->ce_entry->e_nname = newndn;
4420 config_rename_kids( ce2 );
4425 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4426 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4427 struct berval *nnewrdn, int use_ldif )
4431 struct berval odn, ondn;
4435 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4436 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4439 free( a->a_vals[0].bv_val );
4440 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4441 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4442 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4443 strcpy( a->a_vals[0].bv_val, ptr1 );
4445 if ( a->a_nvals != a->a_vals ) {
4446 free( a->a_nvals[0].bv_val );
4447 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4448 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4449 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4450 strcpy( a->a_nvals[0].bv_val, ptr1 );
4453 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4454 BackendDB *be = op->o_bd;
4455 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4456 struct berval dn, ndn, xdn, xndn;
4458 op->o_bd = &cfb->cb_db;
4460 /* Save current rootdn; use the underlying DB's rootdn */
4464 xndn = op->o_req_ndn;
4465 op->o_dn = op->o_bd->be_rootdn;
4466 op->o_ndn = op->o_bd->be_rootndn;
4468 op->o_req_ndn = ondn;
4470 scp = op->o_callback;
4471 op->o_callback = ≻
4472 op->orr_newrdn = *newrdn;
4473 op->orr_nnewrdn = *nnewrdn;
4474 op->orr_newSup = NULL;
4475 op->orr_nnewSup = NULL;
4476 op->orr_deleteoldrdn = 1;
4477 op->orr_modlist = NULL;
4478 slap_modrdn2mods( op, rs );
4479 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4480 rc = op->o_bd->be_modrdn( op, rs );
4481 slap_mods_free( op->orr_modlist, 1 );
4484 op->o_callback = scp;
4488 op->o_req_ndn = xndn;
4491 free( ondn.bv_val );
4493 config_rename_kids( e->e_private );
4498 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4499 Entry *e, int idx, int tailindex, int use_ldif )
4501 struct berval ival, newrdn, nnewrdn;
4504 char ibuf[32], *ptr1, *ptr2 = NULL;
4507 rc = config_rename_attr( rs, e, &rdn, &a );
4508 if ( rc ) return rc;
4511 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4512 if ( ival.bv_len >= sizeof( ibuf ) ) {
4513 return LDAP_NAMING_VIOLATION;
4516 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4517 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4520 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4521 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4524 ptr2 = ber_bvchr( &rdn, '}' );
4528 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4530 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4531 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4532 a->a_desc->ad_cname.bv_len );
4534 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4535 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4539 /* Do the equivalent of ModRDN */
4540 /* Replace DN / NDN */
4541 newrdn.bv_len = ptr1 - newrdn.bv_val;
4542 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4543 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4545 free( nnewrdn.bv_val );
4546 free( newrdn.bv_val );
4551 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4552 SlapReply *rs, int *renum, int *ibase )
4555 int index = -1, gotindex = 0, nsibs, rc = 0;
4556 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4557 char *ptr1, *ptr2 = NULL;
4560 if ( renum ) *renum = 0;
4562 /* These entries don't get indexed/renumbered */
4563 if ( ce_type == Cft_Global ) return 0;
4564 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4566 if ( ce_type == Cft_Module )
4569 /* See if the rdn has an index already */
4570 dnRdn( &e->e_name, &rdn );
4571 if ( ce_type == Cft_Database ) {
4572 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4573 "frontend", STRLENOF("frontend") ))
4575 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4576 "config", STRLENOF("config") ))
4579 ptr1 = ber_bvchr( &e->e_name, '{' );
4580 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4582 ptr2 = strchr( ptr1, '}' );
4583 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4584 return LDAP_NAMING_VIOLATION;
4585 if ( ptr2-ptr1 == 1)
4586 return LDAP_NAMING_VIOLATION;
4588 index = strtol( ptr1 + 1, &next, 10 );
4589 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4590 return LDAP_NAMING_VIOLATION;
4593 /* Special case, we allow -1 for the frontendDB */
4594 if ( index != -1 || !isfrontend )
4595 return LDAP_NAMING_VIOLATION;
4597 if ( isconfig && index != 0 ){
4598 return LDAP_NAMING_VIOLATION;
4602 /* count related kids */
4603 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4604 if ( ce->ce_type == ce_type ) nsibs++;
4607 /* account for -1 frontend */
4608 if ( ce_type == Cft_Database )
4611 if ( index != nsibs ) {
4613 if ( index < nsibs ) {
4614 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4615 /* Siblings need to be renumbered */
4616 if ( index != -1 || !isfrontend )
4620 /* config DB is always "0" */
4621 if ( isconfig && index == -1 ) {
4624 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4628 /* just make index = nsibs */
4630 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4633 if ( ibase ) *ibase = index;
4634 if ( renum ) *renum = renumber;
4638 /* Insert all superior classes of the given class */
4640 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4645 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4646 if ( count_oc( *sups, copp, nocs ) ) {
4651 co.co_name = &oc->soc_cname;
4652 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4656 /* check for duplicates */
4657 for ( i = 0; i < *nocs; i++ ) {
4658 if ( *copp && (*copp)[i] == cop ) {
4664 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4665 if ( tmp == NULL ) {
4669 (*copp)[*nocs] = cop;
4677 /* Find all superior classes of the given objectclasses,
4678 * return list in order of most-subordinate first.
4680 * Special / auxiliary / Cft_Misc classes always take precedence.
4683 count_ocs( Attribute *oc_at, int *nocs )
4685 int i, j, misc = -1;
4686 ConfigOCs **colst = NULL;
4690 for ( i = oc_at->a_numvals; i--; ) {
4691 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4693 assert( oc != NULL );
4694 if ( count_oc( oc, &colst, nocs ) ) {
4704 ConfigOCs *tmp = colst[i];
4705 colst[i] = colst[j];
4707 if (tmp->co_type == Cft_Misc)
4711 /* Move misc class to front of list */
4713 ConfigOCs *tmp = colst[misc];
4714 for (i=misc; i>0; i--)
4715 colst[i] = colst[i-1];
4723 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4725 /* Leftover from RE23. Never parse this entry */
4726 return LDAP_COMPARE_TRUE;
4730 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4734 /* This entry is hardcoded, don't re-parse it */
4735 if ( p->ce_type == Cft_Global ) {
4736 cfn = p->ce_private;
4737 ca->ca_private = cfn;
4738 return LDAP_COMPARE_TRUE;
4740 if ( p->ce_type != Cft_Schema )
4741 return LDAP_CONSTRAINT_VIOLATION;
4743 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4744 ca->ca_private = cfn;
4745 cfo = p->ce_private;
4746 cfn->c_sibs = cfo->c_kids;
4748 return LDAP_SUCCESS;
4752 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4754 if ( p->ce_type != Cft_Global ) {
4755 return LDAP_CONSTRAINT_VIOLATION;
4757 /* config must be {0}, nothing else allowed */
4758 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4759 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4760 return LDAP_CONSTRAINT_VIOLATION;
4762 ca->be = frontendDB; /* just to get past check_vals */
4763 return LDAP_SUCCESS;
4767 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4769 if ( p->ce_type != Cft_Global ) {
4770 return LDAP_CONSTRAINT_VIOLATION;
4772 return LDAP_SUCCESS;
4776 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4778 if ( p->ce_type != Cft_Global ) {
4779 return LDAP_CONSTRAINT_VIOLATION;
4781 return LDAP_SUCCESS;
4785 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4787 if ( p->ce_type != Cft_Database ) {
4788 return LDAP_CONSTRAINT_VIOLATION;
4791 return LDAP_SUCCESS;
4795 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4800 AttributeDescription *ad;
4806 if ( cfn->c_cr_head ) {
4807 struct berval bv = BER_BVC("olcDitContentRules");
4809 slap_bv2ad( &bv, &ad, &text );
4810 ct = config_find_table( colst, nocs, ad, ca );
4811 config_del_vals( ct, ca );
4813 if ( cfn->c_oc_head ) {
4814 struct berval bv = BER_BVC("olcObjectClasses");
4816 slap_bv2ad( &bv, &ad, &text );
4817 ct = config_find_table( colst, nocs, ad, ca );
4818 config_del_vals( ct, ca );
4820 if ( cfn->c_at_head ) {
4821 struct berval bv = BER_BVC("olcAttributeTypes");
4823 slap_bv2ad( &bv, &ad, &text );
4824 ct = config_find_table( colst, nocs, ad, ca );
4825 config_del_vals( ct, ca );
4827 if ( cfn->c_syn_head ) {
4828 struct berval bv = BER_BVC("olcLdapSyntaxes");
4830 slap_bv2ad( &bv, &ad, &text );
4831 ct = config_find_table( colst, nocs, ad, ca );
4832 config_del_vals( ct, ca );
4834 if ( cfn->c_om_head ) {
4835 struct berval bv = BER_BVC("olcObjectIdentifier");
4837 slap_bv2ad( &bv, &ad, &text );
4838 ct = config_find_table( colst, nocs, ad, ca );
4839 config_del_vals( ct, ca );
4841 cfo = p->ce_private;
4842 cfo->c_kids = cfn->c_sibs;
4847 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4849 int rc = LDAP_CONSTRAINT_VIOLATION;
4852 if ( (*cop)->co_ldadd ) {
4853 rc = (*cop)->co_ldadd( last, e, ca );
4854 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4859 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4860 ConfigOCs co = { 0 };
4862 co.co_name = &(*ocp)->soc_cname;
4863 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4864 if ( *cop == NULL ) {
4868 rc = config_add_oc( cop, last, e, ca );
4869 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4877 /* Parse an LDAP entry into config directives */
4879 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4880 int *renum, Operation *op )
4882 CfEntryInfo *ce, *last = NULL;
4883 ConfigOCs co, *coptr, **colst;
4884 Attribute *a, *oc_at, *soc_at;
4885 int i, ibase = -1, nocs, rc = 0;
4888 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4890 memset( ca, 0, sizeof(ConfigArgs));
4892 /* Make sure parent exists and entry does not. But allow
4893 * Databases and Overlays to be inserted. Don't do any
4894 * auto-renumbering if manageDSAit control is present.
4896 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4898 if ( ( op && op->o_managedsait ) ||
4899 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4900 ce->ce_type != Cft_Module ) )
4902 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4903 "DN=\"%s\" already exists\n",
4904 log_prefix, e->e_name.bv_val, 0 );
4905 /* global schema ignores all writes */
4906 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
4907 return LDAP_COMPARE_TRUE;
4908 return LDAP_ALREADY_EXISTS;
4912 dnParent( &e->e_nname, &pdn );
4914 /* If last is NULL, the new entry is the root/suffix entry,
4915 * otherwise last should be the parent.
4917 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4919 rs->sr_matched = last->ce_entry->e_name.bv_val;
4921 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4922 "DN=\"%s\" not child of DN=\"%s\"\n",
4923 log_prefix, e->e_name.bv_val,
4924 last->ce_entry->e_name.bv_val );
4925 return LDAP_NO_SUCH_OBJECT;
4929 /* No parent, must be root. This will never happen... */
4930 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4931 return LDAP_NO_SUCH_OBJECT;
4934 if ( last && !access_allowed( op, last->ce_entry,
4935 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4937 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4938 "DN=\"%s\" no write access to \"children\" of parent\n",
4939 log_prefix, e->e_name.bv_val, 0 );
4940 return LDAP_INSUFFICIENT_ACCESS;
4944 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4946 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4947 "DN=\"%s\" no objectClass\n",
4948 log_prefix, e->e_name.bv_val, 0 );
4949 return LDAP_OBJECT_CLASS_VIOLATION;
4952 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4954 ObjectClass *soc = NULL;
4955 char textbuf[ SLAP_TEXT_BUFLEN ];
4956 const char *text = textbuf;
4958 /* FIXME: check result */
4959 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4960 &text, textbuf, sizeof(textbuf), NULL );
4961 if ( rc != LDAP_SUCCESS ) {
4962 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4963 "DN=\"%s\" no structural objectClass (%s)\n",
4964 log_prefix, e->e_name.bv_val, text );
4967 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4968 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4969 if ( soc_at == NULL ) {
4970 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4971 "DN=\"%s\" no structural objectClass; "
4972 "unable to merge computed class %s\n",
4973 log_prefix, e->e_name.bv_val,
4974 soc->soc_cname.bv_val );
4975 return LDAP_OBJECT_CLASS_VIOLATION;
4978 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4979 "DN=\"%s\" no structural objectClass; "
4980 "computed objectClass %s merged\n",
4981 log_prefix, e->e_name.bv_val,
4982 soc->soc_cname.bv_val );
4985 /* Fake the coordinates based on whether we're part of an
4986 * LDAP Add or if reading the config dir
4989 ca->fname = "slapd";
4992 ca->fname = cfdir.bv_val;
4997 co.co_name = &soc_at->a_nvals[0];
4998 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4999 if ( coptr == NULL ) {
5000 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5001 "DN=\"%s\" no structural objectClass in configuration table\n",
5002 log_prefix, e->e_name.bv_val, 0 );
5003 return LDAP_OBJECT_CLASS_VIOLATION;
5006 /* Only the root can be Cft_Global, everything else must
5007 * have a parent. Only limited nesting arrangements are allowed.
5009 rc = LDAP_CONSTRAINT_VIOLATION;
5010 if ( coptr->co_type == Cft_Global && !last ) {
5011 cfn = cfb->cb_config;
5012 ca->ca_private = cfn;
5013 ca->be = frontendDB; /* just to get past check_vals */
5017 colst = count_ocs( oc_at, &nocs );
5019 /* Check whether the Add is allowed by its parent, and do
5020 * any necessary arg setup
5023 rc = config_add_oc( &coptr, last, e, ca );
5024 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5025 for ( i = 0; i<nocs; i++ ) {
5026 /* Already checked these */
5027 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5029 if ( colst[i]->co_ldadd &&
5030 ( rc = colst[i]->co_ldadd( last, e, ca ))
5031 != LDAP_CONSTRAINT_VIOLATION ) {
5037 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5038 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5039 "DN=\"%s\" no structural objectClass add function\n",
5040 log_prefix, e->e_name.bv_val, 0 );
5041 return LDAP_OBJECT_CLASS_VIOLATION;
5045 /* Add the entry but don't parse it, we already have its contents */
5046 if ( rc == LDAP_COMPARE_TRUE ) {
5051 if ( rc != LDAP_SUCCESS )
5054 /* Parse all the values and check for simple syntax errors before
5055 * performing any set actions.
5057 * If doing an LDAPadd, check for indexed names and any necessary
5058 * renaming/renumbering. Entries that don't need indexed names are
5059 * ignored. Entries that need an indexed name and arrive without one
5060 * are assigned to the end. Entries that arrive with an index may
5061 * cause the following entries to be renumbered/bumped down.
5063 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5064 * don't allow Adding an entry with an index that's already in use.
5065 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5067 * These entries can have auto-assigned indexes (appended to the end)
5068 * but only the other types support auto-renumbering of siblings.
5071 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5076 if ( renum && *renum && coptr->co_type != Cft_Database &&
5077 coptr->co_type != Cft_Overlay )
5079 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5080 "operation requires sibling renumbering" );
5081 rc = LDAP_UNWILLING_TO_PERFORM;
5086 init_config_argv( ca );
5088 /* Make sure we process attrs in the required order */
5089 sort_attrs( e, colst, nocs );
5091 for ( a = e->e_attrs; a; a = a->a_next ) {
5092 if ( a == oc_at ) continue;
5093 ct = config_find_table( colst, nocs, a->a_desc, ca );
5094 if ( !ct ) continue; /* user data? */
5095 rc = check_vals( ct, ca, a, 1 );
5096 if ( rc ) goto done_noop;
5099 /* Basic syntax checks are OK. Do the actual settings. */
5100 for ( a=e->e_attrs; a; a=a->a_next ) {
5101 if ( a == oc_at ) continue;
5102 ct = config_find_table( colst, nocs, a->a_desc, ca );
5103 if ( !ct ) continue; /* user data? */
5104 for (i=0; a->a_vals[i].bv_val; i++) {
5107 ca->line = a->a_vals[i].bv_val;
5108 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5109 ptr = strchr( ca->line, '}' );
5111 iptr = strchr( ca->line, '{' );
5115 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5117 ca->valx = strtol( iptr+1, NULL, 0 );
5122 rc = config_parse_add( ct, ca, i );
5130 /* Newly added databases and overlays need to be started up */
5131 if ( CONFIG_ONLINE_ADD( ca )) {
5132 if ( coptr->co_type == Cft_Database ) {
5133 rc = backend_startup_one( ca->be, &ca->reply );
5135 } else if ( coptr->co_type == Cft_Overlay ) {
5136 if ( ca->bi->bi_db_open ) {
5137 BackendInfo *bi_orig = ca->be->bd_info;
5138 ca->be->bd_info = ca->bi;
5139 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5140 ca->be->bd_info = bi_orig;
5142 } else if ( ca->cleanup ) {
5143 rc = ca->cleanup( ca );
5146 if (ca->cr_msg[0] == '\0')
5147 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5149 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5150 ca->log, ca->cr_msg, ca->argv[1] );
5157 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5158 ce->ce_parent = last;
5159 ce->ce_entry = entry_dup( e );
5160 ce->ce_entry->e_private = ce;
5161 ce->ce_type = coptr->co_type;
5164 ce->ce_private = ca->ca_private;
5165 ca->ca_entry = ce->ce_entry;
5168 } else if ( last->ce_kids ) {
5169 CfEntryInfo *c2, **cprev;
5171 /* Advance to first of this type */
5172 cprev = &last->ce_kids;
5173 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5174 cprev = &c2->ce_sibs;
5177 /* Account for the (-1) frontendDB entry */
5178 if ( ce->ce_type == Cft_Database ) {
5179 if ( ca->be == frontendDB )
5181 else if ( ibase != -1 )
5186 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5187 cprev = &c2->ce_sibs;
5193 for ( i=0; i<ibase; i++ ) {
5195 cprev = &c2->ce_sibs;
5198 ce->ce_sibs = *cprev;
5206 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5207 if ( ca->be != frontendDB )
5208 backend_destroy_one( ca->be, 1 );
5209 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5210 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5211 } else if ( coptr->co_type == Cft_Schema ) {
5212 schema_destroy_one( ca, colst, nocs, last );
5217 ch_free( ca->argv );
5218 if ( colst ) ch_free( colst );
5222 #define BIGTMP 10000
5224 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5225 int base, int rebase, int max, int use_ldif )
5227 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5228 ConfigType etype = ce->ce_type;
5229 int count = 0, rc = 0;
5231 /* Reverse ce list */
5232 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5233 if (ce2->ce_type != etype) {
5238 ce2->ce_sibs = cetmp;
5241 if ( max && count >= max ) {
5247 /* Move original to a temp name until increments are done */
5249 ce->ce_entry->e_private = NULL;
5250 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5251 base+BIGTMP, 0, use_ldif );
5252 ce->ce_entry->e_private = ce;
5254 /* start incrementing */
5255 for (ce2=cetmp; ce2; ce2=ce3) {
5257 ce2->ce_sibs = cerem;
5260 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5261 count+base, 0, use_ldif );
5265 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5266 base, 0, use_ldif );
5271 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5272 CfEntryInfo *ce2, int old, int use_ldif )
5276 /* Renumber original to a temp value */
5277 ce->ce_entry->e_private = NULL;
5278 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5279 old+BIGTMP, 0, use_ldif );
5280 ce->ce_entry->e_private = ce;
5282 /* start decrementing */
5283 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5284 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5285 count+old, 0, use_ldif );
5288 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5289 count+old, 0, use_ldif );
5292 /* Parse an LDAP entry into config directives, then store in underlying
5296 config_back_add( Operation *op, SlapReply *rs )
5302 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5303 NULL, ACL_WADD, NULL )) {
5304 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5309 * Check for attribute ACL
5311 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5312 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5313 rs->sr_text = "no write access to attribute";
5317 cfb = (CfBackInfo *)op->o_bd->be_private;
5319 /* add opattrs for syncprov */
5321 char textbuf[SLAP_TEXT_BUFLEN];
5322 size_t textlen = sizeof textbuf;
5323 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5324 &rs->sr_text, textbuf, sizeof( textbuf ) );
5325 if ( rs->sr_err != LDAP_SUCCESS )
5327 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5328 if ( rs->sr_err != LDAP_SUCCESS ) {
5329 Debug( LDAP_DEBUG_TRACE,
5330 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5331 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5336 if ( op->o_abandon ) {
5337 rs->sr_err = SLAPD_ABANDON;
5340 ldap_pvt_thread_pool_pause( &connection_pool );
5343 * 1) check for existence of entry
5344 * 2) check for sibling renumbering
5345 * 3) perform internal add
5346 * 4) perform any necessary renumbering
5347 * 5) store entry in underlying database
5349 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5350 if ( rs->sr_err != LDAP_SUCCESS ) {
5351 rs->sr_text = ca.cr_msg;
5356 CfEntryInfo *ce = ca.ca_entry->e_private;
5357 req_add_s addr = op->oq_add;
5358 op->o_tag = LDAP_REQ_MODRDN;
5359 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5360 op->o_tag = LDAP_REQ_ADD;
5362 if ( rs->sr_err != LDAP_SUCCESS ) {
5367 if ( cfb->cb_use_ldif ) {
5368 BackendDB *be = op->o_bd;
5369 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5370 struct berval dn, ndn;
5372 op->o_bd = &cfb->cb_db;
5374 /* Save current rootdn; use the underlying DB's rootdn */
5377 op->o_dn = op->o_bd->be_rootdn;
5378 op->o_ndn = op->o_bd->be_rootndn;
5380 scp = op->o_callback;
5381 op->o_callback = ≻
5382 op->o_bd->be_add( op, rs );
5384 op->o_callback = scp;
5390 ldap_pvt_thread_pool_resume( &connection_pool );
5393 { int repl = op->o_dont_replicate;
5394 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5395 rs->sr_text = NULL; /* Set after config_add_internal */
5396 rs->sr_err = LDAP_SUCCESS;
5397 op->o_dont_replicate = 1;
5399 send_ldap_result( op, rs );
5400 op->o_dont_replicate = repl;
5402 slap_graduate_commit_csn( op );
5406 typedef struct delrec {
5407 struct delrec *next;
5413 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5419 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5420 ca->line[0] == '{' )
5422 char *ptr = strchr( ca->line + 1, '}' );
5426 ca->valx = strtol( ca->line + 1, &next, 0 );
5427 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5433 rc = config_parse_add( ct, ca, i );
5441 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5444 int rc = LDAP_UNWILLING_TO_PERFORM;
5446 Entry *e = ce->ce_entry;
5447 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5452 delrec *dels = NULL, *deltail = NULL;
5454 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5455 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5457 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5458 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5462 colst = count_ocs( oc_at, &nocs );
5464 /* make sure add/del flags are clear; should always be true */
5465 for ( s = save_attrs; s; s = s->a_next ) {
5466 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5469 e->e_attrs = attrs_dup( e->e_attrs );
5471 init_config_argv( ca );
5474 ca->ca_private = ce->ce_private;
5476 ca->fname = "slapd";
5478 strcpy( ca->log, "back-config" );
5480 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5481 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5482 switch (ml->sml_op) {
5483 case LDAP_MOD_DELETE:
5484 case LDAP_MOD_REPLACE:
5485 case SLAP_MOD_SOFTDEL:
5487 BerVarray vals = NULL, nvals = NULL;
5489 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5491 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5492 ml->sml_desc->ad_cname.bv_val );
5495 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5496 vals = ml->sml_values;
5497 nvals = ml->sml_nvalues;
5498 ml->sml_values = NULL;
5499 ml->sml_nvalues = NULL;
5501 /* If we're deleting by values, remember the indexes of the
5502 * values we deleted.
5504 if ( ct && ml->sml_values ) {
5506 i = ml->sml_numvals;
5507 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5518 rc = modify_delete_vindex(e, &ml->sml_mod,
5519 get_permissiveModify(op),
5520 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5521 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5522 ml->sml_values = vals;
5523 ml->sml_nvalues = nvals;
5525 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5529 /* FIXME: check rc before fallthru? */
5533 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5535 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5536 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5537 && attr_find( e->e_attrs, ml->sml_desc ) )
5544 case SLAP_MOD_SOFTADD: {
5545 int mop = ml->sml_op;
5547 ml->sml_op = LDAP_MOD_ADD;
5549 if ( ct->arg_type & ARG_NO_INSERT ) {
5550 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5552 navals = a->a_numvals;
5555 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5556 if ( ml->sml_values[i].bv_val[0] == '{' &&
5559 char *next, *val = ml->sml_values[i].bv_val + 1;
5562 j = strtol( val, &next, 0 );
5563 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5565 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5566 ml->sml_desc->ad_cname.bv_val );
5570 rc = check_vals( ct, ca, ml, 0 );
5571 if ( rc ) goto out_noop;
5574 rc = modify_add_values(e, &ml->sml_mod,
5575 get_permissiveModify(op),
5576 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5578 /* If value already exists, show success here
5579 * and ignore this operation down below.
5581 if ( mop == SLAP_MOD_SOFTADD ) {
5582 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5592 case LDAP_MOD_INCREMENT: /* FIXME */
5597 if(rc != LDAP_SUCCESS) break;
5600 if ( rc == LDAP_SUCCESS) {
5601 /* check that the entry still obeys the schema */
5602 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5603 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5605 if ( rc ) goto out_noop;
5607 /* Basic syntax checks are OK. Do the actual settings. */
5608 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5609 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5610 if ( !ct ) continue;
5612 s = attr_find( save_attrs, ml->sml_desc );
5613 a = attr_find( e->e_attrs, ml->sml_desc );
5615 switch (ml->sml_op) {
5616 case LDAP_MOD_DELETE:
5617 case LDAP_MOD_REPLACE: {
5618 BerVarray vals = NULL, nvals = NULL;
5621 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5622 vals = ml->sml_values;
5623 nvals = ml->sml_nvalues;
5624 ml->sml_values = NULL;
5625 ml->sml_nvalues = NULL;
5628 if ( ml->sml_values )
5631 /* If we didn't delete the whole attribute */
5632 if ( ml->sml_values && a ) {
5633 struct berval *mvals;
5636 if ( ml->sml_nvalues )
5637 mvals = ml->sml_nvalues;
5639 mvals = ml->sml_values;
5641 /* use the indexes we saved up above */
5642 for (i=0; i < d->nidx; i++) {
5643 struct berval bv = *mvals++;
5644 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5645 bv.bv_val[0] == '{' ) {
5646 ptr = strchr( bv.bv_val, '}' ) + 1;
5647 bv.bv_len -= ptr - bv.bv_val;
5650 ca->line = bv.bv_val;
5651 ca->valx = d->idx[i];
5652 config_parse_vals(ct, ca, d->idx[i] );
5653 rc = config_del_vals( ct, ca );
5654 if ( rc != LDAP_SUCCESS ) break;
5656 s->a_flags |= SLAP_ATTR_IXDEL;
5657 for (j=i+1; j < d->nidx; j++)
5658 if ( d->idx[j] >d->idx[i] )
5665 rc = config_del_vals( ct, ca );
5666 if ( rc ) rc = LDAP_OTHER;
5668 s->a_flags |= SLAP_ATTR_IXDEL;
5670 if ( ml->sml_values ) {
5675 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5676 ml->sml_values = vals;
5677 ml->sml_nvalues = nvals;
5679 if ( !vals || rc != LDAP_SUCCESS )
5682 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5687 for (i=0; ml->sml_values[i].bv_val; i++) {
5688 ca->line = ml->sml_values[i].bv_val;
5690 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5693 a->a_flags |= SLAP_ATTR_IXADD;
5700 /* Undo for a failed operation */
5701 if ( rc != LDAP_SUCCESS ) {
5702 ConfigReply msg = ca->reply;
5703 for ( s = save_attrs; s; s = s->a_next ) {
5704 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5705 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5706 ct = config_find_table( colst, nocs, s->a_desc, ca );
5707 a = attr_find( e->e_attrs, s->a_desc );
5709 /* clear the flag so the add check below will skip it */
5710 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5714 config_del_vals( ct, ca );
5716 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5717 ca->line = s->a_vals[i].bv_val;
5719 config_modify_add( ct, ca, s->a_desc, i );
5723 for ( a = e->e_attrs; a; a = a->a_next ) {
5724 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5725 ct = config_find_table( colst, nocs, a->a_desc, ca );
5729 config_del_vals( ct, ca );
5730 s = attr_find( save_attrs, a->a_desc );
5732 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5733 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5734 ca->line = s->a_vals[i].bv_val;
5736 config_modify_add( ct, ca, s->a_desc, i );
5747 if ( rc == LDAP_SUCCESS ) {
5748 attrs_free( save_attrs );
5751 attrs_free( e->e_attrs );
5752 e->e_attrs = save_attrs;
5754 ch_free( ca->argv );
5755 if ( colst ) ch_free( colst );
5757 deltail = dels->next;
5766 config_back_modify( Operation *op, SlapReply *rs )
5769 CfEntryInfo *ce, *last;
5771 ConfigArgs ca = {0};
5774 AttributeDescription *rad = NULL;
5777 cfb = (CfBackInfo *)op->o_bd->be_private;
5779 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5782 rs->sr_matched = last->ce_entry->e_name.bv_val;
5783 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5787 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5788 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5792 /* Get type of RDN */
5793 rdn = ce->ce_entry->e_nname;
5794 ptr = strchr( rdn.bv_val, '=' );
5795 rdn.bv_len = ptr - rdn.bv_val;
5796 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5797 if ( rs->sr_err != LDAP_SUCCESS ) {
5801 /* Some basic validation... */
5802 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5803 /* Don't allow Modify of RDN; must use ModRdn for that. */
5804 if ( ml->sml_desc == rad ) {
5805 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5806 rs->sr_text = "Use modrdn to change the entry name";
5809 /* Internal update of contextCSN? */
5810 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5816 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5819 if ( op->o_abandon ) {
5820 rs->sr_err = SLAPD_ABANDON;
5823 ldap_pvt_thread_pool_pause( &connection_pool );
5827 * 1) perform the Modify on the cached Entry.
5828 * 2) verify that the Entry still satisfies the schema.
5829 * 3) perform the individual config operations.
5830 * 4) store Modified entry in underlying LDIF backend.
5832 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5834 rs->sr_text = ca.cr_msg;
5835 } else if ( cfb->cb_use_ldif ) {
5836 BackendDB *be = op->o_bd;
5837 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5838 struct berval dn, ndn;
5840 op->o_bd = &cfb->cb_db;
5844 op->o_dn = op->o_bd->be_rootdn;
5845 op->o_ndn = op->o_bd->be_rootndn;
5847 scp = op->o_callback;
5848 op->o_callback = ≻
5849 op->o_bd->be_modify( op, rs );
5851 op->o_callback = scp;
5857 ldap_pvt_thread_pool_resume( &connection_pool );
5859 send_ldap_result( op, rs );
5860 slap_graduate_commit_csn( op );
5865 config_back_modrdn( Operation *op, SlapReply *rs )
5868 CfEntryInfo *ce, *last;
5872 cfb = (CfBackInfo *)op->o_bd->be_private;
5874 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5877 rs->sr_matched = last->ce_entry->e_name.bv_val;
5878 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5881 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5882 NULL, ACL_WRITE, NULL )) {
5883 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5887 if ( ce->ce_parent )
5888 parent = ce->ce_parent->ce_entry;
5890 parent = (Entry *)&slap_entry_root;
5891 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5892 NULL, ACL_WRITE, NULL )) {
5893 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5898 /* We don't allow moving objects to new parents.
5899 * Generally we only allow reordering a set of ordered entries.
5901 if ( op->orr_newSup ) {
5902 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5906 /* If newRDN == oldRDN, quietly succeed */
5907 dnRdn( &op->o_req_ndn, &rdn );
5908 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5909 rs->sr_err = LDAP_SUCCESS;
5913 /* Current behavior, subject to change as needed:
5915 * For backends and overlays, we only allow renumbering.
5916 * For schema, we allow renaming with the same number.
5917 * Otherwise, the op is not allowed.
5920 if ( ce->ce_type == Cft_Schema ) {
5924 /* Can't alter the main cn=schema entry */
5925 if ( ce->ce_parent->ce_type == Cft_Global ) {
5926 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5927 rs->sr_text = "renaming not allowed for this entry";
5931 /* We could support this later if desired */
5932 ptr1 = ber_bvchr( &rdn, '}' );
5933 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5934 len = ptr1 - rdn.bv_val;
5935 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5936 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5937 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5938 rs->sr_text = "schema reordering not supported";
5941 } else if ( ce->ce_type == Cft_Database ||
5942 ce->ce_type == Cft_Overlay ) {
5943 char *ptr1, *ptr2, *iptr1, *iptr2;
5946 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5947 if ( *iptr2 != '{' ) {
5948 rs->sr_err = LDAP_NAMING_VIOLATION;
5949 rs->sr_text = "new ordering index is required";
5953 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5954 ptr1 = ber_bvchr( &rdn, '}' );
5955 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5957 rs->sr_err = LDAP_NAMING_VIOLATION;
5958 rs->sr_text = "new ordering index is required";
5962 len1 = ptr1 - rdn.bv_val;
5963 len2 = ptr2 - op->orr_newrdn.bv_val;
5965 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5966 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5967 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5968 rs->sr_text = "changing database/overlay type not allowed";
5971 ixold = strtol( iptr1, NULL, 0 );
5972 ixnew = strtol( iptr2, &ptr1, 0 );
5973 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5974 rs->sr_err = LDAP_NAMING_VIOLATION;
5977 /* config DB is always 0, cannot be changed */
5978 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5979 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5983 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5984 rs->sr_text = "renaming not supported for this entry";
5988 if ( op->o_abandon ) {
5989 rs->sr_err = SLAPD_ABANDON;
5992 ldap_pvt_thread_pool_pause( &connection_pool );
5994 if ( ce->ce_type == Cft_Schema ) {
5995 req_modrdn_s modr = op->oq_modrdn;
5998 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5999 if ( rs->sr_err == LDAP_SUCCESS ) {
6000 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6001 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6004 op->oq_modrdn = modr;
6006 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6007 req_modrdn_s modr = op->oq_modrdn;
6010 /* Advance to first of this type */
6011 cprev = &ce->ce_parent->ce_kids;
6012 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6013 cprev = &ce2->ce_sibs;
6016 /* Skip the -1 entry */
6017 if ( ce->ce_type == Cft_Database ) {
6018 cprev = &ce2->ce_sibs;
6024 /* Remove from old slot */
6025 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6026 cprev = &ce2->ce_sibs;
6027 *cprev = ce->ce_sibs;
6028 ceold = ce->ce_sibs;
6030 /* Insert into new slot */
6032 for ( i=0; i<ixnew; i++ ) {
6036 cprev = &ce2->ce_sibs;
6038 ce->ce_sibs = *cprev;
6043 /* NOTE: These should be encoded in the OC tables, not inline here */
6044 if ( ce->ce_type == Cft_Database )
6045 backend_db_move( ce->ce_be, ixnew );
6046 else if ( ce->ce_type == Cft_Overlay )
6047 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6049 if ( ixold < ixnew ) {
6050 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6053 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6054 ixold - ixnew, cfb->cb_use_ldif );
6056 op->oq_modrdn = modr;
6059 ldap_pvt_thread_pool_resume( &connection_pool );
6061 send_ldap_result( op, rs );
6066 config_back_delete( Operation *op, SlapReply *rs )
6068 #ifdef SLAP_CONFIG_DELETE
6070 CfEntryInfo *ce, *last, *ce2;
6072 cfb = (CfBackInfo *)op->o_bd->be_private;
6074 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6077 rs->sr_matched = last->ce_entry->e_name.bv_val;
6078 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6079 } else if ( ce->ce_kids ) {
6080 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6081 } else if ( op->o_abandon ) {
6082 rs->sr_err = SLAPD_ABANDON;
6083 } else if ( ce->ce_type == Cft_Overlay ){
6087 ldap_pvt_thread_pool_pause( &connection_pool );
6089 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
6091 /* remove CfEntryInfo from the siblings list */
6092 if ( ce->ce_parent->ce_kids == ce ) {
6093 ce->ce_parent->ce_kids = ce->ce_sibs;
6095 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6096 if ( ce2->ce_sibs == ce ) {
6097 ce2->ce_sibs = ce->ce_sibs;
6103 /* remove from underlying database */
6104 if ( cfb->cb_use_ldif ) {
6105 BackendDB *be = op->o_bd;
6106 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6107 struct berval dn, ndn, req_dn, req_ndn;
6109 op->o_bd = &cfb->cb_db;
6113 req_dn = op->o_req_dn;
6114 req_ndn = op->o_req_ndn;
6116 op->o_dn = op->o_bd->be_rootdn;
6117 op->o_ndn = op->o_bd->be_rootndn;
6118 op->o_req_dn = ce->ce_entry->e_name;
6119 op->o_req_ndn = ce->ce_entry->e_nname;
6121 scp = op->o_callback;
6122 op->o_callback = ≻
6123 op->o_bd->be_delete( op, rs );
6125 op->o_callback = scp;
6128 op->o_req_dn = req_dn;
6129 op->o_req_ndn = req_ndn;
6132 /* renumber siblings */
6133 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6134 ixold = strtol( iptr, NULL, 0 );
6135 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6136 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6137 count+ixold, 0, cfb->cb_use_ldif );
6141 ce->ce_entry->e_private=NULL;
6142 entry_free(ce->ce_entry);
6144 ldap_pvt_thread_pool_resume( &connection_pool );
6146 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6149 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6150 #endif /* SLAP_CONFIG_DELETE */
6151 send_ldap_result( op, rs );
6156 config_back_search( Operation *op, SlapReply *rs )
6159 CfEntryInfo *ce, *last;
6162 cfb = (CfBackInfo *)op->o_bd->be_private;
6164 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6167 rs->sr_matched = last->ce_entry->e_name.bv_val;
6168 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6171 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6172 ACL_SEARCH, NULL, &mask ))
6174 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6175 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6177 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6181 switch ( op->ors_scope ) {
6182 case LDAP_SCOPE_BASE:
6183 case LDAP_SCOPE_SUBTREE:
6184 rs->sr_err = config_send( op, rs, ce, 0 );
6187 case LDAP_SCOPE_ONELEVEL:
6188 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6189 rs->sr_err = config_send( op, rs, ce, 1 );
6198 send_ldap_result( op, rs );
6202 /* no-op, we never free entries */
6203 int config_entry_release(
6208 if ( !e->e_private ) {
6211 return LDAP_SUCCESS;
6214 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6216 int config_back_entry_get(
6220 AttributeDescription *at,
6225 CfEntryInfo *ce, *last;
6226 int rc = LDAP_NO_SUCH_OBJECT;
6228 cfb = (CfBackInfo *)op->o_bd->be_private;
6230 ce = config_find_base( cfb->cb_root, ndn, &last );
6232 *ent = ce->ce_entry;
6235 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6236 rc = LDAP_NO_SUCH_ATTRIBUTE;
6246 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6247 ConfigTable *ct, ConfigArgs *c )
6251 for (; at && *at; at++) {
6252 /* Skip the naming attr */
6253 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6255 for (i=0;ct[i].name;i++) {
6256 if (ct[i].ad == (*at)->sat_ad) {
6257 rc = config_get_vals(&ct[i], c);
6258 /* NOTE: tolerate that config_get_vals()
6259 * returns success with no values */
6260 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6261 if ( c->rvalue_nvals )
6262 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6265 slap_syntax_validate_func *validate =
6266 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6269 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6270 rc = ordered_value_validate( ct[i].ad,
6271 &c->rvalue_vals[j], LDAP_MOD_ADD );
6273 Debug( LDAP_DEBUG_ANY,
6274 "config_build_attrs: error %d on %s value #%d\n",
6275 rc, ct[i].ad->ad_cname.bv_val, j );
6281 rc = attr_merge_normalize(e, ct[i].ad,
6282 c->rvalue_vals, NULL);
6284 ber_bvarray_free( c->rvalue_nvals );
6285 ber_bvarray_free( c->rvalue_vals );
6287 Debug( LDAP_DEBUG_ANY,
6288 "config_build_attrs: error %d on %s\n",
6289 rc, ct[i].ad->ad_cname.bv_val, 0 );
6300 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6303 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6304 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6306 Entry *e = entry_alloc();
6307 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6309 struct berval ad_name;
6310 AttributeDescription *ad = NULL;
6313 const char *text = "";
6317 CfEntryInfo *ceprev = NULL;
6319 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6322 ce->ce_type = main->co_type;
6323 ce->ce_parent = parent;
6325 pdn = parent->ce_entry->e_nname;
6326 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6327 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6328 ceprev->ce_type <= ce->ce_type;
6329 ceprev = ceprev->ce_sibs );
6334 ce->ce_private = c->ca_private;
6338 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6339 ber_dupbv( &e->e_nname, &e->e_name );
6341 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6342 main->co_name, NULL );
6344 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6345 extra->co_name, NULL );
6346 ptr = strchr(rdn->bv_val, '=');
6347 ad_name.bv_val = rdn->bv_val;
6348 ad_name.bv_len = ptr - rdn->bv_val;
6349 rc = slap_bv2ad( &ad_name, &ad, &text );
6354 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6355 attr_merge_normalize_one(e, ad, &val, NULL );
6358 c->table = main->co_type;
6359 if ( oc->soc_required ) {
6360 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6361 if ( rc ) goto fail;
6364 if ( oc->soc_allowed ) {
6365 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6366 if ( rc ) goto fail;
6371 c->table = extra->co_type;
6372 if ( oc->soc_required ) {
6373 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6374 if ( rc ) goto fail;
6377 if ( oc->soc_allowed ) {
6378 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6379 if ( rc ) goto fail;
6383 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6384 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6385 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6386 if ( rc != LDAP_SUCCESS ) {
6388 Debug( LDAP_DEBUG_ANY,
6389 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6390 rdn->bv_val, text, 0);
6393 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6396 op->ora_modlist = NULL;
6397 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6398 if ( !op->o_noop ) {
6399 SlapReply rs2 = {REP_RESULT};
6400 op->o_bd->be_add( op, &rs2 );
6401 rs->sr_err = rs2.sr_err;
6402 rs_assert_done( &rs2 );
6403 if ( ( rs2.sr_err != LDAP_SUCCESS )
6404 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6410 ce->ce_sibs = ceprev->ce_sibs;
6411 ceprev->ce_sibs = ce;
6412 } else if ( parent ) {
6413 ce->ce_sibs = parent->ce_kids;
6414 parent->ce_kids = ce;
6421 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6422 Operation *op, SlapReply *rs )
6425 ConfigFile *cf = c->ca_private;
6427 struct berval bv, rdn;
6429 for (; cf; cf=cf->c_sibs, c->depth++) {
6430 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6431 !cf->c_om_head && !cf->c_syn_head ) continue;
6432 c->value_dn.bv_val = c->log;
6433 LUTIL_SLASHPATH( cf->c_file.bv_val );
6434 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6439 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6441 ptr = strchr( bv.bv_val, '.' );
6443 bv.bv_len = ptr - bv.bv_val;
6444 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6445 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6446 /* FIXME: how can indicate error? */
6449 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6451 c->value_dn.bv_len += bv.bv_len;
6452 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6453 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6456 e = config_build_entry( op, rs, ceparent, c, &rdn,
6457 &CFOC_SCHEMA, NULL );
6458 ch_free( rdn.bv_val );
6461 } else if ( e && cf->c_kids ) {
6462 c->ca_private = cf->c_kids;
6463 config_build_schema_inc( c, e->e_private, op, rs );
6469 #ifdef SLAPD_MODULES
6472 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6473 Operation *op, SlapReply *rs )
6478 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6479 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6481 c->value_dn.bv_val = c->log;
6482 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6483 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6484 /* FIXME: how can indicate error? */
6488 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6497 config_check_schema(Operation *op, CfBackInfo *cfb)
6499 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6501 CfEntryInfo *ce, *last;
6504 /* If there's no root entry, we must be in the midst of converting */
6505 if ( !cfb->cb_root )
6508 /* Make sure the main schema entry exists */
6509 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6516 /* Make sure it's up to date */
6517 if ( cf_om_tail != om_sys_tail ) {
6518 a = attr_find( e->e_attrs, cfAd_om );
6520 if ( a->a_nvals != a->a_vals )
6521 ber_bvarray_free( a->a_nvals );
6522 ber_bvarray_free( a->a_vals );
6527 oidm_unparse( &bv, NULL, NULL, 1 );
6528 attr_merge_normalize( e, cfAd_om, bv, NULL );
6529 ber_bvarray_free( bv );
6530 cf_om_tail = om_sys_tail;
6532 if ( cf_at_tail != at_sys_tail ) {
6533 a = attr_find( e->e_attrs, cfAd_attr );
6535 if ( a->a_nvals != a->a_vals )
6536 ber_bvarray_free( a->a_nvals );
6537 ber_bvarray_free( a->a_vals );
6542 at_unparse( &bv, NULL, NULL, 1 );
6543 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6544 ber_bvarray_free( bv );
6545 cf_at_tail = at_sys_tail;
6547 if ( cf_oc_tail != oc_sys_tail ) {
6548 a = attr_find( e->e_attrs, cfAd_oc );
6550 if ( a->a_nvals != a->a_vals )
6551 ber_bvarray_free( a->a_nvals );
6552 ber_bvarray_free( a->a_vals );
6557 oc_unparse( &bv, NULL, NULL, 1 );
6558 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6559 ber_bvarray_free( bv );
6560 cf_oc_tail = oc_sys_tail;
6562 if ( cf_syn_tail != syn_sys_tail ) {
6563 a = attr_find( e->e_attrs, cfAd_syntax );
6565 if ( a->a_nvals != a->a_vals )
6566 ber_bvarray_free( a->a_nvals );
6567 ber_bvarray_free( a->a_vals );
6572 syn_unparse( &bv, NULL, NULL, 1 );
6573 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6574 ber_bvarray_free( bv );
6575 cf_syn_tail = syn_sys_tail;
6578 SlapReply rs = {REP_RESULT};
6579 c.ca_private = NULL;
6580 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6581 &CFOC_SCHEMA, NULL );
6586 ce->ce_private = cfb->cb_config;
6587 cf_at_tail = at_sys_tail;
6588 cf_oc_tail = oc_sys_tail;
6589 cf_om_tail = om_sys_tail;
6590 cf_syn_tail = syn_sys_tail;
6595 static const char *defacl[] = {
6596 NULL, "to", "*", "by", "*", "none", NULL
6600 config_back_db_open( BackendDB *be, ConfigReply *cr )
6602 CfBackInfo *cfb = be->be_private;
6605 CfEntryInfo *ce, *ceparent;
6609 Connection conn = {0};
6610 OperationBuffer opbuf;
6612 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6613 SlapReply rs = {REP_RESULT};
6614 void *thrctx = NULL;
6615 AccessControl *save_access;
6617 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6619 /* If we have no explicitly configured ACLs, don't just use
6620 * the global ACLs. Explicitly deny access to everything.
6622 save_access = be->bd_self->be_acl;
6623 be->bd_self->be_acl = NULL;
6624 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6625 defacl_parsed = be->bd_self->be_acl;
6626 if ( save_access ) {
6627 be->bd_self->be_acl = save_access;
6629 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6630 "No explicit ACL for back-config configured. "
6631 "Using hardcoded default\n", 0, 0, 0 );
6634 thrctx = ldap_pvt_thread_pool_context();
6635 connection_fake_init( &conn, &opbuf, thrctx );
6638 op->o_tag = LDAP_REQ_ADD;
6639 op->o_callback = &cb;
6640 op->o_bd = &cfb->cb_db;
6641 op->o_dn = op->o_bd->be_rootdn;
6642 op->o_ndn = op->o_bd->be_rootndn;
6644 if ( !cfb->cb_use_ldif ) {
6648 /* If we read the config from back-ldif, do some quick sanity checks */
6649 if ( cfb->cb_got_ldif ) {
6650 return config_check_schema( op, cfb );
6653 /* create root of tree */
6655 c.ca_private = cfb->cb_config;
6657 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6667 #ifdef SLAPD_MODULES
6668 /* Create Module nodes... */
6669 if ( modpaths.mp_loads ) {
6670 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6676 /* Create schema nodes... cn=schema will contain the hardcoded core
6677 * schema, read-only. Child objects will contain runtime loaded schema
6681 c.ca_private = NULL;
6682 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6687 ce->ce_private = cfb->cb_config;
6688 cf_at_tail = at_sys_tail;
6689 cf_oc_tail = oc_sys_tail;
6690 cf_om_tail = om_sys_tail;
6691 cf_syn_tail = syn_sys_tail;
6693 /* Create schema nodes for included schema... */
6694 if ( cfb->cb_config->c_kids ) {
6697 c.ca_private = cfb->cb_config->c_kids;
6698 rc = config_build_schema_inc( &c, ce, op, &rs );
6704 /* Create backend nodes. Skip if they don't provide a cf_table.
6705 * There usually aren't any of these.
6709 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6710 if (!bi->bi_cf_ocs) {
6711 /* If it only supports the old config mech, complain. */
6712 if ( bi->bi_config ) {
6713 Debug( LDAP_DEBUG_ANY,
6714 "WARNING: No dynamic config support for backend %s.\n",
6715 bi->bi_type, 0, 0 );
6720 if (!bi->bi_private) continue;
6723 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6724 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6725 if ( rdn.bv_len >= sizeof( c.log ) ) {
6726 /* FIXME: holler ... */ ;
6729 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6736 /* Create database nodes... */
6737 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6738 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6739 for ( i = -1, be = frontendDB ; be;
6740 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6741 slap_overinfo *oi = NULL;
6743 if ( overlay_is_over( be )) {
6744 oi = be->bd_info->bi_private;
6750 /* If this backend supports the old config mechanism, but not
6751 * the new mech, complain.
6753 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6754 Debug( LDAP_DEBUG_ANY,
6755 "WARNING: No dynamic config support for database %s.\n",
6756 bi->bi_type, 0, 0 );
6760 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6761 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6763 if ( rdn.bv_len >= sizeof( c.log ) ) {
6764 /* FIXME: holler ... */ ;
6768 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6774 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6775 rs_reinit( &rs, REP_RESULT );
6776 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6778 /* Iterate through overlays */
6783 voidList *vl, *v0 = NULL;
6785 /* overlays are in LIFO order, must reverse stack */
6786 for (on=oi->oi_list; on; on=on->on_next) {
6787 vl = ch_malloc( sizeof( voidList ));
6792 for (j=0; vl; j++,vl=v0) {
6796 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6797 Debug( LDAP_DEBUG_ANY,
6798 "WARNING: No dynamic config support for overlay %s.\n",
6799 on->on_bi.bi_type, 0, 0 );
6803 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6804 "%s=" SLAP_X_ORDERED_FMT "%s",
6805 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6806 if ( rdn.bv_len >= sizeof( c.log ) ) {
6807 /* FIXME: holler ... */ ;
6811 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6812 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6816 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6817 rs_reinit( &rs, REP_RESULT );
6818 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6824 ldap_pvt_thread_pool_context_reset( thrctx );
6826 if ( unsupp && cfb->cb_use_ldif ) {
6827 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6828 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6835 cfb_free_cffile( ConfigFile *cf )
6839 for (; cf; cf=next) {
6842 cfb_free_cffile( cf->c_kids );
6843 ch_free( cf->c_file.bv_val );
6844 ber_bvarray_free( cf->c_dseFiles );
6850 cfb_free_entries( CfEntryInfo *ce )
6854 for (; ce; ce=next) {
6857 cfb_free_entries( ce->ce_kids );
6858 ce->ce_entry->e_private = NULL;
6859 entry_free( ce->ce_entry );
6865 config_back_db_close( BackendDB *be, ConfigReply *cr )
6867 CfBackInfo *cfb = be->be_private;
6869 cfb_free_entries( cfb->cb_root );
6870 cfb->cb_root = NULL;
6872 if ( cfb->cb_db.bd_info ) {
6873 backend_shutdown( &cfb->cb_db );
6876 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
6877 acl_free( defacl_parsed );
6878 defacl_parsed = NULL;
6885 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6887 CfBackInfo *cfb = be->be_private;
6889 cfb_free_cffile( cfb->cb_config );
6891 ch_free( cfdir.bv_val );
6893 avl_free( CfOcTree, NULL );
6895 if ( cfb->cb_db.bd_info ) {
6896 cfb->cb_db.be_suffix = NULL;
6897 cfb->cb_db.be_nsuffix = NULL;
6898 BER_BVZERO( &cfb->cb_db.be_rootdn );
6899 BER_BVZERO( &cfb->cb_db.be_rootndn );
6901 backend_destroy_one( &cfb->cb_db, 0 );
6910 config_back_db_init( BackendDB *be, ConfigReply* cr )
6916 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6917 cfn = cfb->cb_config;
6918 be->be_private = cfb;
6920 ber_dupbv( &be->be_rootdn, &config_rdn );
6921 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6922 ber_dupbv( &dn, &be->be_rootdn );
6923 ber_bvarray_add( &be->be_suffix, &dn );
6924 ber_dupbv( &dn, &be->be_rootdn );
6925 ber_bvarray_add( &be->be_nsuffix, &dn );
6927 /* Hide from namingContexts */
6928 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6930 /* Check ACLs on content of Adds by default */
6931 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6937 config_back_destroy( BackendInfo *bi )
6939 ldif_must_b64_encode_release();
6944 config_tool_entry_open( BackendDB *be, int mode )
6946 CfBackInfo *cfb = be->be_private;
6947 BackendInfo *bi = cfb->cb_db.bd_info;
6949 if ( bi && bi->bi_tool_entry_open )
6950 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6957 config_tool_entry_close( BackendDB *be )
6959 CfBackInfo *cfb = be->be_private;
6960 BackendInfo *bi = cfb->cb_db.bd_info;
6962 if ( bi && bi->bi_tool_entry_close )
6963 return bi->bi_tool_entry_close( &cfb->cb_db );
6969 config_tool_entry_first( BackendDB *be )
6971 CfBackInfo *cfb = be->be_private;
6972 BackendInfo *bi = cfb->cb_db.bd_info;
6974 if ( bi && bi->bi_tool_entry_first ) {
6975 return bi->bi_tool_entry_first( &cfb->cb_db );
6977 if ( bi && bi->bi_tool_entry_first_x ) {
6978 return bi->bi_tool_entry_first_x( &cfb->cb_db,
6979 NULL, LDAP_SCOPE_DEFAULT, NULL );
6985 config_tool_entry_first_x(
6987 struct berval *base,
6991 CfBackInfo *cfb = be->be_private;
6992 BackendInfo *bi = cfb->cb_db.bd_info;
6994 if ( bi && bi->bi_tool_entry_first_x ) {
6995 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7001 config_tool_entry_next( BackendDB *be )
7003 CfBackInfo *cfb = be->be_private;
7004 BackendInfo *bi = cfb->cb_db.bd_info;
7006 if ( bi && bi->bi_tool_entry_next )
7007 return bi->bi_tool_entry_next( &cfb->cb_db );
7013 config_tool_entry_get( BackendDB *be, ID id )
7015 CfBackInfo *cfb = be->be_private;
7016 BackendInfo *bi = cfb->cb_db.bd_info;
7018 if ( bi && bi->bi_tool_entry_get )
7019 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7024 static int entry_put_got_frontend=0;
7025 static int entry_put_got_config=0;
7027 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7029 CfBackInfo *cfb = be->be_private;
7030 BackendInfo *bi = cfb->cb_db.bd_info;
7032 struct berval rdn, vals[ 2 ];
7034 OperationBuffer opbuf;
7036 Connection conn = {0};
7037 Operation *op = NULL;
7040 int isFrontendChild = 0;
7042 /* Create entry for frontend database if it does not exist already */
7043 if ( !entry_put_got_frontend ) {
7044 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7045 STRLENOF( "olcDatabase" ))) {
7046 if ( strncmp( e->e_nname.bv_val +
7047 STRLENOF( "olcDatabase" ), "={-1}frontend",
7048 STRLENOF( "={-1}frontend" )) &&
7049 strncmp( e->e_nname.bv_val +
7050 STRLENOF( "olcDatabase" ), "=frontend",
7051 STRLENOF( "=frontend" ))) {
7053 vals[1].bv_val = NULL;
7054 memset( &ca, 0, sizeof(ConfigArgs));
7056 ca.bi = frontendDB->bd_info;
7057 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7058 rdn.bv_val = ca.log;
7059 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7060 "%s=" SLAP_X_ORDERED_FMT "%s",
7061 cfAd_database->ad_cname.bv_val, -1,
7063 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7064 &CFOC_DATABASE, ca.be->be_cf_ocs );
7065 thrctx = ldap_pvt_thread_pool_context();
7066 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7068 op->o_bd = &cfb->cb_db;
7069 op->o_tag = LDAP_REQ_ADD;
7071 op->o_dn = be->be_rootdn;
7072 op->o_ndn = be->be_rootndn;
7073 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7074 if ( rc != LDAP_SUCCESS ) {
7075 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7076 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7080 if ( ce && bi && bi->bi_tool_entry_put &&
7081 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7082 entry_put_got_frontend++;
7084 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7085 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7089 if ( !strncmp( e->e_nname.bv_val +
7090 STRLENOF( "olcDatabase" ), "=frontend",
7091 STRLENOF( "=frontend" ) ) )
7093 struct berval rdn, pdn, ndn;
7094 dnParent( &e->e_nname, &pdn );
7095 rdn.bv_val = ca.log;
7096 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7097 "%s=" SLAP_X_ORDERED_FMT "%s",
7098 cfAd_database->ad_cname.bv_val, -1,
7099 frontendDB->bd_info->bi_type );
7100 build_new_dn( &ndn, &pdn, &rdn, NULL );
7101 ber_memfree( e->e_name.bv_val );
7103 ber_bvreplace( &e->e_nname, &e->e_name );
7105 entry_put_got_frontend++;
7111 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7112 * instances, may appear before the config database entry in the ldif, skip
7113 * auto-creation of olcDatabase={0}config in such a case */
7114 if ( !entry_put_got_config &&
7115 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7117 dnParent( &e->e_nname, &pdn );
7118 while ( pdn.bv_len ) {
7119 if ( !strncmp( pdn.bv_val, "olcDatabase",
7120 STRLENOF( "olcDatabase" ))) {
7121 if ( !strncmp( pdn.bv_val +
7122 STRLENOF( "olcDatabase" ), "={-1}frontend",
7123 STRLENOF( "={-1}frontend" )) ||
7124 !strncmp( pdn.bv_val +
7125 STRLENOF( "olcDatabase" ), "=frontend",
7126 STRLENOF( "=frontend" ))) {
7128 isFrontendChild = 1;
7132 dnParent( &pdn, &pdn );
7136 /* Create entry for config database if it does not exist already */
7137 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7138 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7139 STRLENOF( "olcDatabase" ))) {
7140 if ( strncmp( e->e_nname.bv_val +
7141 STRLENOF( "olcDatabase" ), "={0}config",
7142 STRLENOF( "={0}config" )) &&
7143 strncmp( e->e_nname.bv_val +
7144 STRLENOF( "olcDatabase" ), "=config",
7145 STRLENOF( "=config" )) ) {
7147 vals[1].bv_val = NULL;
7148 memset( &ca, 0, sizeof(ConfigArgs));
7149 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7150 ca.bi = ca.be->bd_info;
7151 rdn.bv_val = ca.log;
7152 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7153 "%s=" SLAP_X_ORDERED_FMT "%s",
7154 cfAd_database->ad_cname.bv_val, 0,
7156 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7159 thrctx = ldap_pvt_thread_pool_context();
7160 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7162 op->o_bd = &cfb->cb_db;
7163 op->o_tag = LDAP_REQ_ADD;
7164 op->o_dn = be->be_rootdn;
7165 op->o_ndn = be->be_rootndn;
7168 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7169 if ( rc != LDAP_SUCCESS ) {
7170 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7171 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7174 if (ce && bi && bi->bi_tool_entry_put &&
7175 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7176 entry_put_got_config++;
7178 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7179 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7183 entry_put_got_config++;
7187 if ( bi && bi->bi_tool_entry_put &&
7188 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7189 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7196 AttributeDescription **desc;
7198 { "attribute", &cfAd_attr },
7199 { "backend", &cfAd_backend },
7200 { "database", &cfAd_database },
7201 { "include", &cfAd_include },
7202 { "ldapsyntax", &cfAd_syntax },
7203 { "objectclass", &cfAd_oc },
7204 { "objectidentifier", &cfAd_om },
7205 { "overlay", &cfAd_overlay },
7210 * add / delete: all types that may be added or deleted must use an
7211 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7212 * should automatically renumber the index of any siblings as needed,
7213 * so that no gaps in the numbering sequence exist after the add/delete
7215 * What can be added:
7217 * backend objects for backend-specific config directives
7221 * delete: probably no support this time around.
7223 * modrdn: generally not done. Will be invoked automatically by add/
7224 * delete to update numbering sequence. Perform as an explicit operation
7225 * so that the renumbering effect may be replicated. Subtree rename must
7226 * be supported, since renumbering a database will affect all its child
7229 * modify: must be fully supported.
7233 config_back_initialize( BackendInfo *bi )
7235 ConfigTable *ct = config_back_cf_table;
7239 AttributeDescription *ad = NULL;
7241 static char *controls[] = {
7242 LDAP_CONTROL_MANAGEDSAIT,
7246 /* Make sure we don't exceed the bits reserved for userland */
7247 config_check_userland( CFG_LAST );
7249 bi->bi_controls = controls;
7254 bi->bi_destroy = config_back_destroy;
7256 bi->bi_db_init = config_back_db_init;
7257 bi->bi_db_config = 0;
7258 bi->bi_db_open = config_back_db_open;
7259 bi->bi_db_close = config_back_db_close;
7260 bi->bi_db_destroy = config_back_db_destroy;
7262 bi->bi_op_bind = config_back_bind;
7263 bi->bi_op_unbind = 0;
7264 bi->bi_op_search = config_back_search;
7265 bi->bi_op_compare = 0;
7266 bi->bi_op_modify = config_back_modify;
7267 bi->bi_op_modrdn = config_back_modrdn;
7268 bi->bi_op_add = config_back_add;
7269 bi->bi_op_delete = config_back_delete;
7270 bi->bi_op_abandon = 0;
7272 bi->bi_extended = 0;
7274 bi->bi_chk_referrals = 0;
7276 bi->bi_access_allowed = slap_access_allowed;
7278 bi->bi_connection_init = 0;
7279 bi->bi_connection_destroy = 0;
7281 bi->bi_entry_release_rw = config_entry_release;
7282 bi->bi_entry_get_rw = config_back_entry_get;
7284 bi->bi_tool_entry_open = config_tool_entry_open;
7285 bi->bi_tool_entry_close = config_tool_entry_close;
7286 bi->bi_tool_entry_first = config_tool_entry_first;
7287 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7288 bi->bi_tool_entry_next = config_tool_entry_next;
7289 bi->bi_tool_entry_get = config_tool_entry_get;
7290 bi->bi_tool_entry_put = config_tool_entry_put;
7293 argv[ 0 ] = "slapd";
7299 for (i=0; OidMacros[i].name; i++ ) {
7300 argv[1] = OidMacros[i].name;
7301 argv[2] = OidMacros[i].oid;
7302 parse_oidm( &ca, 0, NULL );
7305 bi->bi_cf_ocs = cf_ocs;
7307 i = config_register_schema( ct, cf_ocs );
7310 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7313 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7314 * basically, we don't care if it fails */
7315 i = slap_str2ad( "olcRootPW", &ad, &text );
7317 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7318 "warning, unable to get \"olcRootPW\" "
7319 "attribute description: %d: %s\n",
7322 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7323 ad->ad_type->sat_oid );
7326 /* set up the notable AttributeDescriptions */
7328 for (;ct->name;ct++) {
7329 if (strcmp(ct->name, ads[i].name)) continue;
7330 *ads[i].desc = ct->ad;
7332 if (!ads[i].name) break;