ctrl_array[0] = &auth_resp_ctrl; ctrl_array[1] = NULL;
if ( !no_pwpolicy_req_ctrl ) { pwpolicy_req_ctrl.ldctl_oid = LDAP_X_CONTROL_PWPOLICY_REQUEST; pwpolicy_req_ctrl.ldctl_value.bv_val = NULL; pwpolicy_req_ctrl.ldctl_value.bv_len = 0; pwpolicy_req_ctrl.ldctl_iscritical = 0; ctrl_array[ctrl_index++] = &pwpolicy_req_ctrl; }  if ( ctrl_index == 0 ) { bindctrls = NULL; } else { ctrl_array[ctrl_index] = NULL;
ldaptool_bind( LDAP *ld ){    int		rc;    char	*conv;    LDAPControl	auth_resp_ctrl, *ctrl_array[ 2 ], **bindctrls;    if ( ldaptool_not ) {	return;    }    if ( send_auth_response_ctrl ) {	auth_resp_ctrl.ldctl_oid = LDAP_CONTROL_AUTH_REQUEST;	auth_resp_ctrl.ldctl_value.bv_val = NULL;	auth_resp_ctrl.ldctl_value.bv_len = 0;	auth_resp_ctrl.ldctl_iscritical = 0;	ctrl_array[0] = &auth_resp_ctrl;	ctrl_array[1] = NULL;	bindctrls = ctrl_array;    } else {	bindctrls = NULL;    }    /*     * if using LDAPv3 and not using client auth., omit NULL bind for     * efficiency.     */    if ( ldversion > LDAP_VERSION2 && binddn == NULL && passwd == NULL	    && ssl_certname == NULL ) {	return;    }    /*     * do the bind, backing off one LDAP version if necessary     */    conv = ldaptool_local2UTF8( binddn, "bind DN" );    /*     * if using LDAPv3 and client auth., try a SASL EXTERNAL bind     */    if ( ldversion > LDAP_VERSION2 && binddn == NULL && passwd == NULL	    && ssl_certname != NULL ) {	rc = ldaptool_sasl_bind_s( ld, NULL, LDAP_SASL_EXTERNAL, NULL,		bindctrls, NULL, NULL, "ldap_sasl_bind" );    } else {	rc = ldaptool_simple_bind_s( ld, conv, passwd, bindctrls, NULL,		    "ldap_simple_bind" );    }    if ( rc == LDAP_SUCCESS ) {        if ( conv != NULL ) {           free( conv );	}	return;			/* success */    }    if ( rc == LDAP_PROTOCOL_ERROR && ldversion > LDAP_VERSION2 ) {	/*	 * try again, backing off one LDAP version	 * this is okay even for client auth. because the way to achieve	 * client auth. with LDAPv2 is to perform a NULL simple bind.	 */	--ldversion;	fprintf( stderr, "%s: the server doesn't understand LDAPv%d;"		" trying LDAPv%d instead...\n", ldaptool_progname,		ldversion + 1, ldversion );	ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &ldversion );	if (( rc = ldaptool_simple_bind_s( ld, conv, passwd,		bindctrls, NULL, "ldap_simple_bind" )) == LDAP_SUCCESS ) {            if( conv != NULL )                free( conv );	    return;		/* a qualified success */	}    }    if ( conv != NULL ) {        free( conv );    }    /*     * bind(s) failed -- fatal error     */    ldap_unbind( ld );    exit( rc );}