1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate */
5*7c478bd9Sstevel@tonic-gate
6*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
7*7c478bd9Sstevel@tonic-gate
8*7c478bd9Sstevel@tonic-gate /*
9*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
10*7c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
11*7c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
12*7c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
15*7c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16*7c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing
17*7c478bd9Sstevel@tonic-gate * rights and limitations under the License.
18*7c478bd9Sstevel@tonic-gate *
19*7c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
20*7c478bd9Sstevel@tonic-gate * March 31, 1998.
21*7c478bd9Sstevel@tonic-gate *
22*7c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
23*7c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
24*7c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25*7c478bd9Sstevel@tonic-gate * Rights Reserved.
26*7c478bd9Sstevel@tonic-gate *
27*7c478bd9Sstevel@tonic-gate * Contributor(s):
28*7c478bd9Sstevel@tonic-gate */
29*7c478bd9Sstevel@tonic-gate #include "ldap-int.h"
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate #define LDAP_GET_BITOPT( ld, bit ) \
32*7c478bd9Sstevel@tonic-gate ((ld)->ld_options & bit ) != 0 ? 1 : 0
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate static int nsldapi_get_api_info( LDAPAPIInfo *aip );
35*7c478bd9Sstevel@tonic-gate static int nsldapi_get_feature_info( LDAPAPIFeatureInfo *fip );
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate int
39*7c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_get_option(LDAP * ld,int option,void * optdata)40*7c478bd9Sstevel@tonic-gate ldap_get_option( LDAP *ld, int option, void *optdata )
41*7c478bd9Sstevel@tonic-gate {
42*7c478bd9Sstevel@tonic-gate int rc = 0;
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate if ( !nsldapi_initialized ) {
45*7c478bd9Sstevel@tonic-gate nsldapi_initialize_defaults();
46*7c478bd9Sstevel@tonic-gate }
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate * optdata MUST be a valid pointer...
50*7c478bd9Sstevel@tonic-gate */
51*7c478bd9Sstevel@tonic-gate if (NULL == optdata)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate return(LDAP_PARAM_ERROR);
54*7c478bd9Sstevel@tonic-gate }
55*7c478bd9Sstevel@tonic-gate /*
56*7c478bd9Sstevel@tonic-gate * process global options (not associated with an LDAP session handle)
57*7c478bd9Sstevel@tonic-gate */
58*7c478bd9Sstevel@tonic-gate if ( option == LDAP_OPT_MEMALLOC_FN_PTRS ) {
59*7c478bd9Sstevel@tonic-gate /* struct copy */
60*7c478bd9Sstevel@tonic-gate *((struct ldap_memalloc_fns *)optdata) = nsldapi_memalloc_fns;
61*7c478bd9Sstevel@tonic-gate return( 0 );
62*7c478bd9Sstevel@tonic-gate }
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate if ( option == LDAP_OPT_API_INFO ) {
65*7c478bd9Sstevel@tonic-gate rc = nsldapi_get_api_info( (LDAPAPIInfo *)optdata );
66*7c478bd9Sstevel@tonic-gate if ( rc != LDAP_SUCCESS ) {
67*7c478bd9Sstevel@tonic-gate if ( ld != NULL ) {
68*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
69*7c478bd9Sstevel@tonic-gate }
70*7c478bd9Sstevel@tonic-gate return( -1 );
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate return( 0 );
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate /*
75*7c478bd9Sstevel@tonic-gate * LDAP_OPT_DEBUG_LEVEL is global
76*7c478bd9Sstevel@tonic-gate */
77*7c478bd9Sstevel@tonic-gate if (LDAP_OPT_DEBUG_LEVEL == option)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate #ifdef LDAP_DEBUG
80*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ldap_debug;
81*7c478bd9Sstevel@tonic-gate #endif /* LDAP_DEBUG */
82*7c478bd9Sstevel@tonic-gate return ( 0 );
83*7c478bd9Sstevel@tonic-gate }
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate * if ld is NULL, arrange to return options from our default settings
87*7c478bd9Sstevel@tonic-gate */
88*7c478bd9Sstevel@tonic-gate if ( ld == NULL ) {
89*7c478bd9Sstevel@tonic-gate ld = &nsldapi_ld_defaults;
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
93*7c478bd9Sstevel@tonic-gate return( -1 ); /* punt */
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate if (ld != &nsldapi_ld_defaults)
98*7c478bd9Sstevel@tonic-gate LDAP_MUTEX_LOCK( ld, LDAP_OPTION_LOCK );
99*7c478bd9Sstevel@tonic-gate switch( option ) {
100*7c478bd9Sstevel@tonic-gate #ifdef LDAP_DNS
101*7c478bd9Sstevel@tonic-gate case LDAP_OPT_DNS:
102*7c478bd9Sstevel@tonic-gate *((int *) optdata) = LDAP_GET_BITOPT( ld, LDAP_BITOPT_DNS );
103*7c478bd9Sstevel@tonic-gate break;
104*7c478bd9Sstevel@tonic-gate #endif
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate case LDAP_OPT_REFERRALS:
107*7c478bd9Sstevel@tonic-gate *((int *) optdata) =
108*7c478bd9Sstevel@tonic-gate LDAP_GET_BITOPT( ld, LDAP_BITOPT_REFERRALS );
109*7c478bd9Sstevel@tonic-gate break;
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate #ifdef LDAP_SSLIO_HOOKS
112*7c478bd9Sstevel@tonic-gate case LDAP_OPT_SSL:
113*7c478bd9Sstevel@tonic-gate *((int *) optdata) = LDAP_GET_BITOPT( ld, LDAP_BITOPT_SSL );
114*7c478bd9Sstevel@tonic-gate break;
115*7c478bd9Sstevel@tonic-gate #endif
116*7c478bd9Sstevel@tonic-gate case LDAP_OPT_RESTART:
117*7c478bd9Sstevel@tonic-gate *((int *) optdata) = LDAP_GET_BITOPT( ld, LDAP_BITOPT_RESTART );
118*7c478bd9Sstevel@tonic-gate break;
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate case LDAP_OPT_RECONNECT:
121*7c478bd9Sstevel@tonic-gate *((int *) optdata) =
122*7c478bd9Sstevel@tonic-gate LDAP_GET_BITOPT( ld, LDAP_BITOPT_RECONNECT );
123*7c478bd9Sstevel@tonic-gate break;
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate #ifdef LDAP_ASYNC_IO
126*7c478bd9Sstevel@tonic-gate case LDAP_OPT_ASYNC_CONNECT:
127*7c478bd9Sstevel@tonic-gate *((int *) optdata) =
128*7c478bd9Sstevel@tonic-gate LDAP_GET_BITOPT( ld, LDAP_BITOPT_ASYNC );
129*7c478bd9Sstevel@tonic-gate break;
130*7c478bd9Sstevel@tonic-gate #endif /* LDAP_ASYNC_IO */
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate /* stuff in the sockbuf */
133*7c478bd9Sstevel@tonic-gate case LDAP_X_OPT_SOCKBUF:
134*7c478bd9Sstevel@tonic-gate *((Sockbuf **) optdata) = ld->ld_sbp;
135*7c478bd9Sstevel@tonic-gate break;
136*7c478bd9Sstevel@tonic-gate case LDAP_OPT_DESC:
137*7c478bd9Sstevel@tonic-gate if ( ber_sockbuf_get_option( ld->ld_sbp,
138*7c478bd9Sstevel@tonic-gate LBER_SOCKBUF_OPT_DESC, optdata ) != 0 ) {
139*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_LOCAL_ERROR, NULL, NULL );
140*7c478bd9Sstevel@tonic-gate rc = -1;
141*7c478bd9Sstevel@tonic-gate }
142*7c478bd9Sstevel@tonic-gate break;
143*7c478bd9Sstevel@tonic-gate
144*7c478bd9Sstevel@tonic-gate /* fields in the LDAP structure */
145*7c478bd9Sstevel@tonic-gate case LDAP_OPT_DEREF:
146*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_deref;
147*7c478bd9Sstevel@tonic-gate break;
148*7c478bd9Sstevel@tonic-gate case LDAP_OPT_SIZELIMIT:
149*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_sizelimit;
150*7c478bd9Sstevel@tonic-gate break;
151*7c478bd9Sstevel@tonic-gate case LDAP_OPT_TIMELIMIT:
152*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_timelimit;
153*7c478bd9Sstevel@tonic-gate break;
154*7c478bd9Sstevel@tonic-gate case LDAP_OPT_REFERRAL_HOP_LIMIT:
155*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_refhoplimit;
156*7c478bd9Sstevel@tonic-gate break;
157*7c478bd9Sstevel@tonic-gate case LDAP_OPT_PROTOCOL_VERSION:
158*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_version;
159*7c478bd9Sstevel@tonic-gate break;
160*7c478bd9Sstevel@tonic-gate case LDAP_OPT_SERVER_CONTROLS:
161*7c478bd9Sstevel@tonic-gate /* fall through */
162*7c478bd9Sstevel@tonic-gate case LDAP_OPT_CLIENT_CONTROLS:
163*7c478bd9Sstevel@tonic-gate *((LDAPControl ***)optdata) = NULL;
164*7c478bd9Sstevel@tonic-gate /* nsldapi_dup_controls returns -1 and sets lderrno on error */
165*7c478bd9Sstevel@tonic-gate rc = nsldapi_dup_controls( ld, (LDAPControl ***)optdata,
166*7c478bd9Sstevel@tonic-gate ( option == LDAP_OPT_SERVER_CONTROLS ) ?
167*7c478bd9Sstevel@tonic-gate ld->ld_servercontrols : ld->ld_clientcontrols );
168*7c478bd9Sstevel@tonic-gate break;
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate /* rebind proc */
171*7c478bd9Sstevel@tonic-gate case LDAP_OPT_REBIND_FN:
172*7c478bd9Sstevel@tonic-gate *((LDAP_REBINDPROC_CALLBACK **) optdata) = ld->ld_rebind_fn;
173*7c478bd9Sstevel@tonic-gate break;
174*7c478bd9Sstevel@tonic-gate case LDAP_OPT_REBIND_ARG:
175*7c478bd9Sstevel@tonic-gate *((void **) optdata) = ld->ld_rebind_arg;
176*7c478bd9Sstevel@tonic-gate break;
177*7c478bd9Sstevel@tonic-gate
178*7c478bd9Sstevel@tonic-gate #ifdef LDAP_SSLIO_HOOKS
179*7c478bd9Sstevel@tonic-gate /* i/o function pointers */
180*7c478bd9Sstevel@tonic-gate case LDAP_OPT_IO_FN_PTRS:
181*7c478bd9Sstevel@tonic-gate if ( ld->ld_io_fns_ptr == NULL ) {
182*7c478bd9Sstevel@tonic-gate memset( optdata, 0, sizeof( struct ldap_io_fns ));
183*7c478bd9Sstevel@tonic-gate } else {
184*7c478bd9Sstevel@tonic-gate /* struct copy */
185*7c478bd9Sstevel@tonic-gate *((struct ldap_io_fns *)optdata) = *(ld->ld_io_fns_ptr);
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate break;
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate /* extended i/o function pointers */
190*7c478bd9Sstevel@tonic-gate case LDAP_X_OPT_EXTIO_FN_PTRS:
191*7c478bd9Sstevel@tonic-gate if ( ((struct ldap_x_ext_io_fns *) optdata)->lextiof_size == LDAP_X_EXTIO_FNS_SIZE_REV0) {
192*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_close = ld->ld_extclose_fn;
193*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_connect = ld->ld_extconnect_fn;
194*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_read = ld->ld_extread_fn;
195*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_write = ld->ld_extwrite_fn;
196*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_poll = ld->ld_extpoll_fn;
197*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_newhandle = ld->ld_extnewhandle_fn;
198*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_disposehandle = ld->ld_extdisposehandle_fn;
199*7c478bd9Sstevel@tonic-gate ((struct ldap_x_ext_io_fns_rev0 *) optdata)->lextiof_session_arg = ld->ld_ext_session_arg;
200*7c478bd9Sstevel@tonic-gate } else if ( ((struct ldap_x_ext_io_fns *) optdata)->lextiof_size ==
201*7c478bd9Sstevel@tonic-gate LDAP_X_EXTIO_FNS_SIZE ) {
202*7c478bd9Sstevel@tonic-gate /* struct copy */
203*7c478bd9Sstevel@tonic-gate *((struct ldap_x_ext_io_fns *) optdata) = ld->ld_ext_io_fns;
204*7c478bd9Sstevel@tonic-gate } else {
205*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
206*7c478bd9Sstevel@tonic-gate rc = -1;
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate break;
209*7c478bd9Sstevel@tonic-gate #endif /* LDAP_SSLIO_HOOKS */
210*7c478bd9Sstevel@tonic-gate
211*7c478bd9Sstevel@tonic-gate /* thread function pointers */
212*7c478bd9Sstevel@tonic-gate case LDAP_OPT_THREAD_FN_PTRS:
213*7c478bd9Sstevel@tonic-gate /* struct copy */
214*7c478bd9Sstevel@tonic-gate *((struct ldap_thread_fns *) optdata) = ld->ld_thread;
215*7c478bd9Sstevel@tonic-gate break;
216*7c478bd9Sstevel@tonic-gate
217*7c478bd9Sstevel@tonic-gate /* DNS function pointers */
218*7c478bd9Sstevel@tonic-gate case LDAP_OPT_DNS_FN_PTRS:
219*7c478bd9Sstevel@tonic-gate /* struct copy */
220*7c478bd9Sstevel@tonic-gate *((struct ldap_dns_fns *) optdata) = ld->ld_dnsfn;
221*7c478bd9Sstevel@tonic-gate break;
222*7c478bd9Sstevel@tonic-gate
223*7c478bd9Sstevel@tonic-gate /* cache function pointers */
224*7c478bd9Sstevel@tonic-gate case LDAP_OPT_CACHE_FN_PTRS:
225*7c478bd9Sstevel@tonic-gate /* struct copy */
226*7c478bd9Sstevel@tonic-gate *((struct ldap_cache_fns *) optdata) = ld->ld_cache;
227*7c478bd9Sstevel@tonic-gate break;
228*7c478bd9Sstevel@tonic-gate case LDAP_OPT_CACHE_STRATEGY:
229*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_cache_strategy;
230*7c478bd9Sstevel@tonic-gate break;
231*7c478bd9Sstevel@tonic-gate case LDAP_OPT_CACHE_ENABLE:
232*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_cache_on;
233*7c478bd9Sstevel@tonic-gate break;
234*7c478bd9Sstevel@tonic-gate
235*7c478bd9Sstevel@tonic-gate case LDAP_OPT_ERROR_NUMBER:
236*7c478bd9Sstevel@tonic-gate *((int *) optdata) = LDAP_GET_LDERRNO( ld, NULL, NULL );
237*7c478bd9Sstevel@tonic-gate break;
238*7c478bd9Sstevel@tonic-gate
239*7c478bd9Sstevel@tonic-gate case LDAP_OPT_ERROR_STRING:
240*7c478bd9Sstevel@tonic-gate (void)LDAP_GET_LDERRNO( ld, NULL, (char **)optdata );
241*7c478bd9Sstevel@tonic-gate *((char **) optdata) = nsldapi_strdup( *((char **) optdata ));
242*7c478bd9Sstevel@tonic-gate break;
243*7c478bd9Sstevel@tonic-gate
244*7c478bd9Sstevel@tonic-gate case LDAP_OPT_MATCHED_DN:
245*7c478bd9Sstevel@tonic-gate (void)LDAP_GET_LDERRNO( ld, (char **)optdata, NULL );
246*7c478bd9Sstevel@tonic-gate *((char **) optdata) = nsldapi_strdup( *((char **) optdata ));
247*7c478bd9Sstevel@tonic-gate break;
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gate case LDAP_OPT_PREFERRED_LANGUAGE:
250*7c478bd9Sstevel@tonic-gate if ( NULL != ld->ld_preferred_language ) {
251*7c478bd9Sstevel@tonic-gate *((char **) optdata) =
252*7c478bd9Sstevel@tonic-gate nsldapi_strdup(ld->ld_preferred_language);
253*7c478bd9Sstevel@tonic-gate } else {
254*7c478bd9Sstevel@tonic-gate *((char **) optdata) = NULL;
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate break;
257*7c478bd9Sstevel@tonic-gate
258*7c478bd9Sstevel@tonic-gate case LDAP_OPT_API_FEATURE_INFO:
259*7c478bd9Sstevel@tonic-gate rc = nsldapi_get_feature_info( (LDAPAPIFeatureInfo *)optdata );
260*7c478bd9Sstevel@tonic-gate if ( rc != LDAP_SUCCESS ) {
261*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
262*7c478bd9Sstevel@tonic-gate rc = -1;
263*7c478bd9Sstevel@tonic-gate }
264*7c478bd9Sstevel@tonic-gate break;
265*7c478bd9Sstevel@tonic-gate
266*7c478bd9Sstevel@tonic-gate case LDAP_OPT_HOST_NAME:
267*7c478bd9Sstevel@tonic-gate *((char **) optdata) = nsldapi_strdup( ld->ld_defhost );
268*7c478bd9Sstevel@tonic-gate break;
269*7c478bd9Sstevel@tonic-gate
270*7c478bd9Sstevel@tonic-gate case LDAP_X_OPT_CONNECT_TIMEOUT:
271*7c478bd9Sstevel@tonic-gate *((int *) optdata) = ld->ld_connect_timeout;
272*7c478bd9Sstevel@tonic-gate break;
273*7c478bd9Sstevel@tonic-gate
274*7c478bd9Sstevel@tonic-gate #ifdef LDAP_SASLIO_HOOKS
275*7c478bd9Sstevel@tonic-gate /* SASL options */
276*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_MECH:
277*7c478bd9Sstevel@tonic-gate *((char **) optdata) = nsldapi_strdup(ld->ld_def_sasl_mech);
278*7c478bd9Sstevel@tonic-gate break;
279*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_REALM:
280*7c478bd9Sstevel@tonic-gate *((char **) optdata) = nsldapi_strdup(ld->ld_def_sasl_realm);
281*7c478bd9Sstevel@tonic-gate break;
282*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_AUTHCID:
283*7c478bd9Sstevel@tonic-gate *((char **) optdata) = nsldapi_strdup(ld->ld_def_sasl_authcid);
284*7c478bd9Sstevel@tonic-gate break;
285*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_AUTHZID:
286*7c478bd9Sstevel@tonic-gate *((char **) optdata) = nsldapi_strdup(ld->ld_def_sasl_authzid);
287*7c478bd9Sstevel@tonic-gate break;
288*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF:
289*7c478bd9Sstevel@tonic-gate {
290*7c478bd9Sstevel@tonic-gate int sc;
291*7c478bd9Sstevel@tonic-gate sasl_ssf_t *ssf;
292*7c478bd9Sstevel@tonic-gate sasl_conn_t *ctx;
293*7c478bd9Sstevel@tonic-gate if( ld->ld_defconn == NULL ||
294*7c478bd9Sstevel@tonic-gate ld->ld_defconn->lconn_sb == NULL ) {
295*7c478bd9Sstevel@tonic-gate return -1;
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate ctx = (sasl_conn_t *)(ld->ld_defconn->lconn_sb->sb_sasl_ctx);
298*7c478bd9Sstevel@tonic-gate if ( ctx == NULL ) {
299*7c478bd9Sstevel@tonic-gate return -1;
300*7c478bd9Sstevel@tonic-gate }
301*7c478bd9Sstevel@tonic-gate sc = sasl_getprop( ctx, SASL_SSF, (const void **) &ssf );
302*7c478bd9Sstevel@tonic-gate if ( sc != SASL_OK ) {
303*7c478bd9Sstevel@tonic-gate return -1;
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate *((sasl_ssf_t *) optdata) = *ssf;
306*7c478bd9Sstevel@tonic-gate }
307*7c478bd9Sstevel@tonic-gate break;
308*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF_MIN:
309*7c478bd9Sstevel@tonic-gate *((sasl_ssf_t *) optdata) = ld->ld_sasl_secprops.min_ssf;
310*7c478bd9Sstevel@tonic-gate break;
311*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF_MAX:
312*7c478bd9Sstevel@tonic-gate *((sasl_ssf_t *) optdata) = ld->ld_sasl_secprops.max_ssf;
313*7c478bd9Sstevel@tonic-gate break;
314*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_MAXBUFSIZE:
315*7c478bd9Sstevel@tonic-gate *((sasl_ssf_t *) optdata) = ld->ld_sasl_secprops.maxbufsize;
316*7c478bd9Sstevel@tonic-gate break;
317*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_SSF_EXTERNAL:
318*7c478bd9Sstevel@tonic-gate case LDAP_OPT_X_SASL_SECPROPS:
319*7c478bd9Sstevel@tonic-gate /*
320*7c478bd9Sstevel@tonic-gate * These options are write only. Making these options
321*7c478bd9Sstevel@tonic-gate * read/write would expose semi-private interfaces of libsasl
322*7c478bd9Sstevel@tonic-gate * for which there are no cross platform/standardized
323*7c478bd9Sstevel@tonic-gate * definitions.
324*7c478bd9Sstevel@tonic-gate */
325*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
326*7c478bd9Sstevel@tonic-gate rc = -1;
327*7c478bd9Sstevel@tonic-gate break;
328*7c478bd9Sstevel@tonic-gate #endif
329*7c478bd9Sstevel@tonic-gate
330*7c478bd9Sstevel@tonic-gate default:
331*7c478bd9Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
332*7c478bd9Sstevel@tonic-gate rc = -1;
333*7c478bd9Sstevel@tonic-gate }
334*7c478bd9Sstevel@tonic-gate if (ld != &nsldapi_ld_defaults)
335*7c478bd9Sstevel@tonic-gate LDAP_MUTEX_UNLOCK( ld, LDAP_OPTION_LOCK );
336*7c478bd9Sstevel@tonic-gate return( rc );
337*7c478bd9Sstevel@tonic-gate }
338*7c478bd9Sstevel@tonic-gate
339*7c478bd9Sstevel@tonic-gate
340*7c478bd9Sstevel@tonic-gate /*
341*7c478bd9Sstevel@tonic-gate * Table of extended API features we support.
342*7c478bd9Sstevel@tonic-gate * The first field is the version of the info. strcuture itself; we do not
343*7c478bd9Sstevel@tonic-gate * use the ones from this table so it is okay to leave as zero.
344*7c478bd9Sstevel@tonic-gate */
345*7c478bd9Sstevel@tonic-gate static LDAPAPIFeatureInfo nsldapi_extensions[] = {
346*7c478bd9Sstevel@tonic-gate { 0, "SERVER_SIDE_SORT", LDAP_API_FEATURE_SERVER_SIDE_SORT },
347*7c478bd9Sstevel@tonic-gate { 0, "VIRTUAL_LIST_VIEW", LDAP_API_FEATURE_VIRTUAL_LIST_VIEW },
348*7c478bd9Sstevel@tonic-gate { 0, "PERSISTENT_SEARCH", LDAP_API_FEATURE_PERSISTENT_SEARCH },
349*7c478bd9Sstevel@tonic-gate { 0, "PROXY_AUTHORIZATION", LDAP_API_FEATURE_PROXY_AUTHORIZATION },
350*7c478bd9Sstevel@tonic-gate { 0, "X_LDERRNO", LDAP_API_FEATURE_X_LDERRNO },
351*7c478bd9Sstevel@tonic-gate { 0, "X_MEMCACHE", LDAP_API_FEATURE_X_MEMCACHE },
352*7c478bd9Sstevel@tonic-gate { 0, "X_IO_FUNCTIONS", LDAP_API_FEATURE_X_IO_FUNCTIONS },
353*7c478bd9Sstevel@tonic-gate { 0, "X_EXTIO_FUNCTIONS", LDAP_API_FEATURE_X_EXTIO_FUNCTIONS },
354*7c478bd9Sstevel@tonic-gate { 0, "X_DNS_FUNCTIONS", LDAP_API_FEATURE_X_DNS_FUNCTIONS },
355*7c478bd9Sstevel@tonic-gate { 0, "X_MEMALLOC_FUNCTIONS", LDAP_API_FEATURE_X_MEMALLOC_FUNCTIONS },
356*7c478bd9Sstevel@tonic-gate { 0, "X_THREAD_FUNCTIONS", LDAP_API_FEATURE_X_THREAD_FUNCTIONS },
357*7c478bd9Sstevel@tonic-gate { 0, "X_EXTHREAD_FUNCTIONS", LDAP_API_FEATURE_X_EXTHREAD_FUNCTIONS },
358*7c478bd9Sstevel@tonic-gate { 0, "X_GETLANGVALUES", LDAP_API_FEATURE_X_GETLANGVALUES },
359*7c478bd9Sstevel@tonic-gate { 0, "X_CLIENT_SIDE_SORT", LDAP_API_FEATURE_X_CLIENT_SIDE_SORT },
360*7c478bd9Sstevel@tonic-gate { 0, "X_URL_FUNCTIONS", LDAP_API_FEATURE_X_URL_FUNCTIONS },
361*7c478bd9Sstevel@tonic-gate { 0, "X_FILTER_FUNCTIONS", LDAP_API_FEATURE_X_FILTER_FUNCTIONS },
362*7c478bd9Sstevel@tonic-gate };
363*7c478bd9Sstevel@tonic-gate
364*7c478bd9Sstevel@tonic-gate #define NSLDAPI_EXTENSIONS_COUNT \
365*7c478bd9Sstevel@tonic-gate (sizeof(nsldapi_extensions)/sizeof(LDAPAPIFeatureInfo))
366*7c478bd9Sstevel@tonic-gate
367*7c478bd9Sstevel@tonic-gate /*
368*7c478bd9Sstevel@tonic-gate * Retrieve information about this implementation of the LDAP API.
369*7c478bd9Sstevel@tonic-gate * Returns an LDAP error code.
370*7c478bd9Sstevel@tonic-gate */
371*7c478bd9Sstevel@tonic-gate static int
nsldapi_get_api_info(LDAPAPIInfo * aip)372*7c478bd9Sstevel@tonic-gate nsldapi_get_api_info( LDAPAPIInfo *aip )
373*7c478bd9Sstevel@tonic-gate {
374*7c478bd9Sstevel@tonic-gate int i;
375*7c478bd9Sstevel@tonic-gate
376*7c478bd9Sstevel@tonic-gate if ( aip == NULL ) {
377*7c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
378*7c478bd9Sstevel@tonic-gate }
379*7c478bd9Sstevel@tonic-gate
380*7c478bd9Sstevel@tonic-gate aip->ldapai_api_version = LDAP_API_VERSION;
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate if ( aip->ldapai_info_version != LDAP_API_INFO_VERSION ) {
383*7c478bd9Sstevel@tonic-gate aip->ldapai_info_version = LDAP_API_INFO_VERSION;
384*7c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
385*7c478bd9Sstevel@tonic-gate }
386*7c478bd9Sstevel@tonic-gate
387*7c478bd9Sstevel@tonic-gate aip->ldapai_protocol_version = LDAP_VERSION_MAX;
388*7c478bd9Sstevel@tonic-gate aip->ldapai_vendor_version = LDAP_VENDOR_VERSION;
389*7c478bd9Sstevel@tonic-gate
390*7c478bd9Sstevel@tonic-gate if (( aip->ldapai_vendor_name = nsldapi_strdup( LDAP_VENDOR_NAME ))
391*7c478bd9Sstevel@tonic-gate == NULL ) {
392*7c478bd9Sstevel@tonic-gate return( LDAP_NO_MEMORY );
393*7c478bd9Sstevel@tonic-gate }
394*7c478bd9Sstevel@tonic-gate
395*7c478bd9Sstevel@tonic-gate if ( NSLDAPI_EXTENSIONS_COUNT < 1 ) {
396*7c478bd9Sstevel@tonic-gate aip->ldapai_extensions = NULL;
397*7c478bd9Sstevel@tonic-gate } else {
398*7c478bd9Sstevel@tonic-gate if (( aip->ldapai_extensions = NSLDAPI_CALLOC(
399*7c478bd9Sstevel@tonic-gate NSLDAPI_EXTENSIONS_COUNT + 1, sizeof(char *))) == NULL ) {
400*7c478bd9Sstevel@tonic-gate NSLDAPI_FREE( aip->ldapai_vendor_name );
401*7c478bd9Sstevel@tonic-gate aip->ldapai_vendor_name = NULL;
402*7c478bd9Sstevel@tonic-gate return( LDAP_NO_MEMORY );
403*7c478bd9Sstevel@tonic-gate }
404*7c478bd9Sstevel@tonic-gate
405*7c478bd9Sstevel@tonic-gate for ( i = 0; i < NSLDAPI_EXTENSIONS_COUNT; ++i ) {
406*7c478bd9Sstevel@tonic-gate if (( aip->ldapai_extensions[i] = nsldapi_strdup(
407*7c478bd9Sstevel@tonic-gate nsldapi_extensions[i].ldapaif_name )) == NULL ) {
408*7c478bd9Sstevel@tonic-gate ldap_value_free( aip->ldapai_extensions );
409*7c478bd9Sstevel@tonic-gate NSLDAPI_FREE( aip->ldapai_vendor_name );
410*7c478bd9Sstevel@tonic-gate aip->ldapai_extensions = NULL;
411*7c478bd9Sstevel@tonic-gate aip->ldapai_vendor_name = NULL;
412*7c478bd9Sstevel@tonic-gate return( LDAP_NO_MEMORY );
413*7c478bd9Sstevel@tonic-gate }
414*7c478bd9Sstevel@tonic-gate }
415*7c478bd9Sstevel@tonic-gate }
416*7c478bd9Sstevel@tonic-gate
417*7c478bd9Sstevel@tonic-gate return( LDAP_SUCCESS );
418*7c478bd9Sstevel@tonic-gate }
419*7c478bd9Sstevel@tonic-gate
420*7c478bd9Sstevel@tonic-gate
421*7c478bd9Sstevel@tonic-gate /*
422*7c478bd9Sstevel@tonic-gate * Retrieves information about a specific extended feature of the LDAP API/
423*7c478bd9Sstevel@tonic-gate * Returns an LDAP error code.
424*7c478bd9Sstevel@tonic-gate */
425*7c478bd9Sstevel@tonic-gate static int
nsldapi_get_feature_info(LDAPAPIFeatureInfo * fip)426*7c478bd9Sstevel@tonic-gate nsldapi_get_feature_info( LDAPAPIFeatureInfo *fip )
427*7c478bd9Sstevel@tonic-gate {
428*7c478bd9Sstevel@tonic-gate int i;
429*7c478bd9Sstevel@tonic-gate
430*7c478bd9Sstevel@tonic-gate if ( fip == NULL || fip->ldapaif_name == NULL ) {
431*7c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
432*7c478bd9Sstevel@tonic-gate }
433*7c478bd9Sstevel@tonic-gate
434*7c478bd9Sstevel@tonic-gate if ( fip->ldapaif_info_version != LDAP_FEATURE_INFO_VERSION ) {
435*7c478bd9Sstevel@tonic-gate fip->ldapaif_info_version = LDAP_FEATURE_INFO_VERSION;
436*7c478bd9Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
437*7c478bd9Sstevel@tonic-gate }
438*7c478bd9Sstevel@tonic-gate
439*7c478bd9Sstevel@tonic-gate for ( i = 0; i < NSLDAPI_EXTENSIONS_COUNT; ++i ) {
440*7c478bd9Sstevel@tonic-gate if ( strcmp( fip->ldapaif_name,
441*7c478bd9Sstevel@tonic-gate nsldapi_extensions[i].ldapaif_name ) == 0 ) {
442*7c478bd9Sstevel@tonic-gate fip->ldapaif_version =
443*7c478bd9Sstevel@tonic-gate nsldapi_extensions[i].ldapaif_version;
444*7c478bd9Sstevel@tonic-gate break;
445*7c478bd9Sstevel@tonic-gate }
446*7c478bd9Sstevel@tonic-gate }
447*7c478bd9Sstevel@tonic-gate
448*7c478bd9Sstevel@tonic-gate return(( i < NSLDAPI_EXTENSIONS_COUNT ) ? LDAP_SUCCESS
449*7c478bd9Sstevel@tonic-gate : LDAP_PARAM_ERROR );
450*7c478bd9Sstevel@tonic-gate }
451