static int authenticate(BDRVSSHState *s, const char *user)

{

    int r, ret;

    const char *userauthlist;

    LIBSSH2_AGENT *agent = NULL;

    struct libssh2_agent_publickey *identity;

    struct libssh2_agent_publickey *prev_identity = NULL;



    userauthlist = libssh2_userauth_list(s->session, user, strlen(user));

    if (strstr(userauthlist, "publickey") == NULL) {

        ret = -EPERM;

        error_report("remote server does not support \"publickey\" authentication");

        goto out;

    }



    /* Connect to ssh-agent and try each identity in turn. */

    agent = libssh2_agent_init(s->session);

    if (!agent) {

        ret = -EINVAL;

        session_error_report(s, "failed to initialize ssh-agent support");

        goto out;

    }

    if (libssh2_agent_connect(agent)) {

        ret = -ECONNREFUSED;

        session_error_report(s, "failed to connect to ssh-agent");

        goto out;

    }

    if (libssh2_agent_list_identities(agent)) {

        ret = -EINVAL;

        session_error_report(s, "failed requesting identities from ssh-agent");

        goto out;

    }



    for(;;) {

        r = libssh2_agent_get_identity(agent, &identity, prev_identity);

        if (r == 1) {           /* end of list */

            break;

        }

        if (r < 0) {

            ret = -EINVAL;

            session_error_report(s, "failed to obtain identity from ssh-agent");

            goto out;

        }

        r = libssh2_agent_userauth(agent, user, identity);

        if (r == 0) {

            /* Authenticated! */

            ret = 0;

            goto out;

        }

        /* Failed to authenticate with this identity, try the next one. */

        prev_identity = identity;

    }



    ret = -EPERM;

    error_report("failed to authenticate using publickey authentication "

                 "and the identities held by your ssh-agent");



 out:

    if (agent != NULL) {

        /* Note: libssh2 implementation implicitly calls

         * libssh2_agent_disconnect if necessary.

         */

        libssh2_agent_free(agent);

    }



    return ret;

}

static int authenticate(BDRVSSHState *s, const char *user)

{

    int r, ret;

    const char *userauthlist;

    LIBSSH2_AGENT *agent = NULL;

    struct libssh2_agent_publickey *identity;

    struct libssh2_agent_publickey *prev_identity = NULL;



    userauthlist = libssh2_userauth_list(s->session, user, strlen(user));

    if (strstr(userauthlist, "publickey") == NULL) {

        ret = -EPERM;

        error_report("remote server does not support \"publickey\" authentication");

        goto out;

    }



    

    agent = libssh2_agent_init(s->session);

    if (!agent) {

        ret = -EINVAL;

        session_error_report(s, "failed to initialize ssh-agent support");

        goto out;

    }

    if (libssh2_agent_connect(agent)) {

        ret = -ECONNREFUSED;

        session_error_report(s, "failed to connect to ssh-agent");

        goto out;

    }

    if (libssh2_agent_list_identities(agent)) {

        ret = -EINVAL;

        session_error_report(s, "failed requesting identities from ssh-agent");

        goto out;

    }



    for(;;) {

        r = libssh2_agent_get_identity(agent, &identity, prev_identity);

        if (r == 1) {           

            break;

        }

        if (r < 0) {

            ret = -EINVAL;

            session_error_report(s, "failed to obtain identity from ssh-agent");

            goto out;

        }

        r = libssh2_agent_userauth(agent, user, identity);

        if (r == 0) {

            

            ret = 0;

            goto out;

        }

        

        prev_identity = identity;

    }



    ret = -EPERM;

    error_report("failed to authenticate using publickey authentication "

                 "and the identities held by your ssh-agent");



 out:

    if (agent != NULL) {

        





        libssh2_agent_free(agent);

    }



    return ret;

}

static int FUNC_0(BDRVSSHState *VAR_0, const char *VAR_1)

{

    int VAR_2, VAR_3;

    const char *VAR_4;

    LIBSSH2_AGENT *agent = NULL;

    struct libssh2_agent_publickey *VAR_5;

    struct libssh2_agent_publickey *VAR_6 = NULL;



    VAR_4 = libssh2_userauth_list(VAR_0->session, VAR_1, strlen(VAR_1));

    if (strstr(VAR_4, "publickey") == NULL) {

        VAR_3 = -EPERM;

        error_report("remote server does not support \"publickey\" authentication");

        goto out;

    }



    

    agent = libssh2_agent_init(VAR_0->session);

    if (!agent) {

        VAR_3 = -EINVAL;

        session_error_report(VAR_0, "failed to initialize ssh-agent support");

        goto out;

    }

    if (libssh2_agent_connect(agent)) {

        VAR_3 = -ECONNREFUSED;

        session_error_report(VAR_0, "failed to connect to ssh-agent");

        goto out;

    }

    if (libssh2_agent_list_identities(agent)) {

        VAR_3 = -EINVAL;

        session_error_report(VAR_0, "failed requesting identities from ssh-agent");

        goto out;

    }



    for(;;) {

        VAR_2 = libssh2_agent_get_identity(agent, &VAR_5, VAR_6);

        if (VAR_2 == 1) {           

            break;

        }

        if (VAR_2 < 0) {

            VAR_3 = -EINVAL;

            session_error_report(VAR_0, "failed to obtain VAR_5 from ssh-agent");

            goto out;

        }

        VAR_2 = libssh2_agent_userauth(agent, VAR_1, VAR_5);

        if (VAR_2 == 0) {

            

            VAR_3 = 0;

            goto out;

        }

        

        VAR_6 = VAR_5;

    }



    VAR_3 = -EPERM;

    error_report("failed to FUNC_0 using publickey authentication "

                 "and the identities held by your ssh-agent");



 out:

    if (agent != NULL) {

        





        libssh2_agent_free(agent);

    }



    return VAR_3;

}

static int FUNC_0(BDRVSSHState *VAR_0, const char *VAR_1)
{ int VAR_2, VAR_3; const char *VAR_4; LIBSSH2_AGENT *agent = NULL; struct libssh2_agent_publickey *VAR_5; struct libssh2_agent_publickey *VAR_6 = NULL; VAR_4 = libssh2_userauth_list(VAR_0->session, VAR_1, strlen(VAR_1)); if (strstr(VAR_4, "publickey") == NULL) { VAR_3 = -EPERM; error_report("remote server does not support \"publickey\" authentication"); goto out; } agent = libssh2_agent_init(VAR_0->session); if (!agent) { VAR_3 = -EINVAL; session_error_report(VAR_0, "failed to initialize ssh-agent support"); goto out; } if (libssh2_agent_connect(agent)) { VAR_3 = -ECONNREFUSED; session_error_report(VAR_0, "failed to connect to ssh-agent"); goto out; } if (libssh2_agent_list_identities(agent)) { VAR_3 = -EINVAL; session_error_report(VAR_0, "failed requesting identities from ssh-agent"); goto out; } for(;;) { VAR_2 = libssh2_agent_get_identity(agent, &VAR_5, VAR_6); if (VAR_2 == 1) { break; } if (VAR_2 < 0) { VAR_3 = -EINVAL; session_error_report(VAR_0, "failed to obtain VAR_5 from ssh-agent"); goto out; } VAR_2 = libssh2_agent_userauth(agent, VAR_1, VAR_5); if (VAR_2 == 0) { VAR_3 = 0; goto out; } VAR_6 = VAR_5; } VAR_3 = -EPERM; error_report("failed to FUNC_0 using publickey authentication "
"and the identities held by your ssh-agent"); out:
if (agent != NULL) { libssh2_agent_free(agent); } return VAR_3; }