Bad news:  That serial printer you hooked up 30 years ago, with
magic numbers in a printcap file you haven't changed since, well,
that configuration might stop working.

This diff removes the printcap fc, fs, xc, xs capabilities from
lpd.  They allowed configuring a tty with magic numbers that were
poked into sgtty.  If you really need something like this, you can
use the ms capability, which uses symbolic stty modes.  There's a
new description line in printcap.5, snatched from FreeBSD, which
makes this a little bit clearer.

ok?

Index: share/man/man5/printcap.5
===================================================================
RCS file: /cvs/src/share/man/man5/printcap.5,v
retrieving revision 1.23
diff -u -p -r1.23 printcap.5
--- share/man/man5/printcap.5   3 Sep 2011 22:59:07 -0000       1.23
+++ share/man/man5/printcap.5   9 Dec 2013 19:47:19 -0000
@@ -76,12 +76,8 @@ for a description of the file layout.
 call)
 .It "cf" Ta "str" Ta Dv NULL Ta "cifplot data filter"
 .It "df" Ta "str" Ta Dv NULL Ta "tex data filter (DVI format)"
-.It "fc" Ta "num" Ta "0" Ta "if lp is a tty, clear flag bits"
-.Pq Aq Pa sgtty.h
 .It "ff" Ta "str" Ta So Li \ef Sc Ta "string to send for a form feed"
 .It "fo" Ta "bool" Ta "false" Ta "print a form feed when device is opened"
-.It "fs" Ta "num" Ta "0" Ta "if lp is a tty, set flag bits"
-.Pq Aq Pa sgtty.h
 .It "gf" Ta "str" Ta Dv NULL Ta "graph data filter"
 .Pf ( Xr plot 3
 format)
@@ -92,7 +88,9 @@ format)
 .It "lo" Ta "str" Ta Pa lock Ta "name of lock file"
 .It "lp" Ta "str" Ta Pa /dev/lp Ta "local printer device, or port@host for 
remote"
 .It "mc" Ta "num" Ta "0" Ta "maximum number of copies allowed; 0=unlimited"
-.It "ms" Ta "str" Ta Dv NULL Ta "list of terminal modes to set or clear"
+.It "ms" Ta "str" Ta Dv NULL Ta "if lp is a tty, a comma-separated,"
+.Xr stty 1 Ns -like
+list describing the tty modes
 .It "mx" Ta "num" Ta "0" Ta "max file size (in"
 .Dv BUFSIZ
 blocks); 0=unlimited
@@ -119,10 +117,6 @@ blocks); 0=unlimited
 .It "tf" Ta "str" Ta Dv NULL Ta "troff data filter (cat phototypesetter)"
 .It "tr" Ta "str" Ta Dv NULL Ta "trailer string to print when queue empties"
 .It "vf" Ta "str" Ta Dv NULL Ta "raster image filter"
-.It "xc" Ta "num" Ta "0" Ta "if lp is a tty, clear local mode bits"
-.Pq Xr tty 4
-.It "xs" Ta "num" Ta "0" Ta "if lp is a tty, set local mode bits"
-.Pq Xr tty 4
 .El
 .Pp
 If the local line printer driver supports indentation, the daemon
Index: usr.sbin/lpr/common_source/common.c
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/common_source/common.c,v
retrieving revision 1.34
diff -u -p -r1.34 common.c
--- usr.sbin/lpr/common_source/common.c 4 Mar 2012 04:05:15 -0000       1.34
+++ usr.sbin/lpr/common_source/common.c 9 Dec 2013 19:31:43 -0000
@@ -66,9 +66,7 @@ long   BR;            /* baud rate if lp is a tty *
 char   *CF;            /* name of cifplot filter (per job) */
 char   *DF;            /* name of tex filter (per job) */
 long    DU;            /* daemon user-id */
-long    FC;            /* flags to clear if lp is a tty */
 char   *FF;            /* form feed string */
