aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Drasar <drasar@ics.muni.cz>2011-10-19 14:42:55 +0200
committerAndreas Schneider <asn@cryptomilk.org>2012-01-05 11:26:53 +0100
commit31727bf33a1349c0b611ab60059d90d44df7dedf (patch)
tree7789bf5348939c522205778a566005b6f847ab3b
parenta15399992e058aef023d2da894e9f7f77423e8e3 (diff)
downloadlibssh-31727bf33a1349c0b611ab60059d90d44df7dedf.tar.gz
libssh-31727bf33a1349c0b611ab60059d90d44df7dedf.tar.xz
libssh-31727bf33a1349c0b611ab60059d90d44df7dedf.zip
Ignore and debug messages can be sent using public API
Signed-off-by: Martin Drasar <drasar@ics.muni.cz> Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/libssh/libssh.h2
-rw-r--r--src/session.c90
2 files changed, 92 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 815afc5..f22ce71 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -494,6 +494,8 @@ LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
const char *filename);
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
+LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
+LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
LIBSSH_API int ssh_scp_close(ssh_scp scp);
LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
diff --git a/src/session.c b/src/session.c
index 404b36b..6bcc3f6 100644
--- a/src/session.c
+++ b/src/session.c
@@ -614,6 +614,96 @@ void ssh_socket_exception_callback(int code, int errno_code, void *user){
leave_function();
}
+/**
+ * @brief Send a message that should be ignored
+ *
+ * @param[in] session The SSH session
+ * @param[in] data Data to be sent
+ *
+ * @return SSH_OK on success, SSH_ERROR otherwise.
+ */
+int ssh_send_ignore (ssh_session session, const char *data) {
+ ssh_string str;
+
+ if (ssh_socket_is_open(session->socket)) {
+ if (buffer_add_u8(session->out_buffer, SSH2_MSG_IGNORE) < 0) {
+ goto error;
+ }
+
+ str = ssh_string_from_char(data);
+ if (str == NULL) {
+ goto error;
+ }
+
+ if (buffer_add_ssh_string(session->out_buffer, str) < 0) {
+ ssh_string_free(str);
+ goto error;
+ }
+
+ packet_send(session);
+ ssh_handle_packets(session, 0);
+
+ ssh_string_free(str);
+ }
+
+ return SSH_OK;
+
+error:
+ buffer_reinit(session->out_buffer);
+ return SSH_ERROR;
+}
+
+/**
+ * @brief Send a debug message
+ *
+ * @param[in] session The SSH session
+ * @param[in] message Data to be sent
+ * @param[in] always_display Message SHOULD be displayed by the server. It
+ * SHOULD NOT be displayed unless debugging
+ * information has been explicitly requested.
+ *
+ * @return SSH_OK on success, SSH_ERROR otherwise.
+ */
+int ssh_send_debug (ssh_session session, const char *message, int always_display) {
+ ssh_string str;
+
+ if (ssh_socket_is_open(session->socket)) {
+ if (buffer_add_u8(session->out_buffer, SSH2_MSG_DEBUG) < 0) {
+ goto error;
+ }
+
+ if (buffer_add_u8(session->out_buffer, always_display) < 0) {
+ goto error;
+ }
+
+ str = ssh_string_from_char(message);
+ if (str == NULL) {
+ goto error;
+ }
+
+ if (buffer_add_ssh_string(session->out_buffer,str) < 0) {
+ ssh_string_free(str);
+ goto error;
+ }
+
+ /* Empty language tag */
+ if (buffer_add_u32(session->out_buffer, 0) < 0) {
+ goto error;
+ }
+
+ packet_send(session);
+ ssh_handle_packets(session, 0);
+
+ ssh_string_free(str);
+ }
+
+ return SSH_OK;
+
+error:
+ buffer_reinit(session->out_buffer);
+ return SSH_ERROR;
+}
+
/** @} */
/* vim: set ts=4 sw=4 et cindent: */