source: MondoRescue/branches/2.2.9/mindi-busybox/libbb/login.c@ 2729

Last change on this file since 2729 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 2.4 KB
RevLine 
[1765]1/* vi: set sw=4 ts=4: */
[821]2/*
3 * issue.c: issue printing code
4 *
5 * Copyright (C) 2003 Bastian Blank <waldi@tuxbox.org>
6 *
[1765]7 * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru>
[821]8 *
[2725]9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]10 */
11
[2725]12#include "libbb.h"
13/* After libbb.h, since it needs sys/types.h on some systems */
[1765]14#include <sys/utsname.h>
[821]15
16#define LOGIN " login: "
17
[1765]18static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
19static const char fmtstr_t[] ALIGN1 = "%H:%M:%S";
[821]20
[2725]21void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
[821]22{
[2725]23 FILE *fp;
[821]24 int c;
25 char buf[256+1];
26 const char *outbuf;
27 time_t t;
28 struct utsname uts;
29
30 time(&t);
31 uname(&uts);
32
[2725]33 puts("\r"); /* start a new line */
[821]34
[2725]35 fp = fopen_for_read(issue_file);
36 if (!fp)
[1765]37 return;
[2725]38 while ((c = fgetc(fp)) != EOF) {
[1765]39 outbuf = buf;
40 buf[0] = c;
41 buf[1] = '\0';
42 if (c == '\n') {
43 buf[1] = '\r';
44 buf[2] = '\0';
45 }
46 if (c == '\\' || c == '%') {
[2725]47 c = fgetc(fp);
[1765]48 switch (c) {
49 case 's':
50 outbuf = uts.sysname;
51 break;
52 case 'n':
[2725]53 case 'h':
[1765]54 outbuf = uts.nodename;
55 break;
56 case 'r':
57 outbuf = uts.release;
58 break;
59 case 'v':
60 outbuf = uts.version;
61 break;
62 case 'm':
63 outbuf = uts.machine;
64 break;
[2725]65/* The field domainname of struct utsname is Linux specific. */
66#if defined(__linux__)
[1765]67 case 'D':
68 case 'o':
[2725]69 outbuf = uts.domainname;
[1765]70 break;
[2725]71#endif
[1765]72 case 'd':
73 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
74 break;
75 case 't':
76 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
77 break;
78 case 'l':
79 outbuf = tty;
80 break;
81 default:
82 buf[0] = c;
[821]83 }
84 }
[1765]85 fputs(outbuf, stdout);
[821]86 }
[2725]87 fclose(fp);
88 fflush_all();
[821]89}
90
[2725]91void FAST_FUNC print_login_prompt(void)
[821]92{
[2725]93 char *hostname = safe_gethostname();
[821]94
[2725]95 fputs(hostname, stdout);
[821]96 fputs(LOGIN, stdout);
[2725]97 fflush_all();
98 free(hostname);
[821]99}
[2725]100
101/* Clear dangerous stuff, set PATH */
102static const char forbid[] ALIGN1 =
103 "ENV" "\0"
104 "BASH_ENV" "\0"
105 "HOME" "\0"
106 "IFS" "\0"
107 "SHELL" "\0"
108 "LD_LIBRARY_PATH" "\0"
109 "LD_PRELOAD" "\0"
110 "LD_TRACE_LOADED_OBJECTS" "\0"
111 "LD_BIND_NOW" "\0"
112 "LD_AOUT_LIBRARY_PATH" "\0"
113 "LD_AOUT_PRELOAD" "\0"
114 "LD_NOWARN" "\0"
115 "LD_KEEPDIR" "\0";
116
117int FAST_FUNC sanitize_env_if_suid(void)
118{
119 const char *p;
120
121 if (getuid() == geteuid())
122 return 0;
123
124 p = forbid;
125 do {
126 unsetenv(p);
127 p += strlen(p) + 1;
128 } while (*p);
129 putenv((char*)bb_PATH_root_path);
130
131 return 1; /* we indeed were run by different user! */
132}
Note: See TracBrowser for help on using the repository browser.