Subject: slight? changes to getty
To: None <netbsd-bugs@sun-lamp.cs.berkeley.edu>
From: Simon J. Gerraty <sjg@zen.void.oz.au>
List: netbsd-bugs
Date: 11/26/1993 12:23:31
The following diffs produce a getty that I have been using happily for
several months. I'm submitting them in the hope that I won't have to
keep patching getty each time I update :-)
The main change is the addition of a facility whereby getty can be
caused NOT to open a tty device. This allows control of when modems
will answer phones (most decent modems can be configured to not answer
if there is no DTR present). Before opening the device, getty calls
ttydeny() which checks if the device name appears in _PATH_TTYDENY if
so, it simply sleeps until the situation changes.
The other change is to make getty set tty devices to 660 root.daemon
instead of 600 root.wheel, so that facilities such as uucp and MHSnet
can use the modem devices. This change is not necessary if seperate
call out units are being used, but that is not the current NetBSD
situation.
Anyway, if you like you can have. Included is a script that can be
run from cron to enable/disable a modem answering. And nodtr.c which
I run from /etc/rc.local to ensure DTR is forced off initially.
#!/bin/sh
# This is a shell archive.
# remove everything above the "#!/bin/sh" line
# and feed to /bin/sh
# Use -c option to overwrite existing files
#
# Contents:
# ttydeny.sh
# nodtr.c
# getty.diffs
#
# packed by: <sjg@zen.void.oz.au> on Fri Nov 26 12:22:04 EST 1993
#
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f ttydeny.sh -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"ttydeny.sh\"
else
echo shar: Extracting \"ttydeny.sh\" \(599 characters\)
sed 's/^X//' >ttydeny.sh << '!EOF'
X#!/bin/sh
X#
X# This script adds ttynames to /etc/ttydeny which causes
X# getty to not open them.
X#
XMyname=`basename $0 .sh`
Xargs="$@"
X
Xre=
Xfor t in $args
Xdo
X case "$re" in
X "") re=$t;;
X *) re="$re|$t";;
X esac
Xdone
X
XDENYF=/etc/ttydeny
X
Xcase $Myname in
Xttydeny)
X for t in $args
X do
X echo /dev/$t >> $DENYF
X done
X ps -ax | egrep "getty.*($re)\$" | awk '{ print "kill " $1 }' | /bin/sh
X ;;
X*)
X if [ -s $DENYF ]; then
X egrep -v "/dev/($re)\$" $DENYF > $DENYF.new
X if [ -s $DENYF.new ]; then
X mv $DENYF.new $DENYF
X else
X rm -f $DENYF.new $DENYF
X fi
X fi
X ;;
Xesac
!EOF
if test 599 -ne `wc -c < ttydeny.sh`; then
echo shar: \"ttydeny.sh\" unpacked with wrong size!
fi
chmod +x ttydeny.sh
fi
if test -f nodtr.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"nodtr.c\"
else
echo shar: Extracting \"nodtr.c\" \(646 characters\)
sed 's/^X//' >nodtr.c << '!EOF'
X/* include files */
X#include <stdio.h>
X#include <time.h>
X#ifdef POSIX
X#include <termios.h>
X#else
X#include <termio.h>
X#endif
X#include <fcntl.h>
X#include <errno.h>
X
X
X
Xint
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X#ifdef POSIX
X static struct termios tm;
X#else
X static struct termio tm;
X#endif
X int sts = 1;
X int th;
X
X if (argc > 1 && ((th = open(argv[1], O_RDWR|O_NDELAY)) != -1))
X {
X#ifdef POSIX
X tcgetattr(th,&tm);
X tm.c_cflag |= HUPCL;
X tcsetattr(th,TCSADRAIN,&tm);
X#else
X if (ioctl(th, TCGETA, &tm) != -1)
X {
X tm.c_cflag = 0;
X if (ioctl(th, TCSETA, &tm) != -1)
X {
X sts = 0;
X }
X }
X#endif
X close(th);
X }
X exit(sts);
X}
!EOF
if test 646 -ne `wc -c < nodtr.c`; then
echo shar: \"nodtr.c\" unpacked with wrong size!
fi
fi
if test -f getty.diffs -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"getty.diffs\"
else
echo shar: Extracting \"getty.diffs\" \(2040 characters\)
sed 's/^X//' >getty.diffs << '!EOF'
X*** pathnames.h.orig Sun Nov 7 19:38:37 1993
X***************
X*** 38,40 ****
X--- 38,41 ----
X
X #define _PATH_GETTYTAB "/etc/gettytab"
X #define _PATH_LOGIN "/usr/bin/login"
X+ #define _PATH_TTYDENY "/etc/ttydeny"
X*** main.c.orig Sun Nov 7 19:38:35 1993
X***************
X*** 169,177 ****
X
X strcpy(ttyn, dev);
X strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
X if (strcmp(argv[0], "+") != 0) {
X! chown(ttyn, 0, 0);
X! chmod(ttyn, 0600);
X revoke(ttyn);
X /*
X * Delay the open so DTR stays down long enough to be detected.
X--- 169,180 ----
X
X strcpy(ttyn, dev);
X strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
X+
X+ ttydeny(ttyn); /* ensure we are allowed right now */
X+
X if (strcmp(argv[0], "+") != 0) {
X! chown(ttyn, 0, 1);
X! chmod(ttyn, 0660);
X revoke(ttyn);
X /*
X * Delay the open so DTR stays down long enough to be detected.
X***************
X*** 189,194 ****
X--- 192,199 ----
X }
X }
X
X+ set_ttydefaults(0); /* set CRTSCTS sooner */
X+
X gettable("default", defent, defstrs);
X gendefaults();
X tname = "default";
X***************
X*** 516,519 ****
X--- 521,564 ----
X }
X cp++;
X }
X+ }
X+
X+ /*
X+ * a list of devices that we never deny logins on.
X+ * any seperator will do.
X+ */
X+
X+ #ifndef NO_DENY
X+ #define NO_DENY "/dev/console,/dev/vga"
X+ #endif
X+
X+ int
X+ ttydeny(ttyn)
X+ char *ttyn;
X+ {
X+ static char ttyb[MAXHOSTNAMELEN];
X+ static char buf[TABBUFSIZ];
X+ int fd;
X+ int cnt;
X+
X+ if (strstr(NO_DENY, ttyn))
X+ return 0; /* always allowed */
X+
X+ strcpy(ttyb, ttyn);
X+ strcat(ttyb, "\n");
X+
X+ again:
X+ if ((fd = open(_PATH_TTYDENY, O_RDONLY)) >= 0) {
X+ while ((cnt = read(fd, buf, sizeof(buf) - 1)) > 0) {
X+ buf[cnt] = '\0';
X+ if (strstr(buf, ttyb)) {
X+ close(fd);
X+ sleep(60); /* can't use it yet */
X+ goto again; /* yes a goto! */
X+ }
X+ }
X+ }
X+ close(fd);
X+ /* not found so we can return */
X+ return 0;
X }
!EOF
if test 2040 -ne `wc -c < getty.diffs`; then
echo shar: \"getty.diffs\" unpacked with wrong size!
fi
fi
exit 0
------------------------------------------------------------------------------