} else { srv->lsrv_port = secure ? LDAPS_PORT : LDAP_PORT; LDAPDebug( LDAP_DEBUG_TRACE, "chase_one_referral: using default port (%d)\n", srv->lsrv_port, 0, 0 );
chase_one_referral( LDAP *ld, LDAPRequest *lr, LDAPRequest *origreq,    char *refurl, char *desc, int *unknownp ){	int		rc, tmprc, secure, msgid;	LDAPServer	*srv;	BerElement	*ber;	LDAPURLDesc	*ludp;	*unknownp = 0;	ludp = NULLLDAPURLDESC;	if ( nsldapi_url_parse( refurl, &ludp, 0 ) != 0 ) {		LDAPDebug( LDAP_DEBUG_TRACE,		    "ignoring unknown %s <%s>\n", desc, refurl, 0 );		*unknownp = 1;		rc = LDAP_SUCCESS;		goto cleanup_and_return;	}	secure = (( ludp->lud_options & LDAP_URL_OPT_SECURE ) != 0 );/* XXXmcs: can't tell if secure is supported by connect callback */	if ( secure && ld->ld_extconnect_fn == NULL ) {		LDAPDebug( LDAP_DEBUG_TRACE,		    "ignoring LDAPS %s <%s>\n", desc, refurl, 0 );		*unknownp = 1;		rc = LDAP_SUCCESS;		goto cleanup_and_return;	}	LDAPDebug( LDAP_DEBUG_TRACE, "chasing LDAP%s %s: <%s>\n",	    secure ? "S" : "", desc, refurl );	LDAP_MUTEX_LOCK( ld, LDAP_MSGID_LOCK );	msgid = ++ld->ld_msgid;	LDAP_MUTEX_UNLOCK( ld, LDAP_MSGID_LOCK );	if (( tmprc = re_encode_request( ld, origreq->lr_ber, msgid,	    ludp, &ber )) != LDAP_SUCCESS ) {		rc = tmprc;		goto cleanup_and_return;	}	if (( srv = (LDAPServer *)NSLDAPI_CALLOC( 1, sizeof( LDAPServer )))	    == NULL ) {		ber_free( ber, 1 );		rc = LDAP_NO_MEMORY;		goto cleanup_and_return;	}	if ( ludp->lud_host == NULL && ld->ld_defhost == NULL ) {		srv->lsrv_host = NULL;	} else {		if ( ludp->lud_host == NULL ) {		  srv->lsrv_host =		    nsldapi_strdup( origreq->lr_conn->lconn_server->lsrv_host );		  LDAPDebug( LDAP_DEBUG_TRACE,		    "chase_one_referral: using hostname '%s' from original "		    "request on new request\n",		    srv->lsrv_host, 0, 0);		} else {		  srv->lsrv_host = nsldapi_strdup( ludp->lud_host );		  LDAPDebug( LDAP_DEBUG_TRACE,		    "chase_one_referral: using hostname '%s' as specified "		    "on new request\n",		    srv->lsrv_host, 0, 0);		}		if ( srv->lsrv_host == NULL ) {			NSLDAPI_FREE( (char *)srv );			ber_free( ber, 1 );			rc = LDAP_NO_MEMORY;			goto cleanup_and_return;		}	}	if ( ludp->lud_port == 0 && ludp->lud_host == NULL ) {		srv->lsrv_port = origreq->lr_conn->lconn_server->lsrv_port;		LDAPDebug( LDAP_DEBUG_TRACE,		    "chase_one_referral: using port (%d) from original "		    "request on new request\n",		    srv->lsrv_port, 0, 0);	} else {		srv->lsrv_port = ludp->lud_port;		LDAPDebug( LDAP_DEBUG_TRACE,		    "chase_one_referral: using port (%d) as specified on "		    "new request\n",		    srv->lsrv_port, 0, 0);	}	if ( secure ) {		srv->lsrv_options |= LDAP_SRV_OPT_SECURE;	}	if ( nsldapi_send_server_request( ld, ber, msgid,	    lr, srv, NULL, NULL, 1 ) < 0 ) {		rc = LDAP_GET_LDERRNO( ld, NULL, NULL );		LDAPDebug( LDAP_DEBUG_ANY, "Unable to chase %s %s (%s)\n",		    desc, refurl, ldap_err2string( rc ));	} else {		rc = LDAP_SUCCESS;	}cleanup_and_return:	if ( ludp != NULLLDAPURLDESC ) {		ldap_free_urldesc( ludp );	}	return( rc );}