sulogin: add long options

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-03-12 12:23:29 +01:00
parent cd8703ade9
commit 8614335f6b
2 changed files with 40 additions and 20 deletions

View File

@ -39,18 +39,24 @@ optional tty device that can be specified on the command line
After the user exits the single-user shell or presses control\-D at the
prompt, the system will continue to boot.
.SH OPTIONS
.IP "\fB\-t \fIseconds\fP"
Specify the maximum amount of time to wait for user input. By default,
sulogin will wait forever.
.IP "\fB\-p\fP"
Specifying this option causes sulogin to start the shell process as a
login shell.
.IP "\fB\-e\fP"
.IP "\fB\-e, \-\-force\fP"
If the default method of obtaining the root password via \fBgetpwnam\fP(3) from
the system fails, manually examine /etc/passwd and /etc/shadow to get the
password. If they are damaged or nonexistent, sulogin will start a root shell
without asking for a password. Only use the \fB\-e\fP option if you are sure
the console is physically protected against unauthorized access.
without asking for a password.
Only use the \fB\-e\fP option if you are sure the console is physically
protected against unauthorized access.
.IP "\fB\-h, \-\-help\fP"
Print a help message.
.IP "\fB\-p, \-\-login\-shell\fP"
Specifying this option causes sulogin to start the shell process as a
login shell.
.IP "\fB\-t, \-\-timeout \fIseconds\fP"
Specify the maximum amount of time to wait for user input. By default,
sulogin will wait forever.
.IP "\fB\-V, \-\-version\fP"
Output version.
.SH ENVIRONMENT VARIABLES
\fIsulogin\fP looks for the environment variable \fBSUSHELL\fP or
\fBsushell\fP to determine what shell to start. If the environment variable

View File

@ -34,6 +34,7 @@
#include <shadow.h>
#include <termios.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
#ifdef HAVE_CRYPT_H
# include <crypt.h>
@ -395,18 +396,20 @@ static void sushell(struct passwd *pwd)
static void usage(FILE *out)
{
fprintf(out, USAGE_HEADER);
fputs(USAGE_HEADER, out);
fprintf(out, _(
" %s [options] [tty device]\n"), program_invocation_short_name);
" %s [options] [tty device]\n"), program_invocation_short_name);
fprintf(out, USAGE_OPTIONS);
fprintf(out, _(
" -p start a login shell\n"
" -t SEC max time to wait for a password (default: no limit)\n"
" -e examine shadow files directly if getpwnam(3) fails\n"
" -h display this help message\n"));
fputs(USAGE_OPTIONS, out);
fputs(_(" -p, --login-shell start a login shell\n"
" -t, --timeout <seconds> max time to wait for a password (default: no limit)\n"
" -e, --force examine password files directly if getpwnam(3) fails\n"),
out);
fprintf(out, _("\nFor more information see sulogin(8).\n"));
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("sulogin(8)"));
}
int main(int argc, char **argv)
@ -419,11 +422,19 @@ int main(int argc, char **argv)
pid_t pid, pgrp, ppgrp, ttypgrp;
struct sigaction saved_sighup;
static const struct option longopts[] = {
{ "login-shell", 0, 0, 'p' },
{ "timeout", 1, 0, 't' },
{ "force", 0, 0, 'e' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
{ NULL, 0, 0, 0 }
};
/*
* See if we have a timeout flag.
*/
opterr = 0;
while ((c = getopt(argc, argv, "ehpt:")) != EOF) {
while ((c = getopt_long(argc, argv, "ehpt:V", longopts, NULL)) != -1) {
switch(c) {
case 't':
timeout = atoi(optarg);
@ -434,6 +445,9 @@ int main(int argc, char **argv)
case 'e':
opt_e = 1;
break;
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case 'h':
usage(stdout);
return EXIT_SUCCESS;