diff svr-chansession.c @ 306:5d5bbca82aba ucc-axis-hack

Use password file, add serial option
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 17:12:50 +0000
parents 1f5ec029dfe8
children 24b19535264b
line wrap: on
line diff
--- 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 */