config.c 55.1 KB
Newer Older
1
/* config.c - ldap backend configuration file routine */
2
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
4
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
5
 * Copyright 2003-2021 The OpenLDAP Foundation.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
7
 * Portions Copyright 1999-2003 Howard Chu.
 * Portions Copyright 2000-2003 Pierangelo Masarati.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in the file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */
/* ACKNOWLEDGEMENTS:
 * This work was initially developed by the Howard Chu for inclusion
 * in OpenLDAP Software and subsequently enhanced by Pierangelo
 * Masarati.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
22
 */
23
24
25
26
27
28

#include "portable.h"

#include <stdio.h>

#include <ac/string.h>
29
#include <ac/ctype.h>
30
31
32
#include <ac/socket.h>

#include "slap.h"
33
#include "slap-config.h"
34
#include "back-ldap.h"
35
#include "lutil.h"
36
#include "ldif.h"
37

38
39
static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;

40
static ConfigDriver ldap_back_cf_gen;
41
static ConfigDriver ldap_pbind_cf_gen;
42
43
44
45

enum {
	LDAP_BACK_CFG_URI = 1,
	LDAP_BACK_CFG_TLS,
46
	LDAP_BACK_CFG_ACL_BIND,
47
	LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
48
	LDAP_BACK_CFG_IDASSERT_PASSTHRU,
49
	LDAP_BACK_CFG_IDASSERT_BIND,
50
51
52
53
	LDAP_BACK_CFG_REBIND,
	LDAP_BACK_CFG_CHASE,
	LDAP_BACK_CFG_T_F,
	LDAP_BACK_CFG_WHOAMI,
54
	LDAP_BACK_CFG_TIMEOUT,
55
	LDAP_BACK_CFG_IDLE_TIMEOUT,
56
	LDAP_BACK_CFG_CONN_TTL,
57
	LDAP_BACK_CFG_NETWORK_TIMEOUT,
58
	LDAP_BACK_CFG_VERSION,
59
	LDAP_BACK_CFG_SINGLECONN,
60
	LDAP_BACK_CFG_USETEMP,
61
	LDAP_BACK_CFG_CONNPOOLMAX,
62
	LDAP_BACK_CFG_CANCEL,
63
	LDAP_BACK_CFG_QUARANTINE,
64
	LDAP_BACK_CFG_ST_REQUEST,
65
	LDAP_BACK_CFG_NOREFS,
66
	LDAP_BACK_CFG_NOUNDEFFILTER,
67
	LDAP_BACK_CFG_ONERR,
68

69
	LDAP_BACK_CFG_KEEPALIVE,
70
	LDAP_BACK_CFG_TCP_USER_TIMEOUT,
71

72
73
	LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA,

74
	LDAP_BACK_CFG_LAST
75
76
77
78
};

