mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
Add more error checks to ssh_service_request().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@486 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -347,23 +347,60 @@ error:
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @brief Request a service from the SSH server.
|
||||||
|
*
|
||||||
|
* Service requests are for example: ssh-userauth, ssh-connection, etc.
|
||||||
|
*
|
||||||
|
* @param session The session to use to ask for a service request.
|
||||||
|
* @param service The service request.
|
||||||
|
*
|
||||||
|
* @return 0 on success, < 0 on error.
|
||||||
|
*/
|
||||||
int ssh_service_request(SSH_SESSION *session, const char *service) {
|
int ssh_service_request(SSH_SESSION *session, const char *service) {
|
||||||
STRING *service_s;
|
STRING *service_s = NULL;
|
||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
buffer_add_u8(session->out_buffer,SSH2_MSG_SERVICE_REQUEST);
|
|
||||||
service_s=string_from_char(service);
|
if (buffer_add_u8(session->out_buffer, SSH2_MSG_SERVICE_REQUEST) < 0) {
|
||||||
buffer_add_ssh_string(session->out_buffer,service_s);
|
|
||||||
free(service_s);
|
|
||||||
packet_send(session);
|
|
||||||
ssh_log(session, SSH_LOG_PACKET,
|
|
||||||
"Sent SSH_MSG_SERVICE_REQUEST (service %s)\n", service);
|
|
||||||
if (packet_wait(session,SSH2_MSG_SERVICE_ACCEPT,1) != SSH_OK) {
|
|
||||||
ssh_set_error(session,SSH_FATAL,"did not receive SERVICE_ACCEPT");
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
service_s = string_from_char(service);
|
||||||
|
if (service_s == NULL) {
|
||||||
|
leave_function();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer_add_ssh_string(session->out_buffer,service_s) < 0) {
|
||||||
|
string_free(service_s);
|
||||||
|
leave_function();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
string_free(service_s);
|
||||||
|
|
||||||
|
if (packet_send(session) != SSH_OK) {
|
||||||
|
ssh_set_error(session, SSH_FATAL,
|
||||||
|
"Sending SSH2_MSG_SERVICE_REQUEST failed.");
|
||||||
|
leave_function();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
ssh_log(session, SSH_LOG_PACKET,
|
ssh_log(session, SSH_LOG_PACKET,
|
||||||
"Received SSH_MSG_SERVICE_ACCEPT (service %s)\n", service);
|
"Sent SSH_MSG_SERVICE_REQUEST (service %s)", service);
|
||||||
|
|
||||||
|
if (packet_wait(session,SSH2_MSG_SERVICE_ACCEPT,1) != SSH_OK) {
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Did not receive SERVICE_ACCEPT");
|
||||||
|
leave_function();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_log(session, SSH_LOG_PACKET,
|
||||||
|
"Received SSH_MSG_SERVICE_ACCEPT (service %s)", service);
|
||||||
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user