Mercurial > dropbear
changeset 43:942b22d7dd1c
Banner printing
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 02 Aug 2004 04:25:05 +0000 |
parents | 837f9172df09 |
children | 45edf30ea0a6 |
files | auth.h cli-auth.c cli-session.c options.h session.h |
diffstat | 5 files changed, 67 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/auth.h Sun Aug 01 11:02:44 2004 +0000 +++ b/auth.h Mon Aug 02 04:25:05 2004 +0000 @@ -47,6 +47,7 @@ void cli_get_user(); void cli_auth_getmethods(); void cli_auth_try(); +void recv_msg_userauth_banner(); #define MAX_USERNAME_LEN 25 /* arbitrary for the moment */
--- a/cli-auth.c Sun Aug 01 11:02:44 2004 +0000 +++ b/cli-auth.c Mon Aug 02 04:25:05 2004 +0000 @@ -35,6 +35,48 @@ } +void recv_msg_userauth_banner() { + + unsigned char* banner = NULL; + unsigned int bannerlen; + unsigned int i, linecount; + + TRACE(("enter recv_msg_userauth_banner")); + if (ses.authstate.authdone) { + TRACE(("leave recv_msg_userauth_banner: banner after auth done")); + return; + } + + banner = buf_getstring(ses.payload, &bannerlen); + buf_eatstring(ses.payload); /* The language string */ + + if (bannerlen > MAX_BANNER_SIZE) { + TRACE(("recv_msg_userauth_banner: bannerlen too long: %d", bannerlen)); + goto out; + } + + cleantext(banner); + + /* Limit to 25 lines */ + linecount = 1; + for (i = 0; i < bannerlen; i++) { + if (banner[i] == '\n') { + if (linecount >= MAX_BANNER_LINES) { + banner[i] = '\0'; + break; + } + linecount++; + } + } + + printf("%s\n", banner); + +out: + m_free(banner); + TRACE(("leave recv_msg_userauth_banner")); +} + + void recv_msg_userauth_failure() { unsigned char * methods = NULL;
--- a/cli-session.c Sun Aug 01 11:02:44 2004 +0000 +++ b/cli-session.c Mon Aug 02 04:25:05 2004 +0000 @@ -36,6 +36,7 @@ {SSH_MSG_CHANNEL_OPEN_FAILURE, recv_msg_channel_open_failure}, {SSH_MSG_USERAUTH_FAILURE, recv_msg_userauth_failure}, // client {SSH_MSG_USERAUTH_SUCCESS, recv_msg_userauth_success}, // client + {SSH_MSG_USERAUTH_BANNER, recv_msg_userauth_banner}, // client {0, 0} /* End */ }; @@ -217,3 +218,24 @@ ses.sock = -1; dropbear_exit("remote closed the connection"); } + +/* Operates in-place turning dirty (untrusted potentially containing control + * characters) text into clean text. */ +void cleantext(unsigned char* dirtytext) { + + unsigned int i, j; + unsigned char c, lastchar; + + j = 0; + for (i = 0; dirtytext[i] != '\0'; i++) { + + c = dirtytext[i]; + /* We can ignore '\r's */ + if ( (c >= ' ' && c <= '~') || c == '\n' || c == '\t') { + dirtytext[j] = c; + j++; + } + } + /* Null terminate */ + dirtytext[j] = '\0'; +}
--- a/options.h Sun Aug 01 11:02:44 2004 +0000 +++ b/options.h Mon Aug 02 04:25:05 2004 +0000 @@ -195,6 +195,7 @@ #endif #define MAX_BANNER_SIZE 2000 /* this is 25*80 chars, any more is foolish */ +#define MAX_BANNER_LINES 20 /* How many lines the client will display */ #define DEV_URANDOM "/dev/urandom"
--- a/session.h Sun Aug 01 11:02:44 2004 +0000 +++ b/session.h Mon Aug 02 04:25:05 2004 +0000 @@ -56,6 +56,7 @@ void cli_dropbear_exit(int exitcode, const char* format, va_list param); void cli_dropbear_log(int priority, const char* format, va_list param); void cli_session_cleanup(); +void cleantext(unsigned char* dirtytext); struct key_context {