Subject: Re: agent support

Re: agent support

From: Thomas Stover <>
Date: Thu, 17 Jun 2010 10:14:54 -0500

1) as Peter suggested, I changed my libssh2_agent_userauth() function to

libssh2_agent_userauth(LIBSSH2_AGENT *agent,
                       const char *username,
                       struct libssh2_agent_publickey *identity)
    int rc;
    void *abstract = agent;
    if (agent->session->userauth_pblc_state == libssh2_NB_state_idle) {
        memset(&agent->transctx, 0, sizeof agent->transctx);
        agent->identity = identity->node;
    return _libssh2_userauth_publickey(agent->session, username,

    memset(&agent->transctx, 0, sizeof agent->transctx);
    agent->identity = identity->node;
    do {
        rc = _libssh2_userauth_publickey(agent->session, username,
                                         strlen(username), identity->blob,
                                         identity->blob_len, agent_sign,
    } while (LIBSSH2_ERROR_EAGAIN == rc);
    return rc;


which does fix the problem for me. (still haven't tried win32 yet though)

2) Daniel mentions the busy loop problem needs to be addressed with
BLOCK_ADJUST(). Where is that macro defined?

3) Thinking this through further down the line brings up a related
question for me. While in many cases the agent operations would be part of
a program's startup, and therefore blocking for them to complete might be
acceptable, what if it was not - say in a gui program without bringing
threads into the picture. If I had an event loop style program where I
check for input on sockets and then call libssh2_* and other functions in
response to stimulus, could the same be done with the agent socket? ie do
my own poll on agent->fd and on session->socket_fd, then call
libssh2_agent_userauth() until either error or success somehow?

Bare in mind that communication with an agent is not always a "fast" local
program. It could be multiple cascading layers of agent forwarding on
slower connections taking seconds to complete an authenticate operation.

4) Anyway thanks for the help. Now that agent support works at least some
how, I'll revisit my ideas for using the library I put to the side a while

Received on 2010-06-17