static ConfigTable ldapcfg[] = {
	{ "uri", "uri", 2, 2, 0,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
79
		ARG_MAGIC|LDAP_BACK_CFG_URI,
80
81
		ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
			"NAME 'olcDbURI' "
82
			"DESC 'URI (list) for remote DSA' "
83
			"EQUALITY caseExactMatch "
84
85
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
86
		NULL, NULL },
Howard Chu's avatar
Howard Chu committed
87
	{ "tls", "what", 2, 0, 0,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
88
		ARG_MAGIC|LDAP_BACK_CFG_TLS,
89
90
		ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
			"NAME 'olcDbStartTLS' "
91
			"DESC 'StartTLS' "
92
			"EQUALITY caseExactMatch "
93
94
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
95
		NULL, NULL },
96
	{ "acl-bind", "args", 2, 0, 0,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
97
		ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
98
99
100
		ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
			"NAME 'olcDbACLBind' "
			"DESC 'Remote ACL administrative identity auth bind configuration' "
101
			"EQUALITY caseIgnoreMatch "
102
103
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
104
		NULL, NULL },
105
	{ "idassert-bind", "args", 2, 0, 0,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
106
		ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
107
108
109
		ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
			"NAME 'olcDbIDAssertBind' "
			"DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
110
			"EQUALITY caseIgnoreMatch "
111
112
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
113
114
		NULL, NULL },
	{ "idassert-authzFrom", "authzRule", 2, 2, 0,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
115
		ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
116
117
		ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
			"NAME 'olcDbIDAssertAuthzFrom' "
118
			"DESC 'Remote Identity Assertion authz rules' "
119
			"EQUALITY caseIgnoreMatch "
120
121
			"SYNTAX OMsDirectoryString "
			"X-ORDERED 'VALUES' )",
122
		NULL, NULL },
123
	{ "rebind-as-user", "true|FALSE", 1, 2, 0,
124
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_REBIND,
125
126
		ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
			"NAME 'olcDbRebindAsUser' "
127
			"DESC 'Rebind as user' "
128
			"EQUALITY booleanMatch "
129
			"SYNTAX OMsBoolean "
130
			"SINGLE-VALUE )",
131
		NULL, NULL },
132
	{ "chase-referrals", "true|FALSE", 2, 2, 0,
133
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_CHASE,
134
135
		ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
			"NAME 'olcDbChaseReferrals' "
136
			"DESC 'Chase referrals' "
137
			"EQUALITY booleanMatch "
138
			"SYNTAX OMsBoolean "
139
			"SINGLE-VALUE )",
140
		NULL, NULL },
141
	{ "t-f-support", "true|FALSE|discover", 2, 2, 0,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
142
		ARG_MAGIC|LDAP_BACK_CFG_T_F,
143
144
		ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
			"NAME 'olcDbTFSupport' "
145
			"DESC 'Absolute filters support' "
146
			"EQUALITY caseIgnoreMatch "
147
148
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
149
		NULL, NULL },
150
	{ "proxy-whoami", "true|FALSE", 1, 2, 0,
151
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_WHOAMI,
152
153
		ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
			"NAME 'olcDbProxyWhoAmI' "
154
			"DESC 'Proxy whoAmI exop' "
155
			"EQUALITY booleanMatch "
156
			"SYNTAX OMsBoolean "
157
			"SINGLE-VALUE )",
158
		NULL, NULL },
159
	{ "timeout", "timeout(list)", 2, 0, 0,
160
161
162
163
		ARG_MAGIC|LDAP_BACK_CFG_TIMEOUT,
		ldap_back_cf_gen, "( OLcfgDbAt:3.14 "
			"NAME 'olcDbTimeout' "
			"DESC 'Per-operation timeouts' "
164
			"EQUALITY caseIgnoreMatch "
165
166
167
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
168
	{ "idle-timeout", "timeout", 2, 2, 0,
169
170
171
172
		ARG_MAGIC|LDAP_BACK_CFG_IDLE_TIMEOUT,
		ldap_back_cf_gen, "( OLcfgDbAt:3.15 "
			"NAME 'olcDbIdleTimeout' "
			"DESC 'connection idle timeout' "
173
			"EQUALITY caseIgnoreMatch "
174
175
176
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
177
	{ "conn-ttl", "ttl", 2, 2, 0,
178
179
180
181
		ARG_MAGIC|LDAP_BACK_CFG_CONN_TTL,
		ldap_back_cf_gen, "( OLcfgDbAt:3.16 "
			"NAME 'olcDbConnTtl' "
			"DESC 'connection ttl' "
182
			"EQUALITY caseIgnoreMatch "
183
184
185
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
186
	{ "network-timeout", "timeout", 2, 2, 0,
187
188
189
190
		ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
		ldap_back_cf_gen, "( OLcfgDbAt:3.17 "
			"NAME 'olcDbNetworkTimeout' "
			"DESC 'connection network timeout' "
191
			"EQUALITY caseIgnoreMatch "
192
193
194
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
195
	{ "protocol-version", "version", 2, 2, 0,
196
197
198
199
		ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_VERSION,
		ldap_back_cf_gen, "( OLcfgDbAt:3.18 "
			"NAME 'olcDbProtocolVersion' "
			"DESC 'protocol version' "
200
			"EQUALITY integerMatch "
201
202
203
			"SYNTAX OMsInteger "
			"SINGLE-VALUE )",
		NULL, NULL },
204
	{ "single-conn", "true|FALSE", 2, 2, 0,
205
206
207
208
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_SINGLECONN,
		ldap_back_cf_gen, "( OLcfgDbAt:3.19 "
			"NAME 'olcDbSingleConn' "
			"DESC 'cache a single connection per identity' "
209
			"EQUALITY booleanMatch "
210
211
212
			"SYNTAX OMsBoolean "
			"SINGLE-VALUE )",
		NULL, NULL },
213
	{ "cancel", "ABANDON|ignore|exop", 2, 2, 0,
214
215
216
217
		ARG_MAGIC|LDAP_BACK_CFG_CANCEL,
		ldap_back_cf_gen, "( OLcfgDbAt:3.20 "
			"NAME 'olcDbCancel' "
			"DESC 'abandon/ignore/exop operations when appropriate' "
218
			"EQUALITY caseIgnoreMatch "
219
220
221
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
222
	{ "quarantine", "retrylist", 2, 2, 0,
223
224
225
226
		ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
		ldap_back_cf_gen, "( OLcfgDbAt:3.21 "
			"NAME 'olcDbQuarantine' "
			"DESC 'Quarantine database if connection fails and retry according to rule' "
227
			"EQUALITY caseIgnoreMatch "
228
229
230
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
231
	{ "use-temporary-conn", "true|FALSE", 2, 2, 0,
232
233
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_USETEMP,
		ldap_back_cf_gen, "( OLcfgDbAt:3.22 "
234
			"NAME 'olcDbUseTemporaryConn' "
235
			"DESC 'Use temporary connections if the cached one is busy' "
236
			"EQUALITY booleanMatch "
237
238
239
			"SYNTAX OMsBoolean "
			"SINGLE-VALUE )",
		NULL, NULL },
240
	{ "conn-pool-max", "<n>", 2, 2, 0,
241
242
243
244
		ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_CONNPOOLMAX,
		ldap_back_cf_gen, "( OLcfgDbAt:3.23 "
			"NAME 'olcDbConnectionPoolMax' "
			"DESC 'Max size of privileged connections pool' "
245
			"EQUALITY integerMatch "
246
247
248
			"SYNTAX OMsInteger "
			"SINGLE-VALUE )",
		NULL, NULL },
249
250
251
252
253
254
#ifdef SLAP_CONTROL_X_SESSION_TRACKING
	{ "session-tracking-request", "true|FALSE", 2, 2, 0,
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_ST_REQUEST,
		ldap_back_cf_gen, "( OLcfgDbAt:3.24 "
			"NAME 'olcDbSessionTrackingRequest' "
			"DESC 'Add session tracking control to proxied requests' "
255
			"EQUALITY booleanMatch "
256
257
258
259
			"SYNTAX OMsBoolean "
			"SINGLE-VALUE )",
		NULL, NULL },
#endif /* SLAP_CONTROL_X_SESSION_TRACKING */
260
261
262
	{ "norefs", "true|FALSE", 2, 2, 0,
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOREFS,
		ldap_back_cf_gen, "( OLcfgDbAt:3.25 "
263
			"NAME 'olcDbNoRefs' "
264
			"DESC 'Do not return search reference responses' "
265
			"EQUALITY booleanMatch "
266
267
268
			"SYNTAX OMsBoolean "
			"SINGLE-VALUE )",
		NULL, NULL },
269
270
271
272
273
	{ "noundeffilter", "true|FALSE", 2, 2, 0,
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOUNDEFFILTER,
		ldap_back_cf_gen, "( OLcfgDbAt:3.26 "
			"NAME 'olcDbNoUndefFilter' "
			"DESC 'Do not propagate undefined search filters' "
274
			"EQUALITY booleanMatch "
275
276
277
			"SYNTAX OMsBoolean "
			"SINGLE-VALUE )",
		NULL, NULL },
278
279
280
281
282
	{ "onerr", "CONTINUE|report|stop", 2, 2, 0,
		ARG_MAGIC|LDAP_BACK_CFG_ONERR,
		ldap_back_cf_gen, "( OLcfgDbAt:3.108 "
			"NAME 'olcDbOnErr' "
			"DESC 'error handling' "
283
			"EQUALITY caseIgnoreMatch "
284
285
286
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
287
288
289
290
291
292
293
294
295
	{ "idassert-passThru", "authzRule", 2, 2, 0,
		ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSTHRU,
		ldap_back_cf_gen, "( OLcfgDbAt:3.27 "
			"NAME 'olcDbIDAssertPassThru' "
			"DESC 'Remote Identity Assertion passthru rules' "
			"EQUALITY caseIgnoreMatch "
			"SYNTAX OMsDirectoryString "
			"X-ORDERED 'VALUES' )",
		NULL, NULL },
296
297
298
299
300
	{ "omit-unknown-schema", "true|FALSE", 2, 2, 0,
		ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA,
		ldap_back_cf_gen, "( OLcfgDbAt:3.28 "
			"NAME 'olcDbRemoveUnknownSchema' "
			"DESC 'Omit unknown schema when returning search results' "
301
			"EQUALITY booleanMatch "
302
303
304
			"SYNTAX OMsBoolean "
			"SINGLE-VALUE )",
		NULL, NULL },
305
306
307
308
309
	{ "keepalive", "keepalive", 2, 2, 0,
		ARG_MAGIC|LDAP_BACK_CFG_KEEPALIVE,
		ldap_back_cf_gen, "( OLcfgDbAt:3.29 "
			"NAME 'olcDbKeepalive' "
			"DESC 'TCP keepalive' "
310
			"EQUALITY caseIgnoreMatch "
311
312
313
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
314
315
316
317
318
319
320
321
	{ "tcp-user-timeout", "milliseconds", 2, 2, 0,
		ARG_MAGIC|ARG_UINT|LDAP_BACK_CFG_TCP_USER_TIMEOUT,
		ldap_back_cf_gen, "( OLcfgDbAt:3.30 "
			"NAME 'olcDbTcpUserTimeout' "
			"DESC 'TCP User Timeout' "
			"SYNTAX OMsInteger "
			"SINGLE-VALUE )",
		NULL, NULL },
322
323
324
325
326
327
328
329
330
	{ NULL, NULL, 0, 0, 0, ARG_IGNORED,
		NULL, NULL, NULL, NULL }
};

static ConfigOCs ldapocs[] = {
	{ "( OLcfgDbOc:3.1 "
		"NAME 'olcLDAPConfig' "
		"DESC 'LDAP backend configuration' "
		"SUP olcDatabaseConfig "
331
332
		"MAY ( olcDbURI "
			"$ olcDbStartTLS "
333
334
			"$ olcDbACLBind "
			"$ olcDbIDAssertBind "
335
			"$ olcDbIDAssertAuthzFrom "
336
			"$ olcDbIDAssertPassThru "
337
338
339
340
			"$ olcDbRebindAsUser "
			"$ olcDbChaseReferrals "
			"$ olcDbTFSupport "
			"$ olcDbProxyWhoAmI "
341
			"$ olcDbTimeout "
342
			"$ olcDbIdleTimeout "
343
344
345
			"$ olcDbConnTtl "
			"$ olcDbNetworkTimeout "
			"$ olcDbProtocolVersion "
346
			"$ olcDbSingleConn "
347
			"$ olcDbCancel "
348
			"$ olcDbQuarantine "
Pierangelo Masarati's avatar
Pierangelo Masarati committed
349
			"$ olcDbUseTemporaryConn "
350
			"$ olcDbConnectionPoolMax "
351
352
353
#ifdef SLAP_CONTROL_X_SESSION_TRACKING
			"$ olcDbSessionTrackingRequest "
#endif /* SLAP_CONTROL_X_SESSION_TRACKING */
354
355
			"$ olcDbNoRefs "
			"$ olcDbNoUndefFilter "
356
			"$ olcDbOnErr "
357
			"$ olcDbKeepalive "
358
359
360
361
362
		") )",
		 	Cft_Database, ldapcfg},
	{ NULL, 0, NULL }
};

363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
static ConfigTable pbindcfg[] = {
	{ "uri", "uri", 2, 2, 0,
		ARG_MAGIC|LDAP_BACK_CFG_URI,
		ldap_pbind_cf_gen, "( OLcfgDbAt:0.14 "
			"NAME 'olcDbURI' "
			"DESC 'URI (list) for remote DSA' "
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
	{ "tls", "what", 2, 0, 0,
		ARG_MAGIC|LDAP_BACK_CFG_TLS,
		ldap_pbind_cf_gen, "( OLcfgDbAt:3.1 "
			"NAME 'olcDbStartTLS' "
			"DESC 'StartTLS' "
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
	{ "network-timeout", "timeout", 2, 2, 0,
		ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
		ldap_pbind_cf_gen, "( OLcfgDbAt:3.17 "
			"NAME 'olcDbNetworkTimeout' "
			"DESC 'connection network timeout' "
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
	{ "quarantine", "retrylist", 2, 2, 0,
		ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
		ldap_pbind_cf_gen, "( OLcfgDbAt:3.21 "
			"NAME 'olcDbQuarantine' "
			"DESC 'Quarantine database if connection fails and retry according to rule' "
			"SYNTAX OMsDirectoryString "
			"SINGLE-VALUE )",
		NULL, NULL },
	{ NULL, NULL, 0, 0, 0, ARG_IGNORED,
		NULL, NULL, NULL, NULL }
};

static ConfigOCs pbindocs[] = {
	{ "( OLcfgOvOc:3.3 "
		"NAME 'olcPBindConfig' "
		"DESC 'Proxy Bind configuration' "
		"SUP olcOverlayConfig "
		"MUST olcDbURI "
		"MAY ( olcDbStartTLS "
			"$ olcDbNetworkTimeout "
			"$ olcDbQuarantine "
		") )",
		 	Cft_Overlay, pbindcfg},
	{ NULL, 0, NULL }
};

414
415
416
417
static slap_verbmasks idassert_mode[] = {
	{ BER_BVC("self"),		LDAP_BACK_IDASSERT_SELF },
	{ BER_BVC("anonymous"),		LDAP_BACK_IDASSERT_ANONYMOUS },
	{ BER_BVC("none"),		LDAP_BACK_IDASSERT_NOASSERT },
418
	{ BER_BVC("legacy"),		LDAP_BACK_IDASSERT_LEGACY },
419
420
421
422
	{ BER_BVNULL,			0 }
};

static slap_verbmasks tls_mode[] = {
423
424
425
426
	{ BER_BVC( "propagate" ),	LDAP_BACK_F_TLS_PROPAGATE_MASK },
	{ BER_BVC( "try-propagate" ),	LDAP_BACK_F_PROPAGATE_TLS },
	{ BER_BVC( "start" ),		LDAP_BACK_F_TLS_USE_MASK },
	{ BER_BVC( "try-start" ),	LDAP_BACK_F_USE_TLS },
Howard Chu's avatar
Howard Chu committed
427
	{ BER_BVC( "ldaps" ),		LDAP_BACK_F_TLS_LDAPS },
428
	{ BER_BVC( "none" ),		LDAP_BACK_F_NONE },
429
430
431
432
	{ BER_BVNULL,			0 }
};

static slap_verbmasks t_f_mode[] = {
433
434
	{ BER_BVC( "yes" ),		LDAP_BACK_F_T_F },
	{ BER_BVC( "discover" ),	LDAP_BACK_F_T_F_DISCOVER },
435
	{ BER_BVC( "no" ),		LDAP_BACK_F_NONE },
436
437
438
	{ BER_BVNULL,			0 }
};

439
440
441
442
443
444
445
446
static slap_verbmasks cancel_mode[] = {
	{ BER_BVC( "ignore" ),		LDAP_BACK_F_CANCEL_IGNORE },
	{ BER_BVC( "exop" ),		LDAP_BACK_F_CANCEL_EXOP },
	{ BER_BVC( "exop-discover" ),	LDAP_BACK_F_CANCEL_EXOP_DISCOVER },
	{ BER_BVC( "abandon" ),		LDAP_BACK_F_CANCEL_ABANDON },
	{ BER_BVNULL,			0 }
};

447
448
449
450
451
452
453
static slap_verbmasks onerr_mode[] = {
	{ BER_BVC( "stop" ),		LDAP_BACK_F_ONERR_STOP },
	{ BER_BVC( "report" ),		LDAP_BACK_F_ONERR_STOP }, /* same behavior */
	{ BER_BVC( "continue" ),	LDAP_BACK_F_NONE },
	{ BER_BVNULL,			0 }
};

454
/* see enum in slap.h */
455
static slap_cf_aux_table timeout_table[] = {
456
457
458
459
460
461
462
463
464
465
466
467
	{ BER_BVC("bind="),	SLAP_OP_BIND * sizeof( time_t ),	'u', 0, NULL },
	/* unbind makes no sense */
	{ BER_BVC("add="),	SLAP_OP_ADD * sizeof( time_t ),		'u', 0, NULL },
	{ BER_BVC("delete="),	SLAP_OP_DELETE * sizeof( time_t ),	'u', 0, NULL },
	{ BER_BVC("modrdn="),	SLAP_OP_MODRDN * sizeof( time_t ),	'u', 0, NULL },
	{ BER_BVC("modify="),	SLAP_OP_MODIFY * sizeof( time_t ),	'u', 0, NULL },
	{ BER_BVC("compare="),	SLAP_OP_COMPARE * sizeof( time_t ),	'u', 0, NULL },
	{ BER_BVC("search="),	SLAP_OP_SEARCH * sizeof( time_t ),	'u', 0, NULL },
	/* abandon makes little sense */
#if 0	/* not implemented yet */
	{ BER_BVC("extended="),	SLAP_OP_EXTENDED * sizeof( time_t ),	'u', 0, NULL },
#endif
468
469
470
	{ BER_BVNULL, 0, 0, 0, NULL }
};

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
int
slap_retry_info_parse(
	char			*in,
	slap_retry_info_t 	*ri,
	char			*buf,
	ber_len_t		buflen )
{
	char			**retrylist = NULL;
	int			rc = 0;
	int			i;

	slap_str2clist( &retrylist, in, " ;" );
	if ( retrylist == NULL ) {
		return 1;
	}

	for ( i = 0; retrylist[ i ] != NULL; i++ )
		/* count */ ;

	ri->ri_interval = ch_calloc( sizeof( time_t ), i + 1 );
	ri->ri_num = ch_calloc( sizeof( int ), i + 1 );

	for ( i = 0; retrylist[ i ] != NULL; i++ ) {
494
495
		unsigned long	t;
		char		*sep = strchr( retrylist[ i ], ',' );
496
497
498
499
500
501
502
503
504
505
506

		if ( sep == NULL ) {
			snprintf( buf, buflen,
				"missing comma in retry pattern #%d \"%s\"",
				i, retrylist[ i ] );
			rc = 1;
			goto done;
		}

		*sep++ = '\0';

507
		if ( lutil_parse_time( retrylist[ i ], &t ) ) {
508
509
510
511
512
513
			snprintf( buf, buflen,
				"unable to parse interval #%d \"%s\"",
				i, retrylist[ i ] );
			rc = 1;
			goto done;
		}
514
		ri->ri_interval[ i ] = (time_t)t;
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558

		if ( strcmp( sep, "+" ) == 0 ) {
			if ( retrylist[ i + 1 ] != NULL ) {
				snprintf( buf, buflen,
					"extra cruft after retry pattern "
					"#%d \"%s,+\" with \"forever\" mark",
					i, retrylist[ i ] );
				rc = 1;
				goto done;
			}
			ri->ri_num[ i ] = SLAP_RETRYNUM_FOREVER;
			
		} else if ( lutil_atoi( &ri->ri_num[ i ], sep ) ) {
			snprintf( buf, buflen,
				"unable to parse retry num #%d \"%s\"",
				i, sep );
			rc = 1;
			goto done;
		}
	}

	ri->ri_num[ i ] = SLAP_RETRYNUM_TAIL;

	ri->ri_idx = 0;
	ri->ri_count = 0;
	ri->ri_last = (time_t)(-1);

done:;
	ldap_charray_free( retrylist );

	if ( rc ) {
		slap_retry_info_destroy( ri );
	}

	return rc;
}

int
slap_retry_info_unparse(
	slap_retry_info_t	*ri,
	struct berval		*bvout )
{
	char		buf[ BUFSIZ * 2 ],
			*ptr = buf;
559
560
	int		i, len, restlen = (int) sizeof( buf );
	struct berval	bv;
561
562
563
564
565
566
567
568

	assert( ri != NULL );
	assert( bvout != NULL );

	BER_BVZERO( bvout );

	for ( i = 0; ri->ri_num[ i ] != SLAP_RETRYNUM_TAIL; i++ ) {
		if ( i > 0 ) {
569
			if ( --restlen <= 0 ) {
570
571
572
573
574
				return 1;
			}
			*ptr++ = ';';
		}

575
		if ( lutil_unparse_time( ptr, restlen, ri->ri_interval[i] ) < 0 ) {
576
577
			return 1;
		}
578
579
		len = (int) strlen( ptr );
		if ( (restlen -= len + 1) <= 0 ) {
580
581
			return 1;
		}
582
		ptr += len;
583
		*ptr++ = ',';
584
585

		if ( ri->ri_num[i] == SLAP_RETRYNUM_FOREVER ) {
586
			if ( --restlen <= 0 ) {
587
588
589
590
591
				return 1;
			}
			*ptr++ = '+';

		} else {
592
593
			len = snprintf( ptr, restlen, "%d", ri->ri_num[i] );
			if ( (restlen -= len) <= 0 || len < 0 ) {
594
595
				return 1;
			}
596
			ptr += len;
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
		}
	}

	bv.bv_val = buf;
	bv.bv_len = ptr - buf;
	ber_dupbv( bvout, &bv );

	return 0;
}

void
slap_retry_info_destroy(
	slap_retry_info_t	*ri )
{
	assert( ri != NULL );

	assert( ri->ri_interval != NULL );
	ch_free( ri->ri_interval );
	ri->ri_interval = NULL;

	assert( ri->ri_num != NULL );
	ch_free( ri->ri_num );
	ri->ri_num = NULL;
}

622
int
623
624
625
626
627
628
slap_idassert_authzfrom_parse( ConfigArgs *c, slap_idassert_t *si )
{
	struct berval	bv;
	struct berval	in;
	int		rc;

629
630
631
632
633
 	if ( strcmp( c->argv[ 1 ], "*" ) == 0
 		|| strcmp( c->argv[ 1 ], "dn:*" ) == 0
 		|| strcasecmp( c->argv[ 1 ], "dn.regex:.*" ) == 0 )
 	{
 		if ( si->si_authz != NULL ) {
634
 			snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
635
 				"\"%s <authz>\": "
636
 				"\"%s\" conflicts with existing authz rules",
Howard Chu's avatar
Howard Chu committed
637
 				c->argv[ 0 ], c->argv[ 1 ] );
638
			Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
639
640
641
642
643
644
645
646
 			return 1;
 		}
 
 		si->si_flags |= LDAP_BACK_AUTH_AUTHZ_ALL;
 
 		return 0;
 
 	} else if ( ( si->si_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) {
647
  		snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
648
649
  			"\"%s <authz>\": "
 			"\"<authz>\" conflicts with \"*\"", c->argv[0] );
650
		Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
651
652
653
654
655
656
  		return 1;
  	}
 	
 	ber_str2bv( c->argv[ 1 ], 0, 0, &in );
 	rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
 	if ( rc != LDAP_SUCCESS ) {
657
 		snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
658
659
 			"\"%s <authz>\": "
 			"invalid syntax", c->argv[0] );
660
		Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
661
662
 		return 1;
 	}
663
664
665
666
667

	if ( c->valx == -1 ) {
		ber_bvarray_add( &si->si_authz, &bv );

	} else {
Pierangelo Masarati's avatar
Pierangelo Masarati committed
668
669
670
671
672
		int i = 0;
		if ( si->si_authz != NULL ) {
			for ( ; !BER_BVISNULL( &si->si_authz[ i ] ); i++ )
				;
		}
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

		if ( i <= c->valx ) {
			ber_bvarray_add( &si->si_authz, &bv );

		} else {
			BerVarray tmp = ber_memrealloc( si->si_authz,
				sizeof( struct berval )*( i + 2 ) );
			if ( tmp == NULL ) {
				return -1;
			}
			si->si_authz = tmp;
			for ( ; i > c->valx; i-- ) {
				si->si_authz[ i ] = si->si_authz[ i - 1 ];
			}
			si->si_authz[ c->valx ] = bv;
		}
	}

	return 0;
}

static int
slap_idassert_passthru_parse( ConfigArgs *c, slap_idassert_t *si )
{
	struct berval	bv;
	struct berval	in;
	int		rc;

 	ber_str2bv( c->argv[ 1 ], 0, 0, &in );
 	rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
 	if ( rc != LDAP_SUCCESS ) {
 		snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
705
706
 			"\"%s <authz>\": "
 			"invalid syntax", c->argv[0] );
707
		Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
708
709
 		return 1;
 	}
710
  
711
712
713
714
	if ( c->valx == -1 ) {
		ber_bvarray_add( &si->si_passthru, &bv );

	} else {
Pierangelo Masarati's avatar
Pierangelo Masarati committed
715
716
717
718
719
		int i = 0;
		if ( si->si_passthru != NULL ) {
			for ( ; !BER_BVISNULL( &si->si_passthru[ i ] ); i++ )
				;
		}
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736

		if ( i <= c->valx ) {
			ber_bvarray_add( &si->si_passthru, &bv );

		} else {
			BerVarray tmp = ber_memrealloc( si->si_passthru,
				sizeof( struct berval )*( i + 2 ) );
			if ( tmp == NULL ) {
				return -1;
			}
			si->si_passthru = tmp;
			for ( ; i > c->valx; i-- ) {
				si->si_passthru[ i ] = si->si_passthru[ i - 1 ];
			}
			si->si_passthru[ c->valx ] = bv;
		}
	}
737
738
739
740

	return 0;
}

741
int
742
743
744
745
slap_idassert_parse( ConfigArgs *c, slap_idassert_t *si )
{
	int		i;

746
747
748
	/* set default */
	si->si_mode = LDAP_BACK_IDASSERT_LEGACY;

749
750
751
752
753
754
755
	for ( i = 1; i < c->argc; i++ ) {
		if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
			char	*argvi = c->argv[ i ] + STRLENOF( "mode=" );
			int	j;

			j = verb_to_mask( argvi, idassert_mode );
			if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
756
				snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
757
					"\"%s <args>\": "
758
					"unknown mode \"%s\"",
Howard Chu's avatar
Howard Chu committed
759
					c->argv[0], argvi );
760
				Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
761
762
763
764
765
766
767
768
769
770
				return 1;
			}

			si->si_mode = idassert_mode[ j ].mask;

		} else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
			char	*argvi = c->argv[ i ] + STRLENOF( "authz=" );

			if ( strcasecmp( argvi, "native" ) == 0 ) {
				if ( si->si_bc.sb_method != LDAP_AUTH_SASL ) {
771
					snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
772
						"\"%s <args>\": "
773
						"authz=\"native\" incompatible "
Howard Chu's avatar
Howard Chu committed
774
						"with auth method", c->argv[0] );
775
					Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
776
777
778
779
780
781
782
783
					return 1;
				}
				si->si_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;

			} else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
				si->si_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;

			} else {
784
				snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
785
					"\"%s <args>\": "
786
					"unknown authz \"%s\"",
Howard Chu's avatar
Howard Chu committed
787
					c->argv[0], argvi );
788
				Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
789
790
791
792
793
794
795
796
797
				return 1;
			}

		} else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
			char	*argvi = c->argv[ i ] + STRLENOF( "flags=" );
			char	**flags = ldap_str2charray( argvi, "," );
			int	j, err = 0;

			if ( flags == NULL ) {
798
				snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
799
					"\"%s <args>\": "
800
					"unable to parse flags \"%s\"",
Howard Chu's avatar
Howard Chu committed
801
					c->argv[0], argvi );
802
				Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
				return 1;
			}

			for ( j = 0; flags[ j ] != NULL; j++ ) {

				if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
					si->si_flags |= LDAP_BACK_AUTH_OVERRIDE;

				} else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
					si->si_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;

				} else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
					si->si_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );

				} else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) {
					if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
Howard Chu's avatar
Howard Chu committed
819
820
821
822
823
						snprintf( c->cr_msg, sizeof( c->cr_msg ),
							"\"%s <args>\": "
							"\"obsolete-proxy-authz\" flag "
							"incompatible with previously issued \"obsolete-encoding-workaround\" flag.",
							c->argv[0] );
824
						Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
825
826
827
828
829
830
831
832
833
						err = 1;
						break;

					} else {
						si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
					}

				} else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
					if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
