]> git.ipfire.org Git - thirdparty/util-linux.git/blob - login-utils/nologin.c
Merge branch 'master' of https://github.com/pali/util-linux
[thirdparty/util-linux.git] / login-utils / nologin.c
1 /*
2 * Copyright (C) 2013 Karel Zak <kzak@redhat.com>
3 */
4
5 #include <stdio.h>
6 #include <sys/types.h>
7 #include <fcntl.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include <getopt.h>
12
13 #include "c.h"
14 #include "nls.h"
15 #include "pathnames.h"
16
17 /*
18 * Always return EXIT_FAILURE (1), don't try to be smart!
19 */
20
21 static void __attribute__((__noreturn__)) usage(FILE *out)
22 {
23 fputs(USAGE_HEADER, out);
24 fprintf(out,
25 _(" %s [options]\n"), program_invocation_short_name);
26
27 fputs(USAGE_SEPARATOR, out);
28 fputs(_("Politely refuse a login.\n"), out);
29
30 fputs(USAGE_OPTIONS, out);
31 fputs(USAGE_HELP, out);
32 fputs(USAGE_VERSION, out);
33
34 fprintf(out, USAGE_MAN_TAIL("nologin(8)"));
35 exit(EXIT_FAILURE);
36 }
37
38 int main(int argc, char *argv[])
39 {
40 int c, fd;
41 static const struct option longopts[] = {
42 { "help", 0, 0, 'h' },
43 { "version", 0, 0, 'V' },
44 { NULL, 0, 0, 0 }
45 };
46
47 setlocale(LC_ALL, "");
48 bindtextdomain(PACKAGE, LOCALEDIR);
49 textdomain(PACKAGE);
50
51 while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) {
52 switch (c) {
53 case 'h':
54 usage(stdout);
55 break;
56 case 'V':
57 printf(UTIL_LINUX_VERSION);
58 return EXIT_FAILURE;
59 default:
60 usage(stderr);
61 break;
62 }
63 }
64
65 fd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
66 if (fd >= 0) {
67 char buf[BUFSIZ];
68 ssize_t rd;
69
70 while ((rd = read(fd, buf, sizeof(buf))) > 0)
71 ignore_result( write(STDOUT_FILENO, buf, rd) );
72 close(fd);
73 } else
74 fprintf(stdout, _("This account is currently not available.\n"));
75
76 return EXIT_FAILURE;
77 }