Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/login.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/login.c
r1765 r2725 7 7 * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru> 8 8 * 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.9 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 10 */ 11 11 12 #include <sys/param.h> /* MAXHOSTNAMELEN */ 12 #include "libbb.h" 13 /* After libbb.h, since it needs sys/types.h on some systems */ 13 14 #include <sys/utsname.h> 14 #include "libbb.h"15 15 16 16 #define LOGIN " login: " … … 19 19 static const char fmtstr_t[] ALIGN1 = "%H:%M:%S"; 20 20 21 void print_login_issue(const char *issue_file, const char *tty)21 void FAST_FUNC print_login_issue(const char *issue_file, const char *tty) 22 22 { 23 FILE *f d;23 FILE *fp; 24 24 int c; 25 25 char buf[256+1]; … … 31 31 uname(&uts); 32 32 33 puts("\r"); 33 puts("\r"); /* start a new line */ 34 34 35 f d = fopen(issue_file, "r");36 if (!f d)35 fp = fopen_for_read(issue_file); 36 if (!fp) 37 37 return; 38 while ((c = fgetc(f d)) != EOF) {38 while ((c = fgetc(fp)) != EOF) { 39 39 outbuf = buf; 40 40 buf[0] = c; … … 45 45 } 46 46 if (c == '\\' || c == '%') { 47 c = fgetc(f d);47 c = fgetc(fp); 48 48 switch (c) { 49 49 case 's': … … 51 51 break; 52 52 case 'n': 53 case 'h': 53 54 outbuf = uts.nodename; 54 55 break; … … 62 63 outbuf = uts.machine; 63 64 break; 65 /* The field domainname of struct utsname is Linux specific. */ 66 #if defined(__linux__) 64 67 case 'D': 65 68 case 'o': 66 c = getdomainname(buf, sizeof(buf) - 1); 67 buf[c >= 0 ? c : 0] = '\0'; 69 outbuf = uts.domainname; 68 70 break; 71 #endif 69 72 case 'd': 70 73 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); … … 72 75 case 't': 73 76 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); 74 break;75 case 'h':76 gethostname(buf, sizeof(buf) - 1);77 buf[sizeof(buf) - 1] = '\0';78 77 break; 79 78 case 'l': … … 86 85 fputs(outbuf, stdout); 87 86 } 88 fclose(f d);89 fflush (stdout);87 fclose(fp); 88 fflush_all(); 90 89 } 91 90 92 void print_login_prompt(void)91 void FAST_FUNC print_login_prompt(void) 93 92 { 94 char buf[MAXHOSTNAMELEN+1];93 char *hostname = safe_gethostname(); 95 94 96 if (gethostname(buf, MAXHOSTNAMELEN) == 0) 97 fputs(buf, stdout); 95 fputs(hostname, stdout); 96 fputs(LOGIN, stdout); 97 fflush_all(); 98 free(hostname); 99 } 98 100 99 fputs(LOGIN, stdout); 100 fflush(stdout); 101 /* Clear dangerous stuff, set PATH */ 102 static 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 117 int 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! */ 101 132 }
Note:
See TracChangeset
for help on using the changeset viewer.