[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AutoPPP for agetty



I've successfully copied some AutoPPP code from mgetty to agetty.

With this patch, you can start a ppp connection to the debug port, while 
you're still able to login using agetty on the same port.

This is how it works:
When a PPP packet is received on the login prompt, agetty calls login with the 
username AutoPPP, and the -f option (no authentication required).

Now add a user in /etc/passwd called AutoPPP, with /usr/sbin/pppd as shell.
(no password required)

The following option file works for me (/etc/ppp/options)
/dev/ttyS2
115200
10.0.0.1:10.0.0.2
local
noauth

Now you can login with 'pppd /dev/ttyS0 115200 local' from a linux machine.

Then I wanted to login with a WIN2000 machine, using a direct cable 
connection. Doesn't work just like that, I had to make another hack in 
agetty.c, but now it works like a charm. (probably also works with winXP)

The patch below contains both the AutoPPP and win2000 direct cable code.

Regards,

Pieter
--- apps/login/agetty.c	Wed Dec  1 10:37:00 1999
+++ apps/login/agetty.c	Thu Feb 13 12:40:18 2003
@@ -4,13 +4,15 @@
    be here. Now read the real man-page agetty.8 instead.
 
    -f option added by Eric Rasmussen <ear@xxxxxxx.org> - 12/28/95
-   
+
    1999-02-22 Arkadiusz Mi¶kiewicz <misiek@xxxxxxx.org>
    - added Native Language Support
 
    1999-05-05 Thorsten Kranzkowski <dl8bcu@xxxxxxx.net>
    - enable hardware flow control before displaying /etc/issue
-   
+
+   2003-02-13 Pieter Grimmerink <mailinglists@xxxxxxx.nl>
+   - ported AutoPPP support from mgetty, added WIN2000 direct cable connection hack
 */
 
 #ifdef __STDC__
@@ -42,6 +44,23 @@
 #define USE_SYSLOG
 #endif
 
+/*
+ * define AUTO_PPP to include PPP packet recognition,
+ * whenever a PPP packet is recognised as login name input
+ * the login name 'AutoPPP' is offered to 'login'
+ * (with -f option for 'no authentication required')
+ * Create a user named AutoPPP and make pppd its shell
+ * and you should be able to start a ppp link through agetty.
+ */
+#define AUTO_PPP
+
+/* define WINDOWS_PPP_HACK in addition to AUTO_PPP to include ugly
+ * attempts to recognise win2000 attempts to build up a direct cable connection.
+ * the login name 'AutoPPP' will be used when such an
+ * attempt is recognised
+ */
+#define WINDOWS_PPP_HACK
+
  /* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */
 
 #ifdef	USE_SYSLOG
@@ -60,11 +79,11 @@
 
  /*
   * Things you may want to modify.
-  * 
+  *
   * If ISSUE is not defined, agetty will never display the contents of the
   * /etc/issue file. You will not want to spit out large "issue" files at the
   * wrong baud rate. Relevant for System V only.
-  * 
+  *
   * You may disagree with the default line-editing etc. characters defined
   * below. Note, however, that DEL cannot be used for interrupt generation
   * and for line editing at the same time.
@@ -244,7 +263,7 @@
 /* The following is used for understandable diagnostics. */
 
 char *progname;
-
+//#define DEBUGGING
 /* ... */
 #ifdef DEBUGGING
 #define debug(s) fprintf(dbf,s); fflush(dbf)
@@ -381,7 +400,14 @@
 
     /* Let the login program take care of password validation. */
 
+#ifndef AUTO_PPP
     (void) execl(options.login, options.login, "--", logname, (char *) 0);
+#else
+	 if (!strcmp(logname, "AutoPPP"))
+	 	(void) execl(options.login, options.login, "-f", logname, (char *) 0);	 
+	 else
+	 	(void) execl(options.login, options.login, "--", logname, (char *) 0);
+#endif
     error(_("%s: can't exec %s: %m"), options.tty, options.login);
     exit(0);  /* quiet GCC */
 }
@@ -952,6 +978,16 @@
     (void) ioctl(0, TCSETA, tp);
 }
 
+/* defines for auto detection of incoming PPP calls (->PAP/CHAP) */
+
+#define PPP_FRAME	0x7e	/* PPP Framing character */
+#define PPP_STATION	0xff	/* "All Station" character */
+#define PPP_ESCAPE	0x7d	/* Escape Character */ 
+#define PPP_CONTROL	0x03	/* PPP Control Field */
+#define PPP_LCP_HI	0xc0	/* LCP protocol - high byte */
+#define PPP_LCP_LOW	0x21	/* LCP protocol - low byte */
+#define PPP_UNESCAPE(c)	((c) ^ 0x20) /* un-escape character */
+
 /* get_logname - get user name, establish parity, speed, erase, kill, eol */
 
 char   *get_logname(op, cp, tp)
@@ -972,6 +1008,11 @@
 	"\210\240\210",			/* no parity */
     };
 
+#ifdef AUTO_PPP
+    static int ppp_level = 0, ppp_escaped = 0;
+    char   ppp_ch;
+#endif
+
     /* Initialize kill, erase, parity etc. (also after switching speeds). */
 
     *cp = init_chardata;
@@ -1002,6 +1043,42 @@
 	    }
 	    /* Do BREAK handling elsewhere. */
 
+#ifdef AUTO_PPP
+        /* Accept the following sequences as start of PPP packet:
+           PPP_FRAME, PPP_STATION, PPP_ESCAPE, PPP_CONTROL_ESCAPED (normal)
+           PPP_FRAME, PPP_STATION, PPP_CONTROL           (deviant from RFC)
+
+           Odds are pretty low of hitting this by accident.
+           See RFC1662 for more information.
+
+			Copied from mgetty by Pieter Grimmerink
+         */
+
+        ppp_ch = c;
+        if (ppp_escaped) {
+                ppp_ch = PPP_UNESCAPE(c);
+                ppp_escaped = 0;
+        }
+        if (ppp_ch == (char) PPP_ESCAPE) {
+            ppp_escaped = 1;
+        } else if (ppp_ch == (char) PPP_FRAME) {
+            ppp_level = 1;
+        } else if (ppp_ch == (char) PPP_STATION && ppp_level == 1) {
+            ppp_level = 2;
+        } else if (ppp_ch == (char) PPP_CONTROL && ppp_level == 2) {
+            ppp_level = 3;
+        } else if (ppp_ch == (char) PPP_LCP_HI && ppp_level == 3) {
+            ppp_level = 4;
+        } else if (ppp_ch == (char) PPP_LCP_LOW && ppp_level == 4)
+        {
+            strcpy (logname, "AutoPPP");
+				return logname;
+        } else {
+            ppp_level = 0;
+	    		ppp_escaped = 0;
+        }
+#endif
+
 	    if ((c == 0) && op->numspeed > 1)
 		return (0);
 
@@ -1048,6 +1125,17 @@
 		} else {
 		    (void) write(1, &c, 1);	/* echo the character */
 		    *bp++ = ascval;		/* and store it */
+#ifdef AUTO_PPP
+#ifdef WINDOWS_PPP_HACK
+			/* WIN2000's direct cable connection makes itself known by shouting "CLIENT" */
+			if (!memcmp(logname, "CLIENT", 6))
+			{
+				write(1, "SERVER\n", 7);
+				strcpy(logname, "AutoPPP");
+				return logname;
+			}
+#endif
+#endif
 		}
 		break;
 	    }