[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sending arbitrary messages between key exchange and user authentication
[Thread Prev] | [Thread Next]
- Subject: Re: Sending arbitrary messages between key exchange and user authentication
- From: Martin Drasar <drasar@xxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 17 Oct 2011 13:46:03 +0200
- To: libssh@xxxxxxxxxx
Hi, I have just finsihed the patch for sending ignore and debug messages. If you like it - commit it, otherwise tell me what is wrong and I will fix it ;-) Martin
From d641dab86a791f5e256f7db8d1c9b08369ea1194 Mon Sep 17 00:00:00 2001
From: Martin Drasar <drasar@xxxxxxxxxx>
Date: Mon, 17 Oct 2011 13:42:23 +0200
Subject: [PATCH] Added support for sending ignore and debug messages
---
include/libssh/libssh.h | 2 +
src/session.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+), 0 deletions(-)
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 9c60eb3..80efef9 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -420,6 +420,8 @@ LIBSSH_API ssh_message ssh_message_get(ssh_session session);
LIBSSH_API int ssh_message_subtype(ssh_message msg);
LIBSSH_API int ssh_message_type(ssh_message msg);
LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
+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 ssh_session ssh_new(void);
LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
diff --git a/src/session.c b/src/session.c
index b3ee193..41d70ca 100644
--- a/src/session.c
+++ b/src/session.c
@@ -31,6 +31,7 @@
#include "libssh/crypto.h"
#include "libssh/server.h"
#include "libssh/socket.h"
+#include "libssh/ssh1.h"
#include "libssh/ssh2.h"
#include "libssh/agent.h"
#include "libssh/packet.h"
@@ -614,6 +615,110 @@ void ssh_socket_exception_callback(int code, int errno_code, void *user){
leave_function();
}
+/**
+ * @brief Send a message that should be ignored
+ *
+ * @param session SSH session to be used
+ * @param data Data to be sent
+ *
+ * @return SSH_OK or SSH_ERROR
+ */
+int ssh_send_ignore (ssh_session session, const char *data) {
+ ssh_string str = NULL;
+
+ enter_function();
+
+ if (ssh_socket_is_open(session->socket)) {
+ if (buffer_add_u8(session->out_buffer, SSH_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);
+ }
+
+ leave_function();
+ return SSH_OK;
+
+error:
+ buffer_reinit(session->out_buffer);
+ leave_function();
+ return SSH_ERROR;
+}
+
+/**
+ * @brief Send a debug message
+ *
+ * @param session SSH session to be used
+ * @param message Message to be sent
+ * @param always_display Message SHOULD be displayed by the server. It SHOULD
+ * NOT be displayed unless debugging information has
+ * been explicitly requested.
+ *
+ * @return SSH_OK or SSH_ERROR
+ */
+int ssh_send_debug (ssh_session session, const char *message, int always_display) {
+ ssh_string str = NULL;
+
+ enter_function();
+
+ if (ssh_socket_is_open(session->socket)) {
+ if (buffer_add_u8(session->out_buffer, SSH_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 */
+ str = ssh_string_from_char("");
+ 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);
+ }
+
+ leave_function();
+ return SSH_OK;
+
+error:
+ buffer_reinit(session->out_buffer);
+ leave_function();
+ return SSH_ERROR;
+}
+
/** @} */
/* vim: set ts=4 sw=4 et cindent: */
--
1.7.3.1.msysgit.0
| Re: Sending arbitrary messages between key exchange and user authentication | Aris Adamantiadis <aris@xxxxxxxxxxxx> |
| Sending arbitrary messages between key exchange and user authentication | Martin Drasar <drasar@xxxxxxxxxxx> |
| Re: Sending arbitrary messages between key exchange and user authentication | Aris Adamantiadis <aris@xxxxxxxxxxxx> |
| Re: Sending arbitrary messages between key exchange and user authentication | Martin Drasar <drasar@xxxxxxxxxxx> |
| Re: Sending arbitrary messages between key exchange and user authentication | Aris Adamantiadis <aris@xxxxxxxxxxxx> |
| Re: Sending arbitrary messages between key exchange and user authentication | Martin Drasar <drasar@xxxxxxxxxxx> |
| Re: Sending arbitrary messages between key exchange and user authentication | Aris Adamantiadis <aris@xxxxxxxxxxxx> |