1 /* vi: set sw=4 ts=4: */
3 * issue.c: issue printing code
5 * Copyright (C) 2003 Bastian Blank <waldi@tuxbox.org>
7 * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru>
9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
13 /* After libbb.h, since it needs sys/types.h on some systems */
14 #include <sys/utsname.h>
16 #define LOGIN " login: "
18 static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
20 void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
32 puts("\r"); /* start a new line */
34 fp = fopen_for_read(issue_file);
37 while ((c = fgetc(fp)) != EOF) {
45 if (c == '\\' || c == '%') {
48 //From getty manpage (* - supported by us)
49 //========================================
51 // Insert the IPv4 address of the network interface (example: \4{eth0}).
52 // If the interface argument is not specified, then select the first
53 // fully configured (UP, non-LOOPBACK, RUNNING) interface.
54 //6 or 6{interface} -- The same as \4 but for IPv6.
55 //b -- Insert the baudrate of the current line.
56 //*d -- Insert the current date.
57 //*t -- Insert the current time.
59 // Translate the human-readable name to an escape sequence and insert it
60 // (for example: \e{red}Alert text.\e{reset}). If the name argument
61 // is not specified, then insert \033. The currently supported names are:
62 // black, blink, blue, bold, brown, cyan, darkgray, gray, green, halfbright,
63 // lightblue, lightcyan, lightgray, lightgreen, lightmagenta, lightred,
64 // magenta, red, reset, reverse, and yellow. Unknown names are ignored.
66 // Insert the system name (the name of the operating system - `uname -s`)
68 // Insert the VARIABLE data from /etc/os-release.
69 // If the VARIABLE argument is not specified, use PRETTY_NAME.
70 // If PRETTY_NAME is not in /etc/os-release, \S is the same as \s.
71 //*l -- Insert the name of the current tty line.
72 //*m -- Insert the architecture identifier of the machine: `uname -m`.
73 //*n -- Insert the nodename of the machine: `uname -n`.
74 //*o -- Insert the NIS domainname of the machine. Same as `hostname -d'.
75 //*O -- Insert the DNS domainname of the machine.
76 //*r -- Insert the release number of the OS: `uname -r`.
77 //u -- Insert the number of current users logged in.
78 //U -- Insert the string "1 user" or "N users" (current users logged in).
79 //*v -- Insert the version of the OS, e.g. the build-date etc: `uname -v`.
81 //*D -- same as \O "DNS domainname"
82 //*h -- same as \n "nodename"
85 /* minimal implementation, not reading /etc/os-release */
92 outbuf = uts.nodename;
101 outbuf = uts.machine;
103 /* The field domainname of struct utsname is Linux specific. */
104 #if defined(__linux__)
108 outbuf = uts.domainname;
112 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
115 strftime_HHMMSS(buf, sizeof(buf), &t);
124 fputs(outbuf, stdout);
130 void FAST_FUNC print_login_prompt(void)
132 char *hostname = safe_gethostname();
134 fputs(hostname, stdout);
135 fputs(LOGIN, stdout);
140 /* Clear dangerous stuff, set PATH */
141 static const char forbid[] ALIGN1 =
147 "LD_LIBRARY_PATH" "\0"
149 "LD_TRACE_LOADED_OBJECTS" "\0"
151 "LD_AOUT_LIBRARY_PATH" "\0"
152 "LD_AOUT_PRELOAD" "\0"
156 int FAST_FUNC sanitize_env_if_suid(void)
160 if (getuid() == geteuid())
168 putenv((char*)bb_PATH_root_path);
170 return 1; /* we indeed were run by different user! */