SSH_MSG_CHANNEL_OPEN_FAILURE: used defined values
We don't like magic numbers in the code. Now the acceptable failure codes sent in the SSH_MSG_CHANNEL_OPEN_FAILURE message are added as defined values in the private header file.
Этот коммит содержится в:
родитель
2dfa5d38cb
Коммит
8f10da89c5
@ -1001,6 +1001,13 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
|
|||||||
#define SSH_MSG_CHANNEL_SUCCESS 99
|
#define SSH_MSG_CHANNEL_SUCCESS 99
|
||||||
#define SSH_MSG_CHANNEL_FAILURE 100
|
#define SSH_MSG_CHANNEL_FAILURE 100
|
||||||
|
|
||||||
|
/* Error codes returned in SSH_MSG_CHANNEL_OPEN_FAILURE message
|
||||||
|
(see RFC4254) */
|
||||||
|
#define SSH_OPEN_ADMINISTRATIVELY_PROHIBITED 1
|
||||||
|
#define SSH_OPEN_CONNECT_FAILED 2
|
||||||
|
#define SSH_OPEN_UNKNOWN_CHANNELTYPE 3
|
||||||
|
#define SSH_OPEN_RESOURCE_SHORTAGE 4
|
||||||
|
|
||||||
#if defined( WIN32 ) || defined( __VMS )
|
#if defined( WIN32 ) || defined( __VMS )
|
||||||
ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, int flags);
|
ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, int flags);
|
||||||
ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length, int flags);
|
ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length, int flags);
|
||||||
|
20
src/packet.c
20
src/packet.c
@ -82,7 +82,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
unsigned long packet_len = 17 + (sizeof(FwdNotReq) - 1);
|
unsigned long packet_len = 17 + (sizeof(FwdNotReq) - 1);
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
LIBSSH2_LISTENER *listen = _libssh2_list_first(&session->listeners);
|
LIBSSH2_LISTENER *listen = _libssh2_list_first(&session->listeners);
|
||||||
char failure_code = 1; /* SSH_OPEN_ADMINISTRATIVELY_PROHIBITED */
|
char failure_code = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
(void) datalen;
|
(void) datalen;
|
||||||
@ -132,7 +132,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
if (listen->queue_maxsize &&
|
if (listen->queue_maxsize &&
|
||||||
(listen->queue_maxsize <= listen->queue_size)) {
|
(listen->queue_maxsize <= listen->queue_size)) {
|
||||||
/* Queue is full */
|
/* Queue is full */
|
||||||
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
failure_code = SSH_OPEN_RESOURCE_SHORTAGE;
|
||||||
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
|
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
|
||||||
"Listener queue full, ignoring");
|
"Listener queue full, ignoring");
|
||||||
listen_state->state = libssh2_NB_state_sent;
|
listen_state->state = libssh2_NB_state_sent;
|
||||||
@ -144,7 +144,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Unable to allocate a channel for "
|
"Unable to allocate a channel for "
|
||||||
"new connection");
|
"new connection");
|
||||||
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
failure_code = SSH_OPEN_RESOURCE_SHORTAGE;
|
||||||
listen_state->state = libssh2_NB_state_sent;
|
listen_state->state = libssh2_NB_state_sent;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
"Unable to allocate a channel for new"
|
"Unable to allocate a channel for new"
|
||||||
" connection");
|
" connection");
|
||||||
LIBSSH2_FREE(session, channel);
|
LIBSSH2_FREE(session, channel);
|
||||||
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
failure_code = SSH_OPEN_RESOURCE_SHORTAGE;
|
||||||
listen_state->state = libssh2_NB_state_sent;
|
listen_state->state = libssh2_NB_state_sent;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
unsigned long datalen,
|
unsigned long datalen,
|
||||||
packet_x11_open_state_t *x11open_state)
|
packet_x11_open_state_t *x11open_state)
|
||||||
{
|
{
|
||||||
int failure_code = 2; /* SSH_OPEN_CONNECT_FAILED */
|
int failure_code = SSH_OPEN_CONNECT_FAILED;
|
||||||
/* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */
|
/* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */
|
||||||
unsigned long packet_len = 17 + (sizeof(X11FwdUnAvil) - 1);
|
unsigned long packet_len = 17 + (sizeof(X11FwdUnAvil) - 1);
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
@ -299,7 +299,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
if (!channel) {
|
if (!channel) {
|
||||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Unable to allocate a channel for new connection");
|
"Unable to allocate a channel for new connection");
|
||||||
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
failure_code = SSH_OPEN_RESOURCE_SHORTAGE;
|
||||||
goto x11_exit;
|
goto x11_exit;
|
||||||
}
|
}
|
||||||
memset(channel, 0, sizeof(LIBSSH2_CHANNEL));
|
memset(channel, 0, sizeof(LIBSSH2_CHANNEL));
|
||||||
@ -313,7 +313,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||||
"Unable to allocate a channel for new connection");
|
"Unable to allocate a channel for new connection");
|
||||||
LIBSSH2_FREE(session, channel);
|
LIBSSH2_FREE(session, channel);
|
||||||
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
failure_code = SSH_OPEN_RESOURCE_SHORTAGE;
|
||||||
goto x11_exit;
|
goto x11_exit;
|
||||||
}
|
}
|
||||||
memcpy(channel->channel_type, "x11",
|
memcpy(channel->channel_type, "x11",
|
||||||
@ -373,10 +373,10 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
x11open_state->state = libssh2_NB_state_idle;
|
x11open_state->state = libssh2_NB_state_idle;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
failure_code = SSH_OPEN_RESOURCE_SHORTAGE;
|
||||||
|
/* fall-trough */
|
||||||
x11_exit:
|
x11_exit:
|
||||||
p = x11open_state->packet;
|
p = x11open_state->packet;
|
||||||
*(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE;
|
*(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user