diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2019-10-31 16:04:56 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2019-12-09 16:08:03 +0100 |
commit | c820d2a2dcd18d58603ca41bdc0a38410227b29b (patch) | |
tree | cef63c1f783c8e0a232b7e7bf2752764844e603b /src/agent.c | |
parent | b18acbdc7ebf850946e18e6207a5d9a0d598ac49 (diff) | |
download | libssh-c820d2a2dcd18d58603ca41bdc0a38410227b29b.tar.gz libssh-c820d2a2dcd18d58603ca41bdc0a38410227b29b.tar.xz libssh-c820d2a2dcd18d58603ca41bdc0a38410227b29b.zip |
agent: Reformat ssh_agent_get_ident_count()
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'src/agent.c')
-rw-r--r-- | src/agent.c | 147 |
1 files changed, 74 insertions, 73 deletions
diff --git a/src/agent.c b/src/agent.c index c34f3fc4..d35e45a2 100644 --- a/src/agent.c +++ b/src/agent.c @@ -307,90 +307,91 @@ static int agent_talk(struct ssh_session_struct *session, return 0; } -int ssh_agent_get_ident_count(struct ssh_session_struct *session) { - ssh_buffer request = NULL; - ssh_buffer reply = NULL; - unsigned int type = 0; - uint32_t count = 0; - int rc; - - /* send message to the agent requesting the list of identities */ - request = ssh_buffer_new(); - if (request == NULL) { - ssh_set_error_oom(session); - return -1; - } - if (ssh_buffer_add_u8(request, SSH2_AGENTC_REQUEST_IDENTITIES) < 0) { - ssh_set_error_oom(session); - ssh_buffer_free(request); - return -1; - } +int ssh_agent_get_ident_count(struct ssh_session_struct *session) +{ + ssh_buffer request = NULL; + ssh_buffer reply = NULL; + unsigned int type = 0; + uint32_t count = 0; + int rc; - reply = ssh_buffer_new(); - if (reply == NULL) { - ssh_buffer_free(request); - ssh_set_error(session, SSH_FATAL, "Not enough space"); - return -1; - } + /* send message to the agent requesting the list of identities */ + request = ssh_buffer_new(); + if (request == NULL) { + ssh_set_error_oom(session); + return -1; + } + if (ssh_buffer_add_u8(request, SSH2_AGENTC_REQUEST_IDENTITIES) < 0) { + ssh_set_error_oom(session); + ssh_buffer_free(request); + return -1; + } - if (agent_talk(session, request, reply) < 0) { + reply = ssh_buffer_new(); + if (reply == NULL) { + ssh_buffer_free(request); + ssh_set_error(session, SSH_FATAL, "Not enough space"); + return -1; + } + + if (agent_talk(session, request, reply) < 0) { + ssh_buffer_free(request); + ssh_buffer_free(reply); + return 0; + } ssh_buffer_free(request); - ssh_buffer_free(reply); - return 0; - } - ssh_buffer_free(request); - /* get message type and verify the answer */ - rc = ssh_buffer_get_u8(reply, (uint8_t *) &type); - if (rc != sizeof(uint8_t)) { - ssh_set_error(session, SSH_FATAL, - "Bad authentication reply size: %d", rc); - ssh_buffer_free(reply); - return -1; - } + /* get message type and verify the answer */ + rc = ssh_buffer_get_u8(reply, (uint8_t *) &type); + if (rc != sizeof(uint8_t)) { + ssh_set_error(session, SSH_FATAL, + "Bad authentication reply size: %d", rc); + ssh_buffer_free(reply); + return -1; + } #ifdef WORDS_BIGENDIAN - type = bswap_32(type); + type = bswap_32(type); #endif - SSH_LOG(SSH_LOG_WARN, - "Answer type: %d, expected answer: %d", - type, SSH2_AGENT_IDENTITIES_ANSWER); + SSH_LOG(SSH_LOG_WARN, + "Answer type: %d, expected answer: %d", + type, SSH2_AGENT_IDENTITIES_ANSWER); - if (agent_failed(type)) { - ssh_buffer_free(reply); - return 0; - } else if (type != SSH2_AGENT_IDENTITIES_ANSWER) { - ssh_set_error(session, SSH_FATAL, - "Bad authentication reply message type: %u", type); - ssh_buffer_free(reply); - return -1; - } + if (agent_failed(type)) { + ssh_buffer_free(reply); + return 0; + } else if (type != SSH2_AGENT_IDENTITIES_ANSWER) { + ssh_set_error(session, SSH_FATAL, + "Bad authentication reply message type: %u", type); + ssh_buffer_free(reply); + return -1; + } - rc = ssh_buffer_get_u32(reply, &count); - if (rc != 4) { - ssh_set_error(session, - SSH_FATAL, - "Failed to read count"); - ssh_buffer_free(reply); - return -1; - } - session->agent->count = ntohl(count); - SSH_LOG(SSH_LOG_DEBUG, "Agent count: %d", - session->agent->count); - if (session->agent->count > 1024) { - ssh_set_error(session, SSH_FATAL, - "Too many identities in authentication reply: %d", - session->agent->count); - ssh_buffer_free(reply); - return -1; - } + rc = ssh_buffer_get_u32(reply, &count); + if (rc != 4) { + ssh_set_error(session, + SSH_FATAL, + "Failed to read count"); + ssh_buffer_free(reply); + return -1; + } + session->agent->count = ntohl(count); + SSH_LOG(SSH_LOG_DEBUG, "Agent count: %d", + session->agent->count); + if (session->agent->count > 1024) { + ssh_set_error(session, SSH_FATAL, + "Too many identities in authentication reply: %d", + session->agent->count); + ssh_buffer_free(reply); + return -1; + } - if (session->agent->ident) { - ssh_buffer_reinit(session->agent->ident); - } - session->agent->ident = reply; + if (session->agent->ident) { + ssh_buffer_reinit(session->agent->ident); + } + session->agent->ident = reply; - return session->agent->count; + return session->agent->count; } /* caller has to free commment */ |