/* * Function: prldap_set_default_socket_info(). * * Given an LDAP session handle, set socket specific information. * If ld is NULL, LDAP_PARAM_ERROR is returned. * * Returns an LDAP API error code (LDAP_SUCCESS if all goes well, in * which case the fields in the structure that soip points to are filled in). */ int LDAP_CALL prldap_set_default_socket_info( LDAP *ld, PRLDAPSocketInfo *soip ) { int rc; PRLDAPIOSocketArg *prsockp; if ( NULL == soip || PRLDAP_SOCKETINFO_SIZE != soip->soinfo_size ) { ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL ); return( LDAP_PARAM_ERROR ); } if ( NULL != ld ) { if ( LDAP_SUCCESS != ( rc = prldap_socket_arg_from_ld( ld, &prsockp ))) { return( rc ); } } else { ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL ); return( LDAP_PARAM_ERROR ); } prsockp->prsock_prfd = soip->soinfo_prfd; prsockp->prsock_appdata = soip->soinfo_appdata; return( LDAP_SUCCESS ); }
/* * Function: prldap_get_session_info(). * * Given an LDAP session handle, retrieve some application-specific data. * * Returns an LDAP API error code (LDAP_SUCCESS if all goes well, in * which case the fields in the structure that seip points to are filled in). */ int LDAP_CALL prldap_get_session_info( LDAP *ld, void *sessionarg, PRLDAPSessionInfo *seip ) { int rc; PRLDAPIOSessionArg *prsessp; if ( seip == NULL || PRLDAP_SESSIONINFO_SIZE != seip->seinfo_size ) { ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL ); return( LDAP_PARAM_ERROR ); } if ( NULL != ld ) { if ( LDAP_SUCCESS != ( rc = prldap_session_arg_from_ld( ld, &prsessp ))) { return( rc ); } } else if ( NULL != sessionarg ) { prsessp = (PRLDAPIOSessionArg *)sessionarg; } else { ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL ); return( LDAP_PARAM_ERROR ); } seip->seinfo_appdata = prsessp->prsess_appdata; return( LDAP_SUCCESS ); }
/* * Function: prldap_import_connection(). * * Given the LDAP handle the connection parameters for the * file descriptor are imported into NSPR layer. * * Returns an LDAP API code (LDAP_SUCCESS) if all goes well. */ int LDAP_CALL prldap_import_connection (LDAP *ld) { int rc = LDAP_SUCCESS; /* optimistic */ int shared = 1; /* Assume shared init */ LBER_SOCKET orig_socket = -1; PRLDAPIOSessionArg *prsessp = NULL; PRLDAPIOSocketArg *prsockp = NULL; PRFileDesc *pr_socket = NULL; /* Check for invalid ld handle */ if ( ld == NULL) { ldap_set_lderrno( ld, LDAP_PARAM_ERROR, NULL, NULL ); return( LDAP_PARAM_ERROR ); } /* Retrieve TCP socket's integer file descriptor */ if ( ldap_get_option( ld, LDAP_OPT_DESC, &orig_socket ) < 0 ) { return( ldap_get_lderrno( ld, NULL, NULL )); } /* Check for NSPR functions on ld */ if ( prldap_is_installed(ld)) { /* Error : NSPR already Installed */ ldap_set_lderrno( ld, LDAP_LOCAL_ERROR, NULL, NULL ); return( LDAP_LOCAL_ERROR ); } if (LDAP_SUCCESS != (rc = prldap_install_routines(ld, shared))) { return( rc ); } if (LDAP_SUCCESS != (rc = prldap_session_arg_from_ld( ld, &prsessp ))) { return( rc ); } /* Get NSPR Socket Arg */ if ( NULL == ( prsockp = prldap_socket_arg_alloc( prsessp ))) { ldap_set_lderrno( ld, LDAP_NO_MEMORY, NULL, NULL ); return( LDAP_NO_MEMORY ); } /* Import file descriptor of connection made via ldap_init() */ if (NULL == (pr_socket = PR_ImportTCPSocket(orig_socket)) ) { ldap_set_lderrno( ld, LDAP_LOCAL_ERROR, NULL, NULL ); return( LDAP_LOCAL_ERROR ); } prsockp->prsock_prfd = pr_socket; /* Set Socket Arg in Extended I/O Layer */ if ( ldap_set_option( ld, LDAP_X_OPT_SOCKETARG, prsockp) != 0 ) { return( ldap_get_lderrno( ld, NULL, NULL )); } return( rc ); }
/* * Install NSPR thread functions into ld (if ld is NULL, they are installed * as the default functions for new LDAP * handles). * * Returns 0 if all goes well and -1 if not. */ int prldap_install_thread_functions( LDAP *ld, int shared ) { struct ldap_thread_fns tfns; struct ldap_extra_thread_fns xtfns; if ( PR_CallOnce( &prldap_callonce_init_tpd, prldap_init_tpd ) != PR_SUCCESS ) { ldap_set_lderrno( ld, LDAP_LOCAL_ERROR, NULL, NULL ); return( -1 ); } /* set thread function pointers */ memset( &tfns, '\0', sizeof(struct ldap_thread_fns) ); tfns.ltf_get_errno = prldap_get_system_errno; tfns.ltf_set_errno = prldap_set_system_errno; if ( shared ) { tfns.ltf_mutex_alloc = prldap_mutex_alloc; tfns.ltf_mutex_free = prldap_mutex_free; tfns.ltf_mutex_lock = prldap_mutex_lock; tfns.ltf_mutex_unlock = prldap_mutex_unlock; tfns.ltf_get_lderrno = prldap_get_ld_error; tfns.ltf_set_lderrno = prldap_set_ld_error; if ( ld != NULL ) { /* * If this is a real ld (i.e., we are not setting the global * defaults) allocate thread private data for error information. * If ld is NULL we do not do this here but it is done in * prldap_thread_new_handle(). */ if (( tfns.ltf_lderrno_arg = (void *)prldap_allocate_map( ld )) == NULL ) { return( -1 ); } } } if ( ldap_set_option( ld, LDAP_OPT_THREAD_FN_PTRS, (void *)&tfns ) != 0 ) { prldap_return_map( (PRLDAP_TPDMap *)tfns.ltf_lderrno_arg ); return( -1 ); } /* set extended thread function pointers */ memset( &xtfns, '\0', sizeof(struct ldap_extra_thread_fns) ); xtfns.ltf_threadid_fn = prldap_get_thread_id; if ( ldap_set_option( ld, LDAP_OPT_EXTRA_THREAD_FN_PTRS, (void *)&xtfns ) != 0 ) { return( -1 ); } return( 0 ); }
/* * More API masking. */ int our_ldap_set_lderrno(LDAP *ld, int e, char *m, char *s) { int ret; #if (LDAPAPI >= 2000) if(ldap_set_option(ld, LDAP_OPT_ERROR_NUMBER, (void *)&e) == 0) ret = LDAP_SUCCESS; else (void)ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, (void *)&ret); #elif (LDAPAPI >= 15) ret = ldap_set_lderrno(ld, e, m, s); #else /* this is all we care about */ ld->ld_errno = e; ret = LDAP_SUCCESS; #endif return(ret); }