2 * Copyright (c) 1991 - 1993, Julianne Frances Haugh
3 * Copyright (c) 1991 - 1993, Chip Rosenthal
4 * Copyright (c) 1996 - 2000, Marek Michałkiewicz
5 * Copyright (c) 2003 - 2005, Tomasz Kłoczko
6 * Copyright (c) 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 <sys/types.h>
42 #include "prototypes.h"
45 * hushed - determine if a user receives login messages
47 * Look in the hushed-logins file (or user's home directory) to see
48 * if the user is to receive the login-time messages.
50 bool hushed (const struct passwd *pw)
58 * Get the name of the file to use. If this option is not
59 * defined, default to a noisy login.
62 hushfile = getdef_str ("HUSHLOGIN_FILE");
63 if (NULL == hushfile) {
68 * If this is not a fully rooted path then see if the
69 * file exists in the user's home directory.
72 if (hushfile[0] != '/') {
73 snprintf (buf, sizeof (buf), "%s/%s", pw->pw_dir, hushfile);
74 return (access (buf, F_OK) == 0);
78 * If this is a fully rooted path then go through the file
79 * and see if this user, or its shell is in there.
82 fp = fopen (hushfile, "r");
86 for (found = false; !found && (fgets (buf, (int) sizeof buf, fp) == buf);) {
87 buf[strlen (buf) - 1] = '\0';
88 found = (strcmp (buf, pw->pw_shell) == 0) ||
89 (strcmp (buf, pw->pw_name) == 0);