Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/libbb/login.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 815 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 10  Line 10 
10   */   */
11    
12  #include <sys/param.h>  /* MAXHOSTNAMELEN */  #include <sys/param.h>  /* MAXHOSTNAMELEN */
 #include <stdio.h>  
 #include <unistd.h>  
 #include "libbb.h"  
   
13  #include <sys/utsname.h>  #include <sys/utsname.h>
14  #include <time.h>  #include "libbb.h"
15    
16  #define LOGIN " login: "  #define LOGIN " login: "
17    
18  static const char fmtstr_d[] = "%A, %d %B %Y";  static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
19  static const char fmtstr_t[] = "%H:%M:%S";  static const char fmtstr_t[] ALIGN1 = "%H:%M:%S";
20    
21  void print_login_issue(const char *issue_file, const char *tty)  void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
22  {  {
23   FILE *fd;   FILE *fp;
24   int c;   int c;
25   char buf[256+1];   char buf[256+1];
26   const char *outbuf;   const char *outbuf;
# Line 36  void print_login_issue(const char *issue Line 32  void print_login_issue(const char *issue
32    
33   puts("\r"); /* start a new line */   puts("\r"); /* start a new line */
34    
35   fd = fopen(issue_file, "r");   fp = fopen_for_read(issue_file);
36   if (!fd)   if (!fp)
37   return;   return;
38   while ((c = fgetc(fd)) != EOF) {   while ((c = fgetc(fp)) != EOF) {
39   outbuf = buf;   outbuf = buf;
40   buf[0] = c;   buf[0] = c;
41   buf[1] = '\0';   buf[1] = '\0';
42   if(c == '\n') {   if (c == '\n') {
43   buf[1] = '\r';   buf[1] = '\r';
44   buf[2] = '\0';   buf[2] = '\0';
45   }   }
46   if (c == '\\' || c == '%') {   if (c == '\\' || c == '%') {
47   c = fgetc(fd);   c = fgetc(fp);
48   switch (c) {   switch (c) {
49   case 's':   case 's':
50   outbuf = uts.sysname;   outbuf = uts.sysname;
51   break;   break;
52   case 'n':   case 'n':
53     case 'h':
54   outbuf = uts.nodename;   outbuf = uts.nodename;
55   break;   break;
56   case 'r':   case 'r':
# Line 67  void print_login_issue(const char *issue Line 64  void print_login_issue(const char *issue
64   break;   break;
65   case 'D':   case 'D':
66   case 'o':   case 'o':
67   c = getdomainname(buf, sizeof(buf) - 1);   outbuf = uts.domainname;
  buf[c >= 0 ? c : 0] = '\0';  
68   break;   break;
69   case 'd':   case 'd':
70   strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));   strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
# Line 76  void print_login_issue(const char *issue Line 72  void print_login_issue(const char *issue
72   case 't':   case 't':
73   strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));   strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
74   break;   break;
  case 'h':  
  gethostname(buf, sizeof(buf) - 1);  
  buf[sizeof(buf) - 1] = '\0';  
  break;  
75   case 'l':   case 'l':
76   outbuf = tty;   outbuf = tty;
77   break;   break;
# Line 89  void print_login_issue(const char *issue Line 81  void print_login_issue(const char *issue
81   }   }
82   fputs(outbuf, stdout);   fputs(outbuf, stdout);
83   }   }
84   fclose(fd);   fclose(fp);
85   fflush(stdout);   fflush(stdout);
86  }  }
87    
88  void print_login_prompt(void)  void FAST_FUNC print_login_prompt(void)
89  {  {
90   char buf[MAXHOSTNAMELEN+1];   char *hostname = safe_gethostname();
   
  if (gethostname(buf, MAXHOSTNAMELEN) == 0)  
  fputs(buf, stdout);  
91    
92     fputs(hostname, stdout);
93   fputs(LOGIN, stdout);   fputs(LOGIN, stdout);
94   fflush(stdout);   fflush(stdout);
95     free(hostname);
96    }
97    
98    /* Clear dangerous stuff, set PATH */
99    static const char forbid[] ALIGN1 =
100     "ENV" "\0"
101     "BASH_ENV" "\0"
102     "HOME" "\0"
103     "IFS" "\0"
104     "SHELL" "\0"
105     "LD_LIBRARY_PATH" "\0"
106     "LD_PRELOAD" "\0"
107     "LD_TRACE_LOADED_OBJECTS" "\0"
108     "LD_BIND_NOW" "\0"
109     "LD_AOUT_LIBRARY_PATH" "\0"
110     "LD_AOUT_PRELOAD" "\0"
111     "LD_NOWARN" "\0"
112     "LD_KEEPDIR" "\0";
113    
114    int FAST_FUNC sanitize_env_if_suid(void)
115    {
116     const char *p;
117    
118     if (getuid() == geteuid())
119     return 0;
120    
121     p = forbid;
122     do {
123     unsetenv(p);
124     p += strlen(p) + 1;
125     } while (*p);
126     putenv((char*)bb_PATH_root_path);
127    
128     return 1; /* we indeed were run by different user! */
129  }  }

Legend:
Removed from v.815  
changed lines
  Added in v.816