1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
3*0Sstevel@tonic-gate * Use is subject to license terms.
4*0Sstevel@tonic-gate */
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gate /*
9*0Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
10*0Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
11*0Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
12*0Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
15*0Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16*0Sstevel@tonic-gate * implied. See the License for the specific language governing
17*0Sstevel@tonic-gate * rights and limitations under the License.
18*0Sstevel@tonic-gate *
19*0Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
20*0Sstevel@tonic-gate * March 31, 1998.
21*0Sstevel@tonic-gate *
22*0Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
23*0Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
24*0Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25*0Sstevel@tonic-gate * Rights Reserved.
26*0Sstevel@tonic-gate *
27*0Sstevel@tonic-gate * Contributor(s):
28*0Sstevel@tonic-gate */
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate * setoption.c - ldap_set_option implementation
31*0Sstevel@tonic-gate */
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate #include "ldap-int.h"
34*0Sstevel@tonic-gate #ifdef _SOLARIS_SDK
35*0Sstevel@tonic-gate #include "solaris-priv.h"
36*0Sstevel@tonic-gate #endif
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate extern int nsldapi_sasl_secprops(const char *in,
39*0Sstevel@tonic-gate sasl_security_properties_t *secprops);
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate #define LDAP_SETCLR_BITOPT(ld, bit, optdata) \
42*0Sstevel@tonic-gate if (optdata != NULL) { \
43*0Sstevel@tonic-gate (ld)->ld_options |= bit; \
44*0Sstevel@tonic-gate } else { \
45*0Sstevel@tonic-gate (ld)->ld_options &= ~bit; \
46*0Sstevel@tonic-gate }
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate int
50*0Sstevel@tonic-gate LDAP_CALL
ldap_set_option(LDAP * ld,int option,const void * optdata)51*0Sstevel@tonic-gate ldap_set_option(LDAP *ld, int option, const void *optdata)
52*0Sstevel@tonic-gate {
53*0Sstevel@tonic-gate int rc, i;
54*0Sstevel@tonic-gate char *matched, *errstr;
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate if (!nsldapi_initialized) {
57*0Sstevel@tonic-gate nsldapi_initialize_defaults();
58*0Sstevel@tonic-gate }
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate /*
61*0Sstevel@tonic-gate * process global options (not associated with an LDAP session handle)
62*0Sstevel@tonic-gate */
63*0Sstevel@tonic-gate if (option == LDAP_OPT_MEMALLOC_FN_PTRS) {
64*0Sstevel@tonic-gate struct lber_memalloc_fns memalloc_fns;
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate /* set libldap ones via a struct copy */
67*0Sstevel@tonic-gate nsldapi_memalloc_fns = *((struct ldap_memalloc_fns *)optdata);
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate /* also set liblber memory allocation callbacks */
70*0Sstevel@tonic-gate memalloc_fns.lbermem_malloc =
71*0Sstevel@tonic-gate nsldapi_memalloc_fns.ldapmem_malloc;
72*0Sstevel@tonic-gate memalloc_fns.lbermem_calloc =
73*0Sstevel@tonic-gate nsldapi_memalloc_fns.ldapmem_calloc;
74*0Sstevel@tonic-gate memalloc_fns.lbermem_realloc =
75*0Sstevel@tonic-gate nsldapi_memalloc_fns.ldapmem_realloc;
76*0Sstevel@tonic-gate memalloc_fns.lbermem_free =
77*0Sstevel@tonic-gate nsldapi_memalloc_fns.ldapmem_free;
78*0Sstevel@tonic-gate if (ber_set_option(NULL, LBER_OPT_MEMALLOC_FN_PTRS,
79*0Sstevel@tonic-gate &memalloc_fns) != 0) {
80*0Sstevel@tonic-gate return (-1);
81*0Sstevel@tonic-gate }
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate return (0);
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate /*
86*0Sstevel@tonic-gate * LDAP_OPT_DEBUG_LEVEL is global
87*0Sstevel@tonic-gate */
88*0Sstevel@tonic-gate if (LDAP_OPT_DEBUG_LEVEL == option) {
89*0Sstevel@tonic-gate #ifdef LDAP_DEBUG
90*0Sstevel@tonic-gate ldap_debug = *((int *)optdata);
91*0Sstevel@tonic-gate #endif
92*0Sstevel@tonic-gate return (0);
93*0Sstevel@tonic-gate }
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate /*
96*0Sstevel@tonic-gate * if ld is NULL, arrange to modify our default settings
97*0Sstevel@tonic-gate */
98*0Sstevel@tonic-gate if (ld == NULL) {
99*0Sstevel@tonic-gate ld = &nsldapi_ld_defaults;
100*0Sstevel@tonic-gate #ifdef LDAP_DEBUG
101*0Sstevel@tonic-gate ldap_debug = 0;
102*0Sstevel@tonic-gate #endif
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate }
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate /*
107*0Sstevel@tonic-gate * process options that are associated with an LDAP session handle
108*0Sstevel@tonic-gate */
109*0Sstevel@tonic-gate if (!NSLDAPI_VALID_LDAP_POINTER(ld)) {
110*0Sstevel@tonic-gate return (-1); /* punt */
111*0Sstevel@tonic-gate }
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate rc = 0;
114*0Sstevel@tonic-gate if (ld != &nsldapi_ld_defaults &&
115*0Sstevel@tonic-gate option != LDAP_OPT_EXTRA_THREAD_FN_PTRS &&
116*0Sstevel@tonic-gate option != LDAP_OPT_THREAD_FN_PTRS) {
117*0Sstevel@tonic-gate LDAP_MUTEX_LOCK(ld, LDAP_OPTION_LOCK);
118*0Sstevel@tonic-gate }
119*0Sstevel@tonic-gate switch (option) {
120*0Sstevel@tonic-gate /* options that can be turned on and off */
121*0Sstevel@tonic-gate #ifdef LDAP_DNS
122*0Sstevel@tonic-gate case LDAP_OPT_DNS:
123*0Sstevel@tonic-gate LDAP_SETCLR_BITOPT(ld, LDAP_BITOPT_DNS, optdata);
124*0Sstevel@tonic-gate break;
125*0Sstevel@tonic-gate #endif
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate case LDAP_OPT_REFERRALS:
128*0Sstevel@tonic-gate LDAP_SETCLR_BITOPT(ld, LDAP_BITOPT_REFERRALS, optdata);
129*0Sstevel@tonic-gate break;
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate #ifdef LDAP_SSLIO_HOOKS
132*0Sstevel@tonic-gate case LDAP_OPT_SSL:
133*0Sstevel@tonic-gate LDAP_SETCLR_BITOPT(ld, LDAP_BITOPT_SSL, optdata);
134*0Sstevel@tonic-gate break;
135*0Sstevel@tonic-gate #endif
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate case LDAP_OPT_RESTART:
138*0Sstevel@tonic-gate LDAP_SETCLR_BITOPT(ld, LDAP_BITOPT_RESTART, optdata);
139*0Sstevel@tonic-gate break;
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate case LDAP_OPT_RECONNECT:
142*0Sstevel@tonic-gate LDAP_SETCLR_BITOPT(ld, LDAP_BITOPT_RECONNECT, optdata);
143*0Sstevel@tonic-gate break;
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate #ifdef LDAP_ASYNC_IO
146*0Sstevel@tonic-gate case LDAP_OPT_ASYNC_CONNECT:
147*0Sstevel@tonic-gate LDAP_SETCLR_BITOPT(ld, LDAP_BITOPT_ASYNC, optdata);
148*0Sstevel@tonic-gate break;
149*0Sstevel@tonic-gate #endif /* LDAP_ASYNC_IO */
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate /* fields in the LDAP structure */
152*0Sstevel@tonic-gate case LDAP_OPT_DEREF:
153*0Sstevel@tonic-gate ld->ld_deref = *((int *)optdata);
154*0Sstevel@tonic-gate break;
155*0Sstevel@tonic-gate case LDAP_OPT_SIZELIMIT:
156*0Sstevel@tonic-gate ld->ld_sizelimit = *((int *)optdata);
157*0Sstevel@tonic-gate break;
158*0Sstevel@tonic-gate case LDAP_OPT_TIMELIMIT:
159*0Sstevel@tonic-gate ld->ld_timelimit = *((int *)optdata);
160*0Sstevel@tonic-gate break;
161*0Sstevel@tonic-gate case LDAP_OPT_REFERRAL_HOP_LIMIT:
162*0Sstevel@tonic-gate ld->ld_refhoplimit = *((int *)optdata);
163*0Sstevel@tonic-gate break;
164*0Sstevel@tonic-gate case LDAP_OPT_PROTOCOL_VERSION:
165*0Sstevel@tonic-gate ld->ld_version = *((int *)optdata);
166*0Sstevel@tonic-gate if (ld->ld_defconn != NULL) { /* also set in default conn. */
167*0Sstevel@tonic-gate ld->ld_defconn->lconn_version = ld->ld_version;
168*0Sstevel@tonic-gate }
169*0Sstevel@tonic-gate break;
170*0Sstevel@tonic-gate case LDAP_OPT_SERVER_CONTROLS:
171*0Sstevel@tonic-gate /* nsldapi_dup_controls returns -1 and sets lderrno on error */
172*0Sstevel@tonic-gate rc = nsldapi_dup_controls(ld, &ld->ld_servercontrols,
173*0Sstevel@tonic-gate (LDAPControl **)optdata);
174*0Sstevel@tonic-gate break;
175*0Sstevel@tonic-gate case LDAP_OPT_CLIENT_CONTROLS:
176*0Sstevel@tonic-gate /* nsldapi_dup_controls returns -1 and sets lderrno on error */
177*0Sstevel@tonic-gate rc = nsldapi_dup_controls(ld, &ld->ld_clientcontrols,
178*0Sstevel@tonic-gate (LDAPControl **)optdata);
179*0Sstevel@tonic-gate break;
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate /* rebind proc */
182*0Sstevel@tonic-gate case LDAP_OPT_REBIND_FN:
183*0Sstevel@tonic-gate ld->ld_rebind_fn = (LDAP_REBINDPROC_CALLBACK *) optdata;
184*0Sstevel@tonic-gate break;
185*0Sstevel@tonic-gate case LDAP_OPT_REBIND_ARG:
186*0Sstevel@tonic-gate ld->ld_rebind_arg = (void *) optdata;
187*0Sstevel@tonic-gate break;
188*0Sstevel@tonic-gate
189*0Sstevel@tonic-gate #ifdef LDAP_SSLIO_HOOKS
190*0Sstevel@tonic-gate /* i/o function pointers */
191*0Sstevel@tonic-gate case LDAP_OPT_IO_FN_PTRS:
192*0Sstevel@tonic-gate if ((rc = nsldapi_install_compat_io_fns(ld,
193*0Sstevel@tonic-gate (struct ldap_io_fns *)optdata)) != LDAP_SUCCESS) {
194*0Sstevel@tonic-gate LDAP_SET_LDERRNO(ld, rc, NULL, NULL);
195*0Sstevel@tonic-gate rc = -1;
196*0Sstevel@tonic-gate }
197*0Sstevel@tonic-gate break;
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate /* extended i/o function pointers */
200*0Sstevel@tonic-gate case LDAP_X_OPT_EXTIO_FN_PTRS:
201*0Sstevel@tonic-gate /* denotes use of old iofns struct (no writev) */
202*0Sstevel@tonic-gate if (((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_size ==
203*0Sstevel@tonic-gate LDAP_X_EXTIO_FNS_SIZE_REV0) {
204*0Sstevel@tonic-gate ld->ld_extio_size = LDAP_X_EXTIO_FNS_SIZE;
205*0Sstevel@tonic-gate ld->ld_extclose_fn =
206*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_close;
207*0Sstevel@tonic-gate ld->ld_extconnect_fn =
208*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_connect;
209*0Sstevel@tonic-gate ld->ld_extread_fn =
210*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_read;
211*0Sstevel@tonic-gate ld->ld_extwrite_fn =
212*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_write;
213*0Sstevel@tonic-gate ld->ld_extpoll_fn =
214*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_poll;
215*0Sstevel@tonic-gate ld->ld_extnewhandle_fn =
216*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_newhandle;
217*0Sstevel@tonic-gate ld->ld_extdisposehandle_fn =
218*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->
219*0Sstevel@tonic-gate lextiof_disposehandle;
220*0Sstevel@tonic-gate ld->ld_ext_session_arg =
221*0Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *)optdata)->lextiof_session_arg;
222*0Sstevel@tonic-gate ld->ld_extwritev_fn = NULL;
223*0Sstevel@tonic-gate if (ber_sockbuf_set_option(ld->ld_sbp, LBER_SOCKBUF_OPT_EXT_IO_FNS,
224*0Sstevel@tonic-gate &(ld->ld_ext_io_fns)) != 0) {
225*0Sstevel@tonic-gate return (LDAP_LOCAL_ERROR);
226*0Sstevel@tonic-gate }
227*0Sstevel@tonic-gate } else {
228*0Sstevel@tonic-gate /* struct copy */
229*0Sstevel@tonic-gate ld->ld_ext_io_fns = *((struct ldap_x_ext_io_fns *)optdata);
230*0Sstevel@tonic-gate }
231*0Sstevel@tonic-gate if ((rc = nsldapi_install_lber_extiofns(ld, ld->ld_sbp))
232*0Sstevel@tonic-gate != LDAP_SUCCESS) {
233*0Sstevel@tonic-gate LDAP_SET_LDERRNO(ld, rc, NULL, NULL);
234*0Sstevel@tonic-gate rc = -1;
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate break;
237*0Sstevel@tonic-gate #endif
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gate /* thread function pointers */
240*0Sstevel@tonic-gate case LDAP_OPT_THREAD_FN_PTRS:
241*0Sstevel@tonic-gate /*
242*0Sstevel@tonic-gate * It is only safe to set the thread function pointers
243*0Sstevel@tonic-gate * when one thread is using the LDAP session handle.
244*0Sstevel@tonic-gate */
245*0Sstevel@tonic-gate /* free existing mutexes (some are allocated by ldap_init()) */
246*0Sstevel@tonic-gate nsldapi_mutex_free_all(ld);
247*0Sstevel@tonic-gate
248*0Sstevel@tonic-gate /* struct copy */
249*0Sstevel@tonic-gate ld->ld_thread = *((struct ldap_thread_fns *)optdata);
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gate /* allocate new mutexes */
252*0Sstevel@tonic-gate nsldapi_mutex_alloc_all(ld);
253*0Sstevel@tonic-gate
254*0Sstevel@tonic-gate /* LDAP_OPTION_LOCK was never locked... so just return */
255*0Sstevel@tonic-gate return (rc);
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gate /* extra thread function pointers */
258*0Sstevel@tonic-gate case LDAP_OPT_EXTRA_THREAD_FN_PTRS:
259*0Sstevel@tonic-gate /* The extra thread funcs will only pick up the threadid */
260*0Sstevel@tonic-gate ld->ld_thread2 = *((struct ldap_extra_thread_fns *)optdata);
261*0Sstevel@tonic-gate
262*0Sstevel@tonic-gate /* Reset the rest of the structure preserving the threadid fn */
263*0Sstevel@tonic-gate ld->ld_mutex_trylock_fn = (LDAP_TF_MUTEX_TRYLOCK_CALLBACK *)NULL;
264*0Sstevel@tonic-gate ld->ld_sema_alloc_fn = (LDAP_TF_SEMA_ALLOC_CALLBACK *) NULL;
265*0Sstevel@tonic-gate ld->ld_sema_free_fn = (LDAP_TF_SEMA_FREE_CALLBACK *) NULL;
266*0Sstevel@tonic-gate ld->ld_sema_wait_fn = (LDAP_TF_SEMA_WAIT_CALLBACK *) NULL;
267*0Sstevel@tonic-gate ld->ld_sema_post_fn = (LDAP_TF_SEMA_POST_CALLBACK *) NULL;
268*0Sstevel@tonic-gate
269*0Sstevel@tonic-gate /* We assume that only one thread is active when replacing */
270*0Sstevel@tonic-gate /* the threadid function. We will now proceed and reset all */
271*0Sstevel@tonic-gate /* of the threadid/refcounts */
272*0Sstevel@tonic-gate for (i = 0; i < LDAP_MAX_LOCK; i++) {
273*0Sstevel@tonic-gate ld->ld_mutex_threadid[i] = (void *) -1;
274*0Sstevel@tonic-gate ld->ld_mutex_refcnt[i] = 0;
275*0Sstevel@tonic-gate }
276*0Sstevel@tonic-gate
277*0Sstevel@tonic-gate return (rc);
278*0Sstevel@tonic-gate
279*0Sstevel@tonic-gate /* DNS function pointers */
280*0Sstevel@tonic-gate case LDAP_OPT_DNS_FN_PTRS:
281*0Sstevel@tonic-gate /* struct copy */
282*0Sstevel@tonic-gate ld->ld_dnsfn = *((struct ldap_dns_fns *)optdata);
283*0Sstevel@tonic-gate break;
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate /* cache function pointers */
286*0Sstevel@tonic-gate case LDAP_OPT_CACHE_FN_PTRS:
287*0Sstevel@tonic-gate /* struct copy */
288*0Sstevel@tonic-gate ld->ld_cache = *((struct ldap_cache_fns *)optdata);
289*0Sstevel@tonic-gate break;
290*0Sstevel@tonic-gate case LDAP_OPT_CACHE_STRATEGY:
291*0Sstevel@tonic-gate ld->ld_cache_strategy = *((int *)optdata);
292*0Sstevel@tonic-gate break;
293*0Sstevel@tonic-gate case LDAP_OPT_CACHE_ENABLE:
294*0Sstevel@tonic-gate ld->ld_cache_on = *((int *)optdata);
295*0Sstevel@tonic-gate break;
296*0Sstevel@tonic-gate
297*0Sstevel@tonic-gate case LDAP_OPT_ERROR_NUMBER:
298*0Sstevel@tonic-gate LDAP_GET_LDERRNO(ld, &matched, &errstr);
299*0Sstevel@tonic-gate matched = nsldapi_strdup(matched);
300*0Sstevel@tonic-gate errstr = nsldapi_strdup(errstr);
301*0Sstevel@tonic-gate LDAP_SET_LDERRNO(ld, *((int *)optdata), matched, errstr);
302*0Sstevel@tonic-gate break;
303*0Sstevel@tonic-gate
304*0Sstevel@tonic-gate case LDAP_OPT_ERROR_STRING:
305*0Sstevel@tonic-gate rc = LDAP_GET_LDERRNO(ld, &matched, NULL);
306*0Sstevel@tonic-gate matched = nsldapi_strdup(matched);
307*0Sstevel@tonic-gate LDAP_SET_LDERRNO(ld, rc, matched,
308*0Sstevel@tonic-gate nsldapi_strdup((char *)optdata));
309*0Sstevel@tonic-gate rc = LDAP_SUCCESS;
310*0Sstevel@tonic-gate break;
311*0Sstevel@tonic-gate
312*0Sstevel@tonic-gate case LDAP_OPT_MATCHED_DN:
313*0Sstevel@tonic-gate rc = LDAP_GET_LDERRNO(ld, NULL, &errstr);
314*0Sstevel@tonic-gate errstr = nsldapi_strdup(errstr);
315*0Sstevel@tonic-gate LDAP_SET_LDERRNO(ld, rc,
316*0Sstevel@tonic-gate nsldapi_strdup((char *)optdata), errstr);
317*0Sstevel@tonic-gate rc = LDAP_SUCCESS;
318*0Sstevel@tonic-gate break;
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gate case LDAP_OPT_PREFERRED_LANGUAGE:
321*0Sstevel@tonic-gate if (NULL != ld->ld_preferred_language) {
322*0Sstevel@tonic-gate NSLDAPI_FREE(ld->ld_preferred_language);
323*0Sstevel@tonic-gate }
324*0Sstevel@tonic-gate ld->ld_preferred_language = nsldapi_strdup((char *)optdata);
325*0Sstevel@tonic-gate break;
326*0Sstevel@tonic-gate
327*0Sstevel@tonic-gate case LDAP_OPT_HOST_NAME:
328*0Sstevel@tonic-gate if (NULL != ld->ld_defhost) {
329*0Sstevel@tonic-gate NSLDAPI_FREE(ld->ld_defhost);
330*0Sstevel@tonic-gate }
331*0Sstevel@tonic-gate ld->ld_defhost = nsldapi_strdup((char *)optdata);
332*0Sstevel@tonic-gate break;
333*0Sstevel@tonic-gate
334*0Sstevel@tonic-gate case LDAP_X_OPT_CONNECT_TIMEOUT:
335*0Sstevel@tonic-gate ld->ld_connect_timeout = *((int *)optdata);
336*0Sstevel@tonic-gate break;
337*0Sstevel@tonic-gate
338*0Sstevel@tonic-gate #ifdef _SOLARIS_SDK
339*0Sstevel@tonic-gate /* recursion prevention dns functions */
340*0Sstevel@tonic-gate case LDAP_X_OPT_DNS_SKIPDB:
341*0Sstevel@tonic-gate rc = prldap_x_install_dns_skipdb(ld, (const char *)optdata);
342*0Sstevel@tonic-gate break;
343*0Sstevel@tonic-gate #endif
344*0Sstevel@tonic-gate #ifdef LDAP_SASLIO_HOOKS
345*0Sstevel@tonic-gate /* SASL options */
346*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_MECH:
347*0Sstevel@tonic-gate if (NULL != ld->ld_def_sasl_mech) {
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gate NSLDAPI_FREE(ld->ld_def_sasl_mech);
350*0Sstevel@tonic-gate }
351*0Sstevel@tonic-gate ld->ld_def_sasl_mech = nsldapi_strdup((char *)optdata);
352*0Sstevel@tonic-gate break;
353*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_REALM:
354*0Sstevel@tonic-gate if (NULL != ld->ld_def_sasl_realm) {
355*0Sstevel@tonic-gate NSLDAPI_FREE(ld->ld_def_sasl_realm);
356*0Sstevel@tonic-gate }
357*0Sstevel@tonic-gate ld->ld_def_sasl_realm = nsldapi_strdup((char *)optdata);
358*0Sstevel@tonic-gate break;
359*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_AUTHCID:
360*0Sstevel@tonic-gate if (NULL != ld->ld_def_sasl_authcid) {
361*0Sstevel@tonic-gate NSLDAPI_FREE(ld->ld_def_sasl_authcid);
362*0Sstevel@tonic-gate }
363*0Sstevel@tonic-gate ld->ld_def_sasl_authcid = nsldapi_strdup((char *)optdata);
364*0Sstevel@tonic-gate break;
365*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_AUTHZID:
366*0Sstevel@tonic-gate if (NULL != ld->ld_def_sasl_authzid) {
367*0Sstevel@tonic-gate NSLDAPI_FREE(ld->ld_def_sasl_authzid);
368*0Sstevel@tonic-gate }
369*0Sstevel@tonic-gate ld->ld_def_sasl_authzid = nsldapi_strdup((char *)optdata);
370*0Sstevel@tonic-gate break;
371*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF_EXTERNAL:
372*0Sstevel@tonic-gate {
373*0Sstevel@tonic-gate int sc;
374*0Sstevel@tonic-gate sasl_ssf_t extprops;
375*0Sstevel@tonic-gate sasl_conn_t *ctx;
376*0Sstevel@tonic-gate if (ld->ld_defconn == NULL ||
377*0Sstevel@tonic-gate ld->ld_defconn->lconn_sb == NULL) {
378*0Sstevel@tonic-gate return (-1);
379*0Sstevel@tonic-gate }
380*0Sstevel@tonic-gate ctx = (sasl_conn_t *)
381*0Sstevel@tonic-gate (ld->ld_defconn->lconn_sb->sb_sasl_ctx);
382*0Sstevel@tonic-gate if (ctx == NULL) {
383*0Sstevel@tonic-gate return (-1);
384*0Sstevel@tonic-gate }
385*0Sstevel@tonic-gate memset(&extprops, 0L, sizeof (extprops));
386*0Sstevel@tonic-gate extprops = * ((sasl_ssf_t *)optdata);
387*0Sstevel@tonic-gate sc = sasl_setprop(ctx, SASL_SSF_EXTERNAL,
388*0Sstevel@tonic-gate (void *) &extprops);
389*0Sstevel@tonic-gate if (sc != SASL_OK) {
390*0Sstevel@tonic-gate return (-1);
391*0Sstevel@tonic-gate }
392*0Sstevel@tonic-gate }
393*0Sstevel@tonic-gate break;
394*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_SECPROPS:
395*0Sstevel@tonic-gate {
396*0Sstevel@tonic-gate int sc;
397*0Sstevel@tonic-gate sc = nsldapi_sasl_secprops((char *)optdata,
398*0Sstevel@tonic-gate &ld->ld_sasl_secprops);
399*0Sstevel@tonic-gate return (sc == LDAP_SUCCESS ? 0 : -1);
400*0Sstevel@tonic-gate }
401*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF_MIN:
402*0Sstevel@tonic-gate ld->ld_sasl_secprops.min_ssf = *((sasl_ssf_t *)optdata);
403*0Sstevel@tonic-gate break;
404*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF_MAX:
405*0Sstevel@tonic-gate ld->ld_sasl_secprops.max_ssf = *((sasl_ssf_t *)optdata);
406*0Sstevel@tonic-gate break;
407*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_MAXBUFSIZE:
408*0Sstevel@tonic-gate ld->ld_sasl_secprops.maxbufsize = *((sasl_ssf_t *)optdata);
409*0Sstevel@tonic-gate break;
410*0Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF: /* read only */
411*0Sstevel@tonic-gate LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
412*0Sstevel@tonic-gate rc = -1;
413*0Sstevel@tonic-gate break;
414*0Sstevel@tonic-gate #endif
415*0Sstevel@tonic-gate
416*0Sstevel@tonic-gate default:
417*0Sstevel@tonic-gate LDAP_SET_LDERRNO(ld, LDAP_PARAM_ERROR, NULL, NULL);
418*0Sstevel@tonic-gate rc = -1;
419*0Sstevel@tonic-gate }
420*0Sstevel@tonic-gate
421*0Sstevel@tonic-gate if (ld != &nsldapi_ld_defaults) {
422*0Sstevel@tonic-gate LDAP_MUTEX_UNLOCK(ld, LDAP_OPTION_LOCK);
423*0Sstevel@tonic-gate }
424*0Sstevel@tonic-gate return (rc);
425*0Sstevel@tonic-gate }
426