xref: /titanic_51/usr/src/lib/libldap5/sources/ldap/prldap/ldappr-public.c (revision da80a4ab65e70cd50eb02add3b6321ebb16d65b6)
17c478bd9Sstevel@tonic-gate /*
2*da80a4abSjanga  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
77c478bd9Sstevel@tonic-gate 
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
117c478bd9Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
127c478bd9Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
137c478bd9Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
167c478bd9Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
177c478bd9Sstevel@tonic-gate  * implied. See the License for the specific language governing
187c478bd9Sstevel@tonic-gate  * rights and limitations under the License.
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
217c478bd9Sstevel@tonic-gate  * March 31, 1998.
227c478bd9Sstevel@tonic-gate  *
237c478bd9Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
247c478bd9Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
257c478bd9Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
267c478bd9Sstevel@tonic-gate  * Rights Reserved.
277c478bd9Sstevel@tonic-gate  *
287c478bd9Sstevel@tonic-gate  * Contributor(s):
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Public interface for libprldap -- use NSPR (Netscape Portable Runtime)
337c478bd9Sstevel@tonic-gate  * I/O, threads, etc. with libldap.
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include "ldappr-int.h"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Function: prldap_init().
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  * Create a new LDAP session handle, but with NSPR I/O, threading, and DNS
447c478bd9Sstevel@tonic-gate  * functions installed.
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  * Pass a non-zero value for the 'shared' parameter if you plan to use
477c478bd9Sstevel@tonic-gate  * this LDAP * handle from more than one thread.
487c478bd9Sstevel@tonic-gate  *
497c478bd9Sstevel@tonic-gate  * prldap_init() returns an LDAP session handle (or NULL if an error occurs).
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate LDAP * LDAP_CALL
527c478bd9Sstevel@tonic-gate prldap_init( const char *defhost, int defport, int shared )
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate     LDAP	*ld;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate     if (( ld = ldap_init( defhost, defport )) != NULL ) {
577c478bd9Sstevel@tonic-gate 	if ( prldap_install_routines( ld, shared ) != LDAP_SUCCESS ) {
587c478bd9Sstevel@tonic-gate 	    prldap_set_system_errno( EINVAL );	/* XXXmcs: just a guess! */
597c478bd9Sstevel@tonic-gate 	    ldap_unbind( ld );
607c478bd9Sstevel@tonic-gate 	    ld = NULL;
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate     }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate     return( ld );
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Function: prldap_install_routines().
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  * Install NSPR I/O, threading, and DNS functions so they will be used by
727c478bd9Sstevel@tonic-gate  * 'ld'.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  * If 'ld' is NULL, the functions are installed as the default functions
757c478bd9Sstevel@tonic-gate  * for all new LDAP * handles).
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * Pass a non-zero value for the 'shared' parameter if you plan to use
787c478bd9Sstevel@tonic-gate  * this LDAP * handle from more than one thread.
797c478bd9Sstevel@tonic-gate  *
807c478bd9Sstevel@tonic-gate  * prldap_install_routines() returns an LDAP API error code (LDAP_SUCCESS
817c478bd9Sstevel@tonic-gate  * if all goes well).
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate int LDAP_CALL
847c478bd9Sstevel@tonic-gate prldap_install_routines( LDAP *ld, int shared )
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate     if ( prldap_install_io_functions( ld, shared ) != 0
887c478bd9Sstevel@tonic-gate 		|| prldap_install_thread_functions( ld, shared ) != 0
897c478bd9Sstevel@tonic-gate 		|| prldap_install_dns_functions( ld ) != 0 ) {
907c478bd9Sstevel@tonic-gate 	return( ldap_get_lderrno( ld, NULL, NULL ));
917c478bd9Sstevel@tonic-gate     }
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate     return( LDAP_SUCCESS );
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Function: prldap_set_session_option().
997c478bd9Sstevel@tonic-gate  *
1007c478bd9Sstevel@tonic-gate  * Given an LDAP session handle or a session argument such is passed to
1017c478bd9Sstevel@tonic-gate  * SOCKET, POLL, NEWHANDLE, or DISPOSEHANDLE extended I/O callbacks, set
1027c478bd9Sstevel@tonic-gate  * an option that affects the prldap layer.
1037c478bd9Sstevel@tonic-gate  *
1047c478bd9Sstevel@tonic-gate  * If 'ld' and 'session" are both NULL, the option is set as the default
1057c478bd9Sstevel@tonic-gate  * for all new prldap sessions.
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well).
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate int LDAP_CALL
1107c478bd9Sstevel@tonic-gate prldap_set_session_option( LDAP *ld, void *sessionarg, int option, ... )
1117c478bd9Sstevel@tonic-gate {
1127c478bd9Sstevel@tonic-gate     int				rc = LDAP_SUCCESS;	/* optimistic */
1137c478bd9Sstevel@tonic-gate     PRLDAPIOSessionArg		*prsessp = NULL;
1147c478bd9Sstevel@tonic-gate     va_list			ap;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate     if ( NULL != ld ) {
1177c478bd9Sstevel@tonic-gate 	if ( LDAP_SUCCESS !=
1187c478bd9Sstevel@tonic-gate 		( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
1197c478bd9Sstevel@tonic-gate 	    return( rc );
1207c478bd9Sstevel@tonic-gate 	}
1217c478bd9Sstevel@tonic-gate     } else if ( NULL != sessionarg ) {
1227c478bd9Sstevel@tonic-gate 	prsessp = (PRLDAPIOSessionArg *)sessionarg;
1237c478bd9Sstevel@tonic-gate     }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate     va_start( ap, option );
1267c478bd9Sstevel@tonic-gate     switch ( option ) {
1277c478bd9Sstevel@tonic-gate     case PRLDAP_OPT_IO_MAX_TIMEOUT:
1287c478bd9Sstevel@tonic-gate 	rc = prldap_set_io_max_timeout( prsessp, va_arg( ap, int ));
1297c478bd9Sstevel@tonic-gate 	break;
1307c478bd9Sstevel@tonic-gate     default:
1317c478bd9Sstevel@tonic-gate 	rc = LDAP_PARAM_ERROR;
1327c478bd9Sstevel@tonic-gate     }
1337c478bd9Sstevel@tonic-gate     va_end( ap );
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate     return( rc );
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate  * Function: prldap_get_session_option().
1417c478bd9Sstevel@tonic-gate  *
1427c478bd9Sstevel@tonic-gate  * Given an LDAP session handle or a session argument such is passed to
1437c478bd9Sstevel@tonic-gate  * SOCKET, POLL, NEWHANDLE, or DISPOSEHANDLE extended I/O callbacks, retrieve
1447c478bd9Sstevel@tonic-gate  * the setting for an option that affects the prldap layer.
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  * If 'ld' and 'session" are both NULL, the default option value for all new
1477c478bd9Sstevel@tonic-gate  * new prldap sessions is retrieved.
1487c478bd9Sstevel@tonic-gate  *
1497c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well).
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate int LDAP_CALL prldap_get_session_option( LDAP *ld, void *sessionarg,
1527c478bd9Sstevel@tonic-gate         int option, ... )
1537c478bd9Sstevel@tonic-gate {
1547c478bd9Sstevel@tonic-gate     int				rc = LDAP_SUCCESS;	/* optimistic */
1557c478bd9Sstevel@tonic-gate     PRLDAPIOSessionArg		*prsessp = NULL;
1567c478bd9Sstevel@tonic-gate     va_list			ap;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate     if ( NULL != ld ) {
1597c478bd9Sstevel@tonic-gate 	if ( LDAP_SUCCESS !=
1607c478bd9Sstevel@tonic-gate 		( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
1617c478bd9Sstevel@tonic-gate 	    return( rc );
1627c478bd9Sstevel@tonic-gate 	}
1637c478bd9Sstevel@tonic-gate     } else if ( NULL != sessionarg ) {
1647c478bd9Sstevel@tonic-gate 	prsessp = (PRLDAPIOSessionArg *)sessionarg;
1657c478bd9Sstevel@tonic-gate     }
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate     va_start( ap, option );
1687c478bd9Sstevel@tonic-gate     switch ( option ) {
1697c478bd9Sstevel@tonic-gate     case PRLDAP_OPT_IO_MAX_TIMEOUT:
1707c478bd9Sstevel@tonic-gate 	rc = prldap_get_io_max_timeout( prsessp, va_arg( ap, int * ));
1717c478bd9Sstevel@tonic-gate 	break;
1727c478bd9Sstevel@tonic-gate     default:
1737c478bd9Sstevel@tonic-gate 	rc = LDAP_PARAM_ERROR;
1747c478bd9Sstevel@tonic-gate     }
1757c478bd9Sstevel@tonic-gate     va_end( ap );
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate     return( rc );
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * Function: prldap_set_session_info().
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  * Given an LDAP session handle, set some application-specific data.
1857c478bd9Sstevel@tonic-gate  *
1867c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well).
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate int LDAP_CALL
1897c478bd9Sstevel@tonic-gate prldap_set_session_info( LDAP *ld, void *sessionarg, PRLDAPSessionInfo *seip )
1907c478bd9Sstevel@tonic-gate {
1917c478bd9Sstevel@tonic-gate     int				rc;
1927c478bd9Sstevel@tonic-gate     PRLDAPIOSessionArg		*prsessp;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate     if ( seip == NULL || PRLDAP_SESSIONINFO_SIZE != seip->seinfo_size ) {
1957c478bd9Sstevel@tonic-gate 	ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
1967c478bd9Sstevel@tonic-gate 	return( LDAP_PARAM_ERROR );
1977c478bd9Sstevel@tonic-gate     }
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate     if ( NULL != ld ) {
2007c478bd9Sstevel@tonic-gate 	if ( LDAP_SUCCESS !=
2017c478bd9Sstevel@tonic-gate 		( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
2027c478bd9Sstevel@tonic-gate 	    return( rc );
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate     } else if ( NULL != sessionarg ) {
2057c478bd9Sstevel@tonic-gate 	prsessp = (PRLDAPIOSessionArg *)sessionarg;
2067c478bd9Sstevel@tonic-gate     } else {
2077c478bd9Sstevel@tonic-gate 	ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
2087c478bd9Sstevel@tonic-gate 	return( LDAP_PARAM_ERROR );
2097c478bd9Sstevel@tonic-gate     }
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate     prsessp->prsess_appdata = seip->seinfo_appdata;
2127c478bd9Sstevel@tonic-gate     return( LDAP_SUCCESS );
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate /*
2177c478bd9Sstevel@tonic-gate  * Function: prldap_get_session_info().
2187c478bd9Sstevel@tonic-gate  *
2197c478bd9Sstevel@tonic-gate  * Given an LDAP session handle, retrieve some application-specific data.
2207c478bd9Sstevel@tonic-gate  *
2217c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well, in
2227c478bd9Sstevel@tonic-gate  * which case the fields in the structure that seip points to are filled in).
2237c478bd9Sstevel@tonic-gate  */
2247c478bd9Sstevel@tonic-gate int LDAP_CALL
2257c478bd9Sstevel@tonic-gate prldap_get_session_info( LDAP *ld, void *sessionarg, PRLDAPSessionInfo *seip )
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate     int				rc;
2287c478bd9Sstevel@tonic-gate     PRLDAPIOSessionArg		*prsessp;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate     if ( seip == NULL || PRLDAP_SESSIONINFO_SIZE != seip->seinfo_size ) {
2317c478bd9Sstevel@tonic-gate 	ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
2327c478bd9Sstevel@tonic-gate 	return( LDAP_PARAM_ERROR );
2337c478bd9Sstevel@tonic-gate     }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate     if ( NULL != ld ) {
2367c478bd9Sstevel@tonic-gate 	if ( LDAP_SUCCESS !=
2377c478bd9Sstevel@tonic-gate 		( rc = prldap_session_arg_from_ld( ld, &prsessp ))) {
2387c478bd9Sstevel@tonic-gate 	    return( rc );
2397c478bd9Sstevel@tonic-gate 	}
2407c478bd9Sstevel@tonic-gate     } else if ( NULL != sessionarg ) {
2417c478bd9Sstevel@tonic-gate 	prsessp = (PRLDAPIOSessionArg *)sessionarg;
2427c478bd9Sstevel@tonic-gate     } else {
2437c478bd9Sstevel@tonic-gate 	ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
2447c478bd9Sstevel@tonic-gate 	return( LDAP_PARAM_ERROR );
2457c478bd9Sstevel@tonic-gate     }
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate     seip->seinfo_appdata = prsessp->prsess_appdata;
2487c478bd9Sstevel@tonic-gate     return( LDAP_SUCCESS );
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * Function: prldap_set_socket_info().
2547c478bd9Sstevel@tonic-gate  *
2557c478bd9Sstevel@tonic-gate  * Given an integer fd and a void * argument such as those passed to the
2567c478bd9Sstevel@tonic-gate  * extended I/O callback functions, set socket specific information.
2577c478bd9Sstevel@tonic-gate  *
2587c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well).
2597c478bd9Sstevel@tonic-gate  *
2607c478bd9Sstevel@tonic-gate  * Note: it is only safe to change soinfo_prfd from within the SOCKET
2617c478bd9Sstevel@tonic-gate  * extended I/O callback function.
2627c478bd9Sstevel@tonic-gate  */
2637c478bd9Sstevel@tonic-gate int LDAP_CALL
2647c478bd9Sstevel@tonic-gate prldap_set_socket_info( int fd, void *socketarg, PRLDAPSocketInfo *soip )
2657c478bd9Sstevel@tonic-gate {
2667c478bd9Sstevel@tonic-gate     PRLDAPIOSocketArg	*prsockp;
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate     if ( NULL == socketarg || NULL == soip ||
2697c478bd9Sstevel@tonic-gate 		PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
2707c478bd9Sstevel@tonic-gate 	return( LDAP_PARAM_ERROR );
2717c478bd9Sstevel@tonic-gate     }
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate     prsockp = (PRLDAPIOSocketArg *)socketarg;
2747c478bd9Sstevel@tonic-gate     prsockp->prsock_prfd = soip->soinfo_prfd;
2757c478bd9Sstevel@tonic-gate     prsockp->prsock_appdata = soip->soinfo_appdata;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate     return( LDAP_SUCCESS );
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate /*
2827c478bd9Sstevel@tonic-gate  * Function: prldap_get_socket_info().
2837c478bd9Sstevel@tonic-gate  *
2847c478bd9Sstevel@tonic-gate  * Given an integer fd and a void * argument such as those passed to the
2857c478bd9Sstevel@tonic-gate  * extended I/O callback functions, retrieve socket specific information.
2867c478bd9Sstevel@tonic-gate  *
2877c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well, in
2887c478bd9Sstevel@tonic-gate  * which case the fields in the structure that soip points to are filled in).
2897c478bd9Sstevel@tonic-gate  */
2907c478bd9Sstevel@tonic-gate int LDAP_CALL
2917c478bd9Sstevel@tonic-gate prldap_get_socket_info( int fd, void *socketarg, PRLDAPSocketInfo *soip )
2927c478bd9Sstevel@tonic-gate {
2937c478bd9Sstevel@tonic-gate     PRLDAPIOSocketArg	*prsockp;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate     if ( NULL == socketarg || NULL == soip ||
2967c478bd9Sstevel@tonic-gate 		PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
2977c478bd9Sstevel@tonic-gate 	return( LDAP_PARAM_ERROR );
2987c478bd9Sstevel@tonic-gate     }
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate     prsockp = (PRLDAPIOSocketArg *)socketarg;
3017c478bd9Sstevel@tonic-gate     soip->soinfo_prfd = prsockp->prsock_prfd;
3027c478bd9Sstevel@tonic-gate     soip->soinfo_appdata = prsockp->prsock_appdata;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate     return( LDAP_SUCCESS );
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate  * Function: prldap_get_default_socket_info().
3097c478bd9Sstevel@tonic-gate  *
3107c478bd9Sstevel@tonic-gate  * Given an LDAP session handle, retrieve socket specific information.
3117c478bd9Sstevel@tonic-gate  * If ld is NULL, LDAP_PARAM_ERROR is returned.
3127c478bd9Sstevel@tonic-gate  *
3137c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well, in
3147c478bd9Sstevel@tonic-gate  * which case the fields in the structure that soip points to are filled in).
3157c478bd9Sstevel@tonic-gate  */
3167c478bd9Sstevel@tonic-gate int LDAP_CALL
3177c478bd9Sstevel@tonic-gate prldap_get_default_socket_info( LDAP *ld, PRLDAPSocketInfo *soip )
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate     int rc;
3207c478bd9Sstevel@tonic-gate     PRLDAPIOSocketArg *prsockp;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate     if ( NULL == soip || PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
3247c478bd9Sstevel@tonic-gate         ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
3257c478bd9Sstevel@tonic-gate         return( LDAP_PARAM_ERROR );
3267c478bd9Sstevel@tonic-gate     }
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate     if ( NULL != ld ) {
3297c478bd9Sstevel@tonic-gate         if ( LDAP_SUCCESS !=
3307c478bd9Sstevel@tonic-gate                 ( rc = prldap_socket_arg_from_ld( ld, &prsockp ))) {
3317c478bd9Sstevel@tonic-gate             return( rc );
3327c478bd9Sstevel@tonic-gate         }
3337c478bd9Sstevel@tonic-gate     } else {
3347c478bd9Sstevel@tonic-gate         ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
3357c478bd9Sstevel@tonic-gate         return( LDAP_PARAM_ERROR );
3367c478bd9Sstevel@tonic-gate     }
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate     soip->soinfo_prfd = prsockp->prsock_prfd;
3397c478bd9Sstevel@tonic-gate     soip->soinfo_appdata = prsockp->prsock_appdata;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate     return( LDAP_SUCCESS );
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /*
3467c478bd9Sstevel@tonic-gate  * Function: prldap_set_default_socket_info().
3477c478bd9Sstevel@tonic-gate  *
3487c478bd9Sstevel@tonic-gate  * Given an LDAP session handle, set socket specific information.
3497c478bd9Sstevel@tonic-gate  * If ld is NULL, LDAP_PARAM_ERROR is returned.
3507c478bd9Sstevel@tonic-gate  *
3517c478bd9Sstevel@tonic-gate  * Returns an LDAP API error code (LDAP_SUCCESS if all goes well, in
3527c478bd9Sstevel@tonic-gate  * which case the fields in the structure that soip points to are filled in).
3537c478bd9Sstevel@tonic-gate  */
3547c478bd9Sstevel@tonic-gate int LDAP_CALL
3557c478bd9Sstevel@tonic-gate prldap_set_default_socket_info( LDAP *ld, PRLDAPSocketInfo *soip )
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate     int rc;
3587c478bd9Sstevel@tonic-gate     PRLDAPIOSocketArg *prsockp;
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate     if ( NULL == soip || PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) {
3627c478bd9Sstevel@tonic-gate         ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
3637c478bd9Sstevel@tonic-gate         return( LDAP_PARAM_ERROR );
3647c478bd9Sstevel@tonic-gate     }
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate     if ( NULL != ld ) {
3677c478bd9Sstevel@tonic-gate         if ( LDAP_SUCCESS !=
3687c478bd9Sstevel@tonic-gate                 ( rc = prldap_socket_arg_from_ld( ld, &prsockp ))) {
3697c478bd9Sstevel@tonic-gate             return( rc );
3707c478bd9Sstevel@tonic-gate         }
3717c478bd9Sstevel@tonic-gate     } else {
3727c478bd9Sstevel@tonic-gate         ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL );
3737c478bd9Sstevel@tonic-gate         return( LDAP_PARAM_ERROR );
3747c478bd9Sstevel@tonic-gate     }
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate     prsockp->prsock_prfd = soip->soinfo_prfd;
3777c478bd9Sstevel@tonic-gate     prsockp->prsock_appdata = soip->soinfo_appdata;
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate     return( LDAP_SUCCESS );
3807c478bd9Sstevel@tonic-gate }
381