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