Howard Chu's avatar
Howard Chu committed
834
835
836
837
838
						snprintf( c->cr_msg, sizeof( c->cr_msg ),
							"\"%s <args>\": "
							"\"obsolete-encoding-workaround\" flag "
							"incompatible with previously issued \"obsolete-proxy-authz\" flag.",
							c->argv[0] );
839
						Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
840
841
842
843
844
845
846
						err = 1;
						break;

					} else {
						si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
					}

847
848
849
850
851
852
				} else if ( strcasecmp( flags[ j ], "proxy-authz-critical" ) == 0 ) {
					si->si_flags |= LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;

				} else if ( strcasecmp( flags[ j ], "proxy-authz-non-critical" ) == 0 ) {
					si->si_flags &= ~LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;

853
854
855
856
857
858
859
860
861
862
863
				} else if ( strcasecmp( flags[ j ], "dn-none" ) == 0 ) {
					si->si_flags &= ~LDAP_BACK_AUTH_DN_MASK;

				} else if ( strcasecmp( flags[ j ], "dn-authzid" ) == 0 ) {
					si->si_flags &= ~LDAP_BACK_AUTH_DN_MASK;
					si->si_flags |= LDAP_BACK_AUTH_DN_AUTHZID;

				} else if ( strcasecmp( flags[ j ], "dn-whoami" ) == 0 ) {
					si->si_flags &= ~LDAP_BACK_AUTH_DN_MASK;
					si->si_flags |= LDAP_BACK_AUTH_DN_WHOAMI;

864
				} else {
865
					snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
866
						"\"%s <args>\": "
867
						"unknown flag \"%s\"",
Howard Chu's avatar
Howard Chu committed
868
						c->argv[0], flags[ j ] );
