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.
12 /* After libbb.h, since it needs sys/types.h on some systems */
13 #include <sys/utsname.h>
15 #define LOGIN " login: "
17 static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
19 void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
31 puts("\r"); /* start a new line */
33 fp = fopen_for_read(issue_file);
36 while ((c = fgetc(fp)) != EOF) {
44 if (c == '\\' || c == '%') {
47 //From getty manpage (* - supported by us)
48 //========================================
50 // Insert the IPv4 address of the network interface (example: \4{eth0}).
51 // If the interface argument is not specified, then select the first
52 // fully configured (UP, non-LOOPBACK, RUNNING) interface.
53 //6 or 6{interface} -- The same as \4 but for IPv6.
54 //b -- Insert the baudrate of the current line.
55 //*d -- Insert the current date.
56 //*t -- Insert the current time.
58 // Translate the human-readable name to an escape sequence and insert it
59 // (for example: \e{red}Alert text.\e{reset}). If the name argument
60 // is not specified, then insert \033. The currently supported names are:
61 // black, blink, blue, bold, brown, cyan, darkgray, gray, green, halfbright,
62 // lightblue, lightcyan, lightgray, lightgreen, lightmagenta, lightred,
63 // magenta, red, reset, reverse, and yellow. Unknown names are ignored.
65 // Insert the system name (the name of the operating system - `uname -s`)
67 // Insert the VARIABLE data from /etc/os-release.
68 // If the VARIABLE argument is not specified, use PRETTY_NAME.
69 // If PRETTY_NAME is not in /etc/os-release, \S is the same as \s.
70 //*l -- Insert the name of the current tty line.
71 //*m -- Insert the architecture identifier of the machine: `uname -m`.
72 //*n -- Insert the nodename of the machine: `uname -n`.
73 //*o -- Insert the NIS domainname of the machine. Same as `hostname -d'.
74 //*O -- Insert the DNS domainname of the machine.
75 //*r -- Insert the release number of the OS: `uname -r`.
76 //u -- Insert the number of current users logged in.
77 //U -- Insert the string "1 user" or "N users" (current users logged in).
78 //*v -- Insert the version of the OS, e.g. the build-date etc: `uname -v`.
80 //*D -- same as \O "DNS domainname"
81 //*h -- same as \n "nodename"
84 /* minimal implementation, not reading /etc/os-release */
91 outbuf = uts.nodename;
100 outbuf = uts.machine;
102 /* The field domainname of struct utsname is Linux specific. */
103 #if defined(__linux__)
107 outbuf = uts.domainname;
111 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
114 strftime_HHMMSS(buf, sizeof(buf), &t);
123 fputs(outbuf, stdout);
129 void FAST_FUNC print_login_prompt(void)
131 char *hostname = safe_gethostname();
133 fputs(hostname, stdout);
134 fputs(LOGIN, stdout);
139 /* Clear dangerous stuff, set PATH */
140 static const char forbid[] ALIGN1 =
146 "LD_LIBRARY_PATH" "\0"
148 "LD_TRACE_LOADED_OBJECTS" "\0"
150 "LD_AOUT_LIBRARY_PATH" "\0"
151 "LD_AOUT_PRELOAD" "\0"
155 int FAST_FUNC sanitize_env_if_suid(void)
159 if (getuid() == geteuid())
167 putenv((char*)bb_PATH_root_path);
169 return 1; /* we indeed were run by different user! */