2 * Copyright (c) 1991 , Julianne Frances Haugh
3 * Copyright (c) 1991 , Chip Rosenthal
4 * Copyright (c) 1996 - 1998, Marek Michałkiewicz
5 * Copyright (c) 2003 - 2005, Tomasz Kłoczko
6 * Copyright (c) 2007 - 2008, Nicolas François
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the copyright holders or contributors may not be used to
18 * endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include "prototypes.h"
42 /* local function prototypes */
43 static int is_listed (const char *cfgin, const char *tty, int def);
46 * This is now rather generic function which decides if "tty" is listed
47 * under "cfgin" in config (directly or indirectly). Fallback to default if
50 static int is_listed (const char *cfgin, const char *tty, int def)
53 char buf[200], *cons, *s;
56 * If the CONSOLE configuration definition isn't given,
57 * fallback to default.
60 if ((cons = getdef_str (cfgin)) == NULL)
64 * If this isn't a filename, then it is a ":" delimited list of
65 * console devices upon which root logins are allowed.
69 cons = strcpy (buf, cons);
70 while ((s = strtok (cons, ":")) != NULL) {
71 if (strcmp (s, tty) == 0)
80 * If we can't open the console list, then call everything a
81 * console - otherwise root will never be allowed to login.
84 if ((fp = fopen (cons, "r")) == NULL)
88 * See if this tty is listed in the console file.
91 while (fgets (buf, sizeof (buf), fp) != NULL) {
92 buf[strlen (buf) - 1] = '\0';
93 if (strcmp (buf, tty) == 0) {
100 * This tty isn't a console.
108 * console - return 1 if the "tty" is a console device, else 0.
110 * Note - we need to take extreme care here to avoid locking out root logins
111 * if something goes awry. That's why we do things like call everything a
112 * console if the consoles file can't be opened. Because of this, we must
113 * warn the user to protect against the remove of the consoles file since
114 * that would allow an unauthorized root login.
117 int console (const char *tty)
119 return is_listed ("CONSOLE", tty, 1);