2013-09-30 06:36:26 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Karel Zak <kzak@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-10-06 17:15:54 -05:00
|
|
|
#include <sys/stat.h>
|
2013-09-30 06:36:26 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
#include "c.h"
|
|
|
|
#include "nls.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Always return EXIT_FAILURE (1), don't try to be smart!
|
|
|
|
*/
|
|
|
|
|
2017-06-20 13:20:29 -05:00
|
|
|
static void __attribute__((__noreturn__)) usage(void)
|
2013-09-30 06:36:26 -05:00
|
|
|
{
|
2017-06-20 13:20:29 -05:00
|
|
|
FILE *out = stdout;
|
2013-09-30 06:36:26 -05:00
|
|
|
fputs(USAGE_HEADER, out);
|
|
|
|
fprintf(out,
|
|
|
|
_(" %s [options]\n"), program_invocation_short_name);
|
|
|
|
|
2014-12-22 15:57:17 -06:00
|
|
|
fputs(USAGE_SEPARATOR, out);
|
|
|
|
fputs(_("Politely refuse a login.\n"), out);
|
|
|
|
|
2013-09-30 06:36:26 -05:00
|
|
|
fputs(USAGE_OPTIONS, out);
|
2019-10-09 18:08:25 -05:00
|
|
|
fputs(_(" -c, --command <command> does nothing (for compatibility with su -c)\n"), out);
|
|
|
|
printf(USAGE_HELP_OPTIONS(26));
|
2013-09-30 06:36:26 -05:00
|
|
|
|
2017-06-29 08:52:16 -05:00
|
|
|
printf(USAGE_MAN_TAIL("nologin(8)"));
|
2013-09-30 06:36:26 -05:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2017-05-17 05:59:33 -05:00
|
|
|
int c, fd = -1;
|
2015-10-06 17:15:54 -05:00
|
|
|
struct stat st;
|
2013-09-30 06:36:26 -05:00
|
|
|
static const struct option longopts[] = {
|
2019-10-09 18:08:25 -05:00
|
|
|
{ "command", required_argument, NULL, 'c' },
|
2017-02-11 14:23:26 -06:00
|
|
|
{ "help", 0, NULL, 'h' },
|
|
|
|
{ "version", 0, NULL, 'V' },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
2013-09-30 06:36:26 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
|
2019-10-09 18:08:25 -05:00
|
|
|
while ((c = getopt_long(argc, argv, "c:hV", longopts, NULL)) != -1) {
|
2013-09-30 06:36:26 -05:00
|
|
|
switch (c) {
|
2019-10-09 18:08:25 -05:00
|
|
|
case 'c':
|
|
|
|
/* Ignore the command, just don't print unknown option error. */
|
|
|
|
break;
|
2013-09-30 06:36:26 -05:00
|
|
|
case 'h':
|
2017-06-20 13:20:29 -05:00
|
|
|
usage();
|
2013-09-30 06:36:26 -05:00
|
|
|
case 'V':
|
2019-04-16 08:14:13 -05:00
|
|
|
print_version(EXIT_FAILURE); /* yes FAILURE! */
|
2013-09-30 06:36:26 -05:00
|
|
|
default:
|
2016-12-19 06:13:34 -06:00
|
|
|
errtryhelp(EXIT_FAILURE);
|
2013-09-30 06:36:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(_PATH_NOLOGIN_TXT, O_RDONLY);
|
2017-05-17 05:59:33 -05:00
|
|
|
if (fd < 0)
|
|
|
|
goto dflt;
|
|
|
|
|
2015-10-06 17:15:54 -05:00
|
|
|
c = fstat(fd, &st);
|
2017-05-17 05:59:33 -05:00
|
|
|
if (c < 0 || !S_ISREG(st.st_mode))
|
|
|
|
goto dflt;
|
|
|
|
else {
|
2013-09-30 06:36:26 -05:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
ssize_t rd;
|
|
|
|
|
|
|
|
while ((rd = read(fd, buf, sizeof(buf))) > 0)
|
|
|
|
ignore_result( write(STDOUT_FILENO, buf, rd) );
|
2017-05-17 05:59:33 -05:00
|
|
|
|
2013-09-30 06:36:26 -05:00
|
|
|
close(fd);
|
2017-05-17 05:59:33 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2013-09-30 06:36:26 -05:00
|
|
|
|
2017-05-17 05:59:33 -05:00
|
|
|
dflt:
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
fprintf(stdout, _("This account is currently not available.\n"));
|
2013-09-30 06:36:26 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|