From b06ebb3255268c5a297afbb8598e2cc11fab7944 Mon Sep 17 00:00:00 2001 From: David Nugent Date: Sun, 13 Apr 1997 15:16:03 +0000 Subject: [PATCH] Implement two new keywords and status flags for entries in /etc/ttys; TTY_NETWORK (network), TTY_DIALUP (dialup), which determine a basic connection type. TTY_DIALUP in particular will replace the old out of date heuristic "tty[dD]*" in login.c (and better than the current hard-coded method). --- lib/libc/gen/getttyent.3 | 29 +++++++++++++++++++++++++- lib/libc/gen/getttyent.c | 45 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/lib/libc/gen/getttyent.3 b/lib/libc/gen/getttyent.3 index 06b1e9453c49..51290d9b0bd9 100644 --- a/lib/libc/gen/getttyent.3 +++ b/lib/libc/gen/getttyent.3 @@ -40,6 +40,9 @@ .Nm setttyent , .Nm endttyent .Nd get ttys file entry +.Nm isdialuptty , +.Nm isnetworktty +.Nd determine tty type from ttys file entry .Sh SYNOPSIS .Fd #include .Ft struct ttyent * @@ -50,6 +53,10 @@ .Fn setttyent void .Ft int .Fn endttyent void +.Ft int +.Fn isdialuptty "const char *name" +.Ft int +.Fn isnetworktty "const char *name" .Sh DESCRIPTION The .Fn getttyent , @@ -66,6 +73,8 @@ struct ttyent { char *ty_type; /* terminal type for termcap */ #define TTY_ON 0x01 /* enable logins (start ty_getty program) */ #define TTY_SECURE 0x02 /* allow uid of 0 to login */ +#define TTY_DIALUP 0x04 /* is a dialup tty */ +#define TTY_NETWORK 0x08 /* is a network tty */ int ty_status; /* status flags */ char *ty_window; /* command to start up window manager */ char *ty_comment; /* comment field */ @@ -87,7 +96,7 @@ The name of the default terminal type connected to this tty line. A mask of bit fields which indicate various actions allowed on this tty line. The possible flags are as follows: -.Bl -tag -width TTY_SECURE +.Bl -tag -width TTY_NETWORK .It Dv TTY_ON Enables logins (i.e., .Xr init 8 @@ -96,6 +105,16 @@ will start the command referenced by on this entry). .It Dv TTY_SECURE Allow users with a uid of 0 to login on this terminal. +.It Dv TTY_DIALUP +Identifies a tty as a dialin line. +If this flag is set, then +.Fn isdialuptty +will return a non-zero value. +.It Dv TTY_NETWORK +Identifies a tty used for network connections. +If this flag is set, then +.Fn isnetworktty +will return a non-zero value. .El .It Fa ty_window The command to execute for a window system associated with the line. @@ -155,6 +174,14 @@ function and .Fn endttyent return 0 on failure and 1 on success. +.Pp +The routines +.Fn isdialuptty +and +.Fn isnetworktty +return non-zero if the dialup or network flag is set for the +tty entry relating to the tty named by the parameter, and +zero otherwise. .Sh FILES .Bl -tag -width /etc/ttys -compact .It Pa /etc/ttys diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c index ca0413cbe4bf..1fb1960546d7 100644 --- a/lib/libc/gen/getttyent.c +++ b/lib/libc/gen/getttyent.c @@ -57,6 +57,8 @@ getttynam(tty) { register struct ttyent *t; + if (strnchr(tty, "/dev/", 5) == 0) + tty += 5; setttyent(); while ( (t = getttyent()) ) if (!strcmp(tty, t->ty_name)) @@ -96,6 +98,9 @@ getttyent() break; } +#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1]) +#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '=' + zapchar = 0; tty.ty_name = p; p = skip(p); @@ -105,15 +110,19 @@ getttyent() p = skip(p); if (!*(tty.ty_type = p)) tty.ty_type = NULL; - else + else { + /* compatibility kludge: handle network/dialup specially */ + if (scmp(_TTYS_DIALUP)) + tty.ty_status |= TTY_DIALUP; + else if (scmp(_TTYS_NETWORK)) + tty.ty_status |= TTY_NETWORK; p = skip(p); + } } tty.ty_status = 0; tty.ty_window = NULL; tty.ty_group = _TTYS_NOGROUP; -#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1]) -#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '=' for (; *p; p = skip(p)) { if (scmp(_TTYS_OFF)) tty.ty_status &= ~TTY_ON; @@ -123,6 +132,10 @@ getttyent() tty.ty_status |= TTY_SECURE; else if (scmp(_TTYS_INSECURE)) tty.ty_status &= ~TTY_SECURE; + else if (scmp(_TTYS_DIALUP)) + tty.ty_status |= TTY_DIALUP; + else if (scmp(_TTYS_NETWORK)) + tty.ty_status |= TTY_NETWORK; else if (vcmp(_TTYS_WINDOW)) tty.ty_window = value(p); else if (vcmp(_TTYS_GROUP)) @@ -223,3 +236,29 @@ endttyent() } return (1); } + +static int +isttystat(tty, flag) + const char *tty; + int flag; +{ + register struct ttyent *t; + + return ((t = getttynam(tty)) == NULL) ? 0 : !!(t->ty_status & flag); +} + + +int +isdialuptty(tty) + const char *tty; +{ + + return isttystat(tty, TTY_DIALUP); +} + +int isnettty(tty) + const char *tty; +{ + + return isttystat(tty, TTY_NETWORK); +}