Skip to content
Permalink
Browse files

adjust whitespace to conform to style guide

  • Loading branch information
palmin committed Jan 4, 2020
1 parent 4906578 commit df74a322abd530d98cdc540c61eff55fda7dda11
Showing with 29 additions and 19 deletions.
  1. +29 −19 src/userauth.c
@@ -65,7 +65,8 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
unsigned int username_len)
{
static const unsigned char reply_codes[4] =
{ SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE, SSH_MSG_USERAUTH_BANNER, 0 };
{ SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE,
SSH_MSG_USERAUTH_BANNER, 0 };
/* packet_type(1) + username_len(4) + service_len(4) +
service(14)"ssh-connection" + method_len(4) = 27 */
unsigned long methods_len;
@@ -120,11 +121,12 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,

if(session->userauth_list_state == libssh2_NB_state_sent) {
do {
rc = _libssh2_packet_requirev(session, reply_codes,
&session->userauth_list_data,
&session->userauth_list_data_len, 0,
NULL, 0,
&session->userauth_list_packet_requirev_state);
rc =
_libssh2_packet_requirev(session, reply_codes,
&session->userauth_list_data,
&session->userauth_list_data_len, 0,
NULL, 0,
&session->userauth_list_packet_requirev_state);
if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list");
@@ -135,38 +137,46 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
session->userauth_list_state = libssh2_NB_state_idle;
return NULL;
}
if (session->userauth_list_data[0] == SSH_MSG_USERAUTH_BANNER && (session->userauth_list_data_len >= 5)) {
methods_len = _libssh2_ntohu32(session->userauth_list_data + 1);
if(session->userauth_list_data[0] == SSH_MSG_USERAUTH_BANNER &&
(session->userauth_list_data_len >= 5)) {

methods_len =
_libssh2_ntohu32(session->userauth_list_data + 1);

/* Cap to 512 bytes. */
if (methods_len > LIBSSH2_USERAUTH_MAX_BANNER) {
if(methods_len > LIBSSH2_USERAUTH_MAX_BANNER) {
_libssh2_debug(session, LIBSSH2_TRACE_AUTH,
"Banner length %u exceeds max allowed (%u)",
methods_len, LIBSSH2_USERAUTH_MAX_BANNER);
"Banner length %u exceeds max allowed (%u)",
methods_len, LIBSSH2_USERAUTH_MAX_BANNER);
methods_len = LIBSSH2_USERAUTH_MAX_BANNER - 1;
}

if (!session->userauth_banner) {
session->userauth_banner = LIBSSH2_ALLOC(session, methods_len + 1);
if(!session->userauth_banner) {
session->userauth_banner = LIBSSH2_ALLOC(session,
methods_len + 1);
}
else if (session->userauth_banner_len < methods_len) {
session->userauth_banner = LIBSSH2_REALLOC(session, session->userauth_banner, methods_len + 1);
else if(session->userauth_banner_len < methods_len) {
session->userauth_banner =
LIBSSH2_REALLOC(session, session->userauth_banner,
methods_len + 1);
}
if (!session->userauth_banner) {
if(!session->userauth_banner) {
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for userauth_banner");
continue;
}
session->userauth_banner_len = methods_len;

memmove(session->userauth_banner, session->userauth_list_data + 5, methods_len);
memmove(session->userauth_banner,
session->userauth_list_data + 5, methods_len);
session->userauth_banner[methods_len] = '\0';
_libssh2_debug(session, LIBSSH2_TRACE_AUTH,
"Banner: %s",
session->userauth_banner);
LIBSSH2_FREE(session, session->userauth_list_data);
}
else break;
} while (1);
} while(1);

if(session->userauth_list_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
/* Wow, who'dve thought... */
@@ -240,7 +250,7 @@ libssh2_userauth_banner(LIBSSH2_SESSION * session,
size_t *banner_len_out)
{
char *ptr = NULL;
if (session->userauth_banner) {
if(session->userauth_banner) {
ptr = session->userauth_banner;
*banner_len_out = session->userauth_banner_len;
}

0 comments on commit df74a32

Please sign in to comment.
You can’t perform that action at this time.