]>
Commit | Line | Data |
---|---|---|
88407b93 KZ |
1 | /* |
2 | * Copyright (C) 2013 Karel Zak <kzak@redhat.com> | |
3 | */ | |
4 | ||
5 | #include <stdio.h> | |
bd299782 | 6 | #include <sys/stat.h> |
88407b93 KZ |
7 | #include <sys/types.h> |
8 | #include <fcntl.h> | |
9 | #include <string.h> | |
10 | #include <unistd.h> | |
11 | #include <stdlib.h> | |
12 | #include <getopt.h> | |
13 | ||
14 | #include "c.h" | |
15 | #include "nls.h" | |
16 | #include "pathnames.h" | |
17 | ||
18 | /* | |
19 | * Always return EXIT_FAILURE (1), don't try to be smart! | |
20 | */ | |
21 | ||
86be6a32 | 22 | static void __attribute__((__noreturn__)) usage(void) |
88407b93 | 23 | { |
86be6a32 | 24 | FILE *out = stdout; |
88407b93 | 25 | fputs(USAGE_HEADER, out); |
88407b93 KZ |
26 | fprintf(out, |
27 | _(" %s [options]\n"), program_invocation_short_name); | |
28 | ||
451dbcfa BS |
29 | fputs(USAGE_SEPARATOR, out); |
30 | fputs(_("Politely refuse a login.\n"), out); | |
31 | ||
88407b93 KZ |
32 | fputs(USAGE_OPTIONS, out); |
33 | fputs(USAGE_HELP, out); | |
34 | fputs(USAGE_VERSION, out); | |
35 | ||
36 | fprintf(out, USAGE_MAN_TAIL("nologin(8)")); | |
37 | exit(EXIT_FAILURE); | |
38 | } | |
39 | ||
40 | int main(int argc, char *argv[]) | |
41 | { | |
dd732fa2 | 42 | int c, fd = -1; |
bd299782 | 43 | struct stat st; |
88407b93 | 44 | static const struct option longopts[] = { |
87918040 SK |
45 | { "help", 0, NULL, 'h' }, |
46 | { "version", 0, NULL, 'V' }, | |
47 | { NULL, 0, NULL, 0 } | |
88407b93 KZ |
48 | }; |
49 | ||
50 | setlocale(LC_ALL, ""); | |
51 | bindtextdomain(PACKAGE, LOCALEDIR); | |
52 | textdomain(PACKAGE); | |
53 | ||
54 | while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) { | |
55 | switch (c) { | |
56 | case 'h': | |
86be6a32 | 57 | usage(); |
88407b93 KZ |
58 | break; |
59 | case 'V': | |
60 | printf(UTIL_LINUX_VERSION); | |
61 | return EXIT_FAILURE; | |
62 | default: | |
677ec86c | 63 | errtryhelp(EXIT_FAILURE); |
88407b93 KZ |
64 | } |
65 | } | |
66 | ||
67 | fd = open(_PATH_NOLOGIN_TXT, O_RDONLY); | |
dd732fa2 KZ |
68 | if (fd < 0) |
69 | goto dflt; | |
70 | ||
bd299782 | 71 | c = fstat(fd, &st); |
dd732fa2 KZ |
72 | if (c < 0 || !S_ISREG(st.st_mode)) |
73 | goto dflt; | |
74 | else { | |
88407b93 KZ |
75 | char buf[BUFSIZ]; |
76 | ssize_t rd; | |
77 | ||
78 | while ((rd = read(fd, buf, sizeof(buf))) > 0) | |
79 | ignore_result( write(STDOUT_FILENO, buf, rd) ); | |
dd732fa2 | 80 | |
88407b93 | 81 | close(fd); |
dd732fa2 KZ |
82 | return EXIT_FAILURE; |
83 | } | |
88407b93 | 84 | |
dd732fa2 KZ |
85 | dflt: |
86 | if (fd >= 0) | |
87 | close(fd); | |
88 | fprintf(stdout, _("This account is currently not available.\n")); | |
88407b93 KZ |
89 | return EXIT_FAILURE; |
90 | } |