From 671f1979a6d913938f5ced00779bf99db71f8df5 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sat, 1 Feb 2014 18:00:01 +0100 Subject: [PATCH] server: allow custom server banners (bug #83) --- include/libssh/session.h | 1 + src/bind.c | 3 ++- src/client.c | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/libssh/session.h b/include/libssh/session.h index 8a94daa5..c360a70c 100644 --- a/include/libssh/session.h +++ b/include/libssh/session.h @@ -175,6 +175,7 @@ struct ssh_session_struct { char *knownhosts; char *wanted_methods[10]; char *ProxyCommand; + char *custombanner; unsigned long timeout; /* seconds */ unsigned long timeout_usec; unsigned int port; diff --git a/src/bind.c b/src/bind.c index 5234e5b4..8d82d0d4 100644 --- a/src/bind.c +++ b/src/bind.c @@ -413,7 +413,8 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd){ } session->common.log_verbosity = sshbind->common.log_verbosity; - + if(sshbind->banner != NULL) + session->opts.custombanner = strdup(sshbind->banner); ssh_socket_free(session->socket); session->socket = ssh_socket_new(session); if (session->socket == NULL) { diff --git a/src/client.c b/src/client.c index bcb3be21..2c9cc21a 100644 --- a/src/client.c +++ b/src/client.c @@ -152,7 +152,15 @@ int ssh_send_banner(ssh_session session, int server) { banner = session->version == 1 ? CLIENTBANNER1 : CLIENTBANNER2; if (server) { - session->serverbanner = strdup(banner); + if(session->opts.custombanner == NULL){ + session->serverbanner = strdup(banner); + } else { + session->serverbanner = malloc(strlen(session->opts.custombanner) + 9); + if(!session->serverbanner) + goto end; + strcpy(session->serverbanner, "SSH-2.0-"); + strcat(session->serverbanner, session->opts.custombanner); + } if (session->serverbanner == NULL) { goto end; }