1 /* bconfig.c - the config backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 2005-2021 The OpenLDAP Foundation.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
11 *
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>.
15 */
16 /* ACKNOWLEDGEMENTS:
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
19 */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24 #include <ac/string.h>
25 #include <ac/ctype.h>
26 #include <ac/dirent.h>
27 #include <ac/errno.h>
28 #include <sys/stat.h>
29 #include <ac/unistd.h>
30
31 #include "slap.h"
32
33 #ifdef LDAP_SLAPI
34 #include "slapi/slapi.h"
35 #endif
36
37 #include <ldif.h>
38 #include <lutil.h>
39
40 #include "slap-config.h"
41
42 #define CONFIG_RDN "cn=config"
43 #define SCHEMA_RDN "cn=schema"
44
45 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
46 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47
48 extern int slap_DN_strict; /* dn.c */
49
50 #ifdef SLAPD_MODULES
51 typedef struct modpath_s {
52 struct modpath_s *mp_next;
53 struct berval mp_path;
54 BerVarray mp_loads;
55 } ModPaths;
56
57 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 #endif
59
60 typedef struct ConfigFile {
61 struct ConfigFile *c_sibs;
62 struct ConfigFile *c_kids;
63 struct berval c_file;
64 AttributeType *c_at_head, *c_at_tail;
65 ContentRule *c_cr_head, *c_cr_tail;
66 ObjectClass *c_oc_head, *c_oc_tail;
67 OidMacro *c_om_head, *c_om_tail;
68 Syntax *c_syn_head, *c_syn_tail;
69 BerVarray c_dseFiles;
70 } ConfigFile;
71
72 typedef struct {
73 ConfigFile *cb_config;
74 CfEntryInfo *cb_root;
75 BackendDB cb_db; /* underlying database */
76 int cb_got_ldif;
77 int cb_use_ldif;
78 } CfBackInfo;
79
80 static CfBackInfo cfBackInfo;
81
82 static char *passwd_salt;
83 static FILE *logfile;
84 static char *logfileName;
85 static AccessControl *defacl_parsed = NULL;
86
87 static struct berval cfdir;
88
89 /* Private state */
90 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
91 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
92
93 static ConfigFile *cfn;
94
95 static Avlnode *CfOcTree;
96
97 /* System schema state */
98 extern AttributeType *at_sys_tail; /* at.c */
99 extern ObjectClass *oc_sys_tail; /* oc.c */
100 extern OidMacro *om_sys_tail; /* oidm.c */
101 extern Syntax *syn_sys_tail; /* syntax.c */
102 static AttributeType *cf_at_tail;
103 static ObjectClass *cf_oc_tail;
104 static OidMacro *cf_om_tail;
105 static Syntax *cf_syn_tail;
106
107 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
108 SlapReply *rs, int *renumber, Operation *op );
109
110 static int config_check_schema( Operation *op, CfBackInfo *cfb );
111
112 static ConfigDriver config_fname;
113 static ConfigDriver config_cfdir;
114 static ConfigDriver config_generic;
115 static ConfigDriver config_search_base;
116 static ConfigDriver config_passwd_hash;
117 static ConfigDriver config_schema_dn;
118 static ConfigDriver config_sizelimit;
119 static ConfigDriver config_timelimit;
120 static ConfigDriver config_overlay;
121 static ConfigDriver config_subordinate;
122 static ConfigDriver config_suffix;
123 #ifdef LDAP_TCP_BUFFER
124 static ConfigDriver config_tcp_buffer;
125 #endif /* LDAP_TCP_BUFFER */
126 static ConfigDriver config_rootdn;
127 static ConfigDriver config_rootpw;
128 static ConfigDriver config_restrict;
129 static ConfigDriver config_allows;
130 static ConfigDriver config_disallows;
131 static ConfigDriver config_requires;
132 static ConfigDriver config_security;
133 static ConfigDriver config_referral;
134 static ConfigDriver config_loglevel;
135 static ConfigDriver config_updatedn;
136 static ConfigDriver config_updateref;
137 static ConfigDriver config_extra_attrs;
138 static ConfigDriver config_include;
139 static ConfigDriver config_obsolete;
140 #ifdef HAVE_TLS
141 static ConfigDriver config_tls_option;
142 static ConfigDriver config_tls_config;
143 #endif
144 extern ConfigDriver syncrepl_config;
145
146 enum {
147 CFG_ACL = 1,
148 CFG_BACKEND,
149 CFG_DATABASE,
150 CFG_TLS_RAND,
151 CFG_TLS_CIPHER,
152 CFG_TLS_PROTOCOL_MIN,
153 CFG_TLS_CERT_FILE,
154 CFG_TLS_CERT_KEY,
155 CFG_TLS_CA_PATH,
156 CFG_TLS_CA_FILE,
157 CFG_TLS_DH_FILE,
158 CFG_TLS_VERIFY,
159 CFG_TLS_CRLCHECK,
160 CFG_TLS_CRL_FILE,
161 CFG_CONCUR,
162 CFG_THREADS,
163 CFG_SALT,
164 CFG_LIMITS,
165 CFG_RO,
166 CFG_REWRITE,
167 CFG_DEPTH,
168 CFG_OID,
169 CFG_OC,
170 CFG_DIT,
171 CFG_ATTR,
172 CFG_ATOPT,
173 CFG_ROOTDSE,
174 CFG_LOGFILE,
175 CFG_PLUGIN,
176 CFG_MODLOAD,
177 CFG_MODPATH,
178 CFG_LASTMOD,
179 CFG_LASTBIND,
180 CFG_AZPOLICY,
181 CFG_AZREGEXP,
182 CFG_AZDUC,
183 CFG_AZDUC_IGNORE,
184 CFG_SASLSECP,
185 CFG_SSTR_IF_MAX,
186 CFG_SSTR_IF_MIN,
187 CFG_TTHREADS,
188 CFG_MULTIPROVIDER,
189 CFG_HIDDEN,
190 CFG_MONITORING,
191 CFG_SERVERID,
192 CFG_SORTVALS,
193 CFG_IX_INTLEN,
194 CFG_SYNTAX,
195 CFG_ACL_ADD,
196 CFG_SYNC_SUBENTRY,
197 CFG_LTHREADS,
198 CFG_IX_HASH64,
199 CFG_DISABLED,
200 CFG_THREADQS,
201 CFG_TLS_ECNAME,
202 CFG_TLS_CACERT,
203 CFG_TLS_CERT,
204 CFG_TLS_KEY,
205
206 CFG_LAST
207 };
208
209 typedef struct {
210 char *name, *oid;
211 } OidRec;
212
213 static OidRec OidMacros[] = {
214 /* OpenLDAProot:1.12.2 */
215 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
216 { "OLcfgAt", "OLcfg:3" },
217 { "OLcfgGlAt", "OLcfgAt:0" },
218 { "OLcfgBkAt", "OLcfgAt:1" },
219 { "OLcfgDbAt", "OLcfgAt:2" },
220 { "OLcfgOvAt", "OLcfgAt:3" },
221 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
222 { "OLcfgOc", "OLcfg:4" },
223 { "OLcfgGlOc", "OLcfgOc:0" },
224 { "OLcfgBkOc", "OLcfgOc:1" },
225 { "OLcfgDbOc", "OLcfgOc:2" },
226 { "OLcfgOvOc", "OLcfgOc:3" },
227 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
228
229 /* Syntaxes. We should just start using the standard names and
230 * document that they are predefined and available for users
231 * to reference in their own schema. Defining schema without
232 * OID macros is for masochists...
233 */
234 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
235 { "OMsBoolean", "OMsyn:7" },
236 { "OMsDN", "OMsyn:12" },
237 { "OMsDirectoryString", "OMsyn:15" },
238 { "OMsIA5String", "OMsyn:26" },
239 { "OMsInteger", "OMsyn:27" },
240 { "OMsOID", "OMsyn:38" },
241 { "OMsOctetString", "OMsyn:40" },
242 { NULL, NULL }
243 };
244
245 /*
246 * Backend/Database registry
247 *
248 * OLcfg{Bk|Db}{Oc|At}:0 -> common
249 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb) (removed)
250 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
251 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
252 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
253 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
254 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
255 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
256 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
257 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
258 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell (removed)
259 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
260 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
261 * OLcfg{Bk|Db}{Oc|At}:13 -> lloadd
262 */
263
264 /*
265 * Overlay registry
266 *
267 * OLcfgOv{Oc|At}:1 -> syncprov
268 * OLcfgOv{Oc|At}:2 -> pcache
269 * OLcfgOv{Oc|At}:3 -> chain
270 * OLcfgOv{Oc|At}:4 -> accesslog
271 * OLcfgOv{Oc|At}:5 -> valsort
272 * OLcfgOv{Oc|At}:7 -> distproc
273 * OLcfgOv{Oc|At}:8 -> dynlist
274 * OLcfgOv{Oc|At}:9 -> dds
275 * OLcfgOv{Oc|At}:10 -> unique
276 * OLcfgOv{Oc|At}:11 -> refint
277 * OLcfgOv{Oc|At}:12 -> ppolicy
278 * OLcfgOv{Oc|At}:13 -> constraint
279 * OLcfgOv{Oc|At}:14 -> translucent
280 * OLcfgOv{Oc|At}:15 -> auditlog
281 * OLcfgOv{Oc|At}:16 -> rwm
282 * OLcfgOv{Oc|At}:17 -> dyngroup
283 * OLcfgOv{Oc|At}:18 -> memberof
284 * OLcfgOv{Oc|At}:19 -> collect
285 * OLcfgOv{Oc|At}:20 -> retcode
286 * OLcfgOv{Oc|At}:21 -> sssvlv
287 * OLcfgOv{Oc|At}:22 -> autoca
288 * OLcfgOv{Oc|At}:24 -> remoteauth
289 */
290
291 /* alphabetical ordering */
292
293 static ConfigTable config_back_cf_table[] = {
294 /* This attr is read-only */
295 { "", "", 0, 0, 0, ARG_MAGIC,
296 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
297 "DESC 'File for slapd configuration directives' "
298 "EQUALITY caseExactMatch "
299 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
300 { "", "", 0, 0, 0, ARG_MAGIC,
301 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
302 "DESC 'Directory for slapd configuration backend' "
303 "EQUALITY caseExactMatch "
304 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
305 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
306 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
307 "DESC 'Access Control List' "
308 "EQUALITY caseIgnoreMatch "
309 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
310 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
311 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
312 "DESC 'Check ACLs against content of Add ops' "
313 "EQUALITY booleanMatch "
314 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
315 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
316 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
317 "DESC 'Allowed set of deprecated features' "
318 "EQUALITY caseIgnoreMatch "
319 "SYNTAX OMsDirectoryString )", NULL, NULL },
320 { "argsfile", "file", 2, 2, 0, ARG_STRING,
321 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
322 "DESC 'File for slapd command line options' "
323 "EQUALITY caseExactMatch "
324 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
325 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
326 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
327 "EQUALITY caseIgnoreMatch "
328 "SYNTAX OMsDirectoryString )", NULL, NULL },
329 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
330 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
331 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
332 "DESC 'OpenLDAP attributeTypes' "
333 "EQUALITY caseIgnoreMatch "
334 "SUBSTR caseIgnoreSubstringsMatch "
335 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
336 NULL, NULL },
337 { "authid-rewrite", "rewrite", 2, 0, STRLENOF( "authid-rewrite" ),
338 ARG_MAGIC|CFG_REWRITE, &config_generic,
339 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
340 "EQUALITY caseIgnoreMatch "
341 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
342 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
343 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
344 "EQUALITY caseIgnoreMatch "
345 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
346 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
347 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
348 "EQUALITY caseIgnoreMatch "
349 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
350 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
351 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
352 "DESC 'A type of backend' "
353 "EQUALITY caseIgnoreMatch "
354 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
355 NULL, NULL },
356 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
357 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
358 "EQUALITY integerMatch "
359 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
360 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
361 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
362 "EQUALITY integerMatch "
363 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
364 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
365 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
366 "EQUALITY integerMatch "
367 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
368 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
369 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
370 "DESC 'The backend type for a database instance' "
371 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
372 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
373 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
374 "EQUALITY distinguishedNameMatch "
375 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
376 { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
377 &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
378 "EQUALITY booleanMatch "
379 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
380 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
381 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
382 "EQUALITY caseIgnoreMatch "
383 "SYNTAX OMsDirectoryString )", NULL, NULL },
384 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
385 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
386 "DESC 'OpenLDAP DIT content rules' "
387 "EQUALITY caseIgnoreMatch "
388 "SUBSTR caseIgnoreSubstringsMatch "
389 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
390 NULL, NULL },
391 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
392 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
393 "EQUALITY caseIgnoreMatch "
394 "SYNTAX OMsDirectoryString )", NULL, NULL },
395 { "gentlehup", "on|off", 2, 2, 0,
396 #ifdef SIGHUP
397 ARG_ON_OFF, &global_gentlehup,
398 #else
399 ARG_IGNORED, NULL,
400 #endif
401 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
402 "EQUALITY booleanMatch "
403 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
404 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
405 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
406 "EQUALITY booleanMatch "
407 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
408 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
409 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
410 "EQUALITY integerMatch "
411 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
412 { "include", "file", 2, 2, 0, ARG_MAGIC,
413 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
414 "SUP labeledURI )", NULL, NULL },
415 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
416 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
417 "EQUALITY booleanMatch "
418 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
419 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
420 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
421 "EQUALITY integerMatch "
422 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
423 { .v_uint = SLAP_INDEX_SUBSTR_IF_MINLEN_DEFAULT }
424 },
425 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
426 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
427 "EQUALITY integerMatch "
428 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
429 { .v_uint = SLAP_INDEX_SUBSTR_IF_MAXLEN_DEFAULT }
430 },
431 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
432 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
433 "EQUALITY integerMatch "
434 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
435 { .v_uint = SLAP_INDEX_SUBSTR_ANY_LEN_DEFAULT } },
436 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
437 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
438 "EQUALITY integerMatch "
439 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
440 { .v_uint = SLAP_INDEX_SUBSTR_ANY_STEP_DEFAULT } },
441 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
442 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
443 "EQUALITY integerMatch "
444 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
445 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
446 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
447 "EQUALITY booleanMatch "
448 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
449 { "lastbind", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTBIND,
450 &config_generic, "( OLcfgDbAt:0.22 NAME 'olcLastBind' "
451 "EQUALITY booleanMatch "
452 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
453 { "ldapsyntax", "syntax", 2, 0, 0,
454 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
455 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
456 "DESC 'OpenLDAP ldapSyntax' "
457 "EQUALITY caseIgnoreMatch "
458 "SUBSTR caseIgnoreSubstringsMatch "
459 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
460 NULL, NULL },
461 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
462 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
463 "EQUALITY caseIgnoreMatch "
464 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
465 { "listener-threads", "count", 2, 0, 0,
466 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
467 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
468 "EQUALITY integerMatch "
469 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
470 { .v_uint = 1 }
471 },
472 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
473 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
474 "EQUALITY integerMatch "
475 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
476 { .v_int = LDAP_PVT_SASL_LOCAL_SSF } },
477 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
478 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
479 "EQUALITY caseExactMatch "
480 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
481 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
482 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
483 "EQUALITY caseIgnoreMatch "
484 "SYNTAX OMsDirectoryString )", NULL, NULL },
485 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
486 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
487 "EQUALITY integerMatch "
488 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
489 { .v_int = SLAPD_DEFAULT_MAXDEREFDEPTH }
490 },
491 { "maxFilterDepth", "depth", 2, 2, 0, ARG_INT,
492 &slap_max_filter_depth, "( OLcfgGlAt:101 NAME 'olcMaxFilterDepth' "
493 "EQUALITY integerMatch "
494 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
495 { .v_int = SLAP_MAX_FILTER_DEPTH_DEFAULT }
496 },
497 { "multiprovider", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MULTIPROVIDER,
498 &config_generic, "( OLcfgDbAt:0.16 NAME ( 'olcMultiProvider' 'olcMirrorMode' ) "
499 "EQUALITY booleanMatch "
500 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
501 { "moduleload", "file", 2, 0, 0,
502 #ifdef SLAPD_MODULES
503 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
504 #else
505 ARG_IGNORED, NULL,
506 #endif
507 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
508 "EQUALITY caseIgnoreMatch "
509 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
510 { "modulepath", "path", 2, 2, 0,
511 #ifdef SLAPD_MODULES
512 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
513 #else
514 ARG_IGNORED, NULL,
515 #endif
516 "( OLcfgGlAt:31 NAME 'olcModulePath' "
517 "EQUALITY caseExactMatch "
518 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
519 { "monitoring", "TRUE|FALSE", 2, 2, 0,
520 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
521 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
522 "EQUALITY booleanMatch "
523 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
524 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
525 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
526 "DESC 'OpenLDAP object classes' "
527 "EQUALITY caseIgnoreMatch "
528 "SUBSTR caseIgnoreSubstringsMatch "
529 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
530 NULL, NULL },
531 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
532 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
533 "EQUALITY caseIgnoreMatch "
534 "SUBSTR caseIgnoreSubstringsMatch "
535 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
536 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
537 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
538 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
539 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
540 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
541 "EQUALITY caseIgnoreMatch "
542 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
543 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
544 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
545 "EQUALITY caseIgnoreMatch "
546 "SYNTAX OMsDirectoryString )", NULL, NULL },
547 { "pidfile", "file", 2, 2, 0, ARG_STRING,
548 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
549 "EQUALITY caseExactMatch "
550 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
551 { "plugin", NULL, 0, 0, 0,
552 #ifdef LDAP_SLAPI
553 ARG_MAGIC|CFG_PLUGIN, &config_generic,
554 #else
555 ARG_IGNORED, NULL,
556 #endif
557 "( OLcfgGlAt:38 NAME 'olcPlugin' "
558 "EQUALITY caseIgnoreMatch "
559 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
560 { "pluginlog", "filename", 2, 2, 0,
561 #ifdef LDAP_SLAPI
562 ARG_STRING, &slapi_log_file,
563 #else
564 ARG_IGNORED, NULL,
565 #endif
566 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
567 "EQUALITY caseExactMatch "
568 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
569 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
570 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
571 "EQUALITY booleanMatch "
572 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
573 { "referral", "url", 2, 2, 0, ARG_MAGIC,
574 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
575 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
576 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
577 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
578 "EQUALITY caseIgnoreMatch "
579 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
580 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
581 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
582 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
583 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
584 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
585 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
586 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
587 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
588 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
589 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
590 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
591 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
592 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
593 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
594 "EQUALITY caseIgnoreMatch "
595 "SYNTAX OMsDirectoryString )", NULL, NULL },
596 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
597 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
598 "EQUALITY caseIgnoreMatch "
599 "SYNTAX OMsDirectoryString )", NULL, NULL },
600 { "reverse-lookup", "on|off", 2, 2, 0,
601 #ifdef SLAPD_RLOOKUPS
602 ARG_ON_OFF, &use_reverse_lookup,
603 #else
604 ARG_IGNORED, NULL,
605 #endif
606 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
607 "EQUALITY booleanMatch "
608 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
609 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
610 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
611 "EQUALITY distinguishedNameMatch "
612 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
613 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
614 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
615 "EQUALITY caseIgnoreMatch "
616 "SYNTAX OMsDirectoryString )", NULL, NULL },
617 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
618 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
619 "EQUALITY octetStringMatch "
620 "SYNTAX OMsOctetString SINGLE-VALUE )", NULL, NULL },
621 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
622 &config_generic, NULL, NULL, NULL },
623 { "sasl-auxprops", NULL, 2, 0, 0,
624 #ifdef HAVE_CYRUS_SASL
625 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
626 #else
627 ARG_IGNORED, NULL,
628 #endif
629 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
630 "EQUALITY caseIgnoreMatch "
631 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
632 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
633 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
634 ARG_MAGIC|CFG_AZDUC, &config_generic,
635 #else
636 ARG_IGNORED, NULL,
637 #endif
638 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
639 "EQUALITY caseIgnoreMatch "
640 "SYNTAX OMsDirectoryString )", NULL, NULL },
641 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
642 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
643 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
644 #else
645 ARG_IGNORED, NULL,
646 #endif
647 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
648 "EQUALITY booleanMatch "
649 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
650 { "sasl-cbinding", NULL, 2, 2, 0,
651 #ifdef HAVE_CYRUS_SASL
652 ARG_STRING, &sasl_cbinding,
653 #else
654 ARG_IGNORED, NULL,
655 #endif
656 "( OLcfgGlAt:100 NAME 'olcSaslCBinding' "
657 "EQUALITY caseIgnoreMatch "
658 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
659 { "sasl-host", "host", 2, 2, 0,
660 #ifdef HAVE_CYRUS_SASL
661 ARG_STRING|ARG_UNIQUE, &sasl_host,
662 #else
663 ARG_IGNORED, NULL,
664 #endif
665 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
666 "EQUALITY caseIgnoreMatch "
667 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
668 { "sasl-realm", "realm", 2, 2, 0,
669 #ifdef HAVE_CYRUS_SASL
670 ARG_STRING|ARG_UNIQUE, &global_realm,
671 #else
672 ARG_IGNORED, NULL,
673 #endif
674 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
675 "EQUALITY caseExactMatch "
676 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
677 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
678 &config_generic, NULL, NULL, NULL },
679 { "sasl-secprops", "properties", 2, 2, 0,
680 #ifdef HAVE_CYRUS_SASL
681 ARG_MAGIC|CFG_SASLSECP, &config_generic,
682 #else
683 ARG_IGNORED, NULL,
684 #endif
685 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
686 "EQUALITY caseExactMatch "
687 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
688 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
689 &config_generic, NULL, NULL, NULL },
690 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
691 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
692 "EQUALITY distinguishedNameMatch "
693 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
694 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
695 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
696 "EQUALITY caseIgnoreMatch "
697 "SYNTAX OMsDirectoryString )", NULL, NULL },
698 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
699 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
700 "EQUALITY caseIgnoreMatch "
701 "SYNTAX OMsDirectoryString )", NULL, NULL },
702 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
703 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
704 "EQUALITY caseExactMatch "
705 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
706 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
707 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
708 "EQUALITY integerMatch "
709 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
710 { .v_ber_t = SLAP_SB_MAX_INCOMING_DEFAULT } },
711 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
712 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
713 "EQUALITY integerMatch "
714 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
715 { .v_ber_t = SLAP_SB_MAX_INCOMING_AUTH } },
716 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
717 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
718 "DESC 'Attributes whose values will always be sorted' "
719 "EQUALITY caseIgnoreMatch "
720 "SYNTAX OMsDirectoryString )", NULL, NULL },
721 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
722 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
723 "EQUALITY caseExactMatch "
724 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
725 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
726 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
727 "EQUALITY distinguishedNameMatch "
728 "SYNTAX OMsDN )", NULL, NULL },
729 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
730 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
731 "DESC 'Store sync context in a subentry' "
732 "EQUALITY booleanMatch "
733 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
734 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
735 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
736 "EQUALITY caseIgnoreMatch "
737 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
738 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
739 #ifndef LDAP_TCP_BUFFER
740 ARG_IGNORED, NULL,
741 #else /* LDAP_TCP_BUFFER */
742 ARG_MAGIC, &config_tcp_buffer,
743 #endif /* LDAP_TCP_BUFFER */
744 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
745 "EQUALITY caseExactMatch "
746 "DESC 'Custom TCP buffer size' "
747 "SYNTAX OMsDirectoryString )", NULL, NULL },
748 { "threads", "count", 2, 2, 0,
749 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
750 "( OLcfgGlAt:66 NAME 'olcThreads' "
751 "EQUALITY integerMatch "
752 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
753 { .v_int = SLAP_MAX_WORKER_THREADS }
754 },
755 { "threadqueues", "count", 2, 2, 0,
756 ARG_INT|ARG_MAGIC|CFG_THREADQS, &config_generic,
757 "( OLcfgGlAt:95 NAME 'olcThreadQueues' "
758 "EQUALITY integerMatch "
759 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
760 { .v_int = 1 }
761 },
762 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
763 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
764 "EQUALITY caseExactMatch "
765 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
766 { "TLSCACertificate", NULL, 2, 2, 0,
767 #ifdef HAVE_TLS
768 CFG_TLS_CACERT|ARG_BINARY|ARG_MAGIC, &config_tls_option,
769 #else
770 ARG_IGNORED, NULL,
771 #endif
772 "( OLcfgGlAt:97 NAME 'olcTLSCACertificate' "
773 "DESC 'X.509 certificate, must use ;binary' "
774 "EQUALITY certificateExactMatch "
775 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 SINGLE-VALUE )", NULL, NULL },
776 { "TLSCACertificateFile", NULL, 2, 2, 0,
777 #ifdef HAVE_TLS
778 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
779 #else
780 ARG_IGNORED, NULL,
781 #endif
782 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
783 "EQUALITY caseExactMatch "
784 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
785 { "TLSCACertificatePath", NULL, 2, 2, 0,
786 #ifdef HAVE_TLS
787 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
788 #else
789 ARG_IGNORED, NULL,
790 #endif
791 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
792 "EQUALITY caseExactMatch "
793 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
794 { "TLSCertificate", NULL, 2, 2, 0,
795 #ifdef HAVE_TLS
796 CFG_TLS_CERT|ARG_BINARY|ARG_MAGIC, &config_tls_option,
797 #else
798 ARG_IGNORED, NULL,
799 #endif
800 "( OLcfgGlAt:98 NAME 'olcTLSCertificate' "
801 "DESC 'X.509 certificate, must use ;binary' "
802 "EQUALITY certificateExactMatch "
803 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 SINGLE-VALUE )", NULL, NULL },
804 { "TLSCertificateFile", NULL, 2, 2, 0,
805 #ifdef HAVE_TLS
806 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
807 #else
808 ARG_IGNORED, NULL,
809 #endif
810 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
811 "EQUALITY caseExactMatch "
812 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
813 { "TLSCertificateKey", NULL, 2, 2, 0,
814 #ifdef HAVE_TLS
815 CFG_TLS_KEY|ARG_BINARY|ARG_MAGIC, &config_tls_option,
816 #else
817 ARG_IGNORED, NULL,
818 #endif
819 "( OLcfgGlAt:99 NAME 'olcTLSCertificateKey' "
820 "DESC 'X.509 privateKey, must use ;binary' "
821 "EQUALITY privateKeyMatch "
822 "SYNTAX 1.2.840.113549.1.8.1.1 SINGLE-VALUE )", NULL, NULL },
823 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
824 #ifdef HAVE_TLS
825 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
826 #else
827 ARG_IGNORED, NULL,
828 #endif
829 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
830 "EQUALITY caseExactMatch "
831 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
832 { "TLSCipherSuite", NULL, 2, 2, 0,
833 #ifdef HAVE_TLS
834 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
835 #else
836 ARG_IGNORED, NULL,
837 #endif
838 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
839 "EQUALITY caseExactMatch "
840 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
841 { "TLSCRLCheck", NULL, 2, 2, 0,
842 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL)
843 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
844 #else
845 ARG_IGNORED, NULL,
846 #endif
847 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
848 "EQUALITY caseExactMatch "
849 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
850 { "TLSCRLFile", NULL, 2, 2, 0,
851 #if defined(HAVE_GNUTLS)
852 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
853 #else
854 ARG_IGNORED, NULL,
855 #endif
856 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
857 "EQUALITY caseExactMatch "
858 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
859 { "TLSRandFile", NULL, 2, 2, 0,
860 #ifdef HAVE_TLS
861 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
862 #else
863 ARG_IGNORED, NULL,
864 #endif
865 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
866 "EQUALITY caseExactMatch "
867 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
868 { "TLSVerifyClient", NULL, 2, 2, 0,
869 #ifdef HAVE_TLS
870 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
871 #else
872 ARG_IGNORED, NULL,
873 #endif
874 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
875 "EQUALITY caseExactMatch "
876 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
877 { "TLSDHParamFile", NULL, 2, 2, 0,
878 #ifdef HAVE_TLS
879 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
880 #else
881 ARG_IGNORED, NULL,
882 #endif
883 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
884 "EQUALITY caseExactMatch "
885 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
886 { "TLSECName", NULL, 2, 2, 0,
887 #ifdef HAVE_TLS
888 CFG_TLS_ECNAME|ARG_STRING|ARG_MAGIC, &config_tls_option,
889 #else
890 ARG_IGNORED, NULL,
891 #endif
892 "( OLcfgGlAt:96 NAME 'olcTLSECName' "
893 "EQUALITY caseExactMatch "
894 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
895 { "TLSProtocolMin", NULL, 2, 2, 0,
896 #ifdef HAVE_TLS
897 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
898 #else
899 ARG_IGNORED, NULL,
900 #endif
901 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
902 "EQUALITY caseExactMatch "
903 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
904 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
905 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
906 "EQUALITY integerMatch "
907 "SYNTAX OMsInteger SINGLE-VALUE )", NULL,
908 { .v_int = 1 }
909 },
910 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
911 NULL, NULL, NULL, NULL },
912 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
913 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
914 "EQUALITY distinguishedNameMatch "
915 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
916 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
917 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
918 "EQUALITY caseIgnoreMatch "
919 "SUP labeledURI )", NULL, NULL },
920 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
921 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
922 "EQUALITY integerMatch "
923 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
924 /* Legacy keywords */
925 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MULTIPROVIDER,
926 &config_generic, NULL, NULL, NULL },
927 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
928 NULL, NULL, NULL, NULL }
929 };
930
931 /* Need to no-op this keyword for dynamic config */
932 ConfigTable olcDatabaseDummy[] = {
933 { "", "", 0, 0, 0, ARG_IGNORED,
934 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
935 "DESC 'The backend type for a database instance' "
936 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
937 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
938 };
939
940 /* Routines to check if a child can be added to this type */
941 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
942 cfAddBackend, cfAddModule, cfAddOverlay;
943
944 /* NOTE: be careful when defining array members
945 * that can be conditionally compiled */
946 #define CFOC_GLOBAL cf_ocs[1]
947 #define CFOC_SCHEMA cf_ocs[2]
948 #define CFOC_BACKEND cf_ocs[3]
949 #define CFOC_DATABASE cf_ocs[4]
950 #define CFOC_OVERLAY cf_ocs[5]
951 #define CFOC_INCLUDE cf_ocs[6]
952 #define CFOC_FRONTEND cf_ocs[7]
953 #ifdef SLAPD_MODULES
954 #define CFOC_MODULE cf_ocs[8]
955 #endif /* SLAPD_MODULES */
956
957 static ConfigOCs cf_ocs[] = {
958 { "( OLcfgGlOc:0 "
959 "NAME 'olcConfig' "
960 "DESC 'OpenLDAP configuration object' "
961 "ABSTRACT SUP top )", Cft_Abstract, NULL },
962 { "( OLcfgGlOc:1 "
963 "NAME 'olcGlobal' "
964 "DESC 'OpenLDAP Global configuration options' "
965 "SUP olcConfig STRUCTURAL "
966 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
967 "olcAttributeOptions $ olcAuthIDRewrite $ "
968 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
969 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
970 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
971 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
972 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
973 "olcIndexIntLen $ "
974 "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
975 "olcMaxFilterDepth $ "
976 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
977 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
978 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
979 "olcRootDSE $ "
980 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
981 "olcSaslCBinding $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
982 "olcSecurity $ olcServerID $ olcSizeLimit $ "
983 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
984 "olcTCPBuffer $ "
985 "olcThreads $ olcThreadQueues $ "
986 "olcTimeLimit $ olcTLSCACertificateFile $ "
987 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
988 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
989 "olcTLSCACertificate $ olcTLSCertificate $ olcTLSCertificateKey $ "
990 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ olcTLSECName $ "
991 "olcTLSCRLFile $ olcTLSProtocolMin $ olcToolThreads $ olcWriteTimeout $ "
992 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
993 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
994 { "( OLcfgGlOc:2 "
995 "NAME 'olcSchemaConfig' "
996 "DESC 'OpenLDAP schema object' "
997 "SUP olcConfig STRUCTURAL "
998 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
999 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
1000 Cft_Schema, NULL, cfAddSchema },
1001 { "( OLcfgGlOc:3 "
1002 "NAME 'olcBackendConfig' "
1003 "DESC 'OpenLDAP Backend-specific options' "
1004 "SUP olcConfig STRUCTURAL "
1005 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
1006 { "( OLcfgGlOc:4 "
1007 "NAME 'olcDatabaseConfig' "
1008 "DESC 'OpenLDAP Database-specific options' "
1009 "SUP olcConfig STRUCTURAL "
1010 "MUST olcDatabase "
1011 "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
1012 "olcAddContentAcl $ olcLastMod $ olcLastBind $ olcLimits $ "
1013 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
1014 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
1015 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
1016 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
1017 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMultiProvider $ "
1018 "olcMonitoring $ olcExtraAttrs ) )",
1019 Cft_Database, NULL, cfAddDatabase },
1020 { "( OLcfgGlOc:5 "
1021 "NAME 'olcOverlayConfig' "
1022 "DESC 'OpenLDAP Overlay-specific options' "
1023 "SUP olcConfig STRUCTURAL "
1024 "MUST olcOverlay "
1025 "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
1026 { "( OLcfgGlOc:6 "
1027 "NAME 'olcIncludeFile' "
1028 "DESC 'OpenLDAP configuration include file' "
1029 "SUP olcConfig STRUCTURAL "
1030 "MUST olcInclude "
1031 "MAY ( cn $ olcRootDSE ) )",
1032 /* Used to be Cft_Include, that def has been removed */
1033 Cft_Abstract, NULL, cfAddInclude },
1034 /* This should be STRUCTURAL like all the other database classes, but
1035 * that would mean inheriting all of the olcDatabaseConfig attributes,
1036 * which causes them to be merged twice in config_build_entry.
1037 */
1038 { "( OLcfgGlOc:7 "
1039 "NAME 'olcFrontendConfig' "
1040 "DESC 'OpenLDAP frontend configuration' "
1041 "AUXILIARY "
1042 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
1043 Cft_Database, NULL, NULL },
1044 #ifdef SLAPD_MODULES
1045 { "( OLcfgGlOc:8 "
1046 "NAME 'olcModuleList' "
1047 "DESC 'OpenLDAP dynamic module info' "
1048 "SUP olcConfig STRUCTURAL "
1049 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
1050 Cft_Module, NULL, cfAddModule },
1051 #endif
1052 { NULL, 0, NULL }
1053 };
1054
1055 typedef struct ServerID {
1056 struct ServerID *si_next;
1057 struct berval si_url;
1058 int si_num;
1059 } ServerID;
1060
1061 static ServerID *sid_list;
1062 static ServerID *sid_set;
1063
1064 typedef struct voidList {
1065 struct voidList *vl_next;
1066 void *vl_ptr;
1067 } voidList;
1068
1069 typedef struct ADlist {
1070 struct ADlist *al_next;
1071 AttributeDescription *al_desc;
1072 } ADlist;
1073
1074 static ADlist *sortVals;
1075
1076 static int new_daemon_threads;
1077
1078 static int
config_resize_lthreads(ConfigArgs * c)1079 config_resize_lthreads(ConfigArgs *c)
1080 {
1081 return slapd_daemon_resize( new_daemon_threads );
1082 }
1083
1084 #define GOT_CONFIG 1
1085 #define GOT_FRONTEND 2
1086 static int
1087 config_unique_db;
1088
1089 static int
config_generic(ConfigArgs * c)1090 config_generic(ConfigArgs *c) {
1091 int i;
1092
1093 if ( c->op == SLAP_CONFIG_EMIT ) {
1094 int rc = 0;
1095 switch(c->type) {
1096 case CFG_CONCUR:
1097 c->value_int = ldap_pvt_thread_get_concurrency();
1098 break;
1099 case CFG_THREADS:
1100 c->value_int = connection_pool_max;
1101 break;
1102 case CFG_THREADQS:
1103 c->value_int = connection_pool_queues;
1104 break;
1105 case CFG_TTHREADS:
1106 c->value_int = slap_tool_thread_max;
1107 break;
1108 case CFG_LTHREADS:
1109 c->value_uint = slapd_daemon_threads;
1110 break;
1111 case CFG_SALT:
1112 if ( passwd_salt )
1113 c->value_string = ch_strdup( passwd_salt );
1114 else
1115 rc = 1;
1116 break;
1117 case CFG_LIMITS:
1118 if ( c->be->be_limits ) {
1119 char buf[4096*3];
1120 struct berval bv;
1121
1122 for ( i=0; c->be->be_limits[i]; i++ ) {
1123 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
1124 if ( bv.bv_len >= sizeof( buf ) ) {
1125 ber_bvarray_free_x( c->rvalue_vals, NULL );
1126 c->rvalue_vals = NULL;
1127 rc = 1;
1128 break;
1129 }
1130 bv.bv_val = buf + bv.bv_len;
1131 limits_unparse( c->be->be_limits[i], &bv,
1132 sizeof( buf ) - ( bv.bv_val - buf ) );
1133 bv.bv_len += bv.bv_val - buf;
1134 bv.bv_val = buf;
1135 value_add_one( &c->rvalue_vals, &bv );
1136 }
1137 }
1138 if ( !c->rvalue_vals ) rc = 1;
1139 break;
1140 case CFG_RO:
1141 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
1142 break;
1143 case CFG_AZPOLICY:
1144 c->value_string = ch_strdup( slap_sasl_getpolicy());
1145 break;
1146 case CFG_AZREGEXP:
1147 slap_sasl_regexp_unparse( &c->rvalue_vals );
1148 if ( !c->rvalue_vals ) rc = 1;
1149 break;
1150 #ifdef HAVE_CYRUS_SASL
1151 #ifdef SLAP_AUXPROP_DONTUSECOPY
1152 case CFG_AZDUC: {
1153 static int duc_done = 0;
1154
1155 /* take the opportunity to initialize with known values */
1156 if ( !duc_done ) {
1157 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1158 int i;
1159
1160 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1161 const char *text = NULL;
1162 AttributeDescription *ad = NULL;
1163
1164 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1165 int gotit = 0;
1166 if ( slap_dontUseCopy_propnames ) {
1167 int j;
1168
1169 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1170 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1171 gotit = 1;
1172 }
1173 }
1174 }
1175
1176 if ( !gotit ) {
1177 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1178 }
1179 }
1180 }
1181
1182 duc_done = 1;
1183 }
1184
1185 if ( slap_dontUseCopy_propnames != NULL ) {
1186 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1187 } else {
1188 rc = 1;
1189 }
1190 } break;
1191 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1192 case CFG_SASLSECP: {
1193 struct berval bv = BER_BVNULL;
1194 slap_sasl_secprops_unparse( &bv );
1195 if ( !BER_BVISNULL( &bv )) {
1196 ber_bvarray_add( &c->rvalue_vals, &bv );
1197 } else {
1198 rc = 1;
1199 }
1200 }
1201 break;
1202 #endif
1203 case CFG_DEPTH:
1204 c->value_int = c->be->be_max_deref_depth;
1205 break;
1206 case CFG_DISABLED:
1207 if ( c->bi ) {
1208 /* overlay */
1209 if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
1210 c->value_int = 1;
1211 } else {
1212 rc = 1;
1213 }
1214 } else {
1215 /* database */
1216 if ( SLAP_DBDISABLED( c->be )) {
1217 c->value_int = 1;
1218 } else {
1219 rc = 1;
1220 }
1221 }
1222 break;
1223 case CFG_HIDDEN:
1224 if ( SLAP_DBHIDDEN( c->be )) {
1225 c->value_int = 1;
1226 } else {
1227 rc = 1;
1228 }
1229 break;
1230 case CFG_OID: {
1231 ConfigFile *cf = c->ca_private;
1232 if ( !cf )
1233 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1234 else if ( cf->c_om_head )
1235 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1236 cf->c_om_tail, 0 );
1237 if ( !c->rvalue_vals )
1238 rc = 1;
1239 }
1240 break;
1241 case CFG_ATOPT:
1242 ad_unparse_options( &c->rvalue_vals );
1243 break;
1244 case CFG_OC: {
1245 ConfigFile *cf = c->ca_private;
1246 if ( !cf )
1247 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1248 else if ( cf->c_oc_head )
1249 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1250 cf->c_oc_tail, 0 );
1251 if ( !c->rvalue_vals )
1252 rc = 1;
1253 }
1254 break;
1255 case CFG_ATTR: {
1256 ConfigFile *cf = c->ca_private;
1257 if ( !cf )
1258 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1259 else if ( cf->c_at_head )
1260 at_unparse( &c->rvalue_vals, cf->c_at_head,
1261 cf->c_at_tail, 0 );
1262 if ( !c->rvalue_vals )
1263 rc = 1;
1264 }
1265 break;
1266 case CFG_SYNTAX: {
1267 ConfigFile *cf = c->ca_private;
1268 if ( !cf )
1269 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1270 else if ( cf->c_syn_head )
1271 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1272 cf->c_syn_tail, 0 );
1273 if ( !c->rvalue_vals )
1274 rc = 1;
1275 }
1276 break;
1277 case CFG_DIT: {
1278 ConfigFile *cf = c->ca_private;
1279 if ( !cf )
1280 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1281 else if ( cf->c_cr_head )
1282 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1283 cf->c_cr_tail, 0 );
1284 if ( !c->rvalue_vals )
1285 rc = 1;
1286 }
1287 break;
1288
1289 case CFG_ACL: {
1290 AccessControl *a;
1291 char *src, *dst, ibuf[11];
1292 struct berval bv, abv;
1293 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1294 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1295 if ( abv.bv_len >= sizeof( ibuf ) ) {
1296 ber_bvarray_free_x( c->rvalue_vals, NULL );
1297 c->rvalue_vals = NULL;
1298 i = 0;
1299 break;
1300 }
1301 acl_unparse( a, &bv );
1302 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1303 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1304 /* Turn TAB / EOL into plain space */
1305 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1306 if (isspace((unsigned char)*src)) *dst++ = ' ';
1307 else *dst++ = *src;
1308 }
1309 *dst = '\0';
1310 if (dst[-1] == ' ') {
1311 dst--;
1312 *dst = '\0';
1313 }
1314 abv.bv_len = dst - abv.bv_val;
1315 ber_bvarray_add( &c->rvalue_vals, &abv );
1316 }
1317 rc = (!i);
1318 break;
1319 }
1320 case CFG_ACL_ADD:
1321 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1322 break;
1323 case CFG_ROOTDSE: {
1324 ConfigFile *cf = c->ca_private;
1325 if ( cf->c_dseFiles ) {
1326 value_add( &c->rvalue_vals, cf->c_dseFiles );
1327 } else {
1328 rc = 1;
1329 }
1330 }
1331 break;
1332 case CFG_SERVERID:
1333 if ( sid_list ) {
1334 ServerID *si;
1335 struct berval bv;
1336
1337 for ( si = sid_list; si; si=si->si_next ) {
1338 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1339 if ( !BER_BVISEMPTY( &si->si_url )) {
1340 bv.bv_len = si->si_url.bv_len + 6;
1341 bv.bv_val = ch_malloc( bv.bv_len );
1342 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1343 si->si_url.bv_val );
1344 ber_bvarray_add( &c->rvalue_vals, &bv );
1345 } else {
1346 char buf[5];
1347 bv.bv_val = buf;
1348 bv.bv_len = sprintf( buf, "%d", si->si_num );
1349 value_add_one( &c->rvalue_vals, &bv );
1350 }
1351 }
1352 } else {
1353 rc = 1;
1354 }
1355 break;
1356 case CFG_LOGFILE:
1357 if ( logfileName )
1358 c->value_string = ch_strdup( logfileName );
1359 else
1360 rc = 1;
1361 break;
1362 case CFG_LASTMOD:
1363 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1364 break;
1365 case CFG_LASTBIND:
1366 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1367 break;
1368 case CFG_SYNC_SUBENTRY:
1369 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1370 break;
1371 case CFG_MULTIPROVIDER:
1372 if ( SLAP_SHADOW(c->be))
1373 c->value_int = (SLAP_MULTIPROVIDER(c->be) != 0);
1374 else
1375 rc = 1;
1376 break;
1377 case CFG_MONITORING:
1378 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1379 break;
1380 case CFG_SSTR_IF_MAX:
1381 c->value_uint = index_substr_if_maxlen;
1382 break;
1383 case CFG_SSTR_IF_MIN:
1384 c->value_uint = index_substr_if_minlen;
1385 break;
1386 case CFG_IX_HASH64:
1387 c->value_int = slap_hash64( -1 );
1388 break;
1389 case CFG_IX_INTLEN:
1390 c->value_int = index_intlen;
1391 break;
1392 case CFG_SORTVALS: {
1393 ADlist *sv;
1394 rc = 1;
1395 for ( sv = sortVals; sv; sv = sv->al_next ) {
1396 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1397 rc = 0;
1398 }
1399 } break;
1400 #ifdef SLAPD_MODULES
1401 case CFG_MODLOAD: {
1402 ModPaths *mp = c->ca_private;
1403 if (mp->mp_loads) {
1404 int i;
1405 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1406 struct berval bv;
1407 bv.bv_val = c->log;
1408 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1409 SLAP_X_ORDERED_FMT "%s", i,
1410 mp->mp_loads[i].bv_val );
1411 if ( bv.bv_len >= sizeof( c->log ) ) {
1412 ber_bvarray_free_x( c->rvalue_vals, NULL );
1413 c->rvalue_vals = NULL;
1414 break;
1415 }
1416 value_add_one( &c->rvalue_vals, &bv );
1417 }
1418 }
1419
1420 rc = c->rvalue_vals ? 0 : 1;
1421 }
1422 break;
1423 case CFG_MODPATH: {
1424 ModPaths *mp = c->ca_private;
1425 if ( !BER_BVISNULL( &mp->mp_path ))
1426 value_add_one( &c->rvalue_vals, &mp->mp_path );
1427
1428 rc = c->rvalue_vals ? 0 : 1;
1429 }
1430 break;
1431 #endif
1432 #ifdef LDAP_SLAPI
1433 case CFG_PLUGIN:
1434 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1435 if ( !c->rvalue_vals ) rc = 1;
1436 break;
1437 #endif
1438 case CFG_REWRITE:
1439 rc = slap_sasl_rewrite_unparse( &c->rvalue_vals );
1440 break;
1441 default:
1442 rc = 1;
1443 }
1444 return rc;
1445 } else if ( c->op == LDAP_MOD_DELETE ) {
1446 int rc = 0;
1447 switch(c->type) {
1448 /* single-valued attrs */
1449 case CFG_CONCUR:
1450 /* FIXME: There is currently no way to retrieve the default? */
1451 break;
1452
1453 case CFG_THREADS:
1454 if ( slapMode & SLAP_SERVER_MODE )
1455 ldap_pvt_thread_pool_maxthreads(&connection_pool,
1456 SLAP_MAX_WORKER_THREADS);
1457 connection_pool_max = SLAP_MAX_WORKER_THREADS; /* save for reference */
1458 break;
1459
1460 case CFG_THREADQS:
1461 if ( slapMode & SLAP_SERVER_MODE )
1462 ldap_pvt_thread_pool_queues(&connection_pool, 1);
1463 connection_pool_queues = 1; /* save for reference */
1464 break;
1465
1466 case CFG_TTHREADS:
1467 slap_tool_thread_max = 1;
1468 break;
1469
1470 case CFG_LTHREADS:
1471 new_daemon_threads = 1;
1472 config_push_cleanup( c, config_resize_lthreads );
1473 break;
1474
1475 case CFG_AZPOLICY:
1476 slap_sasl_setpolicy( "none" );
1477 break;
1478
1479 case CFG_DEPTH:
1480 c->be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
1481 break;
1482
1483 case CFG_LASTMOD:
1484 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1485 break;
1486
1487 case CFG_LASTBIND:
1488 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_LASTBIND;
1489 break;
1490
1491 case CFG_MONITORING:
1492 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1493 break;
1494
1495 case CFG_SASLSECP:
1496 #ifdef HAVE_CYRUS_SASL
1497 slap_sasl_secprops( "" );
1498 #endif
1499 break;
1500
1501 case CFG_SSTR_IF_MAX:
1502 index_substr_if_maxlen = SLAP_INDEX_SUBSTR_IF_MAXLEN_DEFAULT;
1503 break;
1504
1505 case CFG_SSTR_IF_MIN:
1506 index_substr_if_minlen = SLAP_INDEX_SUBSTR_IF_MINLEN_DEFAULT;
1507 break;
1508
1509 case CFG_ACL_ADD:
1510 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1511 break;
1512
1513 case CFG_SYNC_SUBENTRY:
1514 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
1515 break;
1516
1517 case CFG_RO:
1518 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1519 break;
1520
1521 #ifdef LDAP_SLAPI
1522 case CFG_PLUGIN:
1523 slapi_int_unregister_plugins(c->be, c->valx);
1524 break;
1525 #endif
1526
1527 /* no-op, requires slapd restart */
1528 case CFG_MODLOAD:
1529 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1530 break;
1531
1532 case CFG_MULTIPROVIDER:
1533 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1534 if(SLAP_SHADOW(c->be))
1535 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1536 break;
1537
1538 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1539 case CFG_AZDUC:
1540 if ( c->valx < 0 ) {
1541 if ( slap_dontUseCopy_propnames != NULL ) {
1542 ber_bvarray_free( slap_dontUseCopy_propnames );
1543 slap_dontUseCopy_propnames = NULL;
1544 }
1545
1546 } else {
1547 int i;
1548
1549 if ( slap_dontUseCopy_propnames == NULL ) {
1550 rc = 1;
1551 break;
1552 }
1553
1554 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1555 if ( i < c->valx ) {
1556 rc = 1;
1557 break;
1558 }
1559 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1560 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1561 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1562 }
1563 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1564 }
1565 break;
1566 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1567
1568 case CFG_AZREGEXP:
1569 rc = slap_sasl_regexp_delete( c->valx );
1570 break;
1571
1572 case CFG_REWRITE:
1573 rc = slap_sasl_rewrite_delete( c->valx );
1574 break;
1575
1576 case CFG_SALT:
1577 ch_free( passwd_salt );
1578 passwd_salt = NULL;
1579 break;
1580
1581 case CFG_LOGFILE:
1582 ch_free( logfileName );
1583 logfileName = NULL;
1584 if ( logfile ) {
1585 fclose( logfile );
1586 logfile = NULL;
1587 }
1588 break;
1589
1590 case CFG_SERVERID: {
1591 ServerID *si, **sip;
1592
1593 for ( i=0, si = sid_list, sip = &sid_list;
1594 si; si = *sip, i++ ) {
1595 if ( c->valx == -1 || i == c->valx ) {
1596 *sip = si->si_next;
1597 if ( sid_set == si )
1598 sid_set = NULL;
1599 ch_free( si );
1600 if ( c->valx >= 0 )
1601 break;
1602 } else {
1603 sip = &si->si_next;
1604 }
1605 }
1606 }
1607 break;
1608 case CFG_HIDDEN:
1609 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1610 break;
1611
1612 case CFG_DISABLED:
1613 if ( c->bi ) {
1614 c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
1615 if ( c->bi->bi_db_open ) {
1616 BackendInfo *bi_orig = c->be->bd_info;
1617 c->be->bd_info = c->bi;
1618 rc = c->bi->bi_db_open( c->be, &c->reply );
1619 c->be->bd_info = bi_orig;
1620 }
1621 } else {
1622 c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
1623 rc = backend_startup_one( c->be, &c->reply );
1624 }
1625 break;
1626
1627 case CFG_IX_HASH64:
1628 slap_hash64( 0 );
1629 break;
1630
1631 case CFG_IX_INTLEN:
1632 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1633 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1634 SLAP_INDEX_INTLEN_DEFAULT );
1635 break;
1636
1637 case CFG_ACL:
1638 if ( c->valx < 0 ) {
1639 acl_destroy( c->be->be_acl );
1640 c->be->be_acl = NULL;
1641
1642 } else {
1643 AccessControl **prev, *a;
1644 int i;
1645 for (i=0, prev = &c->be->be_acl; i < c->valx;
1646 i++ ) {
1647 a = *prev;
1648 prev = &a->acl_next;
1649 }
1650 a = *prev;
1651 *prev = a->acl_next;
1652 acl_free( a );
1653 }
1654 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1655 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1656 "Last explicit ACL for back-config removed. "
1657 "Using hardcoded default\n" );
1658 c->be->be_acl = defacl_parsed;
1659 }
1660 break;
1661
1662 case CFG_OC: {
1663 CfEntryInfo *ce;
1664 /* Can be NULL when undoing a failed add */
1665 if ( c->ca_entry ) {
1666 ce = c->ca_entry->e_private;
1667 /* can't modify the hardcoded schema */
1668 if ( ce->ce_parent->ce_type == Cft_Global )
1669 return 1;
1670 }
1671 }
1672 cfn = c->ca_private;
1673 if ( c->valx < 0 ) {
1674 ObjectClass *oc;
1675
1676 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1677 oc_delete( oc );
1678 if ( oc == cfn->c_oc_tail )
1679 break;
1680 }
1681 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1682 } else {
1683 ObjectClass *oc, *prev = NULL;
1684
1685 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1686 prev = oc;
1687 oc_next( &oc );
1688 }
1689 oc_delete( oc );
1690 if ( cfn->c_oc_tail == oc ) {
1691 cfn->c_oc_tail = prev;
1692 }
1693 if ( cfn->c_oc_head == oc ) {
1694 oc_next( &oc );
1695 cfn->c_oc_head = oc;
1696 }
1697 }
1698 break;
1699
1700 case CFG_ATTR: {
1701 CfEntryInfo *ce;
1702 /* Can be NULL when undoing a failed add */
1703 if ( c->ca_entry ) {
1704 ce = c->ca_entry->e_private;
1705 /* can't modify the hardcoded schema */
1706 if ( ce->ce_parent->ce_type == Cft_Global )
1707 return 1;
1708 }
1709 }
1710 cfn = c->ca_private;
1711 if ( c->valx < 0 ) {
1712 AttributeType *at;
1713
1714 for( at = cfn->c_at_head; at; at_next( &at )) {
1715 at_delete( at );
1716 if ( at == cfn->c_at_tail )
1717 break;
1718 }
1719 cfn->c_at_head = cfn->c_at_tail = NULL;
1720 } else {
1721 AttributeType *at, *prev = NULL;
1722
1723 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1724 prev = at;
1725 at_next( &at );
1726 }
1727 at_delete( at );
1728 if ( cfn->c_at_tail == at ) {
1729 cfn->c_at_tail = prev;
1730 }
1731 if ( cfn->c_at_head == at ) {
1732 at_next( &at );
1733 cfn->c_at_head = at;
1734 }
1735 }
1736 break;
1737
1738 case CFG_SYNTAX: {
1739 CfEntryInfo *ce;
1740 /* Can be NULL when undoing a failed add */
1741 if ( c->ca_entry ) {
1742 ce = c->ca_entry->e_private;
1743 /* can't modify the hardcoded schema */
1744 if ( ce->ce_parent->ce_type == Cft_Global )
1745 return 1;
1746 }
1747 }
1748 cfn = c->ca_private;
1749 if ( c->valx < 0 ) {
1750 Syntax *syn;
1751
1752 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1753 syn_delete( syn );
1754 if ( syn == cfn->c_syn_tail )
1755 break;
1756 }
1757 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1758 } else {
1759 Syntax *syn, *prev = NULL;
1760
1761 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1762 prev = syn;
1763 syn_next( &syn );
1764 }
1765 syn_delete( syn );
1766 if ( cfn->c_syn_tail == syn ) {
1767 cfn->c_syn_tail = prev;
1768 }
1769 if ( cfn->c_syn_head == syn ) {
1770 syn_next( &syn );
1771 cfn->c_syn_head = syn;
1772 }
1773 }
1774 break;
1775 case CFG_SORTVALS:
1776 if ( c->valx < 0 ) {
1777 ADlist *sv;
1778 for ( sv = sortVals; sv; sv = sortVals ) {
1779 sortVals = sv->al_next;
1780 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1781 ch_free( sv );
1782 }
1783 } else {
1784 ADlist *sv, **prev;
1785 int i = 0;
1786
1787 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1788 prev = &sv->al_next;
1789 sv = sv->al_next;
1790 }
1791 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1792 *prev = sv->al_next;
1793 ch_free( sv );
1794 }
1795 break;
1796
1797 case CFG_LIMITS:
1798 /* FIXME: there is no limits_free function */
1799 if ( c->valx < 0 ) {
1800 limits_destroy( c->be->be_limits );
1801 c->be->be_limits = NULL;
1802
1803 } else {
1804 int cnt, num = -1;
1805
1806 if ( c->be->be_limits ) {
1807 for ( num = 0; c->be->be_limits[ num ]; num++ )
1808 /* just count */ ;
1809 }
1810
1811 if ( c->valx >= num ) {
1812 return 1;
1813 }
1814
1815 if ( num == 1 ) {
1816 limits_destroy( c->be->be_limits );
1817 c->be->be_limits = NULL;
1818
1819 } else {
1820 limits_free_one( c->be->be_limits[ c->valx ] );
1821
1822 for ( cnt = c->valx; cnt < num; cnt++ ) {
1823 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1824 }
1825 }
1826 }
1827 break;
1828
1829 case CFG_ATOPT:
1830 /* FIXME: there is no ad_option_free function */
1831 case CFG_ROOTDSE:
1832 /* FIXME: there is no way to remove attributes added by
1833 a DSE file */
1834 case CFG_OID:
1835 case CFG_DIT:
1836 case CFG_MODPATH:
1837 default:
1838 rc = 1;
1839 break;
1840 }
1841 return rc;
1842 }
1843
1844 switch(c->type) {
1845 case CFG_BACKEND:
1846 if(!(c->bi = backend_info(c->argv[1]))) {
1847 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1848 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1849 c->log, c->cr_msg, c->argv[1] );
1850 return(1);
1851 }
1852 if ( c->bi->bi_flags & SLAP_BFLAG_STANDALONE ) {
1853 c->bi->bi_nDB++;
1854 nbackends++;
1855 }
1856 c->be = NULL;
1857 break;
1858
1859 case CFG_DATABASE:
1860 c->bi = NULL;
1861 /* NOTE: config is always the first backend!
1862 */
1863 if ( !strcasecmp( c->argv[1], "config" )) {
1864 if (config_unique_db & GOT_CONFIG) {
1865 sprintf( c->cr_msg, "config DB already defined");
1866 return(1);
1867 }
1868 c->be = LDAP_STAILQ_FIRST(&backendDB);
1869 config_unique_db |= GOT_CONFIG;
1870 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1871 if (config_unique_db & GOT_FRONTEND) {
1872 sprintf( c->cr_msg, "frontend DB already defined");
1873 return(1);
1874 }
1875 c->be = frontendDB;
1876 config_unique_db |= GOT_FRONTEND;
1877 } else {
1878 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1879 if ( !c->be ) {
1880 if ( c->cr_msg[0] == 0 )
1881 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1882 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1883 return(1);
1884 }
1885 }
1886 break;
1887
1888 case CFG_CONCUR:
1889 ldap_pvt_thread_set_concurrency(c->value_int);
1890 break;
1891
1892 case CFG_THREADS:
1893 if ( c->value_int < 2 ) {
1894 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1895 "threads=%d smaller than minimum value 2",
1896 c->value_int );
1897 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1898 c->log, c->cr_msg );
1899 return 1;
1900
1901 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1902 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1903 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1904 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1905 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1906 c->log, c->cr_msg );
1907 }
1908 if ( slapMode & SLAP_SERVER_MODE )
1909 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1910 connection_pool_max = c->value_int; /* save for reference */
1911 break;
1912
1913 case CFG_THREADQS:
1914 if ( c->value_int < 1 ) {
1915 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1916 "threadqueues=%d smaller than minimum value 1",
1917 c->value_int );
1918 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1919 c->log, c->cr_msg );
1920 return 1;
1921 }
1922 if ( slapMode & SLAP_SERVER_MODE )
1923 ldap_pvt_thread_pool_queues(&connection_pool, c->value_int);
1924 connection_pool_queues = c->value_int; /* save for reference */
1925 break;
1926
1927 case CFG_TTHREADS:
1928 if ( slapMode & SLAP_TOOL_MODE )
1929 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1930 slap_tool_thread_max = c->value_int; /* save for reference */
1931 break;
1932
1933 case CFG_LTHREADS:
1934 if ( c->value_uint < 1 ) {
1935 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1936 "listenerthreads=%u smaller than minimum value 1",
1937 c->value_uint );
1938 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1939 c->log, c->cr_msg );
1940 return 1;
1941 }
1942 { int mask = 0;
1943 /* use a power of two */
1944 while (c->value_uint > 1) {
1945 c->value_uint >>= 1;
1946 mask <<= 1;
1947 mask |= 1;
1948 }
1949 new_daemon_threads = mask+1;
1950 config_push_cleanup( c, config_resize_lthreads );
1951 }
1952 break;
1953
1954 case CFG_SALT:
1955 if ( passwd_salt ) ch_free( passwd_salt );
1956 passwd_salt = c->value_string;
1957 lutil_salt_format(passwd_salt);
1958 break;
1959
1960 case CFG_LIMITS:
1961 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1962 return(1);
1963 break;
1964
1965 case CFG_RO:
1966 if(c->value_int)
1967 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1968 else
1969 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1970 break;
1971
1972 case CFG_AZPOLICY:
1973 ch_free(c->value_string);
1974 if (slap_sasl_setpolicy( c->argv[1] )) {
1975 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1976 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1977 c->log, c->cr_msg, c->argv[1] );
1978 return(1);
1979 }
1980 break;
1981
1982 case CFG_AZREGEXP:
1983 if (slap_sasl_regexp_config( c->argv[1], c->argv[2], c->valx ))
1984 return(1);
1985 break;
1986
1987 #ifdef HAVE_CYRUS_SASL
1988 #ifdef SLAP_AUXPROP_DONTUSECOPY
1989 case CFG_AZDUC: {
1990 int arg, cnt;
1991
1992 for ( arg = 1; arg < c->argc; arg++ ) {
1993 int duplicate = 0, err;
1994 AttributeDescription *ad = NULL;
1995 const char *text = NULL;
1996
1997 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1998 if ( err != LDAP_SUCCESS ) {
1999 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
2000 c->argv[0], arg, c->argv[ arg ], err, text );
2001 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2002 c->log, c->cr_msg );
2003
2004 } else {
2005 if ( slap_dontUseCopy_propnames != NULL ) {
2006 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
2007 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
2008 duplicate = 1;
2009 break;
2010 }
2011 }
2012 }
2013
2014 if ( duplicate ) {
2015 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
2016 c->argv[0], arg, ad->ad_cname.bv_val);
2017 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2018 c->log, c->cr_msg );
2019 continue;
2020 }
2021
2022 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
2023 }
2024 }
2025
2026 } break;
2027 #endif /* SLAP_AUXPROP_DONTUSECOPY */
2028
2029 case CFG_SASLSECP:
2030 {
2031 char *txt = slap_sasl_secprops( c->argv[1] );
2032 if ( txt ) {
2033 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
2034 c->argv[0], txt );
2035 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg );
2036 return(1);
2037 }
2038 break;
2039 }
2040 #endif
2041
2042 case CFG_DEPTH:
2043 c->be->be_max_deref_depth = c->value_int;
2044 break;
2045
2046 case CFG_OID: {
2047 OidMacro *om;
2048
2049 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2050 cfn = c->ca_private;
2051 if(parse_oidm(c, 1, &om))
2052 return(1);
2053 if (!cfn->c_om_head) cfn->c_om_head = om;
2054 cfn->c_om_tail = om;
2055 }
2056 break;
2057
2058 case CFG_OC: {
2059 ObjectClass *oc, *prev;
2060
2061 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2062 cfn = c->ca_private;
2063 if ( c->valx < 0 ) {
2064 prev = cfn->c_oc_tail;
2065 } else {
2066 prev = NULL;
2067 /* If adding anything after the first, prev is easy */
2068 if ( c->valx ) {
2069 int i;
2070 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
2071 prev = oc;
2072 if ( !oc_next( &oc ))
2073 break;
2074 }
2075 } else
2076 /* If adding the first, and head exists, find its prev */
2077 if (cfn->c_oc_head) {
2078 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
2079 prev = oc;
2080 oc_next( &oc );
2081 }
2082 }
2083 /* else prev is NULL, append to end of global list */
2084 }
2085 if(parse_oc(c, &oc, prev)) return(1);
2086 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
2087 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
2088 }
2089 break;
2090
2091 case CFG_ATTR: {
2092 AttributeType *at, *prev;
2093
2094 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2095 cfn = c->ca_private;
2096 if ( c->valx < 0 ) {
2097 prev = cfn->c_at_tail;
2098 } else {
2099 prev = NULL;
2100 /* If adding anything after the first, prev is easy */
2101 if ( c->valx ) {
2102 int i;
2103 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
2104 prev = at;
2105 if ( !at_next( &at ))
2106 break;
2107 }
2108 } else
2109 /* If adding the first, and head exists, find its prev */
2110 if (cfn->c_at_head) {
2111 for ( at_start( &at ); at != cfn->c_at_head; ) {
2112 prev = at;
2113 at_next( &at );
2114 }
2115 }
2116 /* else prev is NULL, append to end of global list */
2117 }
2118 if(parse_at(c, &at, prev)) return(1);
2119 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
2120 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
2121 }
2122 break;
2123
2124 case CFG_SYNTAX: {
2125 Syntax *syn, *prev;
2126
2127 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2128 cfn = c->ca_private;
2129 if ( c->valx < 0 ) {
2130 prev = cfn->c_syn_tail;
2131 } else {
2132 prev = NULL;
2133 /* If adding anything after the first, prev is easy */
2134 if ( c->valx ) {
2135 int i;
2136 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
2137 prev = syn;
2138 if ( !syn_next( &syn ))
2139 break;
2140 }
2141 } else
2142 /* If adding the first, and head exists, find its prev */
2143 if (cfn->c_syn_head) {
2144 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
2145 prev = syn;
2146 syn_next( &syn );
2147 }
2148 }
2149 /* else prev is NULL, append to end of global list */
2150 }
2151 if ( parse_syn( c, &syn, prev ) ) return(1);
2152 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
2153 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
2154 }
2155 break;
2156
2157 case CFG_DIT: {
2158 ContentRule *cr;
2159
2160 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2161 cfn = c->ca_private;
2162 if(parse_cr(c, &cr)) return(1);
2163 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
2164 cfn->c_cr_tail = cr;
2165 }
2166 break;
2167
2168 case CFG_ATOPT:
2169 ad_define_option(NULL, NULL, 0);
2170 for(i = 1; i < c->argc; i++)
2171 if(ad_define_option(c->argv[i], c->fname, c->lineno))
2172 return(1);
2173 break;
2174
2175 case CFG_IX_HASH64:
2176 if ( slap_hash64( c->value_int != 0 ))
2177 return 1;
2178 break;
2179
2180 case CFG_IX_INTLEN:
2181 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
2182 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
2183 else if ( c->value_int > 255 )
2184 c->value_int = 255;
2185 index_intlen = c->value_int;
2186 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
2187 index_intlen );
2188 break;
2189
2190 case CFG_SORTVALS: {
2191 ADlist *svnew = NULL, *svtail, *sv;
2192
2193 for ( i = 1; i < c->argc; i++ ) {
2194 AttributeDescription *ad = NULL;
2195 const char *text;
2196 int rc;
2197
2198 rc = slap_str2ad( c->argv[i], &ad, &text );
2199 if ( rc ) {
2200 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
2201 c->argv[0], i );
2202 sortval_reject:
2203 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2204 c->log, c->cr_msg, c->argv[i] );
2205 for ( sv = svnew; sv; sv = svnew ) {
2206 svnew = sv->al_next;
2207 ch_free( sv );
2208 }
2209 return 1;
2210 }
2211 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
2212 ad->ad_type->sat_single_value ) {
2213 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
2214 c->argv[0], i );
2215 goto sortval_reject;
2216 }
2217 sv = ch_malloc( sizeof( ADlist ));
2218 sv->al_desc = ad;
2219 if ( !svnew ) {
2220 svnew = sv;
2221 } else {
2222 svtail->al_next = sv;
2223 }
2224 svtail = sv;
2225 }
2226 sv->al_next = NULL;
2227 for ( sv = svnew; sv; sv = sv->al_next )
2228 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
2229 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
2230 if ( sv )
2231 sv->al_next = svnew;
2232 else
2233 sortVals = svnew;
2234 }
2235 break;
2236
2237 case CFG_ACL:
2238 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
2239 c->be->be_acl = NULL;
2240 }
2241 /* Don't append to the global ACL if we're on a specific DB */
2242 i = c->valx;
2243 if ( c->valx == -1 ) {
2244 AccessControl *a;
2245 i = 0;
2246 for ( a=c->be->be_acl; a; a = a->acl_next )
2247 i++;
2248 }
2249 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
2250 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
2251 c->be->be_acl = defacl_parsed;
2252 }
2253 return 1;
2254 }
2255 break;
2256
2257 case CFG_ACL_ADD:
2258 if(c->value_int)
2259 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
2260 else
2261 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
2262 break;
2263
2264 case CFG_ROOTDSE:
2265 if(root_dse_read_file(c->argv[1])) {
2266 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
2267 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2268 c->log, c->cr_msg, c->argv[1] );
2269 return(1);
2270 }
2271 {
2272 struct berval bv;
2273 ber_str2bv( c->argv[1], 0, 1, &bv );
2274 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2275 cfn = c->ca_private;
2276 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2277 }
2278 break;
2279
2280 case CFG_SERVERID:
2281 {
2282 ServerID *si, **sip;
2283 LDAPURLDesc *lud;
2284 int num;
2285 if (( lutil_atoi( &num, c->argv[1] ) &&
2286 lutil_atoix( &num, c->argv[1], 16 )) ||
2287 num < 0 || num > SLAP_SYNC_SID_MAX )
2288 {
2289 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2290 "<%s> illegal server ID", c->argv[0] );
2291 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2292 c->log, c->cr_msg, c->argv[1] );
2293 return 1;
2294 }
2295 /* only one value allowed if no URL is given */
2296 if ( c->argc > 2 ) {
2297 int len;
2298
2299 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2300 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2301 "<%s> only one server ID allowed now", c->argv[0] );
2302 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2303 c->log, c->cr_msg, c->argv[1] );
2304 return 1;
2305 }
2306
2307 if ( ldap_url_parse( c->argv[2], &lud )) {
2308 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2309 "<%s> invalid URL", c->argv[0] );
2310 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2311 c->log, c->cr_msg, c->argv[2] );
2312 return 1;
2313 }
2314 len = strlen( c->argv[2] );
2315 si = ch_malloc( sizeof(ServerID) + len + 1 );
2316 si->si_url.bv_val = (char *)(si+1);
2317 si->si_url.bv_len = len;
2318 strcpy( si->si_url.bv_val, c->argv[2] );
2319 } else {
2320 if ( sid_list ) {
2321 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2322 "<%s> unqualified server ID not allowed now", c->argv[0] );
2323 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2324 c->log, c->cr_msg, c->argv[1] );
2325 return 1;
2326 }
2327 si = ch_malloc( sizeof(ServerID) );
2328 BER_BVZERO( &si->si_url );
2329 slap_serverID = num;
2330 Debug( LDAP_DEBUG_CONFIG,
2331 "%s: SID=0x%03x\n",
2332 c->log, slap_serverID );
2333 sid_set = si;
2334 }
2335 si->si_next = NULL;
2336 si->si_num = num;
2337 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2338 *sip = si;
2339
2340 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2341 Listener *l = config_check_my_url( c->argv[2], lud );
2342 if ( l ) {
2343 if ( sid_set ) {
2344 ldap_free_urldesc( lud );
2345 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2346 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2347 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2348 c->log, c->cr_msg, c->argv[1] );
2349 return 1;
2350 }
2351 slap_serverID = si->si_num;
2352 Debug( LDAP_DEBUG_CONFIG,
2353 "%s: SID=0x%03x (listener=%s)\n",
2354 c->log, slap_serverID,
2355 l->sl_url.bv_val );
2356 sid_set = si;
2357 }
2358 }
2359 if ( c->argc > 2 )
2360 ldap_free_urldesc( lud );
2361 }
2362 break;
2363 case CFG_LOGFILE: {
2364 if ( logfileName ) ch_free( logfileName );
2365 logfileName = c->value_string;
2366 logfile = fopen(logfileName, "w");
2367 if(logfile) lutil_debug_file(logfile);
2368 } break;
2369
2370 case CFG_LASTMOD:
2371 if(SLAP_NOLASTMODCMD(c->be)) {
2372 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2373 c->argv[0], c->be->bd_info->bi_type );
2374 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2375 c->log, c->cr_msg );
2376 return(1);
2377 }
2378 if(c->value_int)
2379 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2380 else
2381 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2382 break;
2383
2384 case CFG_LASTBIND:
2385 if (c->value_int)
2386 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_LASTBIND;
2387 else
2388 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_LASTBIND;
2389 break;
2390
2391 case CFG_MULTIPROVIDER:
2392 if(c->value_int && !SLAP_SHADOW(c->be)) {
2393 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2394 c->argv[0] );
2395 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2396 c->log, c->cr_msg );
2397 return(1);
2398 }
2399 if(c->value_int) {
2400 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2401 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2402 } else {
2403 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2404 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2405 }
2406 break;
2407
2408 case CFG_MONITORING:
2409 if(c->value_int)
2410 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2411 else
2412 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2413 break;
2414
2415 case CFG_DISABLED:
2416 if ( c->bi ) {
2417 if (c->value_int) {
2418 if ( c->bi->bi_db_close ) {
2419 BackendInfo *bi_orig = c->be->bd_info;
2420 c->be->bd_info = c->bi;
2421 c->bi->bi_db_close( c->be, &c->reply );
2422 c->be->bd_info = bi_orig;
2423 }
2424 c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
2425 } else {
2426 c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
2427 }
2428 } else {
2429 if (c->value_int) {
2430 backend_shutdown( c->be );
2431 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
2432 } else {
2433 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
2434 }
2435 }
2436 break;
2437
2438 case CFG_HIDDEN:
2439 if (c->value_int)
2440 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2441 else
2442 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2443 break;
2444
2445 case CFG_SYNC_SUBENTRY:
2446 if (c->value_int)
2447 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2448 else
2449 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2450 break;
2451
2452 case CFG_SSTR_IF_MAX:
2453 if (c->value_uint < index_substr_if_minlen) {
2454 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2455 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2456 c->log, c->cr_msg, c->value_int );
2457 return(1);
2458 }
2459 index_substr_if_maxlen = c->value_uint;
2460 break;
2461
2462 case CFG_SSTR_IF_MIN:
2463 if (c->value_uint > index_substr_if_maxlen) {
2464 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2465 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2466 c->log, c->cr_msg, c->value_int );
2467 return(1);
2468 }
2469 index_substr_if_minlen = c->value_uint;
2470 break;
2471
2472 #ifdef SLAPD_MODULES
2473 case CFG_MODLOAD:
2474 /* If we're just adding a module on an existing modpath,
2475 * make sure we've selected the current path.
2476 */
2477 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2478 modcur = c->ca_private;
2479 /* This should never fail */
2480 if ( module_path( modcur->mp_path.bv_val )) {
2481 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2482 c->argv[0] );
2483 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2484 c->log, c->cr_msg, modcur->mp_path.bv_val );
2485 return(1);
2486 }
2487 }
2488 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2489 return(1);
2490 /* Record this load on the current path */
2491 {
2492 struct berval bv;
2493 char *ptr;
2494 if ( c->op == SLAP_CONFIG_ADD ) {
2495 ptr = c->line + STRLENOF("moduleload");
2496 while (!isspace((unsigned char) *ptr)) ptr++;
2497 while (isspace((unsigned char) *ptr)) ptr++;
2498 } else {
2499 ptr = c->line;
2500 }
2501 ber_str2bv(ptr, 0, 1, &bv);
2502 ber_bvarray_add( &modcur->mp_loads, &bv );
2503 }
2504 /* Check for any new hardcoded schema */
2505 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2506 config_check_schema( NULL, &cfBackInfo );
2507 }
2508 break;
2509
2510 case CFG_MODPATH:
2511 if(module_path(c->argv[1])) return(1);
2512 /* Record which path was used with each module */
2513 {
2514 ModPaths *mp;
2515
2516 if (!modpaths.mp_loads) {
2517 mp = &modpaths;
2518 } else {
2519 mp = ch_malloc( sizeof( ModPaths ));
2520 modlast->mp_next = mp;
2521 }
2522 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2523 mp->mp_next = NULL;
2524 mp->mp_loads = NULL;
2525 modlast = mp;
2526 c->ca_private = mp;
2527 modcur = mp;
2528 }
2529
2530 break;
2531 #endif
2532
2533 #ifdef LDAP_SLAPI
2534 case CFG_PLUGIN:
2535 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx) != LDAP_SUCCESS)
2536 return(1);
2537 slapi_plugins_used++;
2538 break;
2539 #endif
2540
2541 case CFG_REWRITE: {
2542 int rc;
2543
2544 if ( c->op == LDAP_MOD_ADD ) {
2545 c->argv++;
2546 c->argc--;
2547 }
2548 rc = slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv, c->valx);
2549 if ( c->op == LDAP_MOD_ADD ) {
2550 c->argv--;
2551 c->argc++;
2552 }
2553 return rc;
2554 }
2555
2556
2557 default:
2558 Debug( LDAP_DEBUG_ANY,
2559 "%s: unknown CFG_TYPE %d.\n",
2560 c->log, c->type );
2561 return 1;
2562
2563 }
2564 return(0);
2565 }
2566
2567
2568 static int
config_fname(ConfigArgs * c)2569 config_fname(ConfigArgs *c) {
2570 if(c->op == SLAP_CONFIG_EMIT) {
2571 if (c->ca_private) {
2572 ConfigFile *cf = c->ca_private;
2573 value_add_one( &c->rvalue_vals, &cf->c_file );
2574 return 0;
2575 }
2576 return 1;
2577 }
2578 return(0);
2579 }
2580
2581 static int
config_cfdir(ConfigArgs * c)2582 config_cfdir(ConfigArgs *c) {
2583 if(c->op == SLAP_CONFIG_EMIT) {
2584 if ( !BER_BVISEMPTY( &cfdir )) {
2585 value_add_one( &c->rvalue_vals, &cfdir );
2586 return 0;
2587 }
2588 return 1;
2589 }
2590 return(0);
2591 }
2592
2593 static int
config_search_base(ConfigArgs * c)2594 config_search_base(ConfigArgs *c) {
2595 if(c->op == SLAP_CONFIG_EMIT) {
2596 int rc = 1;
2597 if (!BER_BVISEMPTY(&default_search_base)) {
2598 value_add_one(&c->rvalue_vals, &default_search_base);
2599 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2600 rc = 0;
2601 }
2602 return rc;
2603 } else if( c->op == LDAP_MOD_DELETE ) {
2604 ch_free( default_search_base.bv_val );
2605 ch_free( default_search_nbase.bv_val );
2606 BER_BVZERO( &default_search_base );
2607 BER_BVZERO( &default_search_nbase );
2608 return 0;
2609 }
2610
2611 if(c->bi || c->be != frontendDB) {
2612 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2613 "prior to any backend or database definition\n",
2614 c->log );
2615 return(1);
2616 }
2617
2618 if(default_search_nbase.bv_len) {
2619 free(default_search_base.bv_val);
2620 free(default_search_nbase.bv_val);
2621 }
2622
2623 default_search_base = c->value_dn;
2624 default_search_nbase = c->value_ndn;
2625 return(0);
2626 }
2627
2628 /* For RE23 compatibility we allow this in the global entry
2629 * but we now defer it to the frontend entry to allow modules
2630 * to load new hash types.
2631 */
2632 static int
config_passwd_hash(ConfigArgs * c)2633 config_passwd_hash(ConfigArgs *c) {
2634 int i;
2635 if (c->op == SLAP_CONFIG_EMIT) {
2636 struct berval bv;
2637 /* Don't generate it in the global entry */
2638 if ( c->table == Cft_Global )
2639 return 1;
2640 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2641 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2642 value_add_one(&c->rvalue_vals, &bv);
2643 }
2644 return i ? 0 : 1;
2645 } else if ( c->op == LDAP_MOD_DELETE ) {
2646 /* Deleting from global is a no-op, only the frontendDB entry matters */
2647 if ( c->table == Cft_Global )
2648 return 0;
2649 if ( c->valx < 0 ) {
2650 ldap_charray_free( default_passwd_hash );
2651 default_passwd_hash = NULL;
2652 } else {
2653 i = c->valx;
2654 ch_free( default_passwd_hash[i] );
2655 for (; default_passwd_hash[i]; i++ )
2656 default_passwd_hash[i] = default_passwd_hash[i+1];
2657 }
2658 return 0;
2659 }
2660 for(i = 1; i < c->argc; i++) {
2661 if(!lutil_passwd_scheme(c->argv[i])) {
2662 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2663 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2664 c->log, c->cr_msg, c->argv[i]);
2665 } else {
2666 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2667 }
2668 }
2669 if(!default_passwd_hash) {
2670 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2671 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2672 c->log, c->cr_msg );
2673 return(1);
2674 }
2675 return(0);
2676 }
2677
2678 static int
config_schema_dn(ConfigArgs * c)2679 config_schema_dn(ConfigArgs *c) {
2680 if ( c->op == SLAP_CONFIG_EMIT ) {
2681 int rc = 1;
2682 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2683 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2684 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2685 rc = 0;
2686 }
2687 return rc;
2688 } else if ( c->op == LDAP_MOD_DELETE ) {
2689 ch_free( c->be->be_schemadn.bv_val );
2690 ch_free( c->be->be_schemandn.bv_val );
2691 BER_BVZERO( &c->be->be_schemadn );
2692 BER_BVZERO( &c->be->be_schemandn );
2693 return 0;
2694 }
2695 ch_free( c->be->be_schemadn.bv_val );
2696 ch_free( c->be->be_schemandn.bv_val );
2697 c->be->be_schemadn = c->value_dn;
2698 c->be->be_schemandn = c->value_ndn;
2699 return(0);
2700 }
2701
2702 static int
config_sizelimit(ConfigArgs * c)2703 config_sizelimit(ConfigArgs *c) {
2704 int i, rc = 0;
2705 struct slap_limits_set *lim = &c->be->be_def_limit;
2706 if (c->op == SLAP_CONFIG_EMIT) {
2707 char buf[8192];
2708 struct berval bv;
2709 bv.bv_val = buf;
2710 bv.bv_len = 0;
2711 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2712 if ( !BER_BVISEMPTY( &bv ))
2713 value_add_one( &c->rvalue_vals, &bv );
2714 else
2715 rc = 1;
2716 return rc;
2717 } else if ( c->op == LDAP_MOD_DELETE ) {
2718 /* Reset to defaults or values from frontend */
2719 if ( c->be == frontendDB ) {
2720 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2721 lim->lms_s_hard = 0;
2722 lim->lms_s_unchecked = -1;
2723 lim->lms_s_pr = 0;
2724 lim->lms_s_pr_hide = 0;
2725 lim->lms_s_pr_total = 0;
2726 } else {
2727 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2728 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2729 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2730 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2731 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2732 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2733 }
2734 goto ok;
2735 }
2736 for(i = 1; i < c->argc; i++) {
2737 if(!strncasecmp(c->argv[i], "size", 4)) {
2738 rc = limits_parse_one(c->argv[i], lim);
2739 if ( rc ) {
2740 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2741 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2742 c->log, c->cr_msg, c->argv[i]);
2743 return(1);
2744 }
2745 } else {
2746 if(!strcasecmp(c->argv[i], "unlimited")) {
2747 lim->lms_s_soft = -1;
2748 } else {
2749 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2750 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2751 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2752 c->log, c->cr_msg, c->argv[i]);
2753 return(1);
2754 }
2755 }
2756 lim->lms_s_hard = 0;
2757 }
2758 }
2759
2760 ok:
2761 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2762 /* This is a modification to the global limits apply it to
2763 * the other databases as needed */
2764 AttributeDescription *ad=NULL;
2765 const char *text = NULL;
2766 CfEntryInfo *ce = c->ca_entry->e_private;
2767
2768 slap_str2ad(c->argv[0], &ad, &text);
2769 /* if we got here... */
2770 assert( ad != NULL );
2771
2772 if ( ce->ce_type == Cft_Global ){
2773 ce = ce->ce_kids;
2774 }
2775 for (; ce; ce=ce->ce_sibs) {
2776 Entry *dbe = ce->ce_entry;
2777 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2778 && (!attr_find(dbe->e_attrs, ad)) ) {
2779 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2780 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2781 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2782 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2783 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2784 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2785 }
2786 }
2787 }
2788 return(0);
2789 }
2790
2791 static int
config_timelimit(ConfigArgs * c)2792 config_timelimit(ConfigArgs *c) {
2793 int i, rc = 0;
2794 struct slap_limits_set *lim = &c->be->be_def_limit;
2795 if (c->op == SLAP_CONFIG_EMIT) {
2796 char buf[8192];
2797 struct berval bv;
2798 bv.bv_val = buf;
2799 bv.bv_len = 0;
2800 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2801 if ( !BER_BVISEMPTY( &bv ))
2802 value_add_one( &c->rvalue_vals, &bv );
2803 else
2804 rc = 1;
2805 return rc;
2806 } else if ( c->op == LDAP_MOD_DELETE ) {
2807 /* Reset to defaults or values from frontend */
2808 if ( c->be == frontendDB ) {
2809 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2810 lim->lms_t_hard = 0;
2811 } else {
2812 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2813 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2814 }
2815 goto ok;
2816 }
2817 for(i = 1; i < c->argc; i++) {
2818 if(!strncasecmp(c->argv[i], "time", 4)) {
2819 rc = limits_parse_one(c->argv[i], lim);
2820 if ( rc ) {
2821 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2822 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2823 c->log, c->cr_msg, c->argv[i]);
2824 return(1);
2825 }
2826 } else {
2827 if(!strcasecmp(c->argv[i], "unlimited")) {
2828 lim->lms_t_soft = -1;
2829 } else {
2830 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2831 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2832 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2833 c->log, c->cr_msg, c->argv[i]);
2834 return(1);
2835 }
2836 }
2837 lim->lms_t_hard = 0;
2838 }
2839 }
2840
2841 ok:
2842 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2843 /* This is a modification to the global limits apply it to
2844 * the other databases as needed */
2845 AttributeDescription *ad=NULL;
2846 const char *text = NULL;
2847 CfEntryInfo *ce = c->ca_entry->e_private;
2848
2849 slap_str2ad(c->argv[0], &ad, &text);
2850 /* if we got here... */
2851 assert( ad != NULL );
2852
2853 if ( ce->ce_type == Cft_Global ){
2854 ce = ce->ce_kids;
2855 }
2856 for (; ce; ce=ce->ce_sibs) {
2857 Entry *dbe = ce->ce_entry;
2858 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2859 && (!attr_find(dbe->e_attrs, ad)) ) {
2860 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2861 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2862 }
2863 }
2864 }
2865 return(0);
2866 }
2867
2868 static int
config_overlay(ConfigArgs * c)2869 config_overlay(ConfigArgs *c) {
2870 if (c->op == SLAP_CONFIG_EMIT) {
2871 return 1;
2872 } else if ( c->op == LDAP_MOD_DELETE ) {
2873 assert(0);
2874 }
2875 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2876 c->valx, &c->bi, &c->reply)) {
2877 /* log error */
2878 Debug( LDAP_DEBUG_ANY,
2879 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2880 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2881 return 1;
2882 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2883 return(1);
2884 }
2885 return(0);
2886 }
2887
2888 static int
config_subordinate(ConfigArgs * c)2889 config_subordinate(ConfigArgs *c)
2890 {
2891 int rc = 1;
2892 int advertise = 0;
2893
2894 switch( c->op ) {
2895 case SLAP_CONFIG_EMIT:
2896 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2897 struct berval bv;
2898
2899 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2900 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2901 STRLENOF("TRUE");
2902
2903 value_add_one( &c->rvalue_vals, &bv );
2904 rc = 0;
2905 }
2906 break;
2907 case LDAP_MOD_DELETE:
2908 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2909 glue_sub_del( c->be );
2910 } else {
2911 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2912 }
2913 rc = 0;
2914 break;
2915 case LDAP_MOD_ADD:
2916 case SLAP_CONFIG_ADD:
2917 if ( c->be->be_nsuffix == NULL ) {
2918 /* log error */
2919 snprintf( c->cr_msg, sizeof( c->cr_msg),
2920 "subordinate configuration needs a suffix" );
2921 Debug( LDAP_DEBUG_ANY,
2922 "%s: %s.\n",
2923 c->log, c->cr_msg );
2924 rc = 1;
2925 break;
2926 }
2927
2928 if ( c->argc == 2 ) {
2929 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2930 advertise = 1;
2931
2932 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2933 /* log error */
2934 snprintf( c->cr_msg, sizeof( c->cr_msg),
2935 "subordinate must be \"TRUE\" or \"advertise\"" );
2936 Debug( LDAP_DEBUG_ANY,
2937 "%s: suffix \"%s\": %s.\n",
2938 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2939 rc = 1;
2940 break;
2941 }
2942 }
2943
2944 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2945 break;
2946 }
2947
2948 return rc;
2949 }
2950
2951 /*
2952 * [listener=<listener>] [{read|write}=]<size>
2953 */
2954
2955 #ifdef LDAP_TCP_BUFFER
2956 static BerVarray tcp_buffer;
2957 int tcp_buffer_num;
2958
2959 #define SLAP_TCP_RMEM (0x1U)
2960 #define SLAP_TCP_WMEM (0x2U)
2961
2962 static int
tcp_buffer_parse(struct berval * val,int argc,char ** argv,int * size,int * rw,Listener ** l)2963 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2964 int *size, int *rw, Listener **l )
2965 {
2966 int i, rc = LDAP_SUCCESS;
2967 LDAPURLDesc *lud = NULL;
2968 char *ptr;
2969
2970 if ( val != NULL && argv == NULL ) {
2971 char *s = val->bv_val;
2972
2973 argv = ldap_str2charray( s, " \t" );
2974 if ( argv == NULL ) {
2975 return LDAP_OTHER;
2976 }
2977 }
2978
2979 i = 0;
2980 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2981 == 0 )
2982 {
2983 char *url = argv[ i ] + STRLENOF( "listener=" );
2984
2985 if ( ldap_url_parse( url, &lud ) ) {
2986 rc = LDAP_INVALID_SYNTAX;
2987 goto done;
2988 }
2989
2990 *l = config_check_my_url( url, lud );
2991 if ( *l == NULL ) {
2992 rc = LDAP_NO_SUCH_ATTRIBUTE;
2993 goto done;
2994 }
2995
2996 i++;
2997 }
2998
2999 ptr = argv[ i ];
3000 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
3001 *rw |= SLAP_TCP_RMEM;
3002 ptr += STRLENOF( "read=" );
3003
3004 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
3005 *rw |= SLAP_TCP_WMEM;
3006 ptr += STRLENOF( "write=" );
3007
3008 } else {
3009 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
3010 }
3011
3012 /* accept any base */
3013 if ( lutil_atoix( size, ptr, 0 ) ) {
3014 rc = LDAP_INVALID_SYNTAX;
3015 goto done;
3016 }
3017
3018 done:;
3019 if ( val != NULL && argv != NULL ) {
3020 ldap_charray_free( argv );
3021 }
3022
3023 if ( lud != NULL ) {
3024 ldap_free_urldesc( lud );
3025 }
3026
3027 return rc;
3028 }
3029
3030 static int
tcp_buffer_delete_one(struct berval * val)3031 tcp_buffer_delete_one( struct berval *val )
3032 {
3033 int rc = 0;
3034 int size = -1, rw = 0;
3035 Listener *l = NULL;
3036
3037 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
3038 if ( rc != 0 ) {
3039 return rc;
3040 }
3041
3042 if ( l != NULL ) {
3043 int i;
3044 Listener **ll = slapd_get_listeners();
3045
3046 for ( i = 0; ll[ i ] != NULL; i++ ) {
3047 if ( ll[ i ] == l ) break;
3048 }
3049
3050 if ( ll[ i ] == NULL ) {
3051 return LDAP_NO_SUCH_ATTRIBUTE;
3052 }
3053
3054 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
3055 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
3056
3057 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
3058 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
3059 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
3060 }
3061
3062 } else {
3063 /* NOTE: this affects listeners without a specific setting,
3064 * does not reset all listeners. If a listener without
3065 * specific settings was assigned a buffer because of
3066 * a global setting, it will not be reset. In any case,
3067 * buffer changes will only take place at restart. */
3068 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
3069 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
3070 }
3071
3072 return rc;
3073 }
3074
3075 static int
tcp_buffer_delete(BerVarray vals)3076 tcp_buffer_delete( BerVarray vals )
3077 {
3078 int i;
3079
3080 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
3081 tcp_buffer_delete_one( &vals[ i ] );
3082 }
3083
3084 return 0;
3085 }
3086
3087 static int
tcp_buffer_unparse(int size,int rw,Listener * l,struct berval * val)3088 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
3089 {
3090 char buf[sizeof("2147483648")], *ptr;
3091
3092 /* unparse for later use */
3093 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
3094 if ( l != NULL ) {
3095 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
3096 }
3097
3098 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
3099 if ( rw & SLAP_TCP_RMEM ) {
3100 val->bv_len += STRLENOF( "read=" );
3101 } else if ( rw & SLAP_TCP_WMEM ) {
3102 val->bv_len += STRLENOF( "write=" );
3103 }
3104 }
3105
3106 val->bv_val = ch_malloc( val->bv_len + 1 );
3107
3108 ptr = val->bv_val;
3109
3110 if ( l != NULL ) {
3111 ptr = lutil_strcopy( ptr, "listener=" );
3112 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
3113 *ptr++ = ' ';
3114 }
3115
3116 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
3117 if ( rw & SLAP_TCP_RMEM ) {
3118 ptr = lutil_strcopy( ptr, "read=" );
3119 } else if ( rw & SLAP_TCP_WMEM ) {
3120 ptr = lutil_strcopy( ptr, "write=" );
3121 }
3122 }
3123
3124 ptr = lutil_strcopy( ptr, buf );
3125 *ptr = '\0';
3126
3127 assert( val->bv_val + val->bv_len == ptr );
3128
3129 return LDAP_SUCCESS;
3130 }
3131
3132 static int
tcp_buffer_add_one(int argc,char ** argv)3133 tcp_buffer_add_one( int argc, char **argv )
3134 {
3135 int rc = 0;
3136 int size = -1, rw = 0;
3137 Listener *l = NULL;
3138
3139 struct berval val;
3140
3141 /* parse */
3142 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
3143 if ( rc != 0 ) {
3144 return rc;
3145 }
3146
3147 /* unparse for later use */
3148 rc = tcp_buffer_unparse( size, rw, l, &val );
3149 if ( rc != LDAP_SUCCESS ) {
3150 return rc;
3151 }
3152
3153 /* use parsed values */
3154 if ( l != NULL ) {
3155 int i;
3156 Listener **ll = slapd_get_listeners();
3157
3158 for ( i = 0; ll[ i ] != NULL; i++ ) {
3159 if ( ll[ i ] == l ) break;
3160 }
3161
3162 if ( ll[ i ] == NULL ) {
3163 return LDAP_NO_SUCH_ATTRIBUTE;
3164 }
3165
3166 /* buffer only applies to TCP listeners;
3167 * we do not do any check here, and delegate them
3168 * to setsockopt(2) */
3169 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
3170 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
3171
3172 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
3173 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
3174 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
3175 }
3176
3177 } else {
3178 /* NOTE: this affects listeners without a specific setting,
3179 * does not set all listeners */
3180 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
3181 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
3182 }
3183
3184 tcp_buffer = ch_realloc( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
3185 /* append */
3186 tcp_buffer[ tcp_buffer_num ] = val;
3187
3188 tcp_buffer_num++;
3189 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
3190
3191 return rc;
3192 }
3193
3194 static int
config_tcp_buffer(ConfigArgs * c)3195 config_tcp_buffer( ConfigArgs *c )
3196 {
3197 if ( c->op == SLAP_CONFIG_EMIT ) {
3198 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
3199 return 1;
3200 }
3201 value_add( &c->rvalue_vals, tcp_buffer );
3202 value_add( &c->rvalue_nvals, tcp_buffer );
3203
3204 } else if ( c->op == LDAP_MOD_DELETE ) {
3205 if ( !c->line ) {
3206 tcp_buffer_delete( tcp_buffer );
3207 ber_bvarray_free( tcp_buffer );
3208 tcp_buffer = NULL;
3209 tcp_buffer_num = 0;
3210
3211 } else {
3212 int rc = 0;
3213 int size = -1, rw = 0;
3214 Listener *l = NULL;
3215
3216 struct berval val = BER_BVNULL;
3217
3218 int i;
3219
3220 if ( tcp_buffer_num == 0 ) {
3221 return 1;
3222 }
3223
3224 /* parse */
3225 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
3226 if ( rc != 0 ) {
3227 return 1;
3228 }
3229
3230 /* unparse for later use */
3231 rc = tcp_buffer_unparse( size, rw, l, &val );
3232 if ( rc != LDAP_SUCCESS ) {
3233 return 1;
3234 }
3235
3236 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
3237 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
3238 break;
3239 }
3240 }
3241
3242 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
3243 /* not found */
3244 rc = 1;
3245 goto done;
3246 }
3247
3248 tcp_buffer_delete_one( &tcp_buffer[ i ] );
3249 ber_memfree( tcp_buffer[ i ].bv_val );
3250 for ( ; i < tcp_buffer_num; i++ ) {
3251 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
3252 }
3253 tcp_buffer_num--;
3254
3255 done:;
3256 if ( !BER_BVISNULL( &val ) ) {
3257 SLAP_FREE( val.bv_val );
3258 }
3259
3260 }
3261
3262 } else {
3263 int rc;
3264
3265 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
3266 if ( rc ) {
3267 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3268 "<%s> unable to add value #%d",
3269 c->argv[0], tcp_buffer_num );
3270 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
3271 c->log, c->cr_msg );
3272 return 1;
3273 }
3274 }
3275
3276 return 0;
3277 }
3278 #endif /* LDAP_TCP_BUFFER */
3279
3280 static int
config_suffix(ConfigArgs * c)3281 config_suffix(ConfigArgs *c)
3282 {
3283 Backend *tbe;
3284 struct berval pdn, ndn;
3285 char *notallowed = NULL;
3286
3287 if ( c->be == frontendDB ) {
3288 notallowed = "frontend";
3289
3290 } else if ( SLAP_MONITOR(c->be) ) {
3291 notallowed = "monitor";
3292
3293 } else if ( SLAP_CONFIG(c->be) ) {
3294 notallowed = "config";
3295 }
3296
3297 if ( notallowed != NULL ) {
3298 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3299
3300 switch ( c->op ) {
3301 case LDAP_MOD_ADD:
3302 case LDAP_MOD_DELETE:
3303 case LDAP_MOD_REPLACE:
3304 case LDAP_MOD_INCREMENT:
3305 case SLAP_CONFIG_ADD:
3306 if ( !BER_BVISNULL( &c->value_dn ) ) {
3307 snprintf( buf, sizeof( buf ), "<%s> ",
3308 c->value_dn.bv_val );
3309 }
3310
3311 Debug(LDAP_DEBUG_ANY,
3312 "%s: suffix %snot allowed in %s database.\n",
3313 c->log, buf, notallowed );
3314 break;
3315
3316 case SLAP_CONFIG_EMIT:
3317 /* don't complain when emitting... */
3318 break;
3319
3320 default:
3321 /* FIXME: don't know what values may be valid;
3322 * please remove assertion, or add legal values
3323 * to either block */
3324 assert( 0 );
3325 break;
3326 }
3327
3328 return 1;
3329 }
3330
3331 if (c->op == SLAP_CONFIG_EMIT) {
3332 if ( c->be->be_suffix == NULL
3333 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3334 {
3335 return 1;
3336 } else {
3337 value_add( &c->rvalue_vals, c->be->be_suffix );
3338 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3339 return 0;
3340 }
3341 } else if ( c->op == LDAP_MOD_DELETE ) {
3342 if ( c->valx < 0 ) {
3343 ber_bvarray_free( c->be->be_suffix );
3344 ber_bvarray_free( c->be->be_nsuffix );
3345 c->be->be_suffix = NULL;
3346 c->be->be_nsuffix = NULL;
3347 } else {
3348 int i = c->valx;
3349 ch_free( c->be->be_suffix[i].bv_val );
3350 ch_free( c->be->be_nsuffix[i].bv_val );
3351 do {
3352 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3353 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3354 i++;
3355 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3356 }
3357 return 0;
3358 }
3359
3360 #ifdef SLAPD_MONITOR_DN
3361 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3362 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3363 c->argv[0] );
3364 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3365 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3366 return(1);
3367 }
3368 #endif
3369
3370 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3371 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3372 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3373 c->argv[0], c->be->bd_info->bi_type );
3374 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3375 c->log, c->cr_msg );
3376 return(1);
3377 }
3378
3379 pdn = c->value_dn;
3380 ndn = c->value_ndn;
3381
3382 if (SLAP_DBHIDDEN( c->be ))
3383 tbe = NULL;
3384 else
3385 tbe = select_backend(&ndn, 0);
3386 if(tbe == c->be) {
3387 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3388 c->log );
3389 free(pdn.bv_val);
3390 free(ndn.bv_val);
3391 return 1;
3392 } else if(tbe) {
3393 BackendDB *b2 = tbe;
3394
3395 /* Does tbe precede be? */
3396 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3397
3398 if ( b2 ) {
3399 char *type = tbe->bd_info->bi_type;
3400
3401 if ( overlay_is_over( tbe ) ) {
3402 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3403 type = oi->oi_orig->bi_type;
3404 }
3405
3406 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3407 "already served by a preceding %s database",
3408 c->argv[0], pdn.bv_val, type );
3409 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3410 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3411 free(pdn.bv_val);
3412 free(ndn.bv_val);
3413 return(1);
3414 }
3415 }
3416 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3417 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3418 "base provided \"%s\" (assuming okay)\n",
3419 c->log, default_search_base.bv_val );
3420 }
3421 ber_bvarray_add(&c->be->be_suffix, &pdn);
3422 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3423 return(0);
3424 }
3425
3426 static int
config_rootdn(ConfigArgs * c)3427 config_rootdn(ConfigArgs *c) {
3428 if (c->op == SLAP_CONFIG_EMIT) {
3429 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3430 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3431 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3432 return 0;
3433 } else {
3434 return 1;
3435 }
3436 } else if ( c->op == LDAP_MOD_DELETE ) {
3437 ch_free( c->be->be_rootdn.bv_val );
3438 ch_free( c->be->be_rootndn.bv_val );
3439 BER_BVZERO( &c->be->be_rootdn );
3440 BER_BVZERO( &c->be->be_rootndn );
3441 return 0;
3442 }
3443 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3444 ch_free( c->be->be_rootdn.bv_val );
3445 ch_free( c->be->be_rootndn.bv_val );
3446 }
3447 c->be->be_rootdn = c->value_dn;
3448 c->be->be_rootndn = c->value_ndn;
3449 return(0);
3450 }
3451
3452 static int
config_rootpw(ConfigArgs * c)3453 config_rootpw(ConfigArgs *c) {
3454 Backend *tbe;
3455
3456 if (c->op == SLAP_CONFIG_EMIT) {
3457 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3458 /* don't copy, because "rootpw" is marked
3459 * as CFG_BERVAL */
3460 c->value_bv = c->be->be_rootpw;
3461 return 0;
3462 }
3463 return 1;
3464 } else if ( c->op == LDAP_MOD_DELETE ) {
3465 ch_free( c->be->be_rootpw.bv_val );
3466 BER_BVZERO( &c->be->be_rootpw );
3467 return 0;
3468 }
3469
3470 tbe = select_backend(&c->be->be_rootndn, 0);
3471 if(tbe != c->be && !SLAP_DBHIDDEN( c->be )) {
3472 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3473 c->argv[0] );
3474 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3475 c->log, c->cr_msg );
3476 return(1);
3477 }
3478 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3479 ch_free( c->be->be_rootpw.bv_val );
3480 c->be->be_rootpw = c->value_bv;
3481 return(0);
3482 }
3483
3484 static int
config_restrict(ConfigArgs * c)3485 config_restrict(ConfigArgs *c) {
3486 slap_mask_t restrictops = 0;
3487 int i;
3488 slap_verbmasks restrictable_ops[] = {
3489 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3490 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3491 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3492 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3493 { BER_BVC("modrdn"), 0 },
3494 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3495 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3496 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3497 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3498 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3499 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3500 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3501 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3502 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3503 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3504 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3505 { BER_BVNULL, 0 }
3506 };
3507
3508 if (c->op == SLAP_CONFIG_EMIT) {
3509 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3510 &c->rvalue_vals );
3511 } else if ( c->op == LDAP_MOD_DELETE ) {
3512 if ( !c->line ) {
3513 c->be->be_restrictops = 0;
3514 } else {
3515 i = verb_to_mask( c->line, restrictable_ops );
3516 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3517 }
3518 return 0;
3519 }
3520 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3521 if ( i ) {
3522 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3523 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3524 c->log, c->cr_msg, c->argv[i]);
3525 return(1);
3526 }
3527 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3528 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3529 c->be->be_restrictops |= restrictops;
3530 return(0);
3531 }
3532
3533 static int
config_allows(ConfigArgs * c)3534 config_allows(ConfigArgs *c) {
3535 slap_mask_t allows = 0;
3536 int i;
3537 slap_verbmasks allowable_ops[] = {
3538 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3539 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3540 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3541 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3542 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3543 { BER_BVNULL, 0 }
3544 };
3545 if (c->op == SLAP_CONFIG_EMIT) {
3546 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3547 } else if ( c->op == LDAP_MOD_DELETE ) {
3548 if ( !c->line ) {
3549 global_allows = 0;
3550 } else {
3551 i = verb_to_mask( c->line, allowable_ops );
3552 global_allows &= ~allowable_ops[i].mask;
3553 }
3554 return 0;
3555 }
3556 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3557 if ( i ) {
3558 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3559 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3560 c->log, c->cr_msg, c->argv[i]);
3561 return(1);
3562 }
3563 global_allows |= allows;
3564 return(0);
3565 }
3566
3567 static int
config_disallows(ConfigArgs * c)3568 config_disallows(ConfigArgs *c) {
3569 slap_mask_t disallows = 0;
3570 int i;
3571 slap_verbmasks disallowable_ops[] = {
3572 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3573 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3574 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3575 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3576 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3577 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3578 { BER_BVNULL, 0 }
3579 };
3580 if (c->op == SLAP_CONFIG_EMIT) {
3581 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3582 } else if ( c->op == LDAP_MOD_DELETE ) {
3583 if ( !c->line ) {
3584 global_disallows = 0;
3585 } else {
3586 i = verb_to_mask( c->line, disallowable_ops );
3587 global_disallows &= ~disallowable_ops[i].mask;
3588 }
3589 return 0;
3590 }
3591 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3592 if ( i ) {
3593 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3594 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3595 c->log, c->cr_msg, c->argv[i]);
3596 return(1);
3597 }
3598 global_disallows |= disallows;
3599 return(0);
3600 }
3601
3602 static int
config_requires(ConfigArgs * c)3603 config_requires(ConfigArgs *c) {
3604 slap_mask_t requires = frontendDB->be_requires;
3605 int i, argc = c->argc;
3606 char **argv = c->argv;
3607
3608 slap_verbmasks requires_ops[] = {
3609 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3610 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3611 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3612 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3613 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3614 { BER_BVNULL, 0 }
3615 };
3616 if (c->op == SLAP_CONFIG_EMIT) {
3617 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3618 } else if ( c->op == LDAP_MOD_DELETE ) {
3619 if ( !c->line ) {
3620 c->be->be_requires = 0;
3621 } else {
3622 i = verb_to_mask( c->line, requires_ops );
3623 c->be->be_requires &= ~requires_ops[i].mask;
3624 }
3625 return 0;
3626 }
3627 /* "none" can only be first, to wipe out default/global values */
3628 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3629 argv++;
3630 argc--;
3631 requires = 0;
3632 }
3633 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3634 if ( i ) {
3635 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3636 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3637 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3638 c->log, c->cr_msg );
3639 } else {
3640 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3641 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3642 c->log, c->cr_msg, c->argv[i]);
3643 }
3644 return(1);
3645 }
3646 c->be->be_requires = requires;
3647 return(0);
3648 }
3649
3650 static int
config_extra_attrs(ConfigArgs * c)3651 config_extra_attrs(ConfigArgs *c)
3652 {
3653 assert( c->be != NULL );
3654
3655 if ( c->op == SLAP_CONFIG_EMIT ) {
3656 int i;
3657
3658 if ( c->be->be_extra_anlist == NULL ) {
3659 return 1;
3660 }
3661
3662 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3663 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3664 }
3665
3666 } else if ( c->op == LDAP_MOD_DELETE ) {
3667 if ( c->be->be_extra_anlist == NULL ) {
3668 return 1;
3669 }
3670
3671 if ( c->valx < 0 ) {
3672 anlist_free( c->be->be_extra_anlist, 1, NULL );
3673 c->be->be_extra_anlist = NULL;
3674
3675 } else {
3676 int i;
3677
3678 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3679 ;
3680
3681 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3682 return 1;
3683 }
3684
3685 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3686
3687 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3688 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3689 }
3690 }
3691
3692 } else {
3693 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3694 if ( c->be->be_extra_anlist == NULL ) {
3695 return 1;
3696 }
3697 }
3698
3699 return 0;
3700 }
3701
3702 static slap_verbmasks *loglevel_ops;
3703
3704 static int
loglevel_init(void)3705 loglevel_init( void )
3706 {
3707 slap_verbmasks lo[] = {
3708 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3709 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3710 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3711 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3712 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3713 { BER_BVC("BER"), LDAP_DEBUG_BER },
3714 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3715 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3716 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3717 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3718 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3719 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3720 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3721 #if 0 /* no longer used (nor supported) */
3722 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3723 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3724 #endif
3725 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3726 { BER_BVC("None"), LDAP_DEBUG_NONE },
3727 { BER_BVNULL, 0 }
3728 };
3729
3730 return slap_verbmasks_init( &loglevel_ops, lo );
3731 }
3732
3733 static void
loglevel_destroy(void)3734 loglevel_destroy( void )
3735 {
3736 if ( loglevel_ops ) {
3737 (void)slap_verbmasks_destroy( loglevel_ops );
3738 }
3739 loglevel_ops = NULL;
3740 }
3741
3742 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3743
3744 int
slap_loglevel_register(slap_mask_t m,struct berval * s)3745 slap_loglevel_register( slap_mask_t m, struct berval *s )
3746 {
3747 int rc;
3748
3749 if ( loglevel_ops == NULL ) {
3750 loglevel_init();
3751 }
3752
3753 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3754
3755 if ( rc != 0 ) {
3756 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3757 m, s->bv_val );
3758 }
3759
3760 return rc;
3761 }
3762
3763 int
slap_loglevel_get(struct berval * s,int * l)3764 slap_loglevel_get( struct berval *s, int *l )
3765 {
3766 int rc;
3767 slap_mask_t m, i;
3768
3769 if ( loglevel_ops == NULL ) {
3770 loglevel_init();
3771 }
3772
3773 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3774 m |= loglevel_ops[ i ].mask;
3775 }
3776
3777 for ( i = 1; m & i; i <<= 1 )
3778 ;
3779
3780 if ( i == 0 ) {
3781 return -1;
3782 }
3783
3784 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3785
3786 if ( rc != 0 ) {
3787 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3788 i, s->bv_val );
3789
3790 } else {
3791 *l = i;
3792 slap_check_unknown_level( s->bv_val, i );
3793 }
3794
3795 return rc;
3796 }
3797
3798 int
str2loglevel(const char * s,int * l)3799 str2loglevel( const char *s, int *l )
3800 {
3801 int i;
3802
3803 if ( loglevel_ops == NULL ) {
3804 loglevel_init();
3805 }
3806
3807 i = verb_to_mask( s, loglevel_ops );
3808
3809 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3810 return -1;
3811 }
3812
3813 *l = loglevel_ops[ i ].mask;
3814
3815 return 0;
3816 }
3817
3818 const char *
loglevel2str(int l)3819 loglevel2str( int l )
3820 {
3821 struct berval bv = BER_BVNULL;
3822
3823 loglevel2bv( l, &bv );
3824
3825 return bv.bv_val;
3826 }
3827
3828 int
loglevel2bv(int l,struct berval * bv)3829 loglevel2bv( int l, struct berval *bv )
3830 {
3831 if ( loglevel_ops == NULL ) {
3832 loglevel_init();
3833 }
3834
3835 BER_BVZERO( bv );
3836
3837 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3838 }
3839
3840 int
loglevel2bvarray(int l,BerVarray * bva)3841 loglevel2bvarray( int l, BerVarray *bva )
3842 {
3843 if ( loglevel_ops == NULL ) {
3844 loglevel_init();
3845 }
3846
3847 if ( l == 0 ) {
3848 struct berval bv = BER_BVC("0");
3849 return value_add_one( bva, &bv );
3850 }
3851
3852 return mask_to_verbs( loglevel_ops, l, bva );
3853 }
3854
3855 int
loglevel_print(FILE * out)3856 loglevel_print( FILE *out )
3857 {
3858 int i;
3859
3860 if ( loglevel_ops == NULL ) {
3861 loglevel_init();
3862 }
3863
3864 fprintf( out, "Installed log subsystems:\n\n" );
3865 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3866 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3867 fprintf( out,
3868 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3869 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3870 loglevel_ops[ i ].word.bv_val, mask, mask );
3871 }
3872
3873 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3874 "by specific code\n\n" );
3875
3876 return 0;
3877 }
3878
3879 static int config_syslog;
3880
3881 static int
config_loglevel(ConfigArgs * c)3882 config_loglevel(ConfigArgs *c) {
3883 int i;
3884
3885 if ( loglevel_ops == NULL ) {
3886 loglevel_init();
3887 }
3888
3889 if (c->op == SLAP_CONFIG_EMIT) {
3890 /* Get default or commandline slapd setting */
3891 if ( ldap_syslog && !config_syslog )
3892 config_syslog = ldap_syslog;
3893 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3894
3895 } else if ( c->op == LDAP_MOD_DELETE ) {
3896 if ( !c->line ) {
3897 config_syslog = 0;
3898 } else {
3899 i = verb_to_mask( c->line, loglevel_ops );
3900 config_syslog &= ~loglevel_ops[i].mask;
3901 }
3902 if ( slapMode & SLAP_SERVER_MODE ) {
3903 ldap_syslog = config_syslog;
3904 }
3905 return 0;
3906 }
3907
3908 for( i=1; i < c->argc; i++ ) {
3909 int level;
3910
3911 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3912 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3913 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3914 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3915 c->log, c->cr_msg, c->argv[i]);
3916 return( 1 );
3917 }
3918 } else {
3919 if ( str2loglevel( c->argv[i], &level ) ) {
3920 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3921 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3922 c->log, c->cr_msg, c->argv[i]);
3923 return( 1 );
3924 }
3925 }
3926 /* Explicitly setting a zero clears all the levels */
3927 if ( level )
3928 config_syslog |= level;
3929 else
3930 config_syslog = 0;
3931 }
3932 if ( slapMode & SLAP_SERVER_MODE ) {
3933 ldap_syslog = config_syslog;
3934 }
3935 return(0);
3936 }
3937
3938 static int
config_referral(ConfigArgs * c)3939 config_referral(ConfigArgs *c) {
3940 struct berval val;
3941 if (c->op == SLAP_CONFIG_EMIT) {
3942 if ( default_referral ) {
3943 value_add( &c->rvalue_vals, default_referral );
3944 return 0;
3945 } else {
3946 return 1;
3947 }
3948 } else if ( c->op == LDAP_MOD_DELETE ) {
3949 if ( c->valx < 0 ) {
3950 ber_bvarray_free( default_referral );
3951 default_referral = NULL;
3952 } else {
3953 int i = c->valx;
3954 ch_free( default_referral[i].bv_val );
3955 for (; default_referral[i].bv_val; i++ )
3956 default_referral[i] = default_referral[i+1];
3957 }
3958 return 0;
3959 }
3960 if(validate_global_referral(c->argv[1])) {
3961 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3962 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3963 c->log, c->cr_msg, c->argv[1]);
3964 return(1);
3965 }
3966
3967 ber_str2bv(c->argv[1], 0, 0, &val);
3968 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3969 return(0);
3970 }
3971
3972 static struct {
3973 struct berval key;
3974 int off;
3975 } sec_keys[] = {
3976 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3977 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3978 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3979 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3980 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3981 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3982 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3983 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3984 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3985 { BER_BVNULL, 0 }
3986 };
3987
3988 static int
config_security(ConfigArgs * c)3989 config_security(ConfigArgs *c) {
3990 slap_ssf_set_t *set = &c->be->be_ssf_set;
3991 char *next;
3992 int i, j;
3993 if (c->op == SLAP_CONFIG_EMIT) {
3994 char numbuf[32];
3995 struct berval bv;
3996 slap_ssf_t *tgt;
3997 int rc = 1;
3998
3999 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
4000 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
4001 if ( *tgt ) {
4002 rc = 0;
4003 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
4004 if ( bv.bv_len >= sizeof( numbuf ) ) {
4005 ber_bvarray_free_x( c->rvalue_vals, NULL );
4006 c->rvalue_vals = NULL;
4007 rc = 1;
4008 break;
4009 }
4010 bv.bv_len += sec_keys[i].key.bv_len;
4011 bv.bv_val = ch_malloc( bv.bv_len + 1);
4012 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
4013 strcpy( next, numbuf );
4014 ber_bvarray_add( &c->rvalue_vals, &bv );
4015 }
4016 }
4017 return rc;
4018 }
4019 for(i = 1; i < c->argc; i++) {
4020 slap_ssf_t *tgt = NULL;
4021 char *src = NULL;
4022 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
4023 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
4024 sec_keys[j].key.bv_len)) {
4025 src = c->argv[i] + sec_keys[j].key.bv_len;
4026 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
4027 break;
4028 }
4029 }
4030 if ( !tgt ) {
4031 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
4032 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
4033 c->log, c->cr_msg, c->argv[i]);
4034 return(1);
4035 }
4036
4037 if ( lutil_atou( tgt, src ) != 0 ) {
4038 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
4039 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
4040 c->log, c->cr_msg, c->argv[i]);
4041 return(1);
4042 }
4043 }
4044 return(0);
4045 }
4046
4047 char *
anlist_unparse(AttributeName * an,char * ptr,ber_len_t buflen)4048 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
4049 int comma = 0;
4050 char *start = ptr;
4051
4052 for (; !BER_BVISNULL( &an->an_name ); an++) {
4053 /* if buflen == 0, assume the buffer size has been
4054 * already checked otherwise */
4055 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
4056 if ( comma ) *ptr++ = ',';
4057 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
4058 comma = 1;
4059 }
4060 return ptr;
4061 }
4062
4063 int
slap_bv_x_ordered_unparse(BerVarray in,BerVarray * out)4064 slap_bv_x_ordered_unparse( BerVarray in, BerVarray *out )
4065 {
4066 int i;
4067 BerVarray bva = NULL;
4068 char ibuf[32], *ptr;
4069 struct berval idx;
4070
4071 assert( in != NULL );
4072
4073 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ )
4074 /* count'em */ ;
4075
4076 if ( i == 0 ) {
4077 return 1;
4078 }
4079
4080 idx.bv_val = ibuf;
4081
4082 bva = ch_malloc( ( i + 1 ) * sizeof(struct berval) );
4083 BER_BVZERO( &bva[ 0 ] );
4084
4085 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
4086 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
4087 if ( idx.bv_len >= sizeof( ibuf ) ) {
4088 ber_bvarray_free( bva );
4089 return 1;
4090 }
4091
4092 bva[i].bv_len = idx.bv_len + in[i].bv_len;
4093 bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
4094 ptr = lutil_strcopy( bva[i].bv_val, ibuf );
4095 ptr = lutil_strcopy( ptr, in[i].bv_val );
4096 *ptr = '\0';
4097 BER_BVZERO( &bva[ i + 1 ] );
4098 }
4099
4100 *out = bva;
4101 return 0;
4102 }
4103
4104 static int
config_updatedn(ConfigArgs * c)4105 config_updatedn(ConfigArgs *c) {
4106 if (c->op == SLAP_CONFIG_EMIT) {
4107 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
4108 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
4109 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
4110 return 0;
4111 }
4112 return 1;
4113 } else if ( c->op == LDAP_MOD_DELETE ) {
4114 ch_free( c->be->be_update_ndn.bv_val );
4115 BER_BVZERO( &c->be->be_update_ndn );
4116 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
4117 return 0;
4118 }
4119 if(SLAP_SHADOW(c->be)) {
4120 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
4121 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
4122 c->log, c->cr_msg );
4123 return(1);
4124 }
4125
4126 ber_memfree_x( c->value_dn.bv_val, NULL );
4127 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
4128 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
4129 }
4130 c->be->be_update_ndn = c->value_ndn;
4131 BER_BVZERO( &c->value_dn );
4132 BER_BVZERO( &c->value_ndn );
4133
4134 return config_slurp_shadow( c );
4135 }
4136
4137 int
config_shadow(ConfigArgs * c,slap_mask_t flag)4138 config_shadow( ConfigArgs *c, slap_mask_t flag )
4139 {
4140 char *notallowed = NULL;
4141
4142 if ( c->be == frontendDB ) {
4143 notallowed = "frontend";
4144
4145 } else if ( SLAP_MONITOR(c->be) ) {
4146 notallowed = "monitor";
4147 }
4148
4149 if ( notallowed != NULL ) {
4150 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed );
4151 return 1;
4152 }
4153
4154 if ( SLAP_SHADOW(c->be) ) {
4155 /* if already shadow, only check consistency */
4156 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
4157 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
4158 c->log, flag );
4159 return 1;
4160 }
4161
4162 } else {
4163 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
4164 if ( !SLAP_MULTIPROVIDER( c->be ))
4165 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
4166 }
4167
4168 return 0;
4169 }
4170
4171 static int
config_updateref(ConfigArgs * c)4172 config_updateref(ConfigArgs *c) {
4173 struct berval val;
4174 if (c->op == SLAP_CONFIG_EMIT) {
4175 if ( c->be->be_update_refs ) {
4176 value_add( &c->rvalue_vals, c->be->be_update_refs );
4177 return 0;
4178 } else {
4179 return 1;
4180 }
4181 } else if ( c->op == LDAP_MOD_DELETE ) {
4182 if ( c->valx < 0 ) {
4183 ber_bvarray_free( c->be->be_update_refs );
4184 c->be->be_update_refs = NULL;
4185 } else {
4186 int i = c->valx;
4187 ch_free( c->be->be_update_refs[i].bv_val );
4188 for (; c->be->be_update_refs[i].bv_val; i++)
4189 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
4190 }
4191 return 0;
4192 }
4193 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
4194 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
4195 c->argv[0] );
4196 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
4197 c->log, c->cr_msg );
4198 return(1);
4199 }
4200
4201 if(validate_global_referral(c->argv[1])) {
4202 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
4203 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
4204 c->log, c->cr_msg, c->argv[1]);
4205 return(1);
4206 }
4207 ber_str2bv(c->argv[1], 0, 0, &val);
4208 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
4209 return(0);
4210 }
4211
4212 static int
config_obsolete(ConfigArgs * c)4213 config_obsolete(ConfigArgs *c) {
4214 if (c->op == SLAP_CONFIG_EMIT)
4215 return 1;
4216
4217 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
4218 c->argv[0] );
4219 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg );
4220 return(0);
4221 }
4222
4223 static int
config_include(ConfigArgs * c)4224 config_include(ConfigArgs *c) {
4225 int savelineno = c->lineno;
4226 int rc;
4227 ConfigFile *cf;
4228 ConfigFile *cfsave = cfn;
4229 ConfigFile *cf2 = NULL;
4230
4231 /* Leftover from RE23. No dynamic config for include files */
4232 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
4233 return 1;
4234
4235 cf = ch_calloc( 1, sizeof(ConfigFile));
4236 if ( cfn->c_kids ) {
4237 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
4238 cf2->c_sibs = cf;
4239 } else {
4240 cfn->c_kids = cf;
4241 }
4242 cfn = cf;
4243 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
4244 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
4245 c->lineno = savelineno - 1;
4246 cfn = cfsave;
4247 if ( rc ) {
4248 if ( cf2 ) cf2->c_sibs = NULL;
4249 else cfn->c_kids = NULL;
4250 ch_free( cf->c_file.bv_val );
4251 ch_free( cf );
4252 } else {
4253 c->ca_private = cf;
4254 }
4255 return(rc);
4256 }
4257
4258 #ifdef HAVE_TLS
4259 static int
config_tls_cleanup(ConfigArgs * c)4260 config_tls_cleanup(ConfigArgs *c) {
4261 int rc = 0;
4262
4263 if ( slap_tls_ld ) {
4264 int opt = 1;
4265
4266 ldap_pvt_tls_ctx_free( slap_tls_ctx );
4267 slap_tls_ctx = NULL;
4268
4269 /* Force new ctx to be created */
4270 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
4271 if( rc == 0 ) {
4272 /* The ctx's refcount is bumped up here */
4273 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
4274 /* This is a no-op if it's already loaded */
4275 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
4276 } else {
4277 if ( rc == LDAP_NOT_SUPPORTED )
4278 rc = LDAP_UNWILLING_TO_PERFORM;
4279 else
4280 rc = LDAP_OTHER;
4281 }
4282 }
4283 return rc;
4284 }
4285
4286 static int
config_tls_option(ConfigArgs * c)4287 config_tls_option(ConfigArgs *c) {
4288 int flag, rc;
4289 int berval = 0;
4290 LDAP *ld = slap_tls_ld;
4291 switch(c->type) {
4292 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
4293 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
4294 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
4295 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
4296 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
4297 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
4298 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
4299 case CFG_TLS_ECNAME: flag = LDAP_OPT_X_TLS_ECNAME; break;
4300 #ifdef HAVE_GNUTLS
4301 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
4302 #endif
4303 case CFG_TLS_CACERT: flag = LDAP_OPT_X_TLS_CACERT; berval = 1; break;
4304 case CFG_TLS_CERT: flag = LDAP_OPT_X_TLS_CERT; berval = 1; break;
4305 case CFG_TLS_KEY: flag = LDAP_OPT_X_TLS_KEY; berval = 1; break;
4306 default: Debug(LDAP_DEBUG_ANY, "%s: "
4307 "unknown tls_option <0x%x>\n",
4308 c->log, c->type );
4309 return 1;
4310 }
4311 if (c->op == SLAP_CONFIG_EMIT) {
4312 return ldap_pvt_tls_get_option( ld, flag, berval ? (void *)&c->value_bv : (void *)&c->value_string );
4313 } else if ( c->op == LDAP_MOD_DELETE ) {
4314 config_push_cleanup( c, config_tls_cleanup );
4315 return ldap_pvt_tls_set_option( ld, flag, NULL );
4316 }
4317 if ( !berval ) ch_free(c->value_string);
4318 config_push_cleanup( c, config_tls_cleanup );
4319 rc = ldap_pvt_tls_set_option(ld, flag, berval ? (void *)&c->value_bv : (void *)c->argv[1]);
4320 if ( berval ) ch_free(c->value_bv.bv_val);
4321 return rc;
4322 }
4323
4324 /* FIXME: this ought to be provided by libldap */
4325 static int
config_tls_config(ConfigArgs * c)4326 config_tls_config(ConfigArgs *c) {
4327 int i, flag;
4328 switch(c->type) {
4329 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
4330 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
4331 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
4332 default:
4333 Debug(LDAP_DEBUG_ANY, "%s: "
4334 "unknown tls_option <0x%x>\n",
4335 c->log, c->type );
4336 return 1;
4337 }
4338 if (c->op == SLAP_CONFIG_EMIT) {
4339 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
4340 } else if ( c->op == LDAP_MOD_DELETE ) {
4341 int i = 0;
4342 config_push_cleanup( c, config_tls_cleanup );
4343 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4344 }
4345 ch_free( c->value_string );
4346 config_push_cleanup( c, config_tls_cleanup );
4347 if ( isdigit( (unsigned char)c->argv[1][0] ) && c->type != CFG_TLS_PROTOCOL_MIN ) {
4348 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4349 Debug(LDAP_DEBUG_ANY, "%s: "
4350 "unable to parse %s \"%s\"\n",
4351 c->log, c->argv[0], c->argv[1] );
4352 return 1;
4353 }
4354 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4355 } else {
4356 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4357 }
4358 }
4359 #endif
4360
4361 static CfEntryInfo *
config_find_base(CfEntryInfo * root,struct berval * dn,CfEntryInfo ** last)4362 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4363 {
4364 struct berval cdn;
4365 char *c;
4366
4367 if ( !root ) {
4368 *last = NULL;
4369 return NULL;
4370 }
4371
4372 if ( dn_match( &root->ce_entry->e_nname, dn ))
4373 return root;
4374
4375 c = dn->bv_val+dn->bv_len;
4376 for (;*c != ',';c--);
4377
4378 while(root) {
4379 *last = root;
4380 for (--c;c>dn->bv_val && *c != ',';c--);
4381 cdn.bv_val = c;
4382 if ( *c == ',' )
4383 cdn.bv_val++;
4384 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4385
4386 root = root->ce_kids;
4387
4388 for (;root;root=root->ce_sibs) {
4389 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4390 if ( cdn.bv_val == dn->bv_val ) {
4391 return root;
4392 }
4393 break;
4394 }
4395 }
4396 }
4397 return root;
4398 }
4399
4400 typedef struct setup_cookie {
4401 CfBackInfo *cfb;
4402 ConfigArgs *ca;
4403 Entry *frontend;
4404 Entry *config;
4405 int got_frontend;
4406 int got_config;
4407 } setup_cookie;
4408
4409 static int
config_ldif_resp(Operation * op,SlapReply * rs)4410 config_ldif_resp( Operation *op, SlapReply *rs )
4411 {
4412 if ( rs->sr_type == REP_SEARCH ) {
4413 setup_cookie *sc = op->o_callback->sc_private;
4414 struct berval pdn;
4415
4416 sc->cfb->cb_got_ldif = 1;
4417 /* Does the frontend exist? */
4418 if ( !sc->got_frontend ) {
4419 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4420 "olcDatabase", STRLENOF( "olcDatabase" )))
4421 {
4422 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4423 STRLENOF( "olcDatabase" ), "={-1}frontend",
4424 STRLENOF( "={-1}frontend" )))
4425 {
4426 struct berval rdn;
4427 int i = op->o_noop;
4428 sc->ca->be = frontendDB;
4429 sc->ca->bi = frontendDB->bd_info;
4430 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4431 rdn.bv_val = sc->ca->log;
4432 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4433 "%s=" SLAP_X_ORDERED_FMT "%s",
4434 cfAd_database->ad_cname.bv_val, -1,
4435 sc->ca->bi->bi_type);
4436 op->o_noop = 1;
4437 sc->frontend = config_build_entry( op, rs,
4438 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4439 sc->ca->be->be_cf_ocs );
4440 op->o_noop = i;
4441 sc->got_frontend++;
4442 } else {
4443 sc->got_frontend++;
4444 goto ok;
4445 }
4446 }
4447 }
4448
4449 dnParent( &rs->sr_entry->e_nname, &pdn );
4450
4451 /* Does the configDB exist? */
4452 if ( sc->got_frontend && !sc->got_config &&
4453 !strncmp( rs->sr_entry->e_nname.bv_val,
4454 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4455 dn_match( &config_rdn, &pdn ) )
4456 {
4457 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4458 STRLENOF( "olcDatabase" ), "={0}config",
4459 STRLENOF( "={0}config" )))
4460 {
4461 struct berval rdn;
4462 int i = op->o_noop;
4463 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4464 sc->ca->bi = sc->ca->be->bd_info;
4465 rdn.bv_val = sc->ca->log;
4466 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4467 "%s=" SLAP_X_ORDERED_FMT "%s",
4468 cfAd_database->ad_cname.bv_val, 0,
4469 sc->ca->bi->bi_type);
4470 op->o_noop = 1;
4471 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4472 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4473 op->o_noop = i;
4474 }
4475 sc->got_config++;
4476 }
4477
4478 ok:
4479 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4480 if ( rs->sr_err != LDAP_SUCCESS ) {
4481 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4482 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg );
4483 }
4484 }
4485 return rs->sr_err;
4486 }
4487
4488 /* Configure and read the underlying back-ldif store */
4489 static int
config_setup_ldif(BackendDB * be,const char * dir,int readit)4490 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4491 CfBackInfo *cfb = be->be_private;
4492 ConfigArgs c = {0};
4493 ConfigTable *ct;
4494 char *argv[3];
4495 int rc = 0;
4496 setup_cookie sc;
4497 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4498 Connection conn = {0};
4499 OperationBuffer opbuf;
4500 Operation *op;
4501 SlapReply rs = {REP_RESULT};
4502 Filter filter = { LDAP_FILTER_PRESENT };
4503 struct berval filterstr = BER_BVC("(objectclass=*)");
4504 struct stat st;
4505
4506 /* Is the config directory available? */
4507 if ( stat( dir, &st ) < 0 ) {
4508 /* No, so don't bother using the backing store.
4509 * All changes will be in-memory only.
4510 */
4511 return 0;
4512 }
4513
4514 cfb->cb_db.bd_info = backend_info( "ldif" );
4515 if ( !cfb->cb_db.bd_info )
4516 return 0; /* FIXME: eventually this will be a fatal error */
4517
4518 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4519 return 1;
4520
4521 cfb->cb_db.be_suffix = be->be_suffix;
4522 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4523
4524 /* The suffix is always "cn=config". The underlying DB's rootdn
4525 * is always the same as the suffix.
4526 */
4527 cfb->cb_db.be_rootdn = be->be_suffix[0];
4528 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4529
4530 ber_str2bv( dir, 0, 1, &cfdir );
4531
4532 c.be = &cfb->cb_db;
4533 c.fname = "slapd";
4534 c.argc = 2;
4535 argv[0] = "directory";
4536 argv[1] = (char *)dir;
4537 argv[2] = NULL;
4538 c.argv = argv;
4539 c.reply.err = 0;
4540 c.reply.msg[0] = 0;
4541 c.table = Cft_Database;
4542
4543 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4544 if ( !ct )
4545 return 1;
4546
4547 if ( config_add_vals( ct, &c ))
4548 return 1;
4549
4550 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4551 return 1;
4552
4553 if ( readit ) {
4554 void *thrctx = ldap_pvt_thread_pool_context();
4555 int prev_DN_strict;
4556
4557 connection_fake_init( &conn, &opbuf, thrctx );
4558 op = &opbuf.ob_op;
4559
4560 filter.f_desc = slap_schema.si_ad_objectClass;
4561
4562 op->o_tag = LDAP_REQ_SEARCH;
4563
4564 op->ors_filter = &filter;
4565 op->ors_filterstr = filterstr;
4566 op->ors_scope = LDAP_SCOPE_SUBTREE;
4567
4568 op->o_dn = c.be->be_rootdn;
4569 op->o_ndn = c.be->be_rootndn;
4570
4571 op->o_req_dn = be->be_suffix[0];
4572 op->o_req_ndn = be->be_nsuffix[0];
4573
4574 op->ors_tlimit = SLAP_NO_LIMIT;
4575 op->ors_slimit = SLAP_NO_LIMIT;
4576
4577 op->ors_attrs = slap_anlist_all_attributes;
4578 op->ors_attrsonly = 0;
4579
4580 op->o_callback = &cb;
4581 sc.cfb = cfb;
4582 sc.ca = &c;
4583 cb.sc_private = ≻
4584 sc.got_frontend = 0;
4585 sc.got_config = 0;
4586 sc.frontend = NULL;
4587 sc.config = NULL;
4588
4589 op->o_bd = &cfb->cb_db;
4590
4591 /* Allow unknown attrs in DNs */
4592 prev_DN_strict = slap_DN_strict;
4593 slap_DN_strict = 0;
4594
4595 rc = op->o_bd->be_search( op, &rs );
4596
4597 /* Restore normal DN validation */
4598 slap_DN_strict = prev_DN_strict;
4599
4600 op->o_tag = LDAP_REQ_ADD;
4601 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4602 rs_reinit( &rs, REP_RESULT );
4603 op->ora_e = sc.frontend;
4604 rc = op->o_bd->be_add( op, &rs );
4605 }
4606 if ( rc == LDAP_SUCCESS && sc.config ) {
4607 rs_reinit( &rs, REP_RESULT );
4608 op->ora_e = sc.config;
4609 rc = op->o_bd->be_add( op, &rs );
4610 }
4611 ldap_pvt_thread_pool_context_reset( thrctx );
4612 } else {
4613 /* ITS#9016 Check directory is empty (except perhaps hidden files) */
4614 DIR *dir_of_path;
4615 struct dirent *entry;
4616
4617 dir_of_path = opendir( dir );
4618 while ( (entry = readdir( dir_of_path )) != NULL ) {
4619 if ( entry->d_name[0] != '.' ) {
4620 Debug( LDAP_DEBUG_ANY, "config_setup_ldif: "
4621 "expected directory %s to be empty!\n",
4622 dir );
4623 rc = LDAP_ALREADY_EXISTS;
4624 break;
4625 }
4626 }
4627 closedir( dir_of_path );
4628 }
4629
4630 /* ITS#4194 - only use if it's present, or we're converting. */
4631 if ( !readit || rc == LDAP_SUCCESS )
4632 cfb->cb_use_ldif = 1;
4633
4634 return rc;
4635 }
4636
4637 static int
CfOc_cmp(const void * c1,const void * c2)4638 CfOc_cmp( const void *c1, const void *c2 ) {
4639 const ConfigOCs *co1 = c1;
4640 const ConfigOCs *co2 = c2;
4641
4642 return ber_bvcmp( co1->co_name, co2->co_name );
4643 }
4644
4645 int
config_register_schema(ConfigTable * ct,ConfigOCs * ocs)4646 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4647 int i;
4648
4649 i = init_config_attrs( ct );
4650 if ( i ) return i;
4651
4652 /* set up the objectclasses */
4653 i = init_config_ocs( ocs );
4654 if ( i ) return i;
4655
4656 for (i=0; ocs[i].co_def; i++) {
4657 if ( ocs[i].co_oc ) {
4658 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4659 if ( !ocs[i].co_table )
4660 ocs[i].co_table = ct;
4661 ldap_avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, ldap_avl_dup_error );
4662 }
4663 }
4664 return 0;
4665 }
4666
4667 int
read_config(const char * fname,const char * dir)4668 read_config(const char *fname, const char *dir) {
4669 BackendDB *be;
4670 CfBackInfo *cfb;
4671 const char *cfdir, *cfname;
4672 int rc;
4673
4674 /* Setup the config backend */
4675 be = backend_db_init( "config", NULL, 0, NULL );
4676 if ( !be )
4677 return 1;
4678
4679 cfb = be->be_private;
4680 be->be_dfltaccess = ACL_NONE;
4681
4682 /* If no .conf, or a dir was specified, setup the dir */
4683 if ( !fname || dir ) {
4684 if ( dir ) {
4685 /* If explicitly given, check for existence */
4686 struct stat st;
4687
4688 if ( stat( dir, &st ) < 0 ) {
4689 int saved_errno = errno;
4690 Debug( LDAP_DEBUG_ANY,
4691 "invalid config directory %s, error %d\n",
4692 dir, saved_errno );
4693 return 1;
4694 }
4695 cfdir = dir;
4696 } else {
4697 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4698 }
4699 /* if fname is defaulted, try reading .d */
4700 rc = config_setup_ldif( be, cfdir, !fname );
4701
4702 if ( rc ) {
4703 /* It may be OK if the base object doesn't exist yet. */
4704 if ( rc != LDAP_NO_SUCH_OBJECT )
4705 return 1;
4706 /* ITS#4194: But if dir was specified and no fname,
4707 * then we were supposed to read the dir. Unless we're
4708 * trying to slapadd the dir...
4709 */
4710 if ( dir && !fname ) {
4711 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4712 return 1;
4713 /* Assume it's slapadd with a config dir, let it continue */
4714 rc = 0;
4715 cfb->cb_got_ldif = 1;
4716 cfb->cb_use_ldif = 1;
4717 goto done;
4718 }
4719 }
4720
4721 /* If we read the config from back-ldif, nothing to do here */
4722 if ( cfb->cb_got_ldif ) {
4723 rc = 0;
4724 goto done;
4725 }
4726 }
4727
4728 if ( fname )
4729 cfname = fname;
4730 else
4731 cfname = SLAPD_DEFAULT_CONFIGFILE;
4732
4733 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4734
4735 if ( rc == 0 )
4736 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4737
4738 done:
4739 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4740 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4741 &frontendDB->be_schemadn );
4742 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4743 if ( rc != LDAP_SUCCESS ) {
4744 Debug(LDAP_DEBUG_ANY, "read_config: "
4745 "unable to normalize default schema DN \"%s\"\n",
4746 frontendDB->be_schemadn.bv_val );
4747 /* must not happen */
4748 assert( 0 );
4749 }
4750 }
4751 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4752 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4753 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4754 "Check slapd -h arguments.\n" );
4755 rc = LDAP_OTHER;
4756 }
4757 }
4758 return rc;
4759 }
4760
4761 static int
config_back_bind(Operation * op,SlapReply * rs)4762 config_back_bind( Operation *op, SlapReply *rs )
4763 {
4764 if ( be_isroot_pw( op ) ) {
4765 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4766 /* frontend sends result */
4767 return LDAP_SUCCESS;
4768 }
4769
4770 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4771 send_ldap_result( op, rs );
4772
4773 return rs->sr_err;
4774 }
4775
4776 static int
config_send(Operation * op,SlapReply * rs,CfEntryInfo * ce,int depth)4777 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4778 {
4779 int rc = 0;
4780
4781 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4782 {
4783 rs->sr_attrs = op->ors_attrs;
4784 rs->sr_entry = ce->ce_entry;
4785 rs->sr_flags = 0;
4786 rc = send_search_entry( op, rs );
4787 if ( rc != LDAP_SUCCESS ) {
4788 return rc;
4789 }
4790 }
4791 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4792 if ( ce->ce_kids ) {
4793 rc = config_send( op, rs, ce->ce_kids, 1 );
4794 if ( rc ) return rc;
4795 }
4796 if ( depth ) {
4797 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4798 rc = config_send( op, rs, ce, 0 );
4799 if ( rc ) break;
4800 }
4801 }
4802 }
4803 return rc;
4804 }
4805
4806 static ConfigTable *
config_find_table(ConfigOCs ** colst,int nocs,AttributeDescription * ad,ConfigArgs * ca)4807 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4808 ConfigArgs *ca )
4809 {
4810 int i, j;
4811 if (ad->ad_flags & SLAP_DESC_BINARY)
4812 ad = ad->ad_type->sat_ad;
4813
4814 for (j=0; j<nocs; j++) {
4815 for (i=0; colst[j]->co_table[i].name; i++)
4816 if ( colst[j]->co_table[i].ad == ad ) {
4817 ca->table = colst[j]->co_type;
4818 return &colst[j]->co_table[i];
4819 }
4820 }
4821 return NULL;
4822 }
4823
4824 /* Sort the attributes of the entry according to the order defined
4825 * in the objectclass, with required attributes occurring before
4826 * allowed attributes. For any attributes with sequencing dependencies
4827 * (e.g., rootDN must be defined after suffix) the objectclass must
4828 * list the attributes in the desired sequence.
4829 */
4830 static void
sort_attrs(Entry * e,ConfigOCs ** colst,int nocs)4831 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4832 {
4833 Attribute *a, *head = NULL, *tail = NULL, **prev;
4834 int i, j;
4835
4836 for (i=0; i<nocs; i++) {
4837 if ( colst[i]->co_oc->soc_required ) {
4838 AttributeType **at = colst[i]->co_oc->soc_required;
4839 for (j=0; at[j]; j++) {
4840 for (a=e->e_attrs, prev=&e->e_attrs; a;
4841 prev = &(*prev)->a_next, a=a->a_next) {
4842 if ( a->a_desc == at[j]->sat_ad ) {
4843 *prev = a->a_next;
4844 if (!head) {
4845 head = a;
4846 tail = a;
4847 } else {
4848 tail->a_next = a;
4849 tail = a;
4850 }
4851 break;
4852 }
4853 }
4854 }
4855 }
4856 if ( colst[i]->co_oc->soc_allowed ) {
4857 AttributeType **at = colst[i]->co_oc->soc_allowed;
4858 for (j=0; at[j]; j++) {
4859 for (a=e->e_attrs, prev=&e->e_attrs; a;
4860 prev = &(*prev)->a_next, a=a->a_next) {
4861 if ( a->a_desc == at[j]->sat_ad ) {
4862 *prev = a->a_next;
4863 if (!head) {
4864 head = a;
4865 tail = a;
4866 } else {
4867 tail->a_next = a;
4868 tail = a;
4869 }
4870 break;
4871 }
4872 }
4873 }
4874 }
4875 }
4876 if ( tail ) {
4877 tail->a_next = e->e_attrs;
4878 e->e_attrs = head;
4879 }
4880 }
4881
4882 static int
check_vals(ConfigTable * ct,ConfigArgs * ca,void * ptr,int isAttr)4883 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4884 {
4885 Attribute *a = NULL;
4886 AttributeDescription *ad;
4887 BerVarray vals;
4888
4889 int i, rc = 0;
4890
4891 if ( isAttr ) {
4892 a = ptr;
4893 ad = a->a_desc;
4894 vals = a->a_vals;
4895 } else {
4896 Modifications *ml = ptr;
4897 ad = ml->sml_desc;
4898 vals = ml->sml_values;
4899 }
4900
4901 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4902 rc = ordered_value_sort( a, 1 );
4903 if ( rc ) {
4904 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4905 ad->ad_cname.bv_val );
4906 return rc;
4907 }
4908 }
4909 for ( i=0; vals[i].bv_val; i++ ) {
4910 ca->line = vals[i].bv_val;
4911 ca->linelen = vals[i].bv_len;
4912 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4913 ca->line[0] == '{' ) {
4914 char *idx = strchr( ca->line, '}' );
4915 if ( idx ) {
4916 ca->linelen -= (idx+1) - ca->line;
4917 ca->line = idx+1;
4918 }
4919 }
4920 rc = config_parse_vals( ct, ca, i );
4921 if ( rc ) {
4922 break;
4923 }
4924 }
4925 return rc;
4926 }
4927
4928 static int
config_rename_attr(SlapReply * rs,Entry * e,struct berval * rdn,Attribute ** at)4929 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4930 Attribute **at )
4931 {
4932 struct berval rtype, rval;
4933 Attribute *a;
4934 AttributeDescription *ad = NULL;
4935
4936 dnRdn( &e->e_name, rdn );
4937 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4938 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4939 rtype.bv_val = rdn->bv_val;
4940 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4941
4942 /* Find attr */
4943 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4944 a = attr_find( e->e_attrs, ad );
4945 if (!a ) return LDAP_NAMING_VIOLATION;
4946 *at = a;
4947
4948 return 0;
4949 }
4950
4951 static void
config_rename_kids(CfEntryInfo * ce)4952 config_rename_kids( CfEntryInfo *ce )
4953 {
4954 CfEntryInfo *ce2;
4955 struct berval rdn, nrdn;
4956
4957 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4958 struct berval newdn, newndn;
4959 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4960 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4961 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4962 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4963 free( ce2->ce_entry->e_name.bv_val );
4964 free( ce2->ce_entry->e_nname.bv_val );
4965 ce2->ce_entry->e_name = newdn;
4966 ce2->ce_entry->e_nname = newndn;
4967 config_rename_kids( ce2 );
4968 }
4969 }
4970
4971 static int
config_rename_one(Operation * op,SlapReply * rs,Entry * e,CfEntryInfo * parent,Attribute * a,struct berval * newrdn,struct berval * nnewrdn,int use_ldif)4972 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4973 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4974 struct berval *nnewrdn, int use_ldif )
4975 {
4976 int cnt, rc = 0;
4977 struct berval odn, ondn;
4978 const char *text = "";
4979 LDAPRDN rDN;
4980
4981 odn = e->e_name;
4982 ondn = e->e_nname;
4983 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4984 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4985
4986 /* Replace attr */
4987 rc = ldap_bv2rdn( &e->e_name, &rDN, (char **)&text, LDAP_DN_FORMAT_LDAP );
4988 if ( rc ) {
4989 return rc;
4990 }
4991 for ( cnt = 0; rDN[cnt]; cnt++ ) {
4992 AttributeDescription *ad = NULL;
4993 LDAPAVA *ava = rDN[cnt];
4994
4995 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
4996 if ( rc ) {
4997 break;
4998 }
4999
5000 if ( ad != a->a_desc ) continue;
5001
5002 free( a->a_vals[0].bv_val );
5003 ber_dupbv( &a->a_vals[0], &ava->la_value );
5004 if ( a->a_nvals != a->a_vals ) {
5005 free( a->a_nvals[0].bv_val );
5006 rc = attr_normalize_one( ad, &ava->la_value, &a->a_nvals[0], NULL );
5007 if ( rc ) {
5008 break;
5009 }
5010 }
5011
5012 /* attributes with X-ORDERED 'SIBLINGS' are single-valued, we're done */
5013 break;
5014 }
5015 /* the attribute must be present in rDN */
5016 assert( rDN[cnt] );
5017 ldap_rdnfree( rDN );
5018 if ( rc ) {
5019 return rc;
5020 }
5021
5022 if ( use_ldif ) {
5023 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
5024 BackendDB *be = op->o_bd;
5025 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5026 struct berval dn, ndn, xdn, xndn;
5027
5028 op->o_bd = &cfb->cb_db;
5029
5030 /* Save current rootdn; use the underlying DB's rootdn */
5031 dn = op->o_dn;
5032 ndn = op->o_ndn;
5033 xdn = op->o_req_dn;
5034 xndn = op->o_req_ndn;
5035 op->o_dn = op->o_bd->be_rootdn;
5036 op->o_ndn = op->o_bd->be_rootndn;
5037 op->o_req_dn = odn;
5038 op->o_req_ndn = ondn;
5039
5040 scp = op->o_callback;
5041 op->o_callback = ≻
5042 op->orr_newrdn = *newrdn;
5043 op->orr_nnewrdn = *nnewrdn;
5044 op->orr_newSup = NULL;
5045 op->orr_nnewSup = NULL;
5046 op->orr_deleteoldrdn = 1;
5047 op->orr_modlist = NULL;
5048 slap_modrdn2mods( op, rs );
5049 slap_mods_opattrs( op, &op->orr_modlist, 1 );
5050 rc = op->o_bd->be_modrdn( op, rs );
5051 slap_mods_free( op->orr_modlist, 1 );
5052
5053 op->o_bd = be;
5054 op->o_callback = scp;
5055 op->o_dn = dn;
5056 op->o_ndn = ndn;
5057 op->o_req_dn = xdn;
5058 op->o_req_ndn = xndn;
5059 }
5060 free( odn.bv_val );
5061 free( ondn.bv_val );
5062 if ( e->e_private )
5063 config_rename_kids( e->e_private );
5064 return rc;
5065 }
5066
5067 static int
config_renumber_one(Operation * op,SlapReply * rs,CfEntryInfo * parent,Entry * e,int idx,int tailindex,int use_ldif)5068 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5069 Entry *e, int idx, int tailindex, int use_ldif )
5070 {
5071 struct berval ival, newrdn, nnewrdn;
5072 struct berval rdn;
5073 Attribute *a;
5074 char ibuf[32], *ptr1, *ptr2 = NULL;
5075 int rc = 0;
5076
5077 rc = config_rename_attr( rs, e, &rdn, &a );
5078 if ( rc ) return rc;
5079
5080 ival.bv_val = ibuf;
5081 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
5082 if ( ival.bv_len >= sizeof( ibuf ) ) {
5083 return LDAP_NAMING_VIOLATION;
5084 }
5085
5086 newrdn.bv_len = rdn.bv_len + ival.bv_len;
5087 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
5088
5089 if ( tailindex ) {
5090 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
5091 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
5092 } else {
5093 int xlen;
5094 ptr2 = ber_bvchr( &rdn, '}' );
5095 if ( ptr2 ) {
5096 ptr2++;
5097 } else {
5098 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
5099 }
5100 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
5101 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
5102 a->a_desc->ad_cname.bv_len );
5103 *ptr1++ = '=';
5104 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
5105 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
5106 *ptr1 = '\0';
5107 }
5108
5109 /* Do the equivalent of ModRDN */
5110 /* Replace DN / NDN */
5111 newrdn.bv_len = ptr1 - newrdn.bv_val;
5112 rc = rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
5113 if ( rc ) {
5114 free( newrdn.bv_val );
5115 return LDAP_NAMING_VIOLATION;
5116 }
5117 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
5118
5119 free( nnewrdn.bv_val );
5120 free( newrdn.bv_val );
5121 return rc;
5122 }
5123
5124 static int
check_name_index(CfEntryInfo * parent,ConfigType ce_type,Entry * e,SlapReply * rs,int * renum,int * ibase)5125 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
5126 SlapReply *rs, int *renum, int *ibase )
5127 {
5128 CfEntryInfo *ce;
5129 int index = -1, gotindex = 0, nsibs, rc = 0;
5130 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
5131 char *ptr1, *ptr2 = NULL;
5132 struct berval rdn;
5133
5134 if ( renum ) *renum = 0;
5135
5136 /* These entries don't get indexed/renumbered */
5137 if ( ce_type == Cft_Global ) return 0;
5138 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
5139
5140 if ( ce_type == Cft_Module )
5141 tailindex = 1;
5142
5143 /* See if the rdn has an index already */
5144 dnRdn( &e->e_name, &rdn );
5145 if ( ce_type == Cft_Database ) {
5146 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
5147 "frontend", STRLENOF("frontend") ))
5148 isfrontend = 1;
5149 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
5150 "config", STRLENOF("config") ))
5151 isconfig = 1;
5152 }
5153 ptr1 = ber_bvchr( &e->e_name, '{' );
5154 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
5155 char *next;
5156 ptr2 = strchr( ptr1, '}' );
5157 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
5158 return LDAP_NAMING_VIOLATION;
5159 if ( ptr2-ptr1 == 1)
5160 return LDAP_NAMING_VIOLATION;
5161 gotindex = 1;
5162 index = strtol( ptr1 + 1, &next, 10 );
5163 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
5164 return LDAP_NAMING_VIOLATION;
5165 }
5166 if ( index < 0 ) {
5167 /* Special case, we allow -1 for the frontendDB */
5168 if ( index != -1 || !isfrontend )
5169 return LDAP_NAMING_VIOLATION;
5170 }
5171 if ( isconfig && index != 0 ){
5172 return LDAP_NAMING_VIOLATION;
5173 }
5174 }
5175
5176 /* count related kids.
5177 * For entries of type Cft_Misc, only count siblings with same RDN type
5178 */
5179 if ( ce_type == Cft_Misc ) {
5180 rdn.bv_val = e->e_nname.bv_val;
5181 ptr1 = strchr( rdn.bv_val, '=' );
5182 assert( ptr1 != NULL );
5183
5184 rdn.bv_len = ptr1 - rdn.bv_val;
5185
5186 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
5187 struct berval rdn2;
5188 if ( ce->ce_type != ce_type )
5189 continue;
5190
5191 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
5192
5193 ptr1 = strchr( rdn2.bv_val, '=' );
5194 assert( ptr1 != NULL );
5195
5196 rdn2.bv_len = ptr1 - rdn2.bv_val;
5197 if ( bvmatch( &rdn, &rdn2 ))
5198 nsibs++;
5199 }
5200 } else {
5201 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
5202 if ( ce->ce_type == ce_type ) nsibs++;
5203 }
5204 }
5205
5206 /* account for -1 frontend */
5207 if ( ce_type == Cft_Database )
5208 nsibs--;
5209
5210 if ( index != nsibs || isfrontend ) {
5211 if ( gotindex ) {
5212 if ( index < nsibs ) {
5213 if ( tailindex ) return LDAP_NAMING_VIOLATION;
5214 /* Siblings need to be renumbered */
5215 if ( index != -1 || !isfrontend )
5216 renumber = 1;
5217 }
5218 }
5219 /* config DB is always "0" */
5220 if ( isconfig && index == -1 ) {
5221 index = 0;
5222 }
5223 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
5224 index = nsibs;
5225 }
5226
5227 /* just make index = nsibs */
5228 if ( !renumber ) {
5229 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
5230 }
5231 }
5232 if ( ibase ) *ibase = index;
5233 if ( renum ) *renum = renumber;
5234 return rc;
5235 }
5236
5237 /* Insert all superior classes of the given class */
5238 static int
count_oc(ObjectClass * oc,ConfigOCs *** copp,int * nocs)5239 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
5240 {
5241 ConfigOCs co, *cop;
5242 ObjectClass **sups;
5243
5244 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
5245 if ( count_oc( *sups, copp, nocs ) ) {
5246 return -1;
5247 }
5248 }
5249
5250 co.co_name = &oc->soc_cname;
5251 cop = ldap_avl_find( CfOcTree, &co, CfOc_cmp );
5252 if ( cop ) {
5253 int i;
5254
5255 /* check for duplicates */
5256 for ( i = 0; i < *nocs; i++ ) {
5257 if ( *copp && (*copp)[i] == cop ) {
5258 break;
5259 }
5260 }
5261
5262 if ( i == *nocs ) {
5263 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
5264 if ( tmp == NULL ) {
5265 return -1;
5266 }
5267 *copp = tmp;
5268 (*copp)[*nocs] = cop;
5269 (*nocs)++;
5270 }
5271 }
5272
5273 return 0;
5274 }
5275
5276 /* Find all superior classes of the given objectclasses,
5277 * return list in order of most-subordinate first.
5278 *
5279 * Special / auxiliary / Cft_Misc classes always take precedence.
5280 */
5281 static ConfigOCs **
count_ocs(Attribute * oc_at,int * nocs)5282 count_ocs( Attribute *oc_at, int *nocs )
5283 {
5284 int i, j, misc = -1;
5285 ConfigOCs **colst = NULL;
5286
5287 *nocs = 0;
5288
5289 for ( i = oc_at->a_numvals; i--; ) {
5290 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
5291
5292 assert( oc != NULL );
5293 if ( count_oc( oc, &colst, nocs ) ) {
5294 ch_free( colst );
5295 return NULL;
5296 }
5297 }
5298
5299 /* invert order */
5300 i = 0;
5301 j = *nocs - 1;
5302 while ( i < j ) {
5303 ConfigOCs *tmp = colst[i];
5304 colst[i] = colst[j];
5305 colst[j] = tmp;
5306 if (tmp->co_type == Cft_Misc)
5307 misc = j;
5308 i++; j--;
5309 }
5310 /* Move misc class to front of list */
5311 if (misc > 0) {
5312 ConfigOCs *tmp = colst[misc];
5313 for (i=misc; i>0; i--)
5314 colst[i] = colst[i-1];
5315 colst[0] = tmp;
5316 }
5317
5318 return colst;
5319 }
5320
5321 static int
cfAddInclude(CfEntryInfo * p,Entry * e,ConfigArgs * ca)5322 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5323 {
5324 /* Leftover from RE23. Never parse this entry */
5325 return LDAP_COMPARE_TRUE;
5326 }
5327
5328 static int
cfAddSchema(CfEntryInfo * p,Entry * e,ConfigArgs * ca)5329 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5330 {
5331 ConfigFile *cfo;
5332
5333 /* This entry is hardcoded, don't re-parse it */
5334 if ( p->ce_type == Cft_Global ) {
5335 cfn = p->ce_private;
5336 ca->ca_private = cfn;
5337 return LDAP_COMPARE_TRUE;
5338 }
5339 if ( p->ce_type != Cft_Schema )
5340 return LDAP_CONSTRAINT_VIOLATION;
5341
5342 cfn = ch_calloc( 1, sizeof(ConfigFile) );
5343 ca->ca_private = cfn;
5344 cfo = p->ce_private;
5345 cfn->c_sibs = cfo->c_kids;
5346 cfo->c_kids = cfn;
5347 return LDAP_SUCCESS;
5348 }
5349
5350 static int
cfAddDatabase(CfEntryInfo * p,Entry * e,struct config_args_s * ca)5351 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5352 {
5353 if ( p->ce_type != Cft_Global ) {
5354 return LDAP_CONSTRAINT_VIOLATION;
5355 }
5356 /* config must be {0}, nothing else allowed */
5357 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
5358 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
5359 return LDAP_CONSTRAINT_VIOLATION;
5360 }
5361 ca->be = frontendDB; /* just to get past check_vals */
5362 return LDAP_SUCCESS;
5363 }
5364
5365 static int
cfAddBackend(CfEntryInfo * p,Entry * e,struct config_args_s * ca)5366 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5367 {
5368 if ( p->ce_type != Cft_Global ) {
5369 return LDAP_CONSTRAINT_VIOLATION;
5370 }
5371 return LDAP_SUCCESS;
5372 }
5373
5374 static int
cfAddModule(CfEntryInfo * p,Entry * e,struct config_args_s * ca)5375 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5376 {
5377 if ( p->ce_type != Cft_Global ) {
5378 return LDAP_CONSTRAINT_VIOLATION;
5379 }
5380 return LDAP_SUCCESS;
5381 }
5382
5383 static int
cfAddOverlay(CfEntryInfo * p,Entry * e,struct config_args_s * ca)5384 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5385 {
5386 if ( p->ce_type != Cft_Database ) {
5387 return LDAP_CONSTRAINT_VIOLATION;
5388 }
5389 ca->be = p->ce_be;
5390 return LDAP_SUCCESS;
5391 }
5392
5393 static void
schema_destroy_one(ConfigArgs * ca,ConfigOCs ** colst,int nocs,CfEntryInfo * p)5394 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5395 CfEntryInfo *p )
5396 {
5397 ConfigTable *ct;
5398 ConfigFile *cfo;
5399 AttributeDescription *ad;
5400 const char *text;
5401
5402 ca->valx = -1;
5403 ca->line = NULL;
5404 ca->argc = 1;
5405 if ( cfn->c_cr_head ) {
5406 struct berval bv = BER_BVC("olcDitContentRules");
5407 ad = NULL;
5408 slap_bv2ad( &bv, &ad, &text );
5409 ct = config_find_table( colst, nocs, ad, ca );
5410 config_del_vals( ct, ca );
5411 }
5412 if ( cfn->c_oc_head ) {
5413 struct berval bv = BER_BVC("olcObjectClasses");
5414 ad = NULL;
5415 slap_bv2ad( &bv, &ad, &text );
5416 ct = config_find_table( colst, nocs, ad, ca );
5417 config_del_vals( ct, ca );
5418 }
5419 if ( cfn->c_at_head ) {
5420 struct berval bv = BER_BVC("olcAttributeTypes");
5421 ad = NULL;
5422 slap_bv2ad( &bv, &ad, &text );
5423 ct = config_find_table( colst, nocs, ad, ca );
5424 config_del_vals( ct, ca );
5425 }
5426 if ( cfn->c_syn_head ) {
5427 struct berval bv = BER_BVC("olcLdapSyntaxes");
5428 ad = NULL;
5429 slap_bv2ad( &bv, &ad, &text );
5430 ct = config_find_table( colst, nocs, ad, ca );
5431 config_del_vals( ct, ca );
5432 }
5433 if ( cfn->c_om_head ) {
5434 struct berval bv = BER_BVC("olcObjectIdentifier");
5435 ad = NULL;
5436 slap_bv2ad( &bv, &ad, &text );
5437 ct = config_find_table( colst, nocs, ad, ca );
5438 config_del_vals( ct, ca );
5439 }
5440 cfo = p->ce_private;
5441 cfo->c_kids = cfn->c_sibs;
5442 ch_free( cfn );
5443 }
5444
5445 static int
config_add_oc(ConfigOCs ** cop,CfEntryInfo * last,Entry * e,ConfigArgs * ca)5446 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5447 {
5448 int rc = LDAP_CONSTRAINT_VIOLATION;
5449 ObjectClass **ocp;
5450
5451 if ( (*cop)->co_ldadd ) {
5452 rc = (*cop)->co_ldadd( last, e, ca );
5453 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5454 return rc;
5455 }
5456 }
5457
5458 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5459 ConfigOCs co = { 0 };
5460
5461 co.co_name = &(*ocp)->soc_cname;
5462 *cop = ldap_avl_find( CfOcTree, &co, CfOc_cmp );
5463 if ( *cop == NULL ) {
5464 return rc;
5465 }
5466
5467 rc = config_add_oc( cop, last, e, ca );
5468 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5469 return rc;
5470 }
5471 }
5472
5473 return rc;
5474 }
5475
5476 static BackendDB *configDB; /* only set by slapadd */
5477
5478 /* Parse an LDAP entry into config directives */
5479 static int
config_add_internal(CfBackInfo * cfb,Entry * e,ConfigArgs * ca,SlapReply * rs,int * renum,Operation * op)5480 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5481 int *renum, Operation *op )
5482 {
5483 CfEntryInfo *ce, *last = NULL;
5484 ConfigOCs co, *coptr, **colst;
5485 Attribute *a, *oc_at, *soc_at;
5486 int i, ibase = -1, nocs, rc = 0;
5487 struct berval pdn;
5488 ConfigTable *ct;
5489 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5490
5491 memset( ca, 0, sizeof(ConfigArgs));
5492
5493 /* Make sure parent exists and entry does not. But allow
5494 * Databases and Overlays to be inserted. Don't do any
5495 * auto-renumbering if manageDSAit control is present.
5496 */
5497 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5498 if ( ce ) {
5499 if ( ( op && op->o_managedsait ) ||
5500 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5501 ce->ce_type != Cft_Module ) )
5502 {
5503 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5504 "DN=\"%s\" already exists\n",
5505 log_prefix, e->e_name.bv_val );
5506 /* global schema ignores all writes */
5507 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5508 return LDAP_COMPARE_TRUE;
5509 return LDAP_ALREADY_EXISTS;
5510 }
5511 }
5512
5513 dnParent( &e->e_nname, &pdn );
5514
5515 /* If last is NULL, the new entry is the root/suffix entry,
5516 * otherwise last should be the parent.
5517 */
5518 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5519 if ( rs ) {
5520 rs->sr_matched = last->ce_entry->e_name.bv_val;
5521 }
5522 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5523 "DN=\"%s\" not child of DN=\"%s\"\n",
5524 log_prefix, e->e_name.bv_val,
5525 last->ce_entry->e_name.bv_val );
5526 return LDAP_NO_SUCH_OBJECT;
5527 }
5528
5529 if ( op ) {
5530 /* No parent, must be root. This will never happen... */
5531 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5532 return LDAP_NO_SUCH_OBJECT;
5533 }
5534
5535 if ( last && !access_allowed( op, last->ce_entry,
5536 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5537 {
5538 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5539 "DN=\"%s\" no write access to \"children\" of parent\n",
5540 log_prefix, e->e_name.bv_val );
5541 return LDAP_INSUFFICIENT_ACCESS;
5542 }
5543 }
5544
5545 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5546 if ( !oc_at ) {
5547 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5548 "DN=\"%s\" no objectClass\n",
5549 log_prefix, e->e_name.bv_val );
5550 return LDAP_OBJECT_CLASS_VIOLATION;
5551 }
5552
5553 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5554 if ( !soc_at ) {
5555 ObjectClass *soc = NULL;
5556 char textbuf[ SLAP_TEXT_BUFLEN ];
5557 const char *text = textbuf;
5558
5559 /* FIXME: check result */
5560 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5561 &text, textbuf, sizeof(textbuf), NULL );
5562 if ( rc != LDAP_SUCCESS ) {
5563 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5564 "DN=\"%s\" no structural objectClass (%s)\n",
5565 log_prefix, e->e_name.bv_val, text );
5566 return rc;
5567 }
5568 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5569 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5570 if ( soc_at == NULL ) {
5571 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5572 "DN=\"%s\" no structural objectClass; "
5573 "unable to merge computed class %s\n",
5574 log_prefix, e->e_name.bv_val,
5575 soc->soc_cname.bv_val );
5576 return LDAP_OBJECT_CLASS_VIOLATION;
5577 }
5578
5579 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5580 "DN=\"%s\" no structural objectClass; "
5581 "computed objectClass %s merged\n",
5582 log_prefix, e->e_name.bv_val,
5583 soc->soc_cname.bv_val );
5584 }
5585
5586 /* Fake the coordinates based on whether we're part of an
5587 * LDAP Add or if reading the config dir
5588 */
5589 if ( rs ) {
5590 ca->fname = "slapd";
5591 ca->lineno = 0;
5592 } else {
5593 ca->fname = cfdir.bv_val;
5594 ca->lineno = 1;
5595 }
5596 ca->ca_op = op;
5597
5598 {
5599 ObjectClass *soc = oc_bvfind( &soc_at->a_nvals[0] );
5600 if ( !soc ) {
5601 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5602 "DN=\"%s\" invalid structural objectClass %s\n",
5603 log_prefix, e->e_name.bv_val, soc_at->a_vals[0].bv_val );
5604 return LDAP_OBJECT_CLASS_VIOLATION;
5605 }
5606 co.co_name = &soc->soc_cname;
5607 }
5608 coptr = ldap_avl_find( CfOcTree, &co, CfOc_cmp );
5609 if ( coptr == NULL ) {
5610 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5611 "DN=\"%s\" no structural objectClass in configuration table\n",
5612 log_prefix, e->e_name.bv_val );
5613 return LDAP_OBJECT_CLASS_VIOLATION;
5614 }
5615
5616 /* Only the root can be Cft_Global, everything else must
5617 * have a parent. Only limited nesting arrangements are allowed.
5618 */
5619 rc = LDAP_CONSTRAINT_VIOLATION;
5620 if ( coptr->co_type == Cft_Global && !last ) {
5621 cfn = cfb->cb_config;
5622 ca->ca_private = cfn;
5623 ca->be = frontendDB; /* just to get past check_vals */
5624 rc = LDAP_SUCCESS;
5625 }
5626
5627 colst = count_ocs( oc_at, &nocs );
5628
5629 /* Check whether the Add is allowed by its parent, and do
5630 * any necessary arg setup
5631 */
5632 if ( last ) {
5633 rc = config_add_oc( &coptr, last, e, ca );
5634 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5635 for ( i = 0; i<nocs; i++ ) {
5636 /* Already checked these */
5637 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5638 continue;
5639 if ( colst[i]->co_ldadd &&
5640 ( rc = colst[i]->co_ldadd( last, e, ca ))
5641 != LDAP_CONSTRAINT_VIOLATION ) {
5642 coptr = colst[i];
5643 break;
5644 }
5645 }
5646 }
5647 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5648 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5649 "DN=\"%s\" no structural objectClass add function\n",
5650 log_prefix, e->e_name.bv_val );
5651 return LDAP_OBJECT_CLASS_VIOLATION;
5652 }
5653 }
5654
5655 /* Add the entry but don't parse it, we already have its contents */
5656 if ( rc == LDAP_COMPARE_TRUE ) {
5657 rc = LDAP_SUCCESS;
5658 goto ok;
5659 }
5660
5661 if ( rc != LDAP_SUCCESS )
5662 goto done_noop;
5663
5664 /* Parse all the values and check for simple syntax errors before
5665 * performing any set actions.
5666 *
5667 * If doing an LDAPadd, check for indexed names and any necessary
5668 * renaming/renumbering. Entries that don't need indexed names are
5669 * ignored. Entries that need an indexed name and arrive without one
5670 * are assigned to the end. Entries that arrive with an index may
5671 * cause the following entries to be renumbered/bumped down.
5672 *
5673 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5674 * don't allow Adding an entry with an index that's already in use.
5675 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5676 *
5677 * These entries can have auto-assigned indexes (appended to the end)
5678 * but only the other types support auto-renumbering of siblings.
5679 */
5680 {
5681 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5682 &ibase );
5683 if ( rc ) {
5684 goto done_noop;
5685 }
5686 if ( renum && *renum && coptr->co_type != Cft_Database &&
5687 coptr->co_type != Cft_Overlay )
5688 {
5689 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5690 "operation requires sibling renumbering" );
5691 rc = LDAP_UNWILLING_TO_PERFORM;
5692 goto done_noop;
5693 }
5694 }
5695
5696 init_config_argv( ca );
5697
5698 /* Make sure we process attrs in the required order */
5699 sort_attrs( e, colst, nocs );
5700
5701 for ( a = e->e_attrs; a; a = a->a_next ) {
5702 if ( a == oc_at ) continue;
5703 ct = config_find_table( colst, nocs, a->a_desc, ca );
5704 if ( !ct ) continue; /* user data? */
5705 rc = check_vals( ct, ca, a, 1 );
5706 if ( rc ) goto done_noop;
5707 }
5708
5709 /* Basic syntax checks are OK. Do the actual settings. */
5710 for ( a=e->e_attrs; a; a=a->a_next ) {
5711 if ( a == oc_at ) continue;
5712 ct = config_find_table( colst, nocs, a->a_desc, ca );
5713 if ( !ct ) continue; /* user data? */
5714 for (i=0; a->a_vals[i].bv_val; i++) {
5715 char *iptr = NULL;
5716 ca->valx = -1;
5717 ca->line = a->a_vals[i].bv_val;
5718 ca->linelen = a->a_vals[i].bv_len;
5719 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5720 ptr = strchr( ca->line, '}' );
5721 if ( ptr ) {
5722 iptr = strchr( ca->line, '{' );
5723 ca->linelen -= (ptr+1) - ca->line;
5724 ca->line = ptr+1;
5725 }
5726 }
5727 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5728 if ( iptr ) {
5729 ca->valx = strtol( iptr+1, NULL, 0 );
5730 }
5731 } else {
5732 ca->valx = i;
5733 }
5734 rc = config_parse_add( ct, ca, i );
5735 if ( rc ) {
5736 rc = LDAP_OTHER;
5737 goto done;
5738 }
5739 }
5740 }
5741 ok:
5742 /* Newly added databases and overlays need to be started up */
5743 if ( CONFIG_ONLINE_ADD( ca )) {
5744 if ( coptr->co_type == Cft_Database ) {
5745 rc = backend_startup_one( ca->be, &ca->reply );
5746
5747 } else if ( coptr->co_type == Cft_Backend ) {
5748 if ( ca->bi->bi_open ) {
5749 rc = ca->bi->bi_open( ca->bi );
5750 }
5751
5752 } else if ( coptr->co_type == Cft_Overlay ) {
5753 if ( ca->bi->bi_db_open ) {
5754 BackendInfo *bi_orig = ca->be->bd_info;
5755 ca->be->bd_info = ca->bi;
5756 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5757 ca->be->bd_info = bi_orig;
5758 }
5759 } else if ( ca->num_cleanups ) {
5760 rc = config_run_cleanup( ca );
5761 }
5762 if ( rc ) {
5763 if (ca->cr_msg[0] == '\0')
5764 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5765
5766 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5767 ca->log, ca->cr_msg, ca->argv[1] );
5768 rc = LDAP_OTHER;
5769 goto done;
5770 }
5771 }
5772
5773 ca->valx = ibase;
5774 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5775 ce->ce_parent = last;
5776 ce->ce_entry = entry_dup( e );
5777 ce->ce_entry->e_private = ce;
5778 ce->ce_type = coptr->co_type;
5779 ce->ce_be = ca->be;
5780 ce->ce_bi = ca->bi;
5781 ce->ce_private = ca->ca_private;
5782 ca->ca_entry = ce->ce_entry;
5783 if ( !last ) {
5784 cfb->cb_root = ce;
5785 } else if ( last->ce_kids ) {
5786 CfEntryInfo *c2, **cprev;
5787
5788 /* Advance to first of this type */
5789 cprev = &last->ce_kids;
5790 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5791 cprev = &c2->ce_sibs;
5792 c2 = c2->ce_sibs;
5793 }
5794 /* Account for the (-1) frontendDB entry */
5795 if ( ce->ce_type == Cft_Database ) {
5796 if ( ca->be == frontendDB )
5797 ibase = 0;
5798 else if ( ibase != -1 )
5799 ibase++;
5800 }
5801 /* Append */
5802 if ( ibase < 0 ) {
5803 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5804 cprev = &c2->ce_sibs;
5805 c2 = c2->ce_sibs;
5806 }
5807 } else {
5808 /* Insert */
5809 int i;
5810 for ( i=0; i<ibase; i++ ) {
5811 c2 = *cprev;
5812 cprev = &c2->ce_sibs;
5813 }
5814 }
5815 ce->ce_sibs = *cprev;
5816 *cprev = ce;
5817 } else {
5818 last->ce_kids = ce;
5819 }
5820
5821 done:
5822 if ( rc ) {
5823 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5824 if ( ca->be != frontendDB && ca->be != configDB )
5825 backend_destroy_one( ca->be, 1 );
5826 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5827 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5828 } else if ( coptr->co_type == Cft_Schema ) {
5829 schema_destroy_one( ca, colst, nocs, last );
5830 } else if ( ca->num_cleanups ) {
5831 config_run_cleanup( ca );
5832 }
5833 }
5834 done_noop:
5835
5836 ch_free( ca->argv );
5837 if ( colst ) ch_free( colst );
5838 return rc;
5839 }
5840
5841 #define BIGTMP 10000
5842 static int
config_rename_add(Operation * op,SlapReply * rs,CfEntryInfo * ce,int base,int rebase,int max,int use_ldif)5843 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5844 int base, int rebase, int max, int use_ldif )
5845 {
5846 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5847 ConfigType etype = ce->ce_type;
5848 int count = 0, rc = 0;
5849
5850 /* Reverse ce list */
5851 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5852 if (ce2->ce_type != etype) {
5853 cerem = ce2;
5854 break;
5855 }
5856 ce3 = ce2->ce_sibs;
5857 ce2->ce_sibs = cetmp;
5858 cetmp = ce2;
5859 count++;
5860 if ( max && count >= max ) {
5861 cerem = ce3;
5862 break;
5863 }
5864 }
5865
5866 /* Move original to a temp name until increments are done */
5867 if ( rebase ) {
5868 ce->ce_entry->e_private = NULL;
5869 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5870 base+BIGTMP, 0, use_ldif );
5871 ce->ce_entry->e_private = ce;
5872 }
5873 /* start incrementing */
5874 for (ce2=cetmp; ce2; ce2=ce3) {
5875 ce3 = ce2->ce_sibs;
5876 ce2->ce_sibs = cerem;
5877 cerem = ce2;
5878 if ( rc == 0 )
5879 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5880 count+base, 0, use_ldif );
5881 count--;
5882 }
5883 if ( rebase )
5884 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5885 base, 0, use_ldif );
5886 return rc;
5887 }
5888
5889 static int
config_rename_del(Operation * op,SlapReply * rs,CfEntryInfo * ce,CfEntryInfo * ce2,int old,int use_ldif)5890 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5891 CfEntryInfo *ce2, int old, int use_ldif )
5892 {
5893 int count = 0;
5894
5895 /* Renumber original to a temp value */
5896 ce->ce_entry->e_private = NULL;
5897 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5898 old+BIGTMP, 0, use_ldif );
5899 ce->ce_entry->e_private = ce;
5900
5901 /* start decrementing */
5902 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5903 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5904 count+old, 0, use_ldif );
5905 count++;
5906 }
5907 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5908 count+old, 0, use_ldif );
5909 }
5910
5911 /* Parse an LDAP entry into config directives, then store in underlying
5912 * database.
5913 */
5914 static int
config_back_add(Operation * op,SlapReply * rs)5915 config_back_add( Operation *op, SlapReply *rs )
5916 {
5917 CfBackInfo *cfb;
5918 int renumber, dopause = 1;
5919 ConfigArgs ca;
5920
5921 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5922 NULL, ACL_WADD, NULL )) {
5923 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5924 goto out;
5925 }
5926
5927 /*
5928 * Check for attribute ACL
5929 */
5930 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5931 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5932 rs->sr_text = "no write access to attribute";
5933 goto out;
5934 }
5935
5936 cfb = (CfBackInfo *)op->o_bd->be_private;
5937
5938 /* add opattrs for syncprov */
5939 {
5940 char textbuf[SLAP_TEXT_BUFLEN];
5941 size_t textlen = sizeof textbuf;
5942 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5943 &rs->sr_text, textbuf, sizeof( textbuf ) );
5944 if ( rs->sr_err != LDAP_SUCCESS )
5945 goto out;
5946 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5947 if ( rs->sr_err != LDAP_SUCCESS ) {
5948 Debug( LDAP_DEBUG_TRACE,
5949 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5950 "%s (%d)\n", rs->sr_text, rs->sr_err );
5951 goto out;
5952 }
5953 }
5954
5955 if ( op->o_abandon ) {
5956 rs->sr_err = SLAPD_ABANDON;
5957 goto out;
5958 }
5959 if ( slap_pause_server() < 0 )
5960 dopause = 0;
5961
5962 /* Strategy:
5963 * 1) check for existence of entry
5964 * 2) check for sibling renumbering
5965 * 3) perform internal add
5966 * 4) perform any necessary renumbering
5967 * 5) store entry in underlying database
5968 */
5969 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5970 if ( rs->sr_err != LDAP_SUCCESS ) {
5971 rs->sr_text = ca.cr_msg;
5972 goto out2;
5973 }
5974
5975 if ( renumber ) {
5976 CfEntryInfo *ce = ca.ca_entry->e_private;
5977 req_add_s addr = op->oq_add;
5978 op->o_tag = LDAP_REQ_MODRDN;
5979 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5980 op->o_tag = LDAP_REQ_ADD;
5981 op->oq_add = addr;
5982 if ( rs->sr_err != LDAP_SUCCESS ) {
5983 goto out2;
5984 }
5985 }
5986
5987 if ( cfb->cb_use_ldif ) {
5988 BackendDB *be = op->o_bd;
5989 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5990 struct berval dn, ndn;
5991
5992 op->o_bd = &cfb->cb_db;
5993
5994 /* Save current rootdn; use the underlying DB's rootdn */
5995 dn = op->o_dn;
5996 ndn = op->o_ndn;
5997 op->o_dn = op->o_bd->be_rootdn;
5998 op->o_ndn = op->o_bd->be_rootndn;
5999
6000 scp = op->o_callback;
6001 op->o_callback = ≻
6002 op->o_bd->be_add( op, rs );
6003 op->o_bd = be;
6004 op->o_callback = scp;
6005 op->o_dn = dn;
6006 op->o_ndn = ndn;
6007 }
6008
6009 out2:;
6010 if ( dopause )
6011 slap_unpause_server();
6012
6013 out:;
6014 { int repl = op->o_dont_replicate;
6015 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
6016 rs->sr_text = NULL; /* Set after config_add_internal */
6017 rs->sr_err = LDAP_SUCCESS;
6018 op->o_dont_replicate = 1;
6019 }
6020 send_ldap_result( op, rs );
6021 op->o_dont_replicate = repl;
6022 }
6023 slap_graduate_commit_csn( op );
6024 return rs->sr_err;
6025 }
6026
6027 typedef struct delrec {
6028 struct delrec *next;
6029 int nidx;
6030 int idx[1];
6031 } delrec;
6032
6033 static int
config_modify_add(ConfigTable * ct,ConfigArgs * ca,AttributeDescription * ad,int i)6034 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
6035 int i )
6036 {
6037 int rc;
6038
6039 ca->valx = -1;
6040 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
6041 ca->line[0] == '{' )
6042 {
6043 char *ptr = strchr( ca->line + 1, '}' );
6044 if ( ptr ) {
6045 char *next;
6046
6047 ca->valx = strtol( ca->line + 1, &next, 0 );
6048 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
6049 return LDAP_OTHER;
6050 }
6051 ca->linelen -= (ptr+1) - ca->line;
6052 ca->line = ptr+1;
6053 }
6054 }
6055 rc = config_parse_add( ct, ca, i );
6056 if ( rc ) {
6057 rc = LDAP_OTHER;
6058 }
6059 return rc;
6060 }
6061
6062 static int
config_modify_internal(CfEntryInfo * ce,Operation * op,SlapReply * rs,ConfigArgs * ca)6063 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
6064 ConfigArgs *ca )
6065 {
6066 int rc = LDAP_UNWILLING_TO_PERFORM;
6067 Modifications *ml;
6068 Entry *e = ce->ce_entry;
6069 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
6070 ConfigTable *ct;
6071 ConfigOCs **colst;
6072 int i, nocs;
6073 char *ptr;
6074 delrec *dels = NULL, *deltail = NULL;
6075
6076 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6077 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
6078
6079 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
6080 if (ml->sml_desc == slap_schema.si_ad_objectClass)
6081 return rc;
6082 }
6083
6084 colst = count_ocs( oc_at, &nocs );
6085
6086 /* make sure add/del flags are clear; should always be true */
6087 for ( s = save_attrs; s; s = s->a_next ) {
6088 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
6089 }
6090
6091 e->e_attrs = attrs_dup( e->e_attrs );
6092
6093 init_config_argv( ca );
6094 ca->be = ce->ce_be;
6095 ca->bi = ce->ce_bi;
6096 ca->ca_private = ce->ce_private;
6097 ca->ca_entry = e;
6098 ca->fname = "slapd";
6099 ca->ca_op = op;
6100 strcpy( ca->log, "back-config" );
6101
6102 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
6103 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
6104 switch (ml->sml_op) {
6105 case LDAP_MOD_DELETE:
6106 case LDAP_MOD_REPLACE:
6107 case SLAP_MOD_SOFTDEL:
6108 {
6109 BerVarray vals = NULL, nvals = NULL;
6110 int *idx = NULL;
6111 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
6112 rc = LDAP_OTHER;
6113 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
6114 ml->sml_desc->ad_cname.bv_val );
6115 goto out_noop;
6116 }
6117 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
6118 vals = ml->sml_values;
6119 nvals = ml->sml_nvalues;
6120 ml->sml_values = NULL;
6121 ml->sml_nvalues = NULL;
6122 }
6123 /* If we're deleting by values, remember the indexes of the
6124 * values we deleted.
6125 */
6126 if ( ct && ml->sml_values ) {
6127 delrec *d;
6128 i = ml->sml_numvals;
6129 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
6130 d->nidx = i;
6131 d->next = NULL;
6132 if ( dels ) {
6133 deltail->next = d;
6134 } else {
6135 dels = d;
6136 }
6137 deltail = d;
6138 idx = d->idx;
6139 }
6140 rc = modify_delete_vindex(e, &ml->sml_mod,
6141 get_permissiveModify(op),
6142 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
6143 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
6144 ml->sml_values = vals;
6145 ml->sml_nvalues = nvals;
6146 }
6147 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
6148 {
6149 rc = LDAP_SUCCESS;
6150 }
6151 /* FIXME: check rc before fallthru? */
6152 if ( !vals )
6153 break;
6154 }
6155 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
6156
6157 case SLAP_MOD_ADD_IF_NOT_PRESENT:
6158 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
6159 && attr_find( e->e_attrs, ml->sml_desc ) )
6160 {
6161 rc = LDAP_SUCCESS;
6162 break;
6163 }
6164
6165 case LDAP_MOD_ADD:
6166 case SLAP_MOD_SOFTADD: {
6167 int mop = ml->sml_op;
6168 int navals = -1;
6169 ml->sml_op = LDAP_MOD_ADD;
6170 if ( ct ) {
6171 if ( ct->arg_type & ARG_NO_INSERT ) {
6172 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
6173 if ( a ) {
6174 navals = a->a_numvals;
6175 }
6176 }
6177 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
6178 if ( ml->sml_values[i].bv_val[0] == '{' &&
6179 navals >= 0 )
6180 {
6181 char *next, *val = ml->sml_values[i].bv_val + 1;
6182 int j;
6183
6184 j = strtol( val, &next, 0 );
6185 if ( next == val || next[ 0 ] != '}' || j < navals ) {
6186 rc = LDAP_OTHER;
6187 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
6188 ml->sml_desc->ad_cname.bv_val );
6189 goto out_noop;
6190 }
6191 }
6192 rc = check_vals( ct, ca, ml, 0 );
6193 if ( rc ) goto out_noop;
6194 }
6195 }
6196 rc = modify_add_values(e, &ml->sml_mod,
6197 get_permissiveModify(op),
6198 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
6199
6200 /* If value already exists, show success here
6201 * and ignore this operation down below.
6202 */
6203 if ( mop == SLAP_MOD_SOFTADD ) {
6204 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
6205 rc = LDAP_SUCCESS;
6206 else
6207 mop = LDAP_MOD_ADD;
6208 }
6209 ml->sml_op = mop;
6210 break;
6211 }
6212
6213 break;
6214 case LDAP_MOD_INCREMENT: /* FIXME */
6215 break;
6216 default:
6217 break;
6218 }
6219 if(rc != LDAP_SUCCESS) break;
6220 }
6221
6222 if ( rc == LDAP_SUCCESS) {
6223 /* check that the entry still obeys the schema */
6224 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
6225 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
6226 }
6227 if ( rc ) goto out_noop;
6228
6229 /* Basic syntax checks are OK. Do the actual settings. */
6230 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6231 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
6232 if ( !ct ) continue;
6233
6234 s = attr_find( save_attrs, ml->sml_desc );
6235 a = attr_find( e->e_attrs, ml->sml_desc );
6236
6237 switch (ml->sml_op) {
6238 case LDAP_MOD_DELETE:
6239 case LDAP_MOD_REPLACE: {
6240 BerVarray vals = NULL, nvals = NULL;
6241 delrec *d = NULL;
6242
6243 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
6244 vals = ml->sml_values;
6245 nvals = ml->sml_nvalues;
6246 ml->sml_values = NULL;
6247 ml->sml_nvalues = NULL;
6248 }
6249
6250 if ( ml->sml_values )
6251 d = dels;
6252
6253 /* If we didn't delete the whole attribute */
6254 if ( ml->sml_values && a ) {
6255 struct berval *mvals;
6256 int j;
6257
6258 if ( ml->sml_nvalues )
6259 mvals = ml->sml_nvalues;
6260 else
6261 mvals = ml->sml_values;
6262
6263 /* use the indexes we saved up above */
6264 for (i=0; i < d->nidx; i++) {
6265 struct berval bv = *mvals++;
6266 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
6267 bv.bv_val[0] == '{' ) {
6268 ptr = strchr( bv.bv_val, '}' ) + 1;
6269 bv.bv_len -= ptr - bv.bv_val;
6270 bv.bv_val = ptr;
6271 }
6272 ca->line = bv.bv_val;
6273 ca->linelen = bv.bv_len;
6274 ca->valx = d->idx[i];
6275 config_parse_vals(ct, ca, d->idx[i] );
6276 rc = config_del_vals( ct, ca );
6277 if ( rc != LDAP_SUCCESS ) break;
6278 if ( s )
6279 s->a_flags |= SLAP_ATTR_IXDEL;
6280 for (j=i+1; j < d->nidx; j++)
6281 if ( d->idx[j] >d->idx[i] )
6282 d->idx[j]--;
6283 }
6284 } else {
6285 ca->valx = -1;
6286 ca->line = NULL;
6287 ca->argc = 1;
6288 rc = config_del_vals( ct, ca );
6289 if ( rc ) rc = LDAP_OTHER;
6290 if ( s )
6291 s->a_flags |= SLAP_ATTR_IXDEL;
6292 }
6293 if ( ml->sml_values ) {
6294 d = d->next;
6295 ch_free( dels );
6296 dels = d;
6297 }
6298 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
6299 ml->sml_values = vals;
6300 ml->sml_nvalues = nvals;
6301 }
6302 if ( !vals || rc != LDAP_SUCCESS )
6303 break;
6304 }
6305 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
6306
6307 case LDAP_MOD_ADD:
6308 if ( !a )
6309 break;
6310 for (i=0; ml->sml_values[i].bv_val; i++) {
6311 ca->line = ml->sml_values[i].bv_val;
6312 ca->linelen = ml->sml_values[i].bv_len;
6313 ca->valx = -1;
6314 rc = config_modify_add( ct, ca, ml->sml_desc, i );
6315 if ( rc )
6316 goto out;
6317 a->a_flags |= SLAP_ATTR_IXADD;
6318 }
6319 break;
6320 }
6321 }
6322
6323 out:
6324 /* Undo for a failed operation */
6325 if ( rc != LDAP_SUCCESS ) {
6326 ConfigReply msg = ca->reply;
6327 for ( s = save_attrs; s; s = s->a_next ) {
6328 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
6329 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6330 ct = config_find_table( colst, nocs, s->a_desc, ca );
6331 a = attr_find( e->e_attrs, s->a_desc );
6332 if ( a ) {
6333 /* clear the flag so the add check below will skip it */
6334 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6335 ca->valx = -1;
6336 ca->line = NULL;
6337 ca->argc = 1;
6338 config_del_vals( ct, ca );
6339 }
6340 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6341 ca->line = s->a_vals[i].bv_val;
6342 ca->linelen = s->a_vals[i].bv_len;
6343 ca->valx = -1;
6344 config_modify_add( ct, ca, s->a_desc, i );
6345 }
6346 }
6347 }
6348 for ( a = e->e_attrs; a; a = a->a_next ) {
6349 if ( a->a_flags & SLAP_ATTR_IXADD ) {
6350 ct = config_find_table( colst, nocs, a->a_desc, ca );
6351 ca->valx = -1;
6352 ca->line = NULL;
6353 ca->argc = 1;
6354 config_del_vals( ct, ca );
6355 s = attr_find( save_attrs, a->a_desc );
6356 if ( s ) {
6357 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6358 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6359 ca->line = s->a_vals[i].bv_val;
6360 ca->linelen = s->a_vals[i].bv_len;
6361 ca->valx = -1;
6362 config_modify_add( ct, ca, s->a_desc, i );
6363 }
6364 }
6365 }
6366 }
6367 ca->reply = msg;
6368 }
6369
6370 if ( ca->num_cleanups ) {
6371 i = config_run_cleanup( ca );
6372 if (rc == LDAP_SUCCESS)
6373 rc = i;
6374 }
6375 out_noop:
6376 if ( rc == LDAP_SUCCESS ) {
6377 attrs_free( save_attrs );
6378 rs->sr_text = NULL;
6379 } else {
6380 attrs_free( e->e_attrs );
6381 e->e_attrs = save_attrs;
6382 }
6383 ch_free( ca->argv );
6384 if ( colst ) ch_free( colst );
6385 while( dels ) {
6386 deltail = dels->next;
6387 ch_free( dels );
6388 dels = deltail;
6389 }
6390
6391 return rc;
6392 }
6393
6394 static int
config_back_modify(Operation * op,SlapReply * rs)6395 config_back_modify( Operation *op, SlapReply *rs )
6396 {
6397 CfBackInfo *cfb;
6398 CfEntryInfo *ce, *last;
6399 Modifications *ml;
6400 ConfigArgs ca = {0};
6401 struct berval rdn;
6402 char *ptr;
6403 AttributeDescription *rad = NULL;
6404 int do_pause = 1;
6405
6406 cfb = (CfBackInfo *)op->o_bd->be_private;
6407
6408 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6409 if ( !ce ) {
6410 if ( last )
6411 rs->sr_matched = last->ce_entry->e_name.bv_val;
6412 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6413 goto out;
6414 }
6415
6416 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
6417 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6418 goto out;
6419 }
6420
6421 /* Get type of RDN */
6422 rdn = ce->ce_entry->e_nname;
6423 ptr = strchr( rdn.bv_val, '=' );
6424 rdn.bv_len = ptr - rdn.bv_val;
6425 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6426 if ( rs->sr_err != LDAP_SUCCESS ) {
6427 goto out;
6428 }
6429
6430 /* Some basic validation... */
6431 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6432 /* Don't allow Modify of RDN; must use ModRdn for that. */
6433 if ( ml->sml_desc == rad ) {
6434 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6435 rs->sr_text = "Use modrdn to change the entry name";
6436 goto out;
6437 }
6438 /* Internal update of contextCSN? */
6439 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6440 do_pause = 0;
6441 break;
6442 }
6443 }
6444
6445 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6446
6447 if ( do_pause ) {
6448 if ( op->o_abandon ) {
6449 rs->sr_err = SLAPD_ABANDON;
6450 goto out;
6451 }
6452 if ( slap_pause_server() < 0 )
6453 do_pause = 0;
6454 }
6455
6456 /* Strategy:
6457 * 1) perform the Modify on the cached Entry.
6458 * 2) verify that the Entry still satisfies the schema.
6459 * 3) perform the individual config operations.
6460 * 4) store Modified entry in underlying LDIF backend.
6461 */
6462 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6463 if ( rs->sr_err ) {
6464 rs->sr_text = ca.cr_msg;
6465 } else if ( cfb->cb_use_ldif ) {
6466 BackendDB *be = op->o_bd;
6467 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6468 struct berval dn, ndn;
6469
6470 op->o_bd = &cfb->cb_db;
6471
6472 dn = op->o_dn;
6473 ndn = op->o_ndn;
6474 op->o_dn = op->o_bd->be_rootdn;
6475 op->o_ndn = op->o_bd->be_rootndn;
6476
6477 scp = op->o_callback;
6478 op->o_callback = ≻
6479 op->o_bd->be_modify( op, rs );
6480 op->o_bd = be;
6481 op->o_callback = scp;
6482 op->o_dn = dn;
6483 op->o_ndn = ndn;
6484 }
6485
6486 if ( do_pause )
6487 slap_unpause_server();
6488 out:
6489 send_ldap_result( op, rs );
6490 slap_graduate_commit_csn( op );
6491 return rs->sr_err;
6492 }
6493
6494 static int
config_back_modrdn(Operation * op,SlapReply * rs)6495 config_back_modrdn( Operation *op, SlapReply *rs )
6496 {
6497 CfBackInfo *cfb;
6498 CfEntryInfo *ce, *last;
6499 struct berval rdn;
6500 int ixold, ixnew, dopause = 1;
6501
6502 cfb = (CfBackInfo *)op->o_bd->be_private;
6503
6504 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6505 if ( !ce ) {
6506 if ( last )
6507 rs->sr_matched = last->ce_entry->e_name.bv_val;
6508 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6509 goto out;
6510 }
6511 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6512 NULL, ACL_WRITE, NULL )) {
6513 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6514 goto out;
6515 }
6516 { Entry *parent;
6517 if ( ce->ce_parent )
6518 parent = ce->ce_parent->ce_entry;
6519 else
6520 parent = (Entry *)&slap_entry_root;
6521 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6522 NULL, ACL_WRITE, NULL )) {
6523 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6524 goto out;
6525 }
6526 }
6527
6528 /* We don't allow moving objects to new parents.
6529 * Generally we only allow reordering a set of ordered entries.
6530 */
6531 if ( op->orr_newSup ) {
6532 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6533 goto out;
6534 }
6535
6536 /* If newRDN == oldRDN, quietly succeed */
6537 dnRdn( &op->o_req_ndn, &rdn );
6538 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6539 rs->sr_err = LDAP_SUCCESS;
6540 goto out;
6541 }
6542
6543 /* Current behavior, subject to change as needed:
6544 *
6545 * For backends and overlays, we only allow renumbering.
6546 * For schema, we allow renaming with the same number.
6547 * Otherwise, the op is not allowed.
6548 */
6549
6550 if ( ce->ce_type == Cft_Schema ) {
6551 char *ptr1, *ptr2;
6552 int len;
6553
6554 /* Can't alter the main cn=schema entry */
6555 if ( ce->ce_parent->ce_type == Cft_Global ) {
6556 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6557 rs->sr_text = "renaming not allowed for this entry";
6558 goto out;
6559 }
6560
6561 /* We could support this later if desired */
6562 ptr1 = ber_bvchr( &rdn, '}' );
6563 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6564 len = ptr1 - rdn.bv_val;
6565 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6566 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6567 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6568 rs->sr_text = "schema reordering not supported";
6569 goto out;
6570 }
6571 } else if ( ce->ce_type == Cft_Database ||
6572 ce->ce_type == Cft_Overlay ) {
6573 char *ptr1, *ptr2, *iptr1, *iptr2;
6574 int len1, len2;
6575
6576 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6577 if ( *iptr2 != '{' ) {
6578 rs->sr_err = LDAP_NAMING_VIOLATION;
6579 rs->sr_text = "new ordering index is required";
6580 goto out;
6581 }
6582 iptr2++;
6583 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6584 ptr1 = ber_bvchr( &rdn, '}' );
6585 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6586 if ( !ptr2 ) {
6587 rs->sr_err = LDAP_NAMING_VIOLATION;
6588 rs->sr_text = "new ordering index is required";
6589 goto out;
6590 }
6591
6592 len1 = ptr1 - rdn.bv_val;
6593 len2 = ptr2 - op->orr_newrdn.bv_val;
6594
6595 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6596 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6597 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6598 rs->sr_text = "changing database/overlay type not allowed";
6599 goto out;
6600 }
6601 ixold = strtol( iptr1, NULL, 0 );
6602 ixnew = strtol( iptr2, &ptr1, 0 );
6603 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6604 rs->sr_err = LDAP_NAMING_VIOLATION;
6605 goto out;
6606 }
6607 /* config DB is always 0, cannot be changed */
6608 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6609 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6610 goto out;
6611 }
6612 } else {
6613 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6614 rs->sr_text = "renaming not supported for this entry";
6615 goto out;
6616 }
6617
6618 if ( op->o_abandon ) {
6619 rs->sr_err = SLAPD_ABANDON;
6620 goto out;
6621 }
6622 if ( slap_pause_server() < 0 )
6623 dopause = 0;
6624
6625 if ( ce->ce_type == Cft_Schema ) {
6626 req_modrdn_s modr = op->oq_modrdn;
6627 struct berval rdn;
6628 Attribute *a;
6629 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6630 if ( rs->sr_err == LDAP_SUCCESS ) {
6631 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6632 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6633 cfb->cb_use_ldif );
6634 }
6635 op->oq_modrdn = modr;
6636 } else {
6637 CfEntryInfo *ce2, **cprev, **cbprev, *ceold;
6638 req_modrdn_s modr = op->oq_modrdn;
6639 int i;
6640
6641 /* Advance to first of this type */
6642 cprev = &ce->ce_parent->ce_kids;
6643 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6644 cprev = &ce2->ce_sibs;
6645 ce2 = ce2->ce_sibs;
6646 }
6647 /* Skip the -1 entry */
6648 if ( ce->ce_type == Cft_Database ) {
6649 cprev = &ce2->ce_sibs;
6650 ce2 = ce2->ce_sibs;
6651 }
6652 cbprev = cprev;
6653
6654 /* Remove from old slot */
6655 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6656 cprev = &ce2->ce_sibs;
6657 *cprev = ce->ce_sibs;
6658 ceold = ce->ce_sibs;
6659
6660 /* Insert into new slot */
6661 cprev = cbprev;
6662 for ( i=0; i<ixnew; i++ ) {
6663 ce2 = *cprev;
6664 if ( !ce2 )
6665 break;
6666 cprev = &ce2->ce_sibs;
6667 }
6668 ce->ce_sibs = *cprev;
6669 *cprev = ce;
6670
6671 ixnew = i;
6672
6673 /* NOTE: These should be encoded in the OC tables, not inline here */
6674 if ( ce->ce_type == Cft_Database )
6675 backend_db_move( ce->ce_be, ixnew );
6676 else if ( ce->ce_type == Cft_Overlay )
6677 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6678
6679 if ( ixold < ixnew ) {
6680 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6681 cfb->cb_use_ldif );
6682 } else {
6683 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6684 ixold - ixnew, cfb->cb_use_ldif );
6685 }
6686 op->oq_modrdn = modr;
6687 }
6688
6689 if ( dopause )
6690 slap_unpause_server();
6691 out:
6692 send_ldap_result( op, rs );
6693 return rs->sr_err;
6694 }
6695
6696 static int
config_back_delete(Operation * op,SlapReply * rs)6697 config_back_delete( Operation *op, SlapReply *rs )
6698 {
6699 #ifdef SLAP_CONFIG_DELETE
6700 CfBackInfo *cfb;
6701 CfEntryInfo *ce, *last, *ce2;
6702 int dopause = 1;
6703
6704 cfb = (CfBackInfo *)op->o_bd->be_private;
6705
6706 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6707 if ( !ce ) {
6708 if ( last )
6709 rs->sr_matched = last->ce_entry->e_name.bv_val;
6710 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6711 } else if ( ce->ce_kids ) {
6712 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6713 } else if ( op->o_abandon ) {
6714 rs->sr_err = SLAPD_ABANDON;
6715 } else if ( ce->ce_type == Cft_Overlay ||
6716 ce->ce_type == Cft_Database ||
6717 ce->ce_type == Cft_Misc ){
6718 char *iptr;
6719 int count, ixold;
6720
6721 if ( slap_pause_server() < 0 )
6722 dopause = 0;
6723
6724 if ( ce->ce_type == Cft_Overlay ){
6725 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6726 } else if ( ce->ce_type == Cft_Misc ) {
6727 /*
6728 * only Cft_Misc objects that have a co_lddel handler set in
6729 * the ConfigOCs struct can be deleted. This code also
6730 * assumes that the entry can be only have one objectclass
6731 * with co_type == Cft_Misc
6732 */
6733 ConfigOCs co, *coptr;
6734 Attribute *oc_at;
6735 int i;
6736
6737 oc_at = attr_find( ce->ce_entry->e_attrs,
6738 slap_schema.si_ad_objectClass );
6739 if ( !oc_at ) {
6740 rs->sr_err = LDAP_OTHER;
6741 rs->sr_text = "objectclass not found";
6742 if ( dopause ) slap_unpause_server();
6743 goto out;
6744 }
6745 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6746 co.co_name = &oc_at->a_nvals[i];
6747 coptr = ldap_avl_find( CfOcTree, &co, CfOc_cmp );
6748 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6749 continue;
6750 }
6751 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6752 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6753 if ( ! coptr->co_lddel ) {
6754 rs->sr_text = "No delete handler found";
6755 } else {
6756 rs->sr_err = LDAP_OTHER;
6757 /* FIXME: We should return a helpful error message
6758 * here */
6759 }
6760 if ( dopause ) slap_unpause_server();
6761 goto out;
6762 }
6763 break;
6764 }
6765 } else if (ce->ce_type == Cft_Database ) {
6766 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6767 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6768 rs->sr_text = "Cannot delete config or frontend database";
6769 if ( dopause ) slap_unpause_server();
6770 goto out;
6771 }
6772 if ( ce->ce_be->bd_info->bi_db_close ) {
6773 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6774 }
6775 backend_destroy_one( ce->ce_be, 1);
6776 }
6777
6778 /* remove CfEntryInfo from the siblings list */
6779 if ( ce->ce_parent->ce_kids == ce ) {
6780 ce->ce_parent->ce_kids = ce->ce_sibs;
6781 } else {
6782 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6783 if ( ce2->ce_sibs == ce ) {
6784 ce2->ce_sibs = ce->ce_sibs;
6785 break;
6786 }
6787 }
6788 }
6789
6790 /* remove from underlying database */
6791 if ( cfb->cb_use_ldif ) {
6792 BackendDB *be = op->o_bd;
6793 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6794 struct berval dn, ndn, req_dn, req_ndn;
6795
6796 op->o_bd = &cfb->cb_db;
6797
6798 dn = op->o_dn;
6799 ndn = op->o_ndn;
6800 req_dn = op->o_req_dn;
6801 req_ndn = op->o_req_ndn;
6802
6803 op->o_dn = op->o_bd->be_rootdn;
6804 op->o_ndn = op->o_bd->be_rootndn;
6805 op->o_req_dn = ce->ce_entry->e_name;
6806 op->o_req_ndn = ce->ce_entry->e_nname;
6807
6808 scp = op->o_callback;
6809 op->o_callback = ≻
6810 op->o_bd->be_delete( op, rs );
6811 op->o_bd = be;
6812 op->o_callback = scp;
6813 op->o_dn = dn;
6814 op->o_ndn = ndn;
6815 op->o_req_dn = req_dn;
6816 op->o_req_ndn = req_ndn;
6817 }
6818
6819 /* renumber siblings */
6820 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6821 ixold = strtol( iptr, NULL, 0 );
6822 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6823 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6824 count+ixold, 0, cfb->cb_use_ldif );
6825 count++;
6826 }
6827
6828 ce->ce_entry->e_private=NULL;
6829 entry_free(ce->ce_entry);
6830 ch_free(ce);
6831 if ( dopause ) slap_unpause_server();
6832 } else {
6833 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6834 }
6835 out:
6836 #else
6837 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6838 #endif /* SLAP_CONFIG_DELETE */
6839 send_ldap_result( op, rs );
6840 return rs->sr_err;
6841 }
6842
6843 static int
config_back_search(Operation * op,SlapReply * rs)6844 config_back_search( Operation *op, SlapReply *rs )
6845 {
6846 CfBackInfo *cfb;
6847 CfEntryInfo *ce, *last;
6848 slap_mask_t mask;
6849
6850 cfb = (CfBackInfo *)op->o_bd->be_private;
6851
6852 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6853 if ( !ce ) {
6854 if ( last )
6855 rs->sr_matched = last->ce_entry->e_name.bv_val;
6856 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6857 goto out;
6858 }
6859 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6860 ACL_SEARCH, NULL, &mask ))
6861 {
6862 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6863 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6864 } else {
6865 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6866 }
6867 goto out;
6868 }
6869 switch ( op->ors_scope ) {
6870 case LDAP_SCOPE_BASE:
6871 case LDAP_SCOPE_SUBTREE:
6872 rs->sr_err = config_send( op, rs, ce, 0 );
6873 break;
6874
6875 case LDAP_SCOPE_ONELEVEL:
6876 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6877 rs->sr_err = config_send( op, rs, ce, 1 );
6878 if ( rs->sr_err ) {
6879 break;
6880 }
6881 }
6882 break;
6883 }
6884
6885 out:
6886 send_ldap_result( op, rs );
6887 return rs->sr_err;
6888 }
6889
6890 /* no-op, we never free entries */
config_entry_release(Operation * op,Entry * e,int rw)6891 int config_entry_release(
6892 Operation *op,
6893 Entry *e,
6894 int rw )
6895 {
6896 int rc = LDAP_SUCCESS;
6897
6898 if ( !e->e_private ) {
6899 BackendDB *be = op->o_bd;
6900 CfBackInfo *cfb = be->be_private;
6901 BackendInfo *bi = cfb->cb_db.bd_info;
6902
6903 if ( bi && bi->bi_entry_release_rw ) {
6904 op->o_bd = &cfb->cb_db;
6905 rc = bi->bi_entry_release_rw( op, e, rw );
6906 op->o_bd = be;
6907 } else {
6908 entry_free( e );
6909 }
6910 }
6911 return rc;
6912 }
6913
6914 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6915 */
config_back_entry_get(Operation * op,struct berval * ndn,ObjectClass * oc,AttributeDescription * at,int rw,Entry ** ent)6916 int config_back_entry_get(
6917 Operation *op,
6918 struct berval *ndn,
6919 ObjectClass *oc,
6920 AttributeDescription *at,
6921 int rw,
6922 Entry **ent )
6923 {
6924 CfBackInfo *cfb;
6925 CfEntryInfo *ce, *last;
6926 int rc = LDAP_NO_SUCH_OBJECT;
6927
6928 cfb = (CfBackInfo *)op->o_bd->be_private;
6929
6930 ce = config_find_base( cfb->cb_root, ndn, &last );
6931 if ( ce ) {
6932 *ent = ce->ce_entry;
6933 if ( *ent ) {
6934 rc = LDAP_SUCCESS;
6935 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6936 rc = LDAP_NO_SUCH_ATTRIBUTE;
6937 *ent = NULL;
6938 }
6939 }
6940 }
6941
6942 return rc;
6943 }
6944
6945 static int
config_build_attrs(Entry * e,AttributeType ** at,AttributeDescription * ad,ConfigTable * ct,ConfigArgs * c)6946 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6947 ConfigTable *ct, ConfigArgs *c )
6948 {
6949 int i, rc;
6950
6951 for (; at && *at; at++) {
6952 /* Skip the naming attr */
6953 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6954 continue;
6955 for (i=0;ct[i].name;i++) {
6956 if (ct[i].ad == (*at)->sat_ad) {
6957 rc = config_get_vals(&ct[i], c);
6958 /* NOTE: tolerate that config_get_vals()
6959 * returns success with no values */
6960 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6961 if ( c->rvalue_nvals )
6962 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6963 c->rvalue_nvals);
6964 else {
6965 slap_syntax_validate_func *validate =
6966 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6967 if ( validate ) {
6968 int j;
6969 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6970 rc = ordered_value_validate( ct[i].ad,
6971 &c->rvalue_vals[j], LDAP_MOD_ADD );
6972 if ( rc ) {
6973 Debug( LDAP_DEBUG_ANY,
6974 "config_build_attrs: error %d on %s value #%d\n",
6975 rc, ct[i].ad->ad_cname.bv_val, j );
6976 return rc;
6977 }
6978 }
6979 }
6980
6981 rc = attr_merge_normalize(e, ct[i].ad,
6982 c->rvalue_vals, NULL);
6983 }
6984 ber_bvarray_free( c->rvalue_nvals );
6985 ber_bvarray_free( c->rvalue_vals );
6986 if ( rc ) {
6987 Debug( LDAP_DEBUG_ANY,
6988 "config_build_attrs: error %d on %s\n",
6989 rc, ct[i].ad->ad_cname.bv_val );
6990 return rc;
6991 }
6992 }
6993 break;
6994 }
6995 }
6996 }
6997 return 0;
6998 }
6999
7000 /* currently (2010) does not access rs except possibly writing rs->sr_err */
7001
7002 Entry *
config_build_entry(Operation * op,SlapReply * rs,CfEntryInfo * parent,ConfigArgs * c,struct berval * rdn,ConfigOCs * main,ConfigOCs * extra)7003 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
7004 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
7005 {
7006 Entry *e = entry_alloc();
7007 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
7008 AttributeDescription *ad = NULL;
7009 int cnt, rc;
7010 const char *text = "";
7011 Attribute *oc_at;
7012 struct berval pdn;
7013 ObjectClass *oc;
7014 CfEntryInfo *ceprev = NULL;
7015 LDAPRDN rDN;
7016
7017 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val );
7018 e->e_private = ce;
7019 ce->ce_entry = e;
7020 ce->ce_type = main->co_type;
7021 ce->ce_parent = parent;
7022 if ( parent ) {
7023 pdn = parent->ce_entry->e_nname;
7024 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
7025 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
7026 ceprev->ce_type <= ce->ce_type;
7027 ceprev = ceprev->ce_sibs );
7028 } else {
7029 BER_BVZERO( &pdn );
7030 }
7031
7032 ce->ce_private = c->ca_private;
7033 ce->ce_be = c->be;
7034 ce->ce_bi = c->bi;
7035
7036 build_new_dn( &e->e_name, &pdn, rdn, NULL );
7037 ber_dupbv( &e->e_nname, &e->e_name );
7038
7039 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
7040 main->co_name, NULL );
7041 if ( extra )
7042 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
7043 extra->co_name, NULL );
7044
7045 rc = ldap_bv2rdn( rdn, &rDN, (char **)&text, LDAP_DN_FORMAT_LDAP );
7046 if ( rc ) {
7047 goto fail;
7048 }
7049 for ( cnt = 0; rDN[cnt]; cnt++ ) {
7050 LDAPAVA *ava = rDN[cnt];
7051
7052 ad = NULL;
7053 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
7054 if ( rc ) {
7055 break;
7056 }
7057 if ( !ad->ad_type->sat_equality ) {
7058 rc = LDAP_CONSTRAINT_VIOLATION;
7059 text = "attribute has no equality matching rule";
7060 break;
7061 }
7062 if ( !ad->ad_type->sat_equality->smr_match ) {
7063 rc = LDAP_CONSTRAINT_VIOLATION;
7064 text = "attribute has unsupported equality matching rule";
7065 break;
7066 }
7067 attr_merge_normalize_one(e, ad, &ava->la_value, NULL );
7068 }
7069 ldap_rdnfree( rDN );
7070 if ( rc ) {
7071 goto fail;
7072 }
7073
7074 oc = main->co_oc;
7075 c->table = main->co_type;
7076 if ( oc->soc_required ) {
7077 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
7078 if ( rc ) goto fail;
7079 }
7080
7081 if ( oc->soc_allowed ) {
7082 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
7083 if ( rc ) goto fail;
7084 }
7085
7086 if ( extra ) {
7087 oc = extra->co_oc;
7088 c->table = extra->co_type;
7089 if ( oc->soc_required ) {
7090 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
7091 if ( rc ) goto fail;
7092 }
7093
7094 if ( oc->soc_allowed ) {
7095 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
7096 if ( rc ) goto fail;
7097 }
7098 }
7099
7100 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
7101 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
7102 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
7103 if ( rc != LDAP_SUCCESS ) {
7104 fail:
7105 Debug( LDAP_DEBUG_ANY,
7106 "config_build_entry: build \"%s\" failed: \"%s\"\n",
7107 rdn->bv_val, text );
7108 return NULL;
7109 }
7110 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
7111 if ( op ) {
7112 op->ora_e = e;
7113 op->ora_modlist = NULL;
7114 slap_add_opattrs( op, NULL, NULL, 0, 0 );
7115 if ( !op->o_noop ) {
7116 SlapReply rs2 = {REP_RESULT};
7117 op->o_bd->be_add( op, &rs2 );
7118 rs->sr_err = rs2.sr_err;
7119 rs_assert_done( &rs2 );
7120 if ( ( rs2.sr_err != LDAP_SUCCESS )
7121 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
7122 goto fail;
7123 }
7124 }
7125 }
7126 if ( ceprev ) {
7127 ce->ce_sibs = ceprev->ce_sibs;
7128 ceprev->ce_sibs = ce;
7129 } else if ( parent ) {
7130 ce->ce_sibs = parent->ce_kids;
7131 parent->ce_kids = ce;
7132 }
7133
7134 return e;
7135 }
7136
7137 static int
config_build_schema_inc(ConfigArgs * c,CfEntryInfo * ceparent,Operation * op,SlapReply * rs)7138 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
7139 Operation *op, SlapReply *rs )
7140 {
7141 Entry *e;
7142 ConfigFile *cf = c->ca_private;
7143 char *ptr;
7144 struct berval bv, rdn;
7145
7146 for (; cf; cf=cf->c_sibs, c->depth++) {
7147 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
7148 !cf->c_om_head && !cf->c_syn_head && !cf->c_kids ) continue;
7149 c->value_dn.bv_val = c->log;
7150 LUTIL_SLASHPATH( cf->c_file.bv_val );
7151 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
7152 if ( !bv.bv_val ) {
7153 bv = cf->c_file;
7154 } else {
7155 bv.bv_val++;
7156 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
7157 }
7158 ptr = strchr( bv.bv_val, '.' );
7159 if ( ptr )
7160 bv.bv_len = ptr - bv.bv_val;
7161 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
7162 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
7163 /* FIXME: how can indicate error? */
7164 return -1;
7165 }
7166 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
7167 bv.bv_len );
7168 c->value_dn.bv_len += bv.bv_len;
7169 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
7170 if ( rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL )) {
7171 Debug( LDAP_DEBUG_ANY,
7172 "config_build_schema_inc: invalid schema name \"%s\"\n",
7173 bv.bv_val );
7174 return -1;
7175 }
7176
7177 c->ca_private = cf;
7178 e = config_build_entry( op, rs, ceparent, c, &rdn,
7179 &CFOC_SCHEMA, NULL );
7180 ch_free( rdn.bv_val );
7181 if ( !e ) {
7182 return -1;
7183 } else if ( e && cf->c_kids ) {
7184 c->ca_private = cf->c_kids;
7185 config_build_schema_inc( c, e->e_private, op, rs );
7186 }
7187 }
7188 return 0;
7189 }
7190
7191 #ifdef SLAPD_MODULES
7192
7193 static int
config_build_modules(ConfigArgs * c,CfEntryInfo * ceparent,Operation * op,SlapReply * rs)7194 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
7195 Operation *op, SlapReply *rs )
7196 {
7197 int i;
7198 ModPaths *mp;
7199
7200 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
7201 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
7202 continue;
7203 c->value_dn.bv_val = c->log;
7204 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
7205 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
7206 /* FIXME: how can indicate error? */
7207 return -1;
7208 }
7209 c->ca_private = mp;
7210 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
7211 return -1;
7212 }
7213 }
7214 return 0;
7215 }
7216 #endif
7217
7218 static int
config_check_schema(Operation * op,CfBackInfo * cfb)7219 config_check_schema(Operation *op, CfBackInfo *cfb)
7220 {
7221 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
7222 ConfigArgs c = {0};
7223 CfEntryInfo *ce, *last;
7224 Entry *e;
7225
7226 /* If there's no root entry, we must be in the midst of converting */
7227 if ( !cfb->cb_root )
7228 return 0;
7229
7230 /* Make sure the main schema entry exists */
7231 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
7232 if ( ce ) {
7233 Attribute *a;
7234 struct berval *bv;
7235
7236 e = ce->ce_entry;
7237
7238 /* Make sure it's up to date */
7239 if ( cf_om_tail != om_sys_tail ) {
7240 a = attr_find( e->e_attrs, cfAd_om );
7241 if ( a ) {
7242 if ( a->a_nvals != a->a_vals )
7243 ber_bvarray_free( a->a_nvals );
7244 ber_bvarray_free( a->a_vals );
7245 a->a_vals = NULL;
7246 a->a_nvals = NULL;
7247 a->a_numvals = 0;
7248 }
7249 oidm_unparse( &bv, NULL, NULL, 1 );
7250 attr_merge_normalize( e, cfAd_om, bv, NULL );
7251 ber_bvarray_free( bv );
7252 cf_om_tail = om_sys_tail;
7253 }
7254 if ( cf_at_tail != at_sys_tail ) {
7255 a = attr_find( e->e_attrs, cfAd_attr );
7256 if ( a ) {
7257 if ( a->a_nvals != a->a_vals )
7258 ber_bvarray_free( a->a_nvals );
7259 ber_bvarray_free( a->a_vals );
7260 a->a_vals = NULL;
7261 a->a_nvals = NULL;
7262 a->a_numvals = 0;
7263 }
7264 at_unparse( &bv, NULL, NULL, 1 );
7265 attr_merge_normalize( e, cfAd_attr, bv, NULL );
7266 ber_bvarray_free( bv );
7267 cf_at_tail = at_sys_tail;
7268 }
7269 if ( cf_oc_tail != oc_sys_tail ) {
7270 a = attr_find( e->e_attrs, cfAd_oc );
7271 if ( a ) {
7272 if ( a->a_nvals != a->a_vals )
7273 ber_bvarray_free( a->a_nvals );
7274 ber_bvarray_free( a->a_vals );
7275 a->a_vals = NULL;
7276 a->a_nvals = NULL;
7277 a->a_numvals = 0;
7278 }
7279 oc_unparse( &bv, NULL, NULL, 1 );
7280 attr_merge_normalize( e, cfAd_oc, bv, NULL );
7281 ber_bvarray_free( bv );
7282 cf_oc_tail = oc_sys_tail;
7283 }
7284 if ( cf_syn_tail != syn_sys_tail ) {
7285 a = attr_find( e->e_attrs, cfAd_syntax );
7286 if ( a ) {
7287 if ( a->a_nvals != a->a_vals )
7288 ber_bvarray_free( a->a_nvals );
7289 ber_bvarray_free( a->a_vals );
7290 a->a_vals = NULL;
7291 a->a_nvals = NULL;
7292 a->a_numvals = 0;
7293 }
7294 syn_unparse( &bv, NULL, NULL, 1 );
7295 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
7296 ber_bvarray_free( bv );
7297 cf_syn_tail = syn_sys_tail;
7298 }
7299 } else {
7300 SlapReply rs = {REP_RESULT};
7301 c.ca_private = NULL;
7302 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
7303 &CFOC_SCHEMA, NULL );
7304 if ( !e ) {
7305 return -1;
7306 }
7307 ce = e->e_private;
7308 ce->ce_private = cfb->cb_config;
7309 cf_at_tail = at_sys_tail;
7310 cf_oc_tail = oc_sys_tail;
7311 cf_om_tail = om_sys_tail;
7312 cf_syn_tail = syn_sys_tail;
7313 }
7314 return 0;
7315 }
7316
7317 static const char *defacl[] = {
7318 NULL, "to", "*", "by", "*", "none", NULL
7319 };
7320
7321 static int
config_back_db_open(BackendDB * be,ConfigReply * cr)7322 config_back_db_open( BackendDB *be, ConfigReply *cr )
7323 {
7324 CfBackInfo *cfb = be->be_private;
7325 struct berval rdn;
7326 Entry *e;
7327 CfEntryInfo *ce, *ceparent;
7328 int i, unsupp = 0;
7329 BackendInfo *bi;
7330 ConfigArgs c;
7331 Connection conn = {0};
7332 OperationBuffer opbuf;
7333 Operation *op;
7334 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
7335 SlapReply rs = {REP_RESULT};
7336 void *thrctx = NULL;
7337 AccessControl *save_access;
7338
7339 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n" );
7340
7341 /* If we have no explicitly configured ACLs, don't just use
7342 * the global ACLs. Explicitly deny access to everything.
7343 */
7344 save_access = be->bd_self->be_acl;
7345 be->bd_self->be_acl = NULL;
7346 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
7347 defacl_parsed = be->bd_self->be_acl;
7348 if ( save_access ) {
7349 be->bd_self->be_acl = save_access;
7350 } else {
7351 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
7352 "No explicit ACL for back-config configured. "
7353 "Using hardcoded default\n" );
7354 }
7355
7356 thrctx = ldap_pvt_thread_pool_context();
7357 connection_fake_init( &conn, &opbuf, thrctx );
7358 op = &opbuf.ob_op;
7359
7360 op->o_tag = LDAP_REQ_ADD;
7361 op->o_callback = &cb;
7362 op->o_bd = &cfb->cb_db;
7363 op->o_dn = op->o_bd->be_rootdn;
7364 op->o_ndn = op->o_bd->be_rootndn;
7365
7366 if ( !cfb->cb_use_ldif ) {
7367 op->o_noop = 1;
7368 }
7369
7370 /* If we read the config from back-ldif, do some quick sanity checks */
7371 if ( cfb->cb_got_ldif ) {
7372 return config_check_schema( op, cfb );
7373 }
7374
7375 /* create root of tree */
7376 rdn = config_rdn;
7377 c.ca_private = cfb->cb_config;
7378 c.be = frontendDB;
7379 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
7380 if ( !e ) {
7381 return -1;
7382 }
7383 ce = e->e_private;
7384 cfb->cb_root = ce;
7385
7386 ceparent = ce;
7387
7388 #ifdef SLAPD_MODULES
7389 /* Create Module nodes... */
7390 if ( modpaths.mp_loads ) {
7391 if ( config_build_modules( &c, ceparent, op, &rs ) ){
7392 return -1;
7393 }
7394 }
7395 #endif
7396
7397 /* Create schema nodes... cn=schema will contain the hardcoded core
7398 * schema, read-only. Child objects will contain runtime loaded schema
7399 * files.
7400 */
7401 rdn = schema_rdn;
7402 c.ca_private = NULL;
7403 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
7404 if ( !e ) {
7405 return -1;
7406 }
7407 ce = e->e_private;
7408 ce->ce_private = cfb->cb_config;
7409 cf_at_tail = at_sys_tail;
7410 cf_oc_tail = oc_sys_tail;
7411 cf_om_tail = om_sys_tail;
7412 cf_syn_tail = syn_sys_tail;
7413
7414 /* Create schema nodes for included schema... */
7415 if ( cfb->cb_config->c_kids ) {
7416 int rc;
7417 c.depth = 0;
7418 c.ca_private = cfb->cb_config->c_kids;
7419 rc = config_build_schema_inc( &c, ce, op, &rs );
7420 if ( rc ) {
7421 return -1;
7422 }
7423 }
7424
7425 /* Create backend nodes. Skip if they don't provide a cf_table.
7426 * There usually aren't any of these.
7427 */
7428
7429 c.line = 0;
7430 i = 0;
7431 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
7432 if (!bi->bi_cf_ocs) {
7433 /* If it only supports the old config mech, complain. */
7434 if ( bi->bi_config ) {
7435 Debug( LDAP_DEBUG_ANY,
7436 "WARNING: No dynamic config support for backend %s.\n",
7437 bi->bi_type );
7438 unsupp++;
7439 }
7440 continue;
7441 }
7442 if ( !bi->bi_private && !(bi->bi_flags & SLAP_BFLAG_STANDALONE) ) continue;
7443
7444 rdn.bv_val = c.log;
7445 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7446 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_backend->ad_cname.bv_val,
7447 i, bi->bi_type);
7448 if ( rdn.bv_len >= sizeof( c.log ) ) {
7449 /* FIXME: holler ... */ ;
7450 }
7451 c.bi = bi;
7452 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
7453 bi->bi_cf_ocs );
7454 if ( !e ) {
7455 return -1;
7456 }
7457 if ( bi->bi_cf_ocs && bi->bi_cf_ocs->co_cfadd ) {
7458 rs_reinit( &rs, REP_RESULT );
7459 bi->bi_cf_ocs->co_cfadd( op, &rs, e, &c );
7460 }
7461 i++;
7462 }
7463
7464 /* Create database nodes... */
7465 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7466 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7467 for ( i = -1, be = frontendDB ; be;
7468 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7469 slap_overinfo *oi = NULL;
7470
7471 if ( overlay_is_over( be )) {
7472 oi = be->bd_info->bi_private;
7473 bi = oi->oi_orig;
7474 } else {
7475 bi = be->bd_info;
7476 }
7477
7478 /* If this backend supports the old config mechanism, but not
7479 * the new mech, complain.
7480 */
7481 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7482 Debug( LDAP_DEBUG_ANY,
7483 "WARNING: No dynamic config support for database %s.\n",
7484 bi->bi_type );
7485 unsupp++;
7486 }
7487 rdn.bv_val = c.log;
7488 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7489 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7490 i, bi->bi_type);
7491 if ( rdn.bv_len >= sizeof( c.log ) ) {
7492 /* FIXME: holler ... */ ;
7493 }
7494 c.be = be;
7495 c.bi = bi;
7496 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7497 be->be_cf_ocs );
7498 if ( !e ) {
7499 return -1;
7500 }
7501 ce = e->e_private;
7502 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7503 rs_reinit( &rs, REP_RESULT );
7504 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7505 }
7506 /* Iterate through overlays */
7507 if ( oi ) {
7508 slap_overinst *on;
7509 Entry *oe;
7510 int j;
7511 voidList *vl, *v0 = NULL;
7512
7513 /* overlays are in LIFO order, must reverse stack */
7514 for (on=oi->oi_list; on; on=on->on_next) {
7515 vl = ch_malloc( sizeof( voidList ));
7516 vl->vl_next = v0;
7517 v0 = vl;
7518 vl->vl_ptr = on;
7519 }
7520 for (j=0; vl; j++,vl=v0) {
7521 on = vl->vl_ptr;
7522 v0 = vl->vl_next;
7523 ch_free( vl );
7524 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7525 Debug( LDAP_DEBUG_ANY,
7526 "WARNING: No dynamic config support for overlay %s.\n",
7527 on->on_bi.bi_type );
7528 unsupp++;
7529 }
7530 rdn.bv_val = c.log;
7531 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7532 "%s=" SLAP_X_ORDERED_FMT "%s",
7533 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7534 if ( rdn.bv_len >= sizeof( c.log ) ) {
7535 /* FIXME: holler ... */ ;
7536 }
7537 c.be = be;
7538 c.bi = &on->on_bi;
7539 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7540 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7541 if ( !oe ) {
7542 return -1;
7543 }
7544 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7545 rs_reinit( &rs, REP_RESULT );
7546 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7547 }
7548 }
7549 }
7550 }
7551 if ( thrctx )
7552 ldap_pvt_thread_pool_context_reset( thrctx );
7553
7554 if ( unsupp && cfb->cb_use_ldif ) {
7555 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7556 "directory is incomplete and may not work.\n\n" );
7557 }
7558
7559 return 0;
7560 }
7561
7562 static void
cfb_free_cffile(ConfigFile * cf)7563 cfb_free_cffile( ConfigFile *cf )
7564 {
7565 ConfigFile *next;
7566
7567 for (; cf; cf=next) {
7568 next = cf->c_sibs;
7569 if ( cf->c_kids )
7570 cfb_free_cffile( cf->c_kids );
7571 ch_free( cf->c_file.bv_val );
7572 ber_bvarray_free( cf->c_dseFiles );
7573 ch_free( cf );
7574 }
7575 }
7576
7577 static void
cfb_free_entries(CfEntryInfo * ce)7578 cfb_free_entries( CfEntryInfo *ce )
7579 {
7580 CfEntryInfo *next;
7581
7582 for (; ce; ce=next) {
7583 next = ce->ce_sibs;
7584 if ( ce->ce_kids )
7585 cfb_free_entries( ce->ce_kids );
7586 ce->ce_entry->e_private = NULL;
7587 entry_free( ce->ce_entry );
7588 ch_free( ce );
7589 }
7590 }
7591
7592 static int
config_back_db_close(BackendDB * be,ConfigReply * cr)7593 config_back_db_close( BackendDB *be, ConfigReply *cr )
7594 {
7595 CfBackInfo *cfb = be->be_private;
7596
7597 cfb_free_entries( cfb->cb_root );
7598 cfb->cb_root = NULL;
7599
7600 if ( cfb->cb_db.bd_info ) {
7601 backend_shutdown( &cfb->cb_db );
7602 }
7603
7604 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7605 acl_free( defacl_parsed );
7606 defacl_parsed = NULL;
7607 }
7608
7609 return 0;
7610 }
7611
7612 static int
config_back_db_destroy(BackendDB * be,ConfigReply * cr)7613 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7614 {
7615 CfBackInfo *cfb = be->be_private;
7616
7617 cfb_free_cffile( cfb->cb_config );
7618
7619 ch_free( cfdir.bv_val );
7620
7621 ldap_avl_free( CfOcTree, NULL );
7622
7623 if ( cfb->cb_db.bd_info ) {
7624 cfb->cb_db.be_suffix = NULL;
7625 cfb->cb_db.be_nsuffix = NULL;
7626 BER_BVZERO( &cfb->cb_db.be_rootdn );
7627 BER_BVZERO( &cfb->cb_db.be_rootndn );
7628
7629 backend_destroy_one( &cfb->cb_db, 0 );
7630 }
7631
7632 loglevel_destroy();
7633
7634 return 0;
7635 }
7636
7637 static int
config_back_db_init(BackendDB * be,ConfigReply * cr)7638 config_back_db_init( BackendDB *be, ConfigReply* cr )
7639 {
7640 struct berval dn;
7641 CfBackInfo *cfb;
7642
7643 cfb = &cfBackInfo;
7644 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7645 cfn = cfb->cb_config;
7646 be->be_private = cfb;
7647
7648 ber_dupbv( &be->be_rootdn, &config_rdn );
7649 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7650 ber_dupbv( &dn, &be->be_rootdn );
7651 ber_bvarray_add( &be->be_suffix, &dn );
7652 ber_dupbv( &dn, &be->be_rootdn );
7653 ber_bvarray_add( &be->be_nsuffix, &dn );
7654
7655 /* Hide from namingContexts */
7656 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7657
7658 /* Check ACLs on content of Adds by default */
7659 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7660
7661 return 0;
7662 }
7663
7664 static int
config_back_destroy(BackendInfo * bi)7665 config_back_destroy( BackendInfo *bi )
7666 {
7667 ldif_must_b64_encode_release();
7668 return 0;
7669 }
7670
7671 static int
config_tool_entry_open(BackendDB * be,int mode)7672 config_tool_entry_open( BackendDB *be, int mode )
7673 {
7674 CfBackInfo *cfb = be->be_private;
7675 BackendInfo *bi = cfb->cb_db.bd_info;
7676
7677 configDB = be;
7678 if ( bi && bi->bi_tool_entry_open )
7679 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7680 else
7681 return -1;
7682
7683 }
7684
7685 static int
config_tool_entry_close(BackendDB * be)7686 config_tool_entry_close( BackendDB *be )
7687 {
7688 CfBackInfo *cfb = be->be_private;
7689 BackendInfo *bi = cfb->cb_db.bd_info;
7690
7691 if ( bi && bi->bi_tool_entry_close )
7692 return bi->bi_tool_entry_close( &cfb->cb_db );
7693 else
7694 return -1;
7695 }
7696
7697 static ID
config_tool_entry_first(BackendDB * be)7698 config_tool_entry_first( BackendDB *be )
7699 {
7700 CfBackInfo *cfb = be->be_private;
7701 BackendInfo *bi = cfb->cb_db.bd_info;
7702
7703 if ( bi && bi->bi_tool_entry_first ) {
7704 return bi->bi_tool_entry_first( &cfb->cb_db );
7705 }
7706 if ( bi && bi->bi_tool_entry_first_x ) {
7707 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7708 NULL, LDAP_SCOPE_DEFAULT, NULL );
7709 }
7710 return NOID;
7711 }
7712
7713 static ID
config_tool_entry_first_x(BackendDB * be,struct berval * base,int scope,Filter * f)7714 config_tool_entry_first_x(
7715 BackendDB *be,
7716 struct berval *base,
7717 int scope,
7718 Filter *f )
7719 {
7720 CfBackInfo *cfb = be->be_private;
7721 BackendInfo *bi = cfb->cb_db.bd_info;
7722
7723 if ( bi && bi->bi_tool_entry_first_x ) {
7724 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7725 }
7726 return NOID;
7727 }
7728
7729 static ID
config_tool_entry_next(BackendDB * be)7730 config_tool_entry_next( BackendDB *be )
7731 {
7732 CfBackInfo *cfb = be->be_private;
7733 BackendInfo *bi = cfb->cb_db.bd_info;
7734
7735 if ( bi && bi->bi_tool_entry_next )
7736 return bi->bi_tool_entry_next( &cfb->cb_db );
7737 else
7738 return NOID;
7739 }
7740
7741 static ID
config_tool_dn2id_get(Backend * be,struct berval * dn)7742 config_tool_dn2id_get( Backend *be, struct berval *dn )
7743 {
7744 CfBackInfo *cfb = be->be_private;
7745 BackendInfo *bi = cfb->cb_db.bd_info;
7746
7747 if ( bi && bi->bi_tool_dn2id_get )
7748 return bi->bi_tool_dn2id_get( &cfb->cb_db, dn );
7749
7750 return NOID;
7751 }
7752
7753 static Entry *
config_tool_entry_get(BackendDB * be,ID id)7754 config_tool_entry_get( BackendDB *be, ID id )
7755 {
7756 CfBackInfo *cfb = be->be_private;
7757 BackendInfo *bi = cfb->cb_db.bd_info;
7758
7759 if ( bi && bi->bi_tool_entry_get )
7760 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7761 else
7762 return NULL;
7763 }
7764
7765 static int entry_put_got_frontend=0;
7766 static int entry_put_got_config=0;
7767 static ID
config_tool_entry_put(BackendDB * be,Entry * e,struct berval * text)7768 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7769 {
7770 CfBackInfo *cfb = be->be_private;
7771 BackendInfo *bi = cfb->cb_db.bd_info;
7772 int rc;
7773 struct berval rdn;
7774 ConfigArgs ca;
7775 OperationBuffer opbuf;
7776 Entry *ce;
7777 Connection conn = {0};
7778 Operation *op = NULL;
7779 void *thrctx;
7780 int isFrontend = 0;
7781 int isFrontendChild = 0;
7782
7783 /* Create entry for frontend database if it does not exist already */
7784 if ( !entry_put_got_frontend ) {
7785 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7786 STRLENOF( "olcDatabase" ))) {
7787 if ( strncmp( e->e_nname.bv_val +
7788 STRLENOF( "olcDatabase" ), "={-1}frontend",
7789 STRLENOF( "={-1}frontend" )) &&
7790 strncmp( e->e_nname.bv_val +
7791 STRLENOF( "olcDatabase" ), "=frontend",
7792 STRLENOF( "=frontend" ))) {
7793 memset( &ca, 0, sizeof(ConfigArgs));
7794 ca.be = frontendDB;
7795 ca.bi = frontendDB->bd_info;
7796 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7797 rdn.bv_val = ca.log;
7798 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7799 "%s=" SLAP_X_ORDERED_FMT "%s",
7800 cfAd_database->ad_cname.bv_val, -1,
7801 ca.bi->bi_type);
7802 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7803 &CFOC_DATABASE, ca.be->be_cf_ocs );
7804 thrctx = ldap_pvt_thread_pool_context();
7805 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7806 op = &opbuf.ob_op;
7807 op->o_bd = &cfb->cb_db;
7808 op->o_tag = LDAP_REQ_ADD;
7809 op->ora_e = ce;
7810 op->o_dn = be->be_rootdn;
7811 op->o_ndn = be->be_rootndn;
7812 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7813 if ( rc != LDAP_SUCCESS ) {
7814 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7815 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7816 return NOID;
7817 }
7818
7819 if ( ce && bi && bi->bi_tool_entry_put &&
7820 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7821 entry_put_got_frontend++;
7822 } else {
7823 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7824 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7825 return NOID;
7826 }
7827 } else {
7828 entry_put_got_frontend++;
7829 isFrontend = 1;
7830 }
7831 }
7832 }
7833
7834 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7835 * instances, may appear before the config database entry in the ldif, skip
7836 * auto-creation of olcDatabase={0}config in such a case */
7837 if ( !entry_put_got_config &&
7838 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7839 struct berval pdn;
7840 dnParent( &e->e_nname, &pdn );
7841 while ( pdn.bv_len ) {
7842 if ( !strncmp( pdn.bv_val, "olcDatabase",
7843 STRLENOF( "olcDatabase" ))) {
7844 if ( !strncmp( pdn.bv_val +
7845 STRLENOF( "olcDatabase" ), "={-1}frontend",
7846 STRLENOF( "={-1}frontend" )) ||
7847 !strncmp( pdn.bv_val +
7848 STRLENOF( "olcDatabase" ), "=frontend",
7849 STRLENOF( "=frontend" ))) {
7850
7851 isFrontendChild = 1;
7852 break;
7853 }
7854 }
7855 dnParent( &pdn, &pdn );
7856 }
7857 }
7858
7859 /* Create entry for config database if it does not exist already */
7860 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7861 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7862 STRLENOF( "olcDatabase" ))) {
7863 if ( strncmp( e->e_nname.bv_val +
7864 STRLENOF( "olcDatabase" ), "={0}config",
7865 STRLENOF( "={0}config" )) &&
7866 strncmp( e->e_nname.bv_val +
7867 STRLENOF( "olcDatabase" ), "=config",
7868 STRLENOF( "=config" )) ) {
7869 memset( &ca, 0, sizeof(ConfigArgs));
7870 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7871 ca.bi = ca.be->bd_info;
7872 rdn.bv_val = ca.log;
7873 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7874 "%s=" SLAP_X_ORDERED_FMT "%s",
7875 cfAd_database->ad_cname.bv_val, 0,
7876 ca.bi->bi_type);
7877 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7878 ca.be->be_cf_ocs );
7879 if ( ! op ) {
7880 thrctx = ldap_pvt_thread_pool_context();
7881 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7882 op = &opbuf.ob_op;
7883 op->o_bd = &cfb->cb_db;
7884 op->o_tag = LDAP_REQ_ADD;
7885 op->o_dn = be->be_rootdn;
7886 op->o_ndn = be->be_rootndn;
7887 }
7888 op->ora_e = ce;
7889 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7890 if ( rc != LDAP_SUCCESS ) {
7891 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7892 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7893 return NOID;
7894 }
7895 if (ce && bi && bi->bi_tool_entry_put &&
7896 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7897 entry_put_got_config++;
7898 } else {
7899 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7900 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7901 return NOID;
7902 }
7903 } else {
7904 entry_put_got_config++;
7905 }
7906 }
7907 }
7908 if ( bi && bi->bi_tool_entry_put &&
7909 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7910 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7911 else {
7912 ber_str2bv( ca.cr_msg, 0, 0, text );
7913 return NOID;
7914 }
7915 }
7916
7917 static ID
config_tool_entry_modify(BackendDB * be,Entry * e,struct berval * text)7918 config_tool_entry_modify( BackendDB *be, Entry *e, struct berval *text )
7919 {
7920 CfBackInfo *cfb = be->be_private;
7921 BackendInfo *bi = cfb->cb_db.bd_info;
7922 CfEntryInfo *ce, *last;
7923
7924 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
7925
7926 if ( ce && bi && bi->bi_tool_entry_modify )
7927 return bi->bi_tool_entry_modify( &cfb->cb_db, e, text );
7928
7929 return NOID;
7930 }
7931
7932 static int
config_tool_entry_delete(BackendDB * be,struct berval * ndn,struct berval * text)7933 config_tool_entry_delete( BackendDB *be, struct berval *ndn, struct berval *text )
7934 {
7935 CfBackInfo *cfb = be->be_private;
7936 BackendInfo *bi = cfb->cb_db.bd_info;
7937 CfEntryInfo *ce, *last;
7938
7939 ce = config_find_base( cfb->cb_root, ndn, &last );
7940
7941 if ( ce && bi && bi->bi_tool_entry_delete )
7942 return bi->bi_tool_entry_delete( &cfb->cb_db, ndn, text );
7943
7944 return LDAP_OTHER;
7945 }
7946
7947 static struct {
7948 char *name;
7949 AttributeDescription **desc;
7950 } ads[] = {
7951 { "attribute", &cfAd_attr },
7952 { "backend", &cfAd_backend },
7953 { "database", &cfAd_database },
7954 { "include", &cfAd_include },
7955 { "ldapsyntax", &cfAd_syntax },
7956 { "objectclass", &cfAd_oc },
7957 { "objectidentifier", &cfAd_om },
7958 { "overlay", &cfAd_overlay },
7959 { NULL, NULL }
7960 };
7961
7962 /* Notes:
7963 * add / delete: all types that may be added or deleted must use an
7964 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7965 * should automatically renumber the index of any siblings as needed,
7966 * so that no gaps in the numbering sequence exist after the add/delete
7967 * is completed.
7968 * What can be added:
7969 * schema objects
7970 * backend objects for backend-specific config directives
7971 * database objects
7972 * overlay objects
7973 *
7974 * delete: probably no support this time around.
7975 *
7976 * modrdn: generally not done. Will be invoked automatically by add/
7977 * delete to update numbering sequence. Perform as an explicit operation
7978 * so that the renumbering effect may be replicated. Subtree rename must
7979 * be supported, since renumbering a database will affect all its child
7980 * overlays.
7981 *
7982 * modify: must be fully supported.
7983 */
7984
7985 int
config_back_initialize(BackendInfo * bi)7986 config_back_initialize( BackendInfo *bi )
7987 {
7988 ConfigTable *ct = config_back_cf_table;
7989 ConfigArgs ca;
7990 char *argv[4];
7991 int i;
7992 AttributeDescription *ad = NULL;
7993 const char *text;
7994 static char *controls[] = {
7995 LDAP_CONTROL_MANAGEDSAIT,
7996 NULL
7997 };
7998
7999 /* Make sure we don't exceed the bits reserved for userland */
8000 config_check_userland( CFG_LAST );
8001
8002 bi->bi_controls = controls;
8003
8004 bi->bi_open = 0;
8005 bi->bi_close = 0;
8006 bi->bi_config = 0;
8007 bi->bi_destroy = config_back_destroy;
8008
8009 bi->bi_db_init = config_back_db_init;
8010 bi->bi_db_config = 0;
8011 bi->bi_db_open = config_back_db_open;
8012 bi->bi_db_close = config_back_db_close;
8013 bi->bi_db_destroy = config_back_db_destroy;
8014
8015 bi->bi_op_bind = config_back_bind;
8016 bi->bi_op_unbind = 0;
8017 bi->bi_op_search = config_back_search;
8018 bi->bi_op_compare = 0;
8019 bi->bi_op_modify = config_back_modify;
8020 bi->bi_op_modrdn = config_back_modrdn;
8021 bi->bi_op_add = config_back_add;
8022 bi->bi_op_delete = config_back_delete;
8023 bi->bi_op_abandon = 0;
8024
8025 bi->bi_extended = 0;
8026
8027 bi->bi_chk_referrals = 0;
8028
8029 bi->bi_access_allowed = slap_access_allowed;
8030
8031 bi->bi_connection_init = 0;
8032 bi->bi_connection_destroy = 0;
8033
8034 bi->bi_entry_release_rw = config_entry_release;
8035 bi->bi_entry_get_rw = config_back_entry_get;
8036
8037 bi->bi_tool_entry_open = config_tool_entry_open;
8038 bi->bi_tool_entry_close = config_tool_entry_close;
8039 bi->bi_tool_entry_first = config_tool_entry_first;
8040 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
8041 bi->bi_tool_entry_next = config_tool_entry_next;
8042 bi->bi_tool_dn2id_get = config_tool_dn2id_get;
8043 bi->bi_tool_entry_get = config_tool_entry_get;
8044 bi->bi_tool_entry_put = config_tool_entry_put;
8045 bi->bi_tool_entry_modify = config_tool_entry_modify;
8046 bi->bi_tool_entry_delete = config_tool_entry_delete;
8047
8048 ca.argv = argv;
8049 argv[ 0 ] = "slapd";
8050 ca.argv = argv;
8051 ca.argc = 3;
8052 ca.fname = argv[0];
8053
8054 argv[3] = NULL;
8055 for (i=0; OidMacros[i].name; i++ ) {
8056 argv[1] = OidMacros[i].name;
8057 argv[2] = OidMacros[i].oid;
8058 parse_oidm( &ca, 0, NULL );
8059 }
8060
8061 bi->bi_cf_ocs = cf_ocs;
8062
8063 i = config_register_schema( ct, cf_ocs );
8064 if ( i ) return i;
8065
8066 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
8067 if ( i ) return i;
8068
8069 /* setup olcRootPW to be base64-encoded when written in LDIF form;
8070 * basically, we don't care if it fails */
8071 i = slap_str2ad( "olcRootPW", &ad, &text );
8072 if ( i ) {
8073 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
8074 "warning, unable to get \"olcRootPW\" "
8075 "attribute description: %d: %s\n",
8076 i, text );
8077 } else {
8078 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
8079 ad->ad_type->sat_oid );
8080 }
8081
8082 /* set up the notable AttributeDescriptions */
8083 i = 0;
8084 for (;ct->name;ct++) {
8085 if (strcmp(ct->name, ads[i].name)) continue;
8086 *ads[i].desc = ct->ad;
8087 i++;
8088 if (!ads[i].name) break;
8089 }
8090
8091 return 0;
8092 }
8093