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"
|
2020-11-06 04:43:18 -06:00
|
|
|
#include "fileutils.h"
|
2013-09-30 06:36:26 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2019-11-17 02:33:04 -06:00
|
|
|
enum {
|
|
|
|
OPT_INIT_FILE = CHAR_MAX + 1,
|
|
|
|
OPT_NOPROFILE,
|
|
|
|
OPT_NORC,
|
|
|
|
OPT_POSIX,
|
|
|
|
OPT_RCFILE
|
|
|
|
};
|
2013-09-30 06:36:26 -05:00
|
|
|
static const struct option longopts[] = {
|
2019-11-17 02:33:04 -06:00
|
|
|
{ "command", required_argument, NULL, 'c' },
|
|
|
|
{ "init-file", required_argument, NULL, OPT_INIT_FILE },
|
|
|
|
{ "interactive", no_argument, NULL, 'i' },
|
|
|
|
{ "login", no_argument, NULL, 'l' },
|
|
|
|
{ "noprofile", no_argument, NULL, OPT_NOPROFILE },
|
|
|
|
{ "norc", no_argument, NULL, OPT_NORC },
|
|
|
|
{ "posix", no_argument, NULL, OPT_POSIX },
|
|
|
|
{ "rcfile", required_argument, NULL, OPT_RCFILE },
|
|
|
|
{ "restricted", no_argument, NULL, 'r' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2017-02-11 14:23:26 -06:00
|
|
|
{ NULL, 0, NULL, 0 }
|
2013-09-30 06:36:26 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
|
2019-11-17 02:33:04 -06:00
|
|
|
while ((c = getopt_long(argc, argv, "c:ilrhV", longopts, NULL)) != -1) {
|
2013-09-30 06:36:26 -05:00
|
|
|
switch (c) {
|
2019-10-09 18:08:25 -05:00
|
|
|
case 'c':
|
2019-11-17 02:33:04 -06:00
|
|
|
case OPT_INIT_FILE:
|
|
|
|
case 'i':
|
|
|
|
case 'l':
|
|
|
|
case OPT_NOPROFILE:
|
|
|
|
case OPT_NORC:
|
|
|
|
case OPT_POSIX:
|
|
|
|
case OPT_RCFILE:
|
|
|
|
case 'r':
|
|
|
|
/* Ignore well known shell command-line options */
|
2019-10-09 18:08:25 -05:00
|
|
|
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 {
|
2020-11-06 04:43:18 -06:00
|
|
|
ul_copy_file(fd, STDOUT_FILENO);
|
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;
|
|
|
|
}
|