1994-05-27 12:39:25 +00:00
|
|
|
/*
|
1996-05-05 19:01:13 +00:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-05-27 12:39:25 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2014-02-17 22:27:32 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 12:39:25 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-11-21 07:43:53 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)from: subr.c 8.1 (Berkeley) 6/4/93";
|
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-08-28 00:22:10 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-27 12:39:25 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Melbourne getty.
|
|
|
|
*/
|
1996-05-05 19:01:13 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/param.h>
|
1997-11-21 07:43:53 +00:00
|
|
|
#include <sys/time.h>
|
2016-02-26 18:52:06 +00:00
|
|
|
|
|
|
|
#include <poll.h>
|
Try to fix the old "he capability is stupid" bug in gettytab(5)/getty(8)
There is one capability explicitly documented in gettytab(5) as stupid: he.
And it is indeed. It was meant to facilitate system hostname modification,
but is hardly usable in practice because it allows very limited editing
(e.g., it depends on a particular hostname length, making it non-generic).
Replace it with simple implementation that treats ``he'' as POSIX extended
regular expression which is matched against the hostname. If there are no
parenthesized subexpressions in the pattern, entire matched string is used
as the final hostname. Otherwise, use the first matched subexpression.
If the pattern does not match, the original hostname is not modified.
Using regex(3) gives more freedom, does not complicate the code very much,
and makes a lot more sense, in turn making ``he'' less stupid and actually
useful (e.g., it is now possible to obtain node or domain names from the
original hostname string, without knowing it in advance).
Reviewed by: jilles, manpages (wblock)
Approved by: jilles (implied)
Differential Revision: https://reviews.freebsd.org/D9244
2017-02-02 20:30:50 +00:00
|
|
|
#include <regex.h>
|
2016-02-26 18:52:06 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-05-11 10:25:38 +00:00
|
|
|
#include <syslog.h>
|
2016-02-26 18:52:06 +00:00
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
1996-05-05 19:01:13 +00:00
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
#include "gettytab.h"
|
1996-05-05 19:01:13 +00:00
|
|
|
#include "pathnames.h"
|
|
|
|
#include "extern.h"
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a table entry.
|
|
|
|
*/
|
1996-05-05 19:01:13 +00:00
|
|
|
void
|
2002-02-06 16:38:40 +00:00
|
|
|
gettable(const char *name, char *buf)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2002-02-06 16:38:40 +00:00
|
|
|
struct gettystrs *sp;
|
|
|
|
struct gettynums *np;
|
|
|
|
struct gettyflags *fp;
|
1996-05-05 19:01:13 +00:00
|
|
|
long n;
|
1997-05-11 10:25:38 +00:00
|
|
|
int l;
|
|
|
|
char *p;
|
|
|
|
char *msg = NULL;
|
1996-05-05 19:01:13 +00:00
|
|
|
const char *dba[2];
|
1997-05-11 10:25:38 +00:00
|
|
|
|
|
|
|
static int firsttime = 1;
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
dba[0] = _PATH_GETTYTAB;
|
2016-02-26 19:08:37 +00:00
|
|
|
dba[1] = NULL;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1997-05-11 10:25:38 +00:00
|
|
|
if (firsttime) {
|
|
|
|
/*
|
|
|
|
* we need to strdup() anything in the strings array
|
|
|
|
* initially in order to simplify things later
|
|
|
|
*/
|
|
|
|
for (sp = gettystrs; sp->field; sp++)
|
|
|
|
if (sp->value != NULL) {
|
|
|
|
/* handle these ones more carefully */
|
|
|
|
if (sp >= &gettystrs[4] && sp <= &gettystrs[6])
|
|
|
|
l = 2;
|
|
|
|
else
|
|
|
|
l = strlen(sp->value) + 1;
|
|
|
|
if ((p = malloc(l)) != NULL) {
|
|
|
|
strncpy(p, sp->value, l);
|
|
|
|
p[l-1] = '\0';
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* replace, even if NULL, else we'll
|
|
|
|
* have problems with free()ing static mem
|
|
|
|
*/
|
|
|
|
sp->value = p;
|
|
|
|
}
|
|
|
|
firsttime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cgetent(&buf, (char **)dba, (char *)name)) {
|
|
|
|
case 1:
|
|
|
|
msg = "%s: couldn't resolve 'tc=' in gettytab '%s'";
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
msg = "%s: unknown gettytab entry '%s'";
|
|
|
|
break;
|
|
|
|
case -2:
|
|
|
|
msg = "%s: retrieving gettytab entry '%s': %m";
|
|
|
|
break;
|
|
|
|
case -3:
|
|
|
|
msg = "%s: recursive 'tc=' reference gettytab entry '%s'";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msg = "%s: unexpected cgetent() error for entry '%s'";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg != NULL) {
|
|
|
|
syslog(LOG_ERR, msg, "getty", name);
|
1994-05-27 12:39:25 +00:00
|
|
|
return;
|
1997-05-11 10:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (sp = gettystrs; sp->field; sp++) {
|
1997-09-03 01:05:36 +00:00
|
|
|
if ((l = cgetstr(buf, (char*)sp->field, &p)) >= 0) {
|
1997-05-11 10:25:38 +00:00
|
|
|
if (sp->value) {
|
|
|
|
/* prefer existing value */
|
|
|
|
if (strcmp(p, sp->value) != 0)
|
|
|
|
free(sp->value);
|
|
|
|
else {
|
|
|
|
free(p);
|
|
|
|
p = sp->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sp->value = p;
|
|
|
|
} else if (l == -1) {
|
|
|
|
free(sp->value);
|
|
|
|
sp->value = NULL;
|
|
|
|
}
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
for (np = gettynums; np->field; np++) {
|
1997-05-11 10:25:38 +00:00
|
|
|
if (cgetnum(buf, (char*)np->field, &n) == -1)
|
1994-05-27 12:39:25 +00:00
|
|
|
np->set = 0;
|
|
|
|
else {
|
|
|
|
np->set = 1;
|
|
|
|
np->value = n;
|
|
|
|
}
|
|
|
|
}
|
1997-05-11 10:25:38 +00:00
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
for (fp = gettyflags; fp->field; fp++) {
|
1997-05-11 10:25:38 +00:00
|
|
|
if (cgetcap(buf, (char *)fp->field, ':') == NULL)
|
1994-05-27 12:39:25 +00:00
|
|
|
fp->set = 0;
|
|
|
|
else {
|
|
|
|
fp->set = 1;
|
1996-05-05 19:01:13 +00:00
|
|
|
fp->value = 1 ^ fp->invrt;
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
void
|
2002-02-06 16:38:40 +00:00
|
|
|
gendefaults(void)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2002-02-06 16:38:40 +00:00
|
|
|
struct gettystrs *sp;
|
|
|
|
struct gettynums *np;
|
|
|
|
struct gettyflags *fp;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
for (sp = gettystrs; sp->field; sp++)
|
|
|
|
if (sp->value)
|
1997-05-11 10:25:38 +00:00
|
|
|
sp->defalt = strdup(sp->value);
|
1994-05-27 12:39:25 +00:00
|
|
|
for (np = gettynums; np->field; np++)
|
|
|
|
if (np->set)
|
|
|
|
np->defalt = np->value;
|
|
|
|
for (fp = gettyflags; fp->field; fp++)
|
|
|
|
if (fp->set)
|
|
|
|
fp->defalt = fp->value;
|
|
|
|
else
|
|
|
|
fp->defalt = fp->invrt;
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
void
|
2002-02-06 16:38:40 +00:00
|
|
|
setdefaults(void)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2002-02-06 16:38:40 +00:00
|
|
|
struct gettystrs *sp;
|
|
|
|
struct gettynums *np;
|
|
|
|
struct gettyflags *fp;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
for (sp = gettystrs; sp->field; sp++)
|
|
|
|
if (!sp->value)
|
1997-05-11 10:25:38 +00:00
|
|
|
sp->value = !sp->defalt ? sp->defalt
|
|
|
|
: strdup(sp->defalt);
|
1994-05-27 12:39:25 +00:00
|
|
|
for (np = gettynums; np->field; np++)
|
|
|
|
if (!np->set)
|
|
|
|
np->value = np->defalt;
|
|
|
|
for (fp = gettyflags; fp->field; fp++)
|
|
|
|
if (!fp->set)
|
|
|
|
fp->value = fp->defalt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char **
|
|
|
|
charnames[] = {
|
|
|
|
&ER, &KL, &IN, &QU, &XN, &XF, &ET, &BK,
|
|
|
|
&SU, &DS, &RP, &FL, &WE, &LN, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *
|
|
|
|
charvars[] = {
|
1996-05-05 19:01:13 +00:00
|
|
|
&tmode.c_cc[VERASE], &tmode.c_cc[VKILL], &tmode.c_cc[VINTR],
|
|
|
|
&tmode.c_cc[VQUIT], &tmode.c_cc[VSTART], &tmode.c_cc[VSTOP],
|
|
|
|
&tmode.c_cc[VEOF], &tmode.c_cc[VEOL], &tmode.c_cc[VSUSP],
|
|
|
|
&tmode.c_cc[VDSUSP], &tmode.c_cc[VREPRINT], &tmode.c_cc[VDISCARD],
|
2016-02-26 19:35:51 +00:00
|
|
|
&tmode.c_cc[VWERASE], &tmode.c_cc[VLNEXT], 0
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
void
|
2002-02-06 16:38:40 +00:00
|
|
|
setchars(void)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2002-02-06 16:38:40 +00:00
|
|
|
int i;
|
|
|
|
const char *p;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
for (i = 0; charnames[i]; i++) {
|
|
|
|
p = *charnames[i];
|
|
|
|
if (p && *p)
|
|
|
|
*charvars[i] = *p;
|
|
|
|
else
|
1996-05-05 19:01:13 +00:00
|
|
|
*charvars[i] = _POSIX_VDISABLE;
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
/* Macros to clear/set/test flags. */
|
|
|
|
#define SET(t, f) (t) |= (f)
|
|
|
|
#define CLR(t, f) (t) &= ~(f)
|
|
|
|
#define ISSET(t, f) ((t) & (f))
|
|
|
|
|
|
|
|
void
|
2002-02-06 16:38:40 +00:00
|
|
|
set_flags(int n)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2002-02-06 16:38:40 +00:00
|
|
|
tcflag_t iflag, oflag, cflag, lflag;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
switch (n) {
|
|
|
|
case 0:
|
|
|
|
if (C0set && I0set && L0set && O0set) {
|
|
|
|
tmode.c_cflag = C0;
|
|
|
|
tmode.c_iflag = I0;
|
|
|
|
tmode.c_lflag = L0;
|
|
|
|
tmode.c_oflag = O0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (C1set && I1set && L1set && O1set) {
|
|
|
|
tmode.c_cflag = C1;
|
|
|
|
tmode.c_iflag = I1;
|
|
|
|
tmode.c_lflag = L1;
|
|
|
|
tmode.c_oflag = O1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (C2set && I2set && L2set && O2set) {
|
|
|
|
tmode.c_cflag = C2;
|
|
|
|
tmode.c_iflag = I2;
|
|
|
|
tmode.c_lflag = L2;
|
|
|
|
tmode.c_oflag = O2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
iflag = omode.c_iflag;
|
|
|
|
oflag = omode.c_oflag;
|
|
|
|
cflag = omode.c_cflag;
|
|
|
|
lflag = omode.c_lflag;
|
|
|
|
|
|
|
|
if (NP) {
|
|
|
|
CLR(cflag, CSIZE|PARENB);
|
|
|
|
SET(cflag, CS8);
|
|
|
|
CLR(iflag, ISTRIP|INPCK|IGNPAR);
|
|
|
|
} else if (AP || EP || OP) {
|
|
|
|
CLR(cflag, CSIZE);
|
|
|
|
SET(cflag, CS7|PARENB);
|
|
|
|
SET(iflag, ISTRIP);
|
|
|
|
if (OP && !EP) {
|
|
|
|
SET(iflag, INPCK|IGNPAR);
|
|
|
|
SET(cflag, PARODD);
|
|
|
|
if (AP)
|
|
|
|
CLR(iflag, INPCK);
|
|
|
|
} else if (EP && !OP) {
|
|
|
|
SET(iflag, INPCK|IGNPAR);
|
|
|
|
CLR(cflag, PARODD);
|
|
|
|
if (AP)
|
|
|
|
CLR(iflag, INPCK);
|
|
|
|
} else if (AP || (EP && OP)) {
|
|
|
|
CLR(iflag, INPCK|IGNPAR);
|
|
|
|
CLR(cflag, PARODD);
|
|
|
|
}
|
|
|
|
} /* else, leave as is */
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
#if 0
|
1994-05-27 12:39:25 +00:00
|
|
|
if (UC)
|
|
|
|
f |= LCASE;
|
1996-05-05 19:01:13 +00:00
|
|
|
#endif
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
if (HC)
|
|
|
|
SET(cflag, HUPCL);
|
|
|
|
else
|
|
|
|
CLR(cflag, HUPCL);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
if (MB)
|
|
|
|
SET(cflag, MDMBUF);
|
|
|
|
else
|
|
|
|
CLR(cflag, MDMBUF);
|
|
|
|
|
1997-02-02 14:24:57 +00:00
|
|
|
if (HW)
|
|
|
|
SET(cflag, CRTSCTS);
|
|
|
|
else
|
|
|
|
CLR(cflag, CRTSCTS);
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
if (NL) {
|
|
|
|
SET(iflag, ICRNL);
|
|
|
|
SET(oflag, ONLCR|OPOST);
|
|
|
|
} else {
|
|
|
|
CLR(iflag, ICRNL);
|
|
|
|
CLR(oflag, ONLCR);
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!HT)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(oflag, OXTABS|OPOST);
|
|
|
|
else
|
|
|
|
CLR(oflag, OXTABS);
|
|
|
|
|
|
|
|
#ifdef XXX_DELAY
|
|
|
|
SET(f, delaybits());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (n == 1) { /* read mode flags */
|
|
|
|
if (RW) {
|
|
|
|
iflag = 0;
|
|
|
|
CLR(oflag, OPOST);
|
|
|
|
CLR(cflag, CSIZE|PARENB);
|
|
|
|
SET(cflag, CS8);
|
|
|
|
lflag = 0;
|
|
|
|
} else {
|
|
|
|
CLR(lflag, ICANON);
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (n == 0)
|
1996-05-05 19:01:13 +00:00
|
|
|
goto out;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
#if 0
|
1994-05-27 12:39:25 +00:00
|
|
|
if (CB)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(f, CRTBS);
|
|
|
|
#endif
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (CE)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(lflag, ECHOE);
|
|
|
|
else
|
|
|
|
CLR(lflag, ECHOE);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (CK)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(lflag, ECHOKE);
|
|
|
|
else
|
|
|
|
CLR(lflag, ECHOKE);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (PE)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(lflag, ECHOPRT);
|
|
|
|
else
|
|
|
|
CLR(lflag, ECHOPRT);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (EC)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(lflag, ECHO);
|
|
|
|
else
|
|
|
|
CLR(lflag, ECHO);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (XC)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(lflag, ECHOCTL);
|
|
|
|
else
|
|
|
|
CLR(lflag, ECHOCTL);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (DX)
|
1996-05-05 19:01:13 +00:00
|
|
|
SET(lflag, IXANY);
|
|
|
|
else
|
|
|
|
CLR(lflag, IXANY);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
out:
|
|
|
|
tmode.c_iflag = iflag;
|
|
|
|
tmode.c_oflag = oflag;
|
|
|
|
tmode.c_cflag = cflag;
|
|
|
|
tmode.c_lflag = lflag;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
#ifdef XXX_DELAY
|
1994-05-27 12:39:25 +00:00
|
|
|
struct delayval {
|
|
|
|
unsigned delay; /* delay in ms */
|
|
|
|
int bits;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* below are random guesses, I can't be bothered checking
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct delayval crdelay[] = {
|
1996-05-05 19:01:13 +00:00
|
|
|
{ 1, CR1 },
|
|
|
|
{ 2, CR2 },
|
|
|
|
{ 3, CR3 },
|
|
|
|
{ 83, CR1 },
|
|
|
|
{ 166, CR2 },
|
|
|
|
{ 0, CR3 },
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct delayval nldelay[] = {
|
1996-05-05 19:01:13 +00:00
|
|
|
{ 1, NL1 }, /* special, calculated */
|
|
|
|
{ 2, NL2 },
|
|
|
|
{ 3, NL3 },
|
|
|
|
{ 100, NL2 },
|
|
|
|
{ 0, NL3 },
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct delayval bsdelay[] = {
|
1996-05-05 19:01:13 +00:00
|
|
|
{ 1, BS1 },
|
|
|
|
{ 0, 0 },
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct delayval ffdelay[] = {
|
1996-05-05 19:01:13 +00:00
|
|
|
{ 1, FF1 },
|
|
|
|
{ 1750, FF1 },
|
|
|
|
{ 0, FF1 },
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct delayval tbdelay[] = {
|
1996-05-05 19:01:13 +00:00
|
|
|
{ 1, TAB1 },
|
|
|
|
{ 2, TAB2 },
|
|
|
|
{ 3, XTABS }, /* this is expand tabs */
|
|
|
|
{ 100, TAB1 },
|
|
|
|
{ 0, TAB2 },
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
int
|
2002-02-06 16:38:40 +00:00
|
|
|
delaybits(void)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2002-02-06 16:38:40 +00:00
|
|
|
int f;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
f = adelay(CD, crdelay);
|
|
|
|
f |= adelay(ND, nldelay);
|
|
|
|
f |= adelay(FD, ffdelay);
|
|
|
|
f |= adelay(TD, tbdelay);
|
|
|
|
f |= adelay(BD, bsdelay);
|
|
|
|
return (f);
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
int
|
2002-02-06 16:38:40 +00:00
|
|
|
adelay(int ms, struct delayval *dp)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
if (ms == 0)
|
|
|
|
return (0);
|
|
|
|
while (dp->delay && ms > dp->delay)
|
|
|
|
dp++;
|
|
|
|
return (dp->bits);
|
|
|
|
}
|
1996-05-05 19:01:13 +00:00
|
|
|
#endif
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
char editedhost[MAXHOSTNAMELEN];
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
void
|
Try to fix the old "he capability is stupid" bug in gettytab(5)/getty(8)
There is one capability explicitly documented in gettytab(5) as stupid: he.
And it is indeed. It was meant to facilitate system hostname modification,
but is hardly usable in practice because it allows very limited editing
(e.g., it depends on a particular hostname length, making it non-generic).
Replace it with simple implementation that treats ``he'' as POSIX extended
regular expression which is matched against the hostname. If there are no
parenthesized subexpressions in the pattern, entire matched string is used
as the final hostname. Otherwise, use the first matched subexpression.
If the pattern does not match, the original hostname is not modified.
Using regex(3) gives more freedom, does not complicate the code very much,
and makes a lot more sense, in turn making ``he'' less stupid and actually
useful (e.g., it is now possible to obtain node or domain names from the
original hostname string, without knowing it in advance).
Reviewed by: jilles, manpages (wblock)
Approved by: jilles (implied)
Differential Revision: https://reviews.freebsd.org/D9244
2017-02-02 20:30:50 +00:00
|
|
|
edithost(const char *pattern)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
Try to fix the old "he capability is stupid" bug in gettytab(5)/getty(8)
There is one capability explicitly documented in gettytab(5) as stupid: he.
And it is indeed. It was meant to facilitate system hostname modification,
but is hardly usable in practice because it allows very limited editing
(e.g., it depends on a particular hostname length, making it non-generic).
Replace it with simple implementation that treats ``he'' as POSIX extended
regular expression which is matched against the hostname. If there are no
parenthesized subexpressions in the pattern, entire matched string is used
as the final hostname. Otherwise, use the first matched subexpression.
If the pattern does not match, the original hostname is not modified.
Using regex(3) gives more freedom, does not complicate the code very much,
and makes a lot more sense, in turn making ``he'' less stupid and actually
useful (e.g., it is now possible to obtain node or domain names from the
original hostname string, without knowing it in advance).
Reviewed by: jilles, manpages (wblock)
Approved by: jilles (implied)
Differential Revision: https://reviews.freebsd.org/D9244
2017-02-02 20:30:50 +00:00
|
|
|
regex_t regex;
|
|
|
|
regmatch_t *match;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
if (pattern == NULL || *pattern == '\0')
|
|
|
|
goto copyasis;
|
|
|
|
if (regcomp(®ex, pattern, REG_EXTENDED) != 0)
|
|
|
|
goto copyasis;
|
|
|
|
|
|
|
|
match = calloc(regex.re_nsub + 1, sizeof(*match));
|
|
|
|
if (match == NULL) {
|
|
|
|
regfree(®ex);
|
|
|
|
goto copyasis;
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
|
Try to fix the old "he capability is stupid" bug in gettytab(5)/getty(8)
There is one capability explicitly documented in gettytab(5) as stupid: he.
And it is indeed. It was meant to facilitate system hostname modification,
but is hardly usable in practice because it allows very limited editing
(e.g., it depends on a particular hostname length, making it non-generic).
Replace it with simple implementation that treats ``he'' as POSIX extended
regular expression which is matched against the hostname. If there are no
parenthesized subexpressions in the pattern, entire matched string is used
as the final hostname. Otherwise, use the first matched subexpression.
If the pattern does not match, the original hostname is not modified.
Using regex(3) gives more freedom, does not complicate the code very much,
and makes a lot more sense, in turn making ``he'' less stupid and actually
useful (e.g., it is now possible to obtain node or domain names from the
original hostname string, without knowing it in advance).
Reviewed by: jilles, manpages (wblock)
Approved by: jilles (implied)
Differential Revision: https://reviews.freebsd.org/D9244
2017-02-02 20:30:50 +00:00
|
|
|
found = !regexec(®ex, HN, regex.re_nsub + 1, match, 0);
|
|
|
|
if (found) {
|
|
|
|
size_t subex, totalsize;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
Try to fix the old "he capability is stupid" bug in gettytab(5)/getty(8)
There is one capability explicitly documented in gettytab(5) as stupid: he.
And it is indeed. It was meant to facilitate system hostname modification,
but is hardly usable in practice because it allows very limited editing
(e.g., it depends on a particular hostname length, making it non-generic).
Replace it with simple implementation that treats ``he'' as POSIX extended
regular expression which is matched against the hostname. If there are no
parenthesized subexpressions in the pattern, entire matched string is used
as the final hostname. Otherwise, use the first matched subexpression.
If the pattern does not match, the original hostname is not modified.
Using regex(3) gives more freedom, does not complicate the code very much,
and makes a lot more sense, in turn making ``he'' less stupid and actually
useful (e.g., it is now possible to obtain node or domain names from the
original hostname string, without knowing it in advance).
Reviewed by: jilles, manpages (wblock)
Approved by: jilles (implied)
Differential Revision: https://reviews.freebsd.org/D9244
2017-02-02 20:30:50 +00:00
|
|
|
/*
|
|
|
|
* We found a match. If there were no parenthesized
|
|
|
|
* subexpressions in the pattern, use entire matched
|
|
|
|
* string as ``editedhost''; otherwise use the first
|
|
|
|
* matched subexpression.
|
|
|
|
*/
|
|
|
|
subex = !!regex.re_nsub;
|
|
|
|
totalsize = match[subex].rm_eo - match[subex].rm_so + 1;
|
|
|
|
strlcpy(editedhost, HN + match[subex].rm_so, totalsize >
|
|
|
|
sizeof(editedhost) ? sizeof(editedhost) : totalsize);
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
Try to fix the old "he capability is stupid" bug in gettytab(5)/getty(8)
There is one capability explicitly documented in gettytab(5) as stupid: he.
And it is indeed. It was meant to facilitate system hostname modification,
but is hardly usable in practice because it allows very limited editing
(e.g., it depends on a particular hostname length, making it non-generic).
Replace it with simple implementation that treats ``he'' as POSIX extended
regular expression which is matched against the hostname. If there are no
parenthesized subexpressions in the pattern, entire matched string is used
as the final hostname. Otherwise, use the first matched subexpression.
If the pattern does not match, the original hostname is not modified.
Using regex(3) gives more freedom, does not complicate the code very much,
and makes a lot more sense, in turn making ``he'' less stupid and actually
useful (e.g., it is now possible to obtain node or domain names from the
original hostname string, without knowing it in advance).
Reviewed by: jilles, manpages (wblock)
Approved by: jilles (implied)
Differential Revision: https://reviews.freebsd.org/D9244
2017-02-02 20:30:50 +00:00
|
|
|
free(match);
|
|
|
|
regfree(®ex);
|
|
|
|
if (found)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* In case of any errors, or if the pattern did not match, pass
|
|
|
|
* the original hostname as is.
|
|
|
|
*/
|
|
|
|
copyasis:
|
|
|
|
strlcpy(editedhost, HN, sizeof(editedhost));
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static struct speedtab {
|
1994-05-27 12:39:25 +00:00
|
|
|
int speed;
|
|
|
|
int uxname;
|
|
|
|
} speedtab[] = {
|
1996-05-05 19:01:13 +00:00
|
|
|
{ 50, B50 },
|
|
|
|
{ 75, B75 },
|
|
|
|
{ 110, B110 },
|
|
|
|
{ 134, B134 },
|
|
|
|
{ 150, B150 },
|
|
|
|
{ 200, B200 },
|
|
|
|
{ 300, B300 },
|
|
|
|
{ 600, B600 },
|
|
|
|
{ 1200, B1200 },
|
|
|
|
{ 1800, B1800 },
|
|
|
|
{ 2400, B2400 },
|
|
|
|
{ 4800, B4800 },
|
|
|
|
{ 9600, B9600 },
|
|
|
|
{ 19200, EXTA },
|
|
|
|
{ 19, EXTA }, /* for people who say 19.2K */
|
|
|
|
{ 38400, EXTB },
|
|
|
|
{ 38, EXTB },
|
|
|
|
{ 7200, EXTB }, /* alternative */
|
|
|
|
{ 57600, B57600 },
|
|
|
|
{ 115200, B115200 },
|
1998-07-22 05:57:22 +00:00
|
|
|
{ 230400, B230400 },
|
1996-05-05 19:01:13 +00:00
|
|
|
{ 0 }
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
int
|
2002-02-06 16:38:40 +00:00
|
|
|
speed(int val)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2002-02-06 16:38:40 +00:00
|
|
|
struct speedtab *sp;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1998-07-22 05:57:22 +00:00
|
|
|
if (val <= B230400)
|
1994-05-27 12:39:25 +00:00
|
|
|
return (val);
|
|
|
|
|
|
|
|
for (sp = speedtab; sp->speed; sp++)
|
|
|
|
if (sp->speed == val)
|
|
|
|
return (sp->uxname);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
return (B300); /* default in impossible cases */
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
void
|
2002-02-06 16:38:40 +00:00
|
|
|
makeenv(char *env[])
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
static char termbuf[128] = "TERM=";
|
2002-02-06 16:38:40 +00:00
|
|
|
char *p, *q;
|
|
|
|
char **ep;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
ep = env;
|
|
|
|
if (TT && *TT) {
|
2001-04-24 10:33:46 +00:00
|
|
|
strlcat(termbuf, TT, sizeof(termbuf));
|
1994-05-27 12:39:25 +00:00
|
|
|
*ep++ = termbuf;
|
|
|
|
}
|
1996-05-05 19:01:13 +00:00
|
|
|
if ((p = EV)) {
|
1994-05-27 12:39:25 +00:00
|
|
|
q = p;
|
1996-05-05 19:01:13 +00:00
|
|
|
while ((q = strchr(q, ','))) {
|
1994-05-27 12:39:25 +00:00
|
|
|
*q++ = '\0';
|
|
|
|
*ep++ = p;
|
|
|
|
p = q;
|
|
|
|
}
|
|
|
|
if (*p)
|
|
|
|
*ep++ = p;
|
|
|
|
}
|
|
|
|
*ep = (char *)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This speed select mechanism is written for the Develcon DATASWITCH.
|
|
|
|
* The Develcon sends a string of the form "B{speed}\n" at a predefined
|
|
|
|
* baud rate. This string indicates the user's actual speed.
|
|
|
|
* The routine below returns the terminal type mapped from derived speed.
|
|
|
|
*/
|
|
|
|
struct portselect {
|
1996-05-05 19:01:13 +00:00
|
|
|
const char *ps_baud;
|
|
|
|
const char *ps_type;
|
1994-05-27 12:39:25 +00:00
|
|
|
} portspeeds[] = {
|
|
|
|
{ "B110", "std.110" },
|
|
|
|
{ "B134", "std.134" },
|
|
|
|
{ "B150", "std.150" },
|
|
|
|
{ "B300", "std.300" },
|
|
|
|
{ "B600", "std.600" },
|
|
|
|
{ "B1200", "std.1200" },
|
|
|
|
{ "B2400", "std.2400" },
|
|
|
|
{ "B4800", "std.4800" },
|
|
|
|
{ "B9600", "std.9600" },
|
|
|
|
{ "B19200", "std.19200" },
|
2016-02-26 19:08:37 +00:00
|
|
|
{ NULL, NULL }
|
1994-05-27 12:39:25 +00:00
|
|
|
};
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
const char *
|
2002-02-06 16:38:40 +00:00
|
|
|
portselector(void)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
1996-05-05 19:01:13 +00:00
|
|
|
char c, baud[20];
|
|
|
|
const char *type = "default";
|
2002-02-06 16:38:40 +00:00
|
|
|
struct portselect *ps;
|
2016-02-26 19:08:37 +00:00
|
|
|
size_t len;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
alarm(5*60);
|
|
|
|
for (len = 0; len < sizeof (baud) - 1; len++) {
|
|
|
|
if (read(STDIN_FILENO, &c, 1) <= 0)
|
|
|
|
break;
|
|
|
|
c &= 0177;
|
|
|
|
if (c == '\n' || c == '\r')
|
|
|
|
break;
|
|
|
|
if (c == 'B')
|
|
|
|
len = 0; /* in case of leading garbage */
|
|
|
|
baud[len] = c;
|
|
|
|
}
|
|
|
|
baud[len] = '\0';
|
|
|
|
for (ps = portspeeds; ps->ps_baud; ps++)
|
|
|
|
if (strcmp(ps->ps_baud, baud) == 0) {
|
|
|
|
type = ps->ps_type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(2); /* wait for connection to complete */
|
|
|
|
return (type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This auto-baud speed select mechanism is written for the Micom 600
|
|
|
|
* portselector. Selection is done by looking at how the character '\r'
|
|
|
|
* is garbled at the different speeds.
|
|
|
|
*/
|
1996-05-05 19:01:13 +00:00
|
|
|
const char *
|
2002-02-06 16:38:40 +00:00
|
|
|
autobaud(void)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
2016-02-27 02:11:00 +00:00
|
|
|
struct pollfd set[1];
|
2016-02-26 18:52:06 +00:00
|
|
|
struct timespec timeout;
|
1996-05-05 19:01:13 +00:00
|
|
|
char c;
|
|
|
|
const char *type = "9600-baud";
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
(void)tcflush(0, TCIOFLUSH);
|
2016-02-26 18:52:06 +00:00
|
|
|
set[0].fd = STDIN_FILENO;
|
|
|
|
set[0].events = POLLIN;
|
|
|
|
if (poll(set, 1, 5000) <= 0)
|
1994-05-27 12:39:25 +00:00
|
|
|
return (type);
|
|
|
|
if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char))
|
|
|
|
return (type);
|
|
|
|
timeout.tv_sec = 0;
|
2016-02-26 18:52:06 +00:00
|
|
|
timeout.tv_nsec = 20000;
|
|
|
|
(void)nanosleep(&timeout, NULL);
|
1996-05-05 19:01:13 +00:00
|
|
|
(void)tcflush(0, TCIOFLUSH);
|
1994-05-27 12:39:25 +00:00
|
|
|
switch (c & 0377) {
|
|
|
|
|
|
|
|
case 0200: /* 300-baud */
|
|
|
|
type = "300-baud";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0346: /* 1200-baud */
|
|
|
|
type = "1200-baud";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 015: /* 2400-baud */
|
|
|
|
case 0215:
|
|
|
|
type = "2400-baud";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* 4800-baud */
|
|
|
|
type = "4800-baud";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0377: /* 9600-baud */
|
|
|
|
type = "9600-baud";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (type);
|
|
|
|
}
|