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
37 /* local function prototypes */
38 static int is_listed (const char *cfgin, const char *tty, int def);
41 * This is now rather generic function which decides if "tty" is listed
42 * under "cfgin" in config (directly or indirectly). Fallback to default if
45 static int is_listed (const char *cfgin, const char *tty, int def)
48 char buf[200], *cons, *s;
51 * If the CONSOLE configuration definition isn't given,
52 * fallback to default.
55 if ((cons = getdef_str (cfgin)) == NULL)
59 * If this isn't a filename, then it is a ":" delimited list of
60 * console devices upon which root logins are allowed.
64 cons = strcpy (buf, cons);
65 while ((s = strtok (cons, ":")) != NULL) {
66 if (strcmp (s, tty) == 0)
75 * If we can't open the console list, then call everything a
76 * console - otherwise root will never be allowed to login.
79 if ((fp = fopen (cons, "r")) == NULL)
83 * See if this tty is listed in the console file.
86 while (fgets (buf, sizeof (buf), fp) != NULL) {
87 buf[strlen (buf) - 1] = '\0';
88 if (strcmp (buf, tty) == 0) {
95 * This tty isn't a console.
103 * console - return 1 if the "tty" is a console device, else 0.
105 * Note - we need to take extreme care here to avoid locking out root logins
106 * if something goes awry. That's why we do things like call everything a
107 * console if the consoles file can't be opened. Because of this, we must
108 * warn the user to protect against the remove of the consoles file since
109 * that would allow an unauthorized root login.
112 int console (const char *tty)
114 return is_listed ("CONSOLE", tty, 1);