-long    FS;            /* flags to set if lp is a tty */
 char   *GF;            /* name of graph(1G) filter (per job) */
 long    HL;            /* print header last */
 char   *IF;            /* name of input filter (created per job) */
@@ -99,8 +97,6 @@ char  *ST;            /* status file name */
 char   *TF;            /* name of troff filter (per job) */
 char   *TR;            /* trailer string to be output when Q empties */
 char   *VF;            /* name of vplot filter (per job) */
-long    XC;            /* flags to clear for local mode */
-long    XS;            /* flags to set for local mode */
 
 char   line[BUFSIZ];
 int    remote;         /* true if sending files to a remote host */
Index: usr.sbin/lpr/common_source/lp.h
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/common_source/lp.h,v
retrieving revision 1.17
diff -u -p -r1.17 lp.h
--- usr.sbin/lpr/common_source/lp.h     5 Dec 2012 23:20:26 -0000       1.17
+++ usr.sbin/lpr/common_source/lp.h     9 Dec 2013 19:31:24 -0000
@@ -42,9 +42,7 @@ extern long    BR;            /* baud rate if lp is 
 extern char    *CF;            /* name of cifplot filter (per job) */
 extern char    *DF;            /* name of tex filter (per job) */
 extern long     DU;            /* daemon user-id */
-extern long     FC;            /* flags to clear if lp is a tty */
 extern char    *FF;            /* form feed string */
-extern long     FS;            /* flags to set if lp is a tty */
 extern char    *GF;            /* name of graph(1G) filter (per job) */
 extern long     HL;            /* print header last */
 extern char    *IF;            /* name of input filter (created per job) */
@@ -75,8 +73,6 @@ extern char   *ST;            /* status file name */
 extern char    *TF;            /* name of troff(1) filter (per job) */
 extern char    *TR;            /* trailer string to be output when Q empties */
 extern char    *VF;            /* name of raster filter (per job) */
-extern long     XC;            /* flags to clear for local mode */
-extern long     XS;            /* flags to set for local mode */
 
 extern char    line[BUFSIZ];
 extern char    *bp;            /* pointer into printcap buffer */
Index: usr.sbin/lpr/lpd/Makefile
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/lpd/Makefile,v
retrieving revision 1.4
diff -u -p -r1.4 Makefile
--- usr.sbin/lpr/lpd/Makefile   8 Jun 2002 01:53:43 -0000       1.4
+++ usr.sbin/lpr/lpd/Makefile   9 Dec 2013 19:30:04 -0000
@@ -5,7 +5,7 @@ PROG=   lpd
 CFLAGS+=-I${.CURDIR}/../common_source
 MAN=   lpd.8
 SRCS=  lpd.c printjob.c recvjob.c displayq.c rmjob.c startdaemon.c \
-       lpdchar.c common.c key.c modes.c ttcompat.c common_vars.c
+       lpdchar.c common.c key.c modes.c common_vars.c
 BINGRP=        daemon
 BINMODE=2550
 .PATH: ${.CURDIR}/../common_source
Index: usr.sbin/lpr/lpd/extern.h
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/lpd/extern.h,v
retrieving revision 1.7
diff -u -p -r1.7 extern.h
--- usr.sbin/lpr/lpd/extern.h   5 Dec 2012 23:20:26 -0000       1.7
+++ usr.sbin/lpr/lpd/extern.h   9 Dec 2013 19:30:34 -0000
@@ -52,7 +52,3 @@ int      ksearch(char ***, struct info *);
 int       msearch(char ***, struct info *);
 void       printjob(void);
 void       recvjob(void);
-void       sttyclearflags(struct termios *tp, int flags);
-void       sttysetflags(struct termios *tp, int flags);
-void       sttyclearlflags(struct termios *tp, int flags);
-void       sttysetlflags(struct termios *tp, int flags);
Index: usr.sbin/lpr/lpd/printjob.c
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/lpd/printjob.c,v
retrieving revision 1.48
diff -u -p -r1.48 printjob.c
--- usr.sbin/lpr/lpd/printjob.c 24 Nov 2013 21:32:32 -0000      1.48
+++ usr.sbin/lpr/lpd/printjob.c 9 Dec 2013 19:33:57 -0000
@@ -1302,14 +1302,6 @@ init(void)
        RW = (cgetcap(bp, "rw", ':') != NULL);
 
        cgetnum(bp, "br", &BR);
-       if (cgetnum(bp, "fc", &FC) < 0)
-               FC = 0;
-       if (cgetnum(bp, "fs", &FS) < 0)
-               FS = 0;
-       if (cgetnum(bp, "xc", &XC) < 0)
-               XC = 0;
-       if (cgetnum(bp, "xs", &XS) < 0)
-               XS = 0;
        cgetstr(bp, "ms", &MS);
 
        tof = (cgetcap(bp, "fo", ':') == NULL);
@@ -1581,23 +1573,6 @@ setty(void)
                                continue;
                        syslog(LOG_INFO, "%s: unknown stty flag: %s",
                               printer, *argv);
-               }
-       } else {
-               if (FC) {
-                       sttyclearflags(&i.t, FC);
-                       i.set = 1;
-               }
-               if (FS) {
-                       sttysetflags(&i.t, FS);
-                       i.set = 1;
-               }
-               if (XC) {
-                       sttyclearlflags(&i.t, XC);
-                       i.set = 1;
-               }
-               if (XS) {
-                       sttysetlflags(&i.t, XS);
-                       i.set = 1;
                }
        }
 
