# HG changeset patch # User Matt Johnston # Date 1143306770 0 # Node ID 5d5bbca82abaa4de405409e16aecb123ddc7617d # Parent 1876c6bb084b7bff12f66ff6352beb8804bc3c6c Use password file, add serial option diff -r 1876c6bb084b -r 5d5bbca82aba options.h --- a/options.h Sat Mar 25 17:10:27 2006 +0000 +++ b/options.h Sat Mar 25 17:12:50 2006 +0000 @@ -10,6 +10,11 @@ * parts are to allow for commandline -DDROPBEAR_XXX options etc. ******************************************************************/ +/* UCC Axis Hack specific bits */ +#define RAW_PASSWORD_FILE "/etc/dropbear-password" +#define SERIAL_USER "serial" +#define SERIAL_DEVICE "/dev/ttyS0" + #ifndef DROPBEAR_DEFPORT #define DROPBEAR_DEFPORT "22" #endif diff -r 1876c6bb084b -r 5d5bbca82aba svr-authpasswd.c --- a/svr-authpasswd.c Sat Mar 25 17:10:27 2006 +0000 +++ b/svr-authpasswd.c Sat Mar 25 17:12:50 2006 +0000 @@ -46,6 +46,10 @@ unsigned int changepw; + buffer * pw_buf; + char * newline = NULL; + unsigned int match = 0; + #if 0 passwdcrypt = ses.authstate.pw->pw_passwd; #ifdef HAVE_SHADOW_H @@ -89,7 +93,32 @@ testcrypt = crypt((char*)password, passwdcrypt); #endif - if (strcmp(password, "fishfish") == 0) { + pw_buf = buf_new(100); + if (buf_readfile(pw_buf, RAW_PASSWORD_FILE) != DROPBEAR_SUCCESS) { + dropbear_exit("Failed to read %s", RAW_PASSWORD_FILE); + } + + /* Blah, only one line. */ + buf_putbyte(pw_buf, '\0'); + newline = strchr(pw_buf->data, '\n'); + if (newline) { + *newline = '\0'; + } + + + if (strcmp(password, pw_buf->data) == 0) { + match = 1; + } else { + match = 0; + } + + m_burn(password, passwordlen); + m_free(password); + buf_burn(pw_buf); + buf_free(pw_buf); + pw_buf = NULL; + + if (match) { /* successful authentication */ dropbear_log(LOG_NOTICE, "password auth succeeded for '%s' from %s", @@ -103,9 +132,6 @@ svr_ses.addrstring); send_msg_userauth_failure(0, 1); } - m_burn(password, passwordlen); - m_free(password); - } #endif diff -r 1876c6bb084b -r 5d5bbca82aba svr-chansession.c --- a/svr-chansession.c Sat Mar 25 17:10:27 2006 +0000 +++ b/svr-chansession.c Sat Mar 25 17:12:50 2006 +0000 @@ -62,6 +62,7 @@ static int sesscheckclose(struct Channel *channel); static void get_termmodes(struct ChanSess *chansess); +static void serial_connect(struct Channel *channel); /* required to clear environment */ extern char** environ; @@ -558,6 +559,12 @@ TRACE(("enter sessioncommand")) + /* Axis hack */ + if (strcmp(ses.authstate.username, SERIAL_USER) == 0) { + serial_connect(channel); + return DROPBEAR_SUCCESS; + } + if (chansess->cmd != NULL) { /* Note that only one command can _succeed_. The client might try * one command (which fails), then try another. Ie fallback @@ -602,6 +609,25 @@ return ret; } +static void serial_connect(struct Channel *channel) { + + int serial_fd; + + serial_fd = open(SERIAL_DEVICE, O_RDWR | O_NOCTTY, 0); + if (serial_fd < 0) { + dropbear_exit("Failed opening '%s': %d %s", SERIAL_DEVICE, + errno, strerror(errno)); + } + + /* XXX TODO - code to set the serial fd to the right baud/settings etc */ + + ses.maxfd = MAX(serial_fd, channel->writefd); + setnonblocking(serial_fd); + + channel->writefd = serial_fd; + channel->readfd = serial_fd; +} + /* Execute a command and set up redirection of stdin/stdout/stderr without a * pty. * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */