2 * Copyright (c) 1996 by
3 * Sean Eric Fagan <sef@kithrup.com>
4 * David Nugent <davidn@blaze.net.au>
7 * Portions copyright (c) 1995,1997 by
8 * Berkeley Software Design, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, is permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice immediately at the beginning of the file, without modification,
16 * this list of conditions, and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. This work was done expressly for inclusion into FreeBSD. Other use
21 * is permitted provided this notation is included.
22 * 4. Absolutely no warranty of function or purpose is made by the authors.
23 * 5. Modifications may be freely made to this file providing the above
26 * Low-level routines relating to the user capabilities database
28 * $FreeBSD: head/lib/libutil/login_auth.c 255007 2013-08-28 21:10:37Z jilles $
31 #include <sys/types.h>
34 #include <login_cap.h>
43 * Checks for the existance of a nologin file in the login_cap
44 * capability <lc>. If there isn't one specified, then it checks
45 * to see if this class should just ignore nologin files. Lastly,
46 * it tries to print out the default nologin file, and, if such
51 auth_checknologin(login_cap_t
*lc
)
55 /* Do we ignore a nologin file? */
56 if (login_getcapbool(lc
, "ignorenologin", 0))
59 /* Note that <file> will be "" if there is no nologin capability */
60 if ((file
= login_getcapstr(lc
, "nologin", "", NULL
)) == NULL
)
64 * *file is true IFF there was a "nologin" capability
65 * Note that auth_cat() returns 1 only if the specified
66 * file exists, and is readable. E.g., /.nologin exists.
68 if ((*file
&& auth_cat(file
)) || auth_cat(_PATH_NOLOGIN
))
75 * Checks for the readability of <file>; if it can be opened for
76 * reading, it prints it out to stdout, and then exits. Otherwise,
77 * it returns 0 (meaning no nologin file).
81 auth_cat(const char *file
)
86 if ((fd
= open(file
, O_RDONLY
| O_CLOEXEC
)) < 0)
88 while ((count
= read(fd
, buf
, sizeof(buf
))) > 0)
89 (void)write(fileno(stdout
), buf
, count
);
91 sleep(5); /* wait an arbitrary time to drain */