Index: usr.sbin/lpr/lpd/ttcompat.c
===================================================================
RCS file: usr.sbin/lpr/lpd/ttcompat.c
diff -N usr.sbin/lpr/lpd/ttcompat.c
--- usr.sbin/lpr/lpd/ttcompat.c 27 Oct 2009 23:59:52 -0000      1.7
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,302 +0,0 @@
-/*     $OpenBSD: ttcompat.c,v 1.7 2009/10/27 23:59:52 deraadt Exp $    */
-/*     $NetBSD: ttcompat.c,v 1.9 1995/11/15 22:50:00 pk Exp $  */
-
-/*
- * Copyright (c) 1995
- *     The Regents of the University of California.  All rights reserved.
- *
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * ttcompat.c -- convert sgtty flags to termios
- *     originally from /sys/kern/tty_compat.c
- */
-
-#include <sys/param.h>
-#include <sys/types.h>
-
-#include <unistd.h>
-#include <sys/ioctl_compat.h>
-#include <termios.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include "extern.h"
-
-/* Macros to clear/set/test flags. */
-#define        SET(t, f)       (t) |= (f)
-#define        CLR(t, f)       (t) &= ~(f)
-#define        ISSET(t, f)     ((t) & (f))
-
-static int     sttygetoflags(struct termios *);
-static void    sttysetoflags(struct termios *, int);
-
-static int
-sttygetoflags(struct termios *tp)
-{
-       tcflag_t iflag = tp->c_iflag;
-       tcflag_t lflag = tp->c_lflag;
-       tcflag_t oflag = tp->c_oflag;
-       tcflag_t cflag = tp->c_cflag;
-       int flags = 0;
-
-       if (ISSET(cflag, PARENB)) {
-               if (ISSET(iflag, INPCK)) {
-                       if (ISSET(cflag, PARODD))
-                               SET(flags, ODDP);
-                       else
-                               SET(flags, EVENP);
-               } else
-                       SET(flags, EVENP|ODDP);
-       }
-       if (ISSET(cflag, CSIZE) == CS8) {
-               if (!ISSET(iflag, ISTRIP))
-                       SET(flags, PASS8);
-               if (!ISSET(oflag, OPOST))
-                       SET(flags, LITOUT);
-       }
-       if (ISSET(lflag, XCASE))
-               SET(flags, LCASE);
-
-       if (!ISSET(lflag, ICANON)) {
-               /* fudge */
-               if (ISSET(iflag, IXON) || ISSET(lflag, ISIG|IEXTEN) ||
-                   ISSET(cflag, PARENB))
-                       SET(flags, CBREAK);
-               else
-                       SET(flags, RAW);
-       }
-
-       return (flags);
-}
-
-static void
-sttysetoflags(struct termios *tp, int flags)
-{
-       tcflag_t iflag = tp->c_iflag;
-       tcflag_t oflag = tp->c_oflag;
-       tcflag_t lflag = tp->c_lflag;
-       tcflag_t cflag = tp->c_cflag;
-
-       if (ISSET(flags, RAW)) {
-               iflag &= IXOFF;
-               CLR(lflag, ISIG|ICANON|IEXTEN|XCASE);
-               CLR(cflag, PARENB);
-       } else {
-               SET(iflag, BRKINT|IXON|IMAXBEL);
-               SET(lflag, ISIG|IEXTEN);
-               if (ISSET(flags, CBREAK))
-                       CLR(lflag, ICANON);
-               else
-                       SET(lflag, ICANON);
-               if (ISSET(iflag, IUCLC) && ISSET(oflag, OLCUC))
-                       SET(lflag, XCASE);
-               switch (ISSET(flags, ANYP)) {
-               case 0:
-                       CLR(cflag, PARENB);
-                       break;
-               case ANYP:
-                       SET(cflag, PARENB);
-                       CLR(iflag, INPCK);
-                       break;
-               case EVENP:
-                       SET(cflag, PARENB);
-                       SET(iflag, INPCK);
-                       CLR(cflag, PARODD);
-                       break;
-               case ODDP:
-                       SET(cflag, PARENB);
-                       SET(iflag, INPCK);
-                       SET(cflag, PARODD);
-                       break;
-               }
-       }
-
-       if (ISSET(flags, RAW|LITOUT|PASS8)) {
-               CLR(cflag, CSIZE);
-               SET(cflag, CS8);
-               if (!ISSET(flags, RAW|PASS8))
-                       SET(iflag, ISTRIP);
-               else
-                       CLR(iflag, ISTRIP);
-               if (!ISSET(flags, RAW|LITOUT))
-                       SET(oflag, OPOST);
-               else
-                       CLR(oflag, OPOST);
-       } else {
-               CLR(cflag, CSIZE);
-               SET(cflag, CS7);
-               SET(iflag, ISTRIP);
-               SET(oflag, OPOST);
-       }
-
-       tp->c_iflag = iflag;
-       tp->c_oflag = oflag;
-       tp->c_lflag = lflag;
-       tp->c_cflag = cflag;
-}
-
-void
-sttyclearflags(struct termios *tp, int flags)
-{
-       tcflag_t iflag = tp->c_iflag;
-       tcflag_t oflag = tp->c_oflag;
-       tcflag_t lflag = tp->c_lflag;
-       tcflag_t cflag = tp->c_cflag;
-       int oflags = sttygetoflags(tp) & ~flags;
-
-       if (ISSET(flags, TANDEM))
-               CLR(iflag, IXOFF);
-       if (ISSET(flags, ECHO))
-               CLR(lflag, ECHO);
-       if (ISSET(flags, CRMOD)) {
-               CLR(iflag, ICRNL);
-               CLR(oflag, ONLCR);
-       }
-       if (ISSET(flags, LCASE)) {
-               CLR(iflag, IUCLC);
-               CLR(oflag, OLCUC);
-               CLR(lflag, XCASE);
-       }
-       if (ISSET(flags, XTABS))
-               CLR(oflag, OXTABS);
-
-
-       tp->c_iflag = iflag;
-       tp->c_oflag = oflag;
-       tp->c_lflag = lflag;
-       tp->c_cflag = cflag;
-
-       sttysetoflags(tp, oflags);
-}
-
-void
-sttysetflags(struct termios *tp, int flags)
-{
-       tcflag_t iflag = tp->c_iflag;
-       tcflag_t oflag = tp->c_oflag;
-       tcflag_t lflag = tp->c_lflag;
-       tcflag_t cflag = tp->c_cflag;
-       int oflags = sttygetoflags(tp) | flags;
-
-       if (ISSET(flags, TANDEM))
-               SET(iflag, IXOFF);
-       if (ISSET(flags, ECHO))
-               SET(lflag, ECHO);
-       if (ISSET(flags, CRMOD)) {
-               SET(iflag, ICRNL);
-               SET(oflag, ONLCR);
-       }
-       if (ISSET(flags, LCASE)) {
-               SET(iflag, IUCLC);
-               SET(oflag, OLCUC);
-               SET(lflag, XCASE);
-       }
-       if (ISSET(flags, XTABS))
-               SET(oflag, OXTABS);
-
-       tp->c_iflag = iflag;
-       tp->c_oflag = oflag;
-       tp->c_lflag = lflag;
-       tp->c_cflag = cflag;
-
-       sttysetoflags(tp, oflags);
-}
-
-void
-sttyclearlflags(struct termios *tp, int flags)
-{
-       tcflag_t iflag = tp->c_iflag;
-       tcflag_t oflag = tp->c_oflag;
-       tcflag_t lflag = tp->c_lflag;
-       tcflag_t cflag = tp->c_cflag;
-       int oflags = sttygetoflags(tp) & ~flags;
-
-       /* Nothing we can do with CRTBS. */
-       if (ISSET(flags, PRTERA))
-               CLR(lflag, ECHOPRT);
-       if (ISSET(flags, CRTERA))
-               CLR(lflag, ECHOE);
-       /* Nothing we can do with TILDE. */
-       if (ISSET(flags, MDMBUF))
-               CLR(cflag, MDMBUF);
-       if (ISSET(flags, NOHANG))
-               SET(cflag, HUPCL);
-       if (ISSET(flags, CRTKIL))
-               CLR(lflag, ECHOKE);
-       if (ISSET(flags, CTLECH))
-               CLR(lflag, ECHOCTL);
-       if (ISSET(flags, DECCTQ))
-               SET(iflag, IXANY);
-       CLR(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
-
-       tp->c_iflag = iflag;
-       tp->c_oflag = oflag;
-       tp->c_lflag = lflag;
-       tp->c_cflag = cflag;
-
-       sttysetoflags(tp, oflags);
-}
-
-void
-sttysetlflags(struct termios *tp, int flags)
-{
-       tcflag_t iflag = tp->c_iflag;
-       tcflag_t oflag = tp->c_oflag;
-       tcflag_t lflag = tp->c_lflag;
-       tcflag_t cflag = tp->c_cflag;
-       int oflags = sttygetoflags(tp) | flags;
-
-       /* Nothing we can do with CRTBS. */
-       if (ISSET(flags, PRTERA))
-               SET(lflag, ECHOPRT);
-       if (ISSET(flags, CRTERA))
-               SET(lflag, ECHOE);
-       /* Nothing we can do with TILDE. */
-       if (ISSET(flags, MDMBUF))
-               SET(cflag, MDMBUF);
-       if (ISSET(flags, NOHANG))
-               CLR(cflag, HUPCL);
-       if (ISSET(flags, CRTKIL))
-               SET(lflag, ECHOKE);
-       if (ISSET(flags, CTLECH))
-               SET(lflag, ECHOCTL);
-       if (ISSET(flags, DECCTQ))
-               CLR(iflag, IXANY);
-       SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
-
-       tp->c_iflag = iflag;
-       tp->c_oflag = oflag;
-       tp->c_lflag = lflag;
-       tp->c_cflag = cflag;
-
-       sttysetoflags(tp, oflags);
-}
-- 
Christian "naddy" Weisgerber                          na...@mips.inka.de

Reply via email to