2 * Copyright 1991, Julianne Frances Haugh and Chip Rosenthal
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Julianne F. Haugh nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * This is now rather generic function which decides if "tty" is listed
40 * under "cfgin" in config (directly or indirectly). Fallback to default if
43 int is_listed (const char *cfgin, const char *tty, int def)
46 char buf[200], *cons, *s;
49 * If the CONSOLE configuration definition isn't given,
50 * fallback to default.
53 if ((cons = getdef_str (cfgin)) == NULL)
57 * If this isn't a filename, then it is a ":" delimited list of
58 * console devices upon which root logins are allowed.
62 cons = strcpy (buf, cons);
63 while ((s = strtok (cons, ":")) != NULL) {
64 if (strcmp (s, tty) == 0)
73 * If we can't open the console list, then call everything a
74 * console - otherwise root will never be allowed to login.
77 if ((fp = fopen (cons, "r")) == NULL)
81 * See if this tty is listed in the console file.
84 while (fgets (buf, sizeof (buf), fp) != NULL) {
85 buf[strlen (buf) - 1] = '\0';
86 if (strcmp (buf, tty) == 0) {
93 * This tty isn't a console.
101 * console - return 1 if the "tty" is a console device, else 0.
103 * Note - we need to take extreme care here to avoid locking out root logins
104 * if something goes awry. That's why we do things like call everything a
105 * console if the consoles file can't be opened. Because of this, we must
106 * warn the user to protect against the remove of the consoles file since
107 * that would allow an unauthorized root login.
110 int console (const char *tty)
112 return is_listed ("CONSOLE", tty, 1);