869
					Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
870
871
872
873
874
875
876
877
878
879
880
					err = 1;
					break;
				}
			}

			ldap_charray_free( flags );
			if ( err ) {
				return 1;
			}

		} else if ( bindconf_parse( c->argv[ i ], &si->si_bc ) ) {
881
			snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
882
				"\"%s <args>\": "
883
				"unable to parse field \"%s\"",
Howard Chu's avatar
Howard Chu committed
884
				c->argv[0], c->argv[ i ] );
885
			Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
886
887
888
			return 1;
		}
	}
889
890
891
892
893
894

	if ( si->si_bc.sb_method == LDAP_AUTH_SIMPLE ) {
		if ( BER_BVISNULL( &si->si_bc.sb_binddn )
			|| BER_BVISNULL( &si->si_bc.sb_cred ) )
		{
			snprintf( c->cr_msg, sizeof( c->cr_msg ),
Howard Chu's avatar
Howard Chu committed
895
896
				"\"%s <args>\": "
				"SIMPLE needs \"binddn\" and \"credentials\"", c->argv[0] );
897
			Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
898
899
			return 1;
		}
900
901
902
903
904

	} else if ( si->si_bc.sb_method == LDAP_AUTH_SASL ) {
		if ( BER_BVISNULL( &si->si_bc.sb_binddn ) &&
			!(si->si_flags & LDAP_BACK_AUTH_DN_MASK) )
		{
Pierangelo Masarati's avatar
Pierangelo Masarati committed
905
906
			static struct berval authid = BER_BVC("cn=auth");
			ber_dupbv( &si->si_bc.sb_binddn, &authid );
907
		}
908
909
	}

Howard Chu's avatar
Howard Chu committed
910
	bindconf_tls_defaults( &si->si_bc );
Howard Chu's avatar
Howard Chu committed
911
#ifdef HAVE_TLS
912
913
914
915
	if ( si->si_bc.sb_tls_ctx ) {
		ldap_pvt_tls_ctx_free( si->si_bc.sb_tls_ctx );
		si->si_bc.sb_tls_ctx = NULL;
	}
Howard Chu's avatar
Howard Chu committed
916
#endif
917
918
919
920
921

	return 0;
}

/* NOTE: temporary, until back-meta is ported to back-config */
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
int
slap_idassert_passthru_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si )
{
	ConfigArgs	c = { 0 };
	char		*argv[ 3 ];

	snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
	c.argc = 2;
	c.argv = argv;
	argv[ 0 ] = "idassert-passThru";
	argv[ 1 ] = (char *)arg;
	argv[ 2 ] = NULL;

	return slap_idassert_passthru_parse( &c, si );
}

938
939
940
static int
ldap_back_cf_gen( ConfigArgs *c )
{
941
	ldapinfo_t	*li = ( ldapinfo_t * )c->be->be_private;
942
	int		rc = 0;
943
944
945
	int		i;

	if ( c->op == SLAP_CONFIG_EMIT ) {
946
947
		struct berval	bv = BER_BVNULL;

948
949
950
951
		if ( li == NULL ) {
			return 1;
		}

952
953
		switch( c->type ) {
		case LDAP_BACK_CFG_URI:
954
			if ( li->li_uri != NULL ) {
955
				struct berval	bv, bv2;
Pierangelo Masarati's avatar
Pierangelo Masarati committed
956
957

				ber_str2bv( li->li_uri, 0, 0, &bv );
958
959
960
961
962
				bv2.bv_len = bv.bv_len + STRLENOF( "\"\"" );
				bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
				snprintf( bv2.bv_val, bv2.bv_len + 1,
					"\"%s\"", bv.bv_val );
				ber_bvarray_add( &c->rvalue_vals, &bv2 );
963
964
965
966
967
968

			} else {
				rc = 1;
			}
			break;

Howard Chu's avatar
Howard Chu committed
969
970
		case LDAP_BACK_CFG_TLS: {
			struct berval bc = BER_BVNULL, bv2;
971
			enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv );
972
			assert( !BER_BVISNULL( &bv ) );
Howard Chu's avatar
Howard Chu committed
973
974
975
976
			bindconf_tls_unparse( &li->li_tls, &bc );

			if ( !BER_BVISEMPTY( &bc )) {
				bv2.bv_len = bv.bv_len + bc.bv_len + 1;
Pierangelo Masarati's avatar
Pierangelo Masarati committed
977
				bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
Howard Chu's avatar
Howard Chu committed
978
979
				strcpy( bv2.bv_val, bv.bv_val );
				bv2.bv_val[bv.bv_len] = ' ';
Pierangelo Masarati's avatar
Pierangelo Masarati committed
980
				strcpy( &bv2.bv_val[bv.bv_len + 1], bc.bv_val );
Howard Chu's avatar
Howard Chu committed
981
				ber_bvarray_add( &c->rvalue_vals, &bv2 );
Pierangelo Masarati's avatar
Pierangelo Masarati committed
982

Howard Chu's avatar
Howard Chu committed
983
984
985
			} else {
				value_add_one( &c->rvalue_vals, &bv );
			}
Pierangelo Masarati's avatar
Pierangelo Masarati committed
986
			ber_memfree( bc.bv_val );
Howard Chu's avatar
Howard Chu committed
987
			}
988
989
			break;

990
		case LDAP_BACK_CFG_ACL_BIND: {
991
992
			int	i;

993
994
995
996
			if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) {
				return 1;
			}

997
			bindconf_unparse( &li->li_acl, &bv );
998

999
			for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1000
1001
1002
				/* count spaces */ ;

			if ( i ) {
1003
1004
1005
				bv.bv_len -= i;
				AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
					bv.bv_len + 1 );
1006
			}
1007

1008
			ber_bvarray_add( &c->rvalue_vals, &bv );
1009
1010
1011
			break;
		}

1012
1013
1014
		case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
		case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
			BerVarray	*bvp;
1015
			int		i;
1016
1017
			struct berval	bv = BER_BVNULL;
			char		buf[SLAP_TEXT_BUFLEN];
1018

1019
1020
1021
1022
1023
1024
1025
			switch ( c->type ) {
			case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
			case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
			default: assert( 0 ); break;
			}

			if ( *bvp == NULL ) {
Pierangelo Masarati's avatar
Pierangelo Masarati committed
1026
				if ( bvp == &li->li_idassert_authz
1027
1028
					&& ( li->li_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
				{
1029
1030
1031
1032
1033
1034
					BER_BVSTR( &bv, "*" );
					value_add_one( &c->rvalue_vals, &bv );

				} else {
					rc = 1;
				}
1035
1036
1037
				break;
			}

1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
			for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ ) {
				char *ptr;
				int len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
				bv.bv_len = ((*bvp)[ i ]).bv_len + len;
				bv.bv_val = ber_memrealloc( bv.bv_val, bv.bv_len + 1 );
				ptr = bv.bv_val;
				ptr = lutil_strcopy( ptr, buf );
				ptr = lutil_strncopy( ptr, ((*bvp)[ i ]).bv_val, ((*bvp)[ i ]).bv_len );
				value_add_one( &c->rvalue_vals, &bv );
			}
			if ( bv.bv_val ) {
				ber_memfree( bv.bv_val );
1050
1051
1052
1053
			}
			break;
		}

1054
1055
		case LDAP_BACK_CFG_IDASSERT_BIND: {
			int		i;
1056
			struct berval	bc = BER_BVNULL;
1057
			char		*ptr;
1058

1059
1060
1061
1062
			if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) {
				return 1;
			}

1063
			if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) {
Pierangelo Masarati's avatar
Pierangelo Masarati committed
1064
				ber_len_t	len;
1065

1066
				switch ( li->li_idassert_mode ) {
1067
1068
1069
1070
1071
				case LDAP_BACK_IDASSERT_OTHERID:
				case LDAP_BACK_IDASSERT_OTHERDN:
					break;

				default: {
1072
1073
					struct berval	mode = BER_BVNULL;

1074
					enum_to_verb( idassert_mode, li->li_idassert_mode, &mode );
1075
					if ( BER_BVISNULL( &mode ) ) {
1076
1077
1078
1079
1080
						/* there's something wrong... */
						assert( 0 );
						rc = 1;
	
					} else {
1081
1082
1083
1084
1085
						bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
						bv.bv_val = ch_malloc( bv.bv_len + 1 );

						ptr = lutil_strcopy( bv.bv_val, "mode=" );
						ptr = lutil_strcopy( ptr, mode.bv_val );
1086
1087
1088
1089
					}
					break;
				}
				}
1090

1091
				if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
Pierangelo Masarati's avatar
Pierangelo Masarati committed
1092
					len = bv.bv_len + STRLENOF( "authz=native" );
1093
1094
1095
1096
1097
1098
1099

					if ( !BER_BVISEMPTY( &bv ) ) {
						len += STRLENOF( " " );
					}

					bv.bv_val = ch_realloc( bv.bv_val, len + 1 );