Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 816 - (hide annotations) (download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2383 byte(s)
-updated to busybox-1.13.4
1 niro 532 /* vi: set sw=4 ts=4: */
2     /*
3     * issue.c: issue printing code
4     *
5     * Copyright (C) 2003 Bastian Blank <waldi@tuxbox.org>
6     *
7     * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru>
8     *
9     * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10     */
11    
12     #include <sys/param.h> /* MAXHOSTNAMELEN */
13 niro 816 #include <sys/utsname.h>
14 niro 532 #include "libbb.h"
15    
16     #define LOGIN " login: "
17    
18 niro 816 static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
19     static const char fmtstr_t[] ALIGN1 = "%H:%M:%S";
20 niro 532
21 niro 816 void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
22 niro 532 {
23 niro 816 FILE *fp;
24 niro 532 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    
33     puts("\r"); /* start a new line */
34    
35 niro 816 fp = fopen_for_read(issue_file);
36     if (!fp)
37 niro 532 return;
38 niro 816 while ((c = fgetc(fp)) != EOF) {
39 niro 532 outbuf = buf;
40     buf[0] = c;
41     buf[1] = '\0';
42 niro 816 if (c == '\n') {
43 niro 532 buf[1] = '\r';
44     buf[2] = '\0';
45     }
46     if (c == '\\' || c == '%') {
47 niro 816 c = fgetc(fp);
48 niro 532 switch (c) {
49     case 's':
50     outbuf = uts.sysname;
51     break;
52     case 'n':
53 niro 816 case 'h':
54 niro 532 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;
65     case 'D':
66     case 'o':
67 niro 816 outbuf = uts.domainname;
68 niro 532 break;
69     case 'd':
70     strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
71     break;
72     case 't':
73     strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
74     break;
75     case 'l':
76     outbuf = tty;
77     break;
78     default:
79     buf[0] = c;
80     }
81     }
82     fputs(outbuf, stdout);
83     }
84 niro 816 fclose(fp);
85 niro 532 fflush(stdout);
86     }
87    
88 niro 816 void FAST_FUNC print_login_prompt(void)
89 niro 532 {
90 niro 816 char *hostname = safe_gethostname();
91 niro 532
92 niro 816 fputs(hostname, stdout);
93 niro 532 fputs(LOGIN, stdout);
94     fflush(stdout);
95 niro 816 free(hostname);
96 niro 532 }
97 niro 816
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     }