]> git.ipfire.org Git - thirdparty/util-linux.git/blob - login-utils/nologin.c
Merge branch 'master' of https://github.com/yurchor/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
25 fprintf(out,
26 _(" %s [options]\n"), program_invocation_short_name);
27
28 fputs(USAGE_OPTIONS, out);
29 fputs(USAGE_HELP, out);
30 fputs(USAGE_VERSION, out);
31
32 fprintf(out, USAGE_MAN_TAIL("nologin(8)"));
33 exit(EXIT_FAILURE);
34 }
35
36 int main(int argc, char *argv[])
37 {
38 int c, fd;
39 static const struct option longopts[] = {
40 { "help", 0, 0, 'h' },
41 { "version", 0, 0, 'V' },
42 { NULL, 0, 0, 0 }
43 };
44
45 setlocale(LC_ALL, "");
46 bindtextdomain(PACKAGE, LOCALEDIR);
47 textdomain(PACKAGE);
48
49 while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) {
50 switch (c) {
51 case 'h':
52 usage(stdout);
53 break;
54 case 'V':
55 printf(UTIL_LINUX_VERSION);
56 return EXIT_FAILURE;
57 default:
58 usage(stderr);
59 break;
60 }
61 }
62
63 fd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
64 if (fd >= 0) {
65 char buf[BUFSIZ];
66 ssize_t rd;
67
68 while ((rd = read(fd, buf, sizeof(buf))) > 0)
69 ignore_result( write(STDOUT_FILENO, buf, rd) );
70 close(fd);
71 } else
72 fprintf(stdout, _("This account is currently not available.\n"));
73
74 return EXIT_FAILURE;
75 }