2 * Copyright (c) 1989 - 1994, Julianne Frances Haugh
3 * Copyright (c) 1996 - 2001, Marek Michałkiewicz
4 * Copyright (c) 2003 - 2005, Tomasz Kłoczko
5 * Copyright (c) 2007 - 2009, Nicolas François
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the copyright holders or contributors may not be used to
17 * endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/types.h>
42 #include "prototypes.h"
48 * chown_tty() sets the login tty to be owned by the new user ID
52 void chown_tty (const struct passwd *info)
58 * See if login.defs has some value configured for the port group
59 * ID. Otherwise, use the user's primary group ID.
62 grent = getgr_nam_gid (getdef_str ("TTYGROUP"));
70 * Change the permissions on the TTY to be owned by the user with
71 * the group as determined above.
74 if ( (fchown (STDIN_FILENO, info->pw_uid, gid) != 0)
75 || (fchmod (STDIN_FILENO, getdef_num ("TTYPERM", 0600)) != 0)) {
79 _("Unable to change owner or mode of tty stdin: %s"),
82 "unable to change owner or mode of tty stdin for user `%s': %s\n",
83 info->pw_name, strerror (err)));
91 * Please don't add code to chown /dev/vcs* to the user logging in -
92 * it's a potential security hole. I wouldn't like the previous user
93 * to hold the file descriptor open and watch my screen. We don't
94 * have the *BSD revoke() system call yet, and vhangup() only works
95 * for tty devices (which vcs* is not). --marekm