Allow the system adminstrator to provide options to the login program. Soem changes for several layouts of the agetty prompt like short host name or full qualified host name. Signed-off-by: Werner Fink <werner@xxxxxxx> --- term-utils/agetty.8 | 94 ++++++++++++++++++++++++++++++--------------------- term-utils/agetty.c | 65 +++++++++++++++++++++++++++++++---- 2 files changed, 112 insertions(+), 47 deletions(-) diff --git a/term-utils/agetty.8 b/term-utils/agetty.8 index ddd8196..8b29ad0 100644 --- a/term-utils/agetty.8 +++ b/term-utils/agetty.8 @@ -4,12 +4,12 @@ agetty \- alternative Linux getty .SH SYNOPSIS .BR "agetty " [\-8chiLmnsUw] -.RI "[-a " user ] -.RI "[-f " issue_file ] -.RI "[-H " login_host ] -.RI "[-I " init ] -.RI "[-l " login_program ] -.RI "[-t " timeout ] +.RI "[\-a " user ] +.RI "[\-f " issue_file ] +.RI "[\-H " login_host ] +.RI "[\-I " init ] +.RI "[\-l " login_program ] +.RI "[\-t " timeout ] .I port .I baud_rate,... .RI [ term ] @@ -58,13 +58,13 @@ This program does not use the \fI/etc/gettydefs\fP (System V) or .ad .TP port -A path name relative to the \fI/dev\fP directory. If a "-" is +A path name relative to the \fI/dev\fP directory. If a "\-" is specified, \fBagetty\fP assumes that its standard input is already connected to a tty port and that a connection to a remote user has already been established. .sp -Under System V, a "-" \fIport\fP argument should be preceded -by a "--". +Under System V, a "\-" \fIport\fP argument should be preceded +by a "\-\-". .TP baud_rate,... A comma-separated list of one or more baud rates. Each time @@ -72,7 +72,7 @@ A comma-separated list of one or more baud rates. Each time the list, which is treated as if it were circular. .sp Baud rates should be specified in descending order, so that the -null character (Ctrl-@) can also be used for baud rate switching. +null character (Ctrl\-@) can also be used for baud rate switching. .TP term The value to be used for the TERM environment variable. This overrides @@ -88,7 +88,7 @@ Assume that the tty is 8-bit clean, hence disable parity detection. .TP \-a, \-\-autologin \fIusername\fP Log the specified user automatically in without asking for a login -name and password. Check the -f option from +name and password. Check the \-f option from \fB/bin/login\fP for this. .TP \-\-loginpause @@ -99,12 +99,12 @@ with \fB\-\-autologin\fP to save memory by lazily spawning shells. Don't reset terminal cflags (control modes). See \fItermios(3)\fP for more details. .TP -\-f, \-\-issue-file \fIissue_file\fP +\-f, \-\-issue\-file \fIissue_file\fP Display the contents of \fIissue_file\fP instead of \fI/etc/issue\fP. This allows custom messages to be displayed on different terminals. The \-i option will override this option. .TP -\-h, \-\-flow-control +\-h, \-\-flow\-control Enable hardware (RTS/CTS) flow control. It is left up to the application to disable software (XON/XOFF) flow protocol where appropriate. @@ -121,7 +121,7 @@ login prompt. Terminals or communications hardware may become confused when receiving lots of text at the wrong baud rate; dial-up scripts may fail if the login prompt is preceded by too much text. .TP -\-I, \-\-init-string \fIinitstring\fP +\-I, \-\-init\-string \fIinitstring\fP Set an initial string to be sent to the tty or modem before sending anything else. This may be used to initialize a modem. Non printable characters may be sent by writing their octal code preceded by a @@ -129,24 +129,18 @@ backslash (\\). For example to send a linefeed character (ASCII 10, octal 012) write \\012. .PP .TP -\-l, \-\-login-program \fIlogin_program\fP +\-l, \-\-login\-program \fIlogin_program\fP Invoke the specified \fIlogin_program\fP instead of /bin/login. This allows the use of a non-standard login program (for example, one that asks for a dial-up password or that uses a different password file). .TP -\-\-logopts \fI"login_options"\fP -Options that are passed to the login program. \\u is replaced -by the login name. Defaults to "-- \\u", which is suitable for -\fB/bin/login\fP. Please read the SECURITY NOTICE below if -you want to use this. -.TP -\-L, \-\-local-line +\-L, \-\-local\-line Force the line to be a local line with no need for carrier detect. This can be useful when you have a locally attached terminal where the serial line does not set the carrier detect signal. .TP -\-m, \-\-extract-baud +\-m, \-\-extract\-baud Try to extract the baud rate the CONNECT status message produced by Hayes(tm)\-compatible modems. These status messages are of the form: "<junk><speed><junk>". @@ -158,7 +152,7 @@ Since the \fI\-m\fP feature may fail on heavily-loaded systems, you still should enable BREAK processing by enumerating all expected baud rates on the command line. .TP -\-n, \-\-skip-login +\-n, \-\-skip\-login Do not prompt the user for a login name. This can be used in connection with \-l option to invoke a non-standard login process such as a BBS system. Note that with the \-n option, \fBagetty\fR gets no input from @@ -168,7 +162,13 @@ space parity, 7 bit characters, and ASCII CR (13) end-of-line character. Beware that the program that \fBagetty\fR starts (usually /bin/login) is run as root. .TP -\-s, \-\-keep-baud +\-o, \-\-login\-options \fI"login_options"\fP +Options that are passed to the login program. \\u is replaced +by the login name. Defaults to "\-\- \\u", which is suitable for +\fB/bin/login\fP. Please read the SECURITY NOTICE below if +you want to use this. +.TP +\-s, \-\-keep\-baud Try to keep the existing baud rate. The baud rates from the command line are used when agetty receives a BREAK character. .TP @@ -177,13 +177,13 @@ Terminate if no user name could be read within \fItimeout\fP seconds. This option should probably not be used with hard-wired lines. .TP -\-U, \-\-detect-case +\-U, \-\-detect\-case Turn on support for detecting an uppercase only terminal. This setting will detect a login name containing only capitals as indicating an uppercase only terminal and turn on some upper to lower case conversions. Note that this has no support for any unicode characters. .TP -\-w, \-\-wait-cr +\-w, \-\-wait\-cr Wait for the user or the modem to send a carriage-return or a linefeed character before sending the \fI/etc/issue\fP (or other) file and the login prompt. Very useful in connection with the \-I option. @@ -191,6 +191,22 @@ and the login prompt. Very useful in connection with the \-I option. \-\-nohangup Do not call vhangup() for a virtually hangup of the specified terminal. .TP +\-\-noclear +Do not clear the screen before prompting for the login name +(the screen is normally cleared). +.TP +\-\-nonewline +Do not print a newline before writing out /etc/issue. +.TP +\-\-no\-hostname +By default the hostname will be printed. With this option enabled, +no hostname at all will be shown. +.TP +\-\-long\-hostname +By default the hostname is only printed until the first dot. With +this option enabled, the full qualified hostname by gethostname() +or if not found by gethostbyname() is shown. +.TP \-\-version Output version information and exit. .TP @@ -227,14 +243,14 @@ dis-connection and turn on auto-answer after 1 ring.) If you use the \fB\-\-login\fP and \fB\-\-logopts\fP options, be aware that a malicious user may try to enter lognames with embedded options, which then get passed to the used login program. Agetty does check -for a leading - and makes sure the logname gets passed as one parameter +for a leading "\-" and makes sure the logname gets passed as one parameter (so embedded spaces will not create yet another parameter), but depending on how the login binary parses the command line that might not be sufficient. Check that the used login program can not be abused this way. .PP -Some programs use -- to indicate that the rest of the commandline should -not be interpreted as options. Use this feature if available by passing -- before -the username gets passed by \\u. +Some programs use "\-\-" to indicate that the rest of the commandline should +not be interpreted as options. Use this feature if available by passing "\-\-" +before the username gets passed by \\u. .SH ISSUE ESCAPES The issue-file (\fI/etc/issue\fP or the file set with the \-f option) @@ -250,25 +266,25 @@ d Insert the current date. .TP s -Insert the system name, the name of the operating system. Same as `uname -s'. +Insert the system name, the name of the operating system. Same as `uname \-s'. .TP l Insert the name of the current tty line. .TP m -Insert the architecture identifier of the machine. Same as `uname -m'. +Insert the architecture identifier of the machine. Same as `uname \-m'. .TP n -Insert the nodename of the machine, also known as the hostname. Same as `uname -n'. +Insert the nodename of the machine, also known as the hostname. Same as `uname \-n'. .TP o -Insert the NIS domainname of the machine. Same as `hostname -d'. +Insert the NIS domainname of the machine. Same as `hostname \-d'. .TP O Insert the DNS domainname of the machine. .TP r -Insert the release number of the OS. Same as `uname -r'. +Insert the release number of the OS. Same as `uname \-r'. .TP t Insert the current time. @@ -307,7 +323,7 @@ This is thingol.orcan.dk (Linux i386 1.1.9) 18:29:30 .SH BUGS .ad .fi -The baud-rate detection feature (the \fI-m\fP option) requires that +The baud-rate detection feature (the \fI\-m\fP option) requires that \fBagetty\fP be scheduled soon enough after completion of a dial-in call (within 30 ms with modems that talk at 2400 baud). For robustness, always use the \fI\-m\fP option in combination with a multiple baud @@ -316,7 +332,7 @@ rate command-line argument, so that BREAK processing is enabled. The text in the \fI/etc/issue\fP file (or other) and the login prompt are always output with 7-bit characters and space parity. -The baud-rate detection feature (the \fI-m\fP option) requires that +The baud-rate detection feature (the \fI\-m\fP option) requires that the modem emits its status message \fIafter\fP raising the DCD line. .SH DIAGNOSTICS .ad @@ -342,4 +358,4 @@ Added \-f option to display custom login messages on different terminals. .SH AVAILABILITY The agetty command is part of the util-linux package and is available from -ftp://ftp.kernel.org/pub/linux/utils/util-linux/. +ftp://ftp.kernel.org/pub/linux/utils/util\-linux/. diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 4c76d96..00bfda2 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -94,7 +94,7 @@ #endif /* Login prompt. */ -#define LOGIN " login: " +#define LOGIN "login: " #define ARRAY_SIZE_MAX 16 /* Some shorthands for control characters. */ @@ -161,6 +161,10 @@ struct options { #define F_NOHANGUP (1<<13) /* No not call vhangup(2) */ #define F_UTF8 (1<<14) /* We can do UTF8 */ #define F_LOGINPAUSE (1<<15) /* Wait for any key before dropping login prompt */ +#define F_NOCLEAR (1<<16) /* Do not clear the screen before prompting */ +#define F_NONL (1<<17) /* No newline before issue */ +#define F_NOHOSTNAME (1<<18) /* Do not show the hostname */ +#define F_LONGHNAME (1<<19) /* Show Full qualified hostname */ /* Storage for things detected while the login name was read. */ struct chardata { @@ -421,6 +425,12 @@ static void parse_args(int argc, char **argv, struct options *op) const struct option longopts[] = { { "nohangup", no_argument, &nipple, F_NOHANGUP }, { "loginpause", no_argument, &nipple, F_LOGINPAUSE }, + { "noclear", no_argument, &nipple, F_NOCLEAR }, + { "nonewline", no_argument, &nipple, F_NONL }, + { "nohangup", no_argument, &nipple, F_NOHANGUP }, + { "no-hostname", no_argument, &nipple, F_NOHOSTNAME }, + { "nohostname", no_argument, &nipple, F_NOHOSTNAME }, /* compat option */ + { "long-hostname", no_argument, &nipple, F_LONGHNAME }, { "8bits", no_argument, 0, '8' }, { "autologin", required_argument, 0, 'a' }, { "noreset", no_argument, 0, 'c' }, @@ -430,9 +440,14 @@ static void parse_args(int argc, char **argv, struct options *op) { "noissue", no_argument, 0, 'i' }, { "init-string", required_argument, 0, 'I' }, { "login-program", required_argument, 0, 'l' }, + { "login", required_argument, 0, 'l' }, /* compat option */ + { "loginprog", required_argument, 0, 'l' }, /* compat option */ { "local-line", no_argument, 0, 'L' }, { "extract-baud", no_argument, 0, 'm' }, { "skip-login", no_argument, 0, 'n' }, + { "login-options", required_argument, 0, 'o' }, + { "loginopts", required_argument, 0, 'o' }, /* compat option */ + { "logopts", required_argument, 0, 'o' }, /* compat option */ { "keep-baud", no_argument, 0, 's' }, { "timeout", required_argument, 0, 't' }, { "detect-case", no_argument, 0, 'U' }, @@ -442,7 +457,7 @@ static void parse_args(int argc, char **argv, struct options *op) { NULL, 0, 0, 0 } }; - while ((c = getopt_long(argc, argv, "8a:cf:hH:iI:l:Lmnst:Uw", longopts, + while ((c = getopt_long(argc, argv, "8a:cf:hH:iI:l:Lmno:st:Uw", longopts, &index)) != -1) { switch (c) { case 0: @@ -486,6 +501,9 @@ static void parse_args(int argc, char **argv, struct options *op) case 'n': op->flags |= F_NOPROMPT; break; + case 'o': + op->logopt = optarg; + break; case 's': op->flags |= F_KEEPSPEED; break; @@ -855,6 +873,18 @@ static void termio_init(struct options *op, struct termios *tp) #endif reset_vc(op); op->flags |= F_EIGHTBITS; + if ((op->flags & F_NOCLEAR) == 0) { + /* + * Do not write a full reset (ESC c) because this destroys + * the unicode mode again if the terminal was in unicode + * mode. Also it clears the CONSOLE_MAGIC features which + * are required for some languages/console-fonts. + * Just put the cursor to the home position (ESC [ H), + * erase everything below the cursor (ESC [ J), and set the + * scrolling region to the full window (ESC [ r) + */ + safe_write(0, "\033[r\033[H\033[J", 9); + } return; } @@ -1065,8 +1095,9 @@ static void do_prompt(struct options *op, struct termios *tp) FILE *fd; #endif /* ISSUE */ - /* Issue not in use, start with a new line. */ - safe_write(STDOUT_FILENO, "\r\n", 2); + if ((op->flags & F_NONL) == 0) + /* Issue not in use, start with a new line. */ + safe_write(STDOUT_FILENO, "\r\n", 2); #ifdef ISSUE if ((op->flags & F_ISSUE) && (fd = fopen(op->issue, "r"))) { @@ -1140,10 +1171,23 @@ static void do_prompt(struct options *op, struct termios *tp) } } #endif - { + if ((op->flags & F_NOHOSTNAME) == 0) { char hn[MAXHOSTNAMELEN + 1]; - if (gethostname(hn, sizeof(hn)) == 0) - safe_write(STDIN_FILENO, hn, strlen(hn)); + if (gethostname(hn, sizeof(hn)) == 0) { + struct hostent *ht; + char *dot = strchr(hn, '.'); + + hn[MAXHOSTNAMELEN] = '\0'; + if ((op->flags & F_LONGHNAME) == 0) { + if (dot) + *dot = '\0'; + safe_write(STDIN_FILENO, hn, strlen(hn)); + } else if (dot == NULL && (ht = gethostbyname(hn))) + safe_write(STDIN_FILENO, ht->h_name, strlen(ht->h_name)); + else + safe_write(STDIN_FILENO, hn, strlen(hn)); + safe_write(STDIN_FILENO, " ", 1); + } } if (op->autolog == (char*)0) @@ -1436,6 +1480,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) fprintf(out, _("\nOptions:\n" " -8, --8bits assume 8-bit tty\n" " -a, --autologin USER login the specified user automatically\n" + " --loginpause Wait for any key before the login\n" " -c, --noreset do not reset control mode\n" " -f, --issue-file FILE display issue file\n" " -h, --flow-control enable hardware flow control\n" @@ -1446,12 +1491,16 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) " -L, --local-line force local line\n" " -m, --extract-baud extract baud rate during connect\n" " -n, --skip-login do not prompt for login\n" + " -o, --login-options OPTS options that are passed to login\n" " -s, --keep-baud try to keep baud rate after break\n" " -t, --timeout NUMBER login process timeout\n" " -U, --detect-case detect uppercase terminal\n" " -w, --wait-cr wait carriage-return\n" " --nohangup do not call vhangup() at start\n" - " --nohangup do not call vhangup() at start\n" + " --noclear do not clear the screen before prompt\n" + " --nonewline do not print a newline before issue\n" + " --no-hostname no hostname at all will be shown\n" + " --long-hostname show full qualified hostname\n" " --version output version information and exit\n" " --help display this help and exit\n\n")); -- 1.6.0.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html