aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-24 17:04:07 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-24 17:04:07 +0000
commitc0415a983349dbd341c535991d948c2bead1ba0a (patch)
treeec52328a03d2907e3369ff5e2fff49bf9c0080a1
parent8a503be840f2632c96af918ad2ba553b9de49dd9 (diff)
downloadbusybox-w32-c0415a983349dbd341c535991d948c2bead1ba0a.tar.gz
busybox-w32-c0415a983349dbd341c535991d948c2bead1ba0a.tar.bz2
busybox-w32-c0415a983349dbd341c535991d948c2bead1ba0a.zip
login: nuke nonblock() - we have it in libbb; -400 bytes bss.
-rw-r--r--loginutils/login.c62
1 files changed, 28 insertions, 34 deletions
diff --git a/loginutils/login.c b/loginutils/login.c
index 830df0a7f..b7428de45 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -8,7 +8,7 @@
8#include <sys/resource.h> 8#include <sys/resource.h>
9#include <syslog.h> 9#include <syslog.h>
10 10
11#ifdef CONFIG_SELINUX 11#if ENABLE_SELINUX
12#include <selinux/selinux.h> /* for is_selinux_enabled() */ 12#include <selinux/selinux.h> /* for is_selinux_enabled() */
13#include <selinux/get_context_list.h> /* for get_default_context() */ 13#include <selinux/get_context_list.h> /* for get_default_context() */
14#include <selinux/flask.h> /* for security class definitions */ 14#include <selinux/flask.h> /* for security class definitions */
@@ -22,8 +22,7 @@ enum {
22 TTYNAME_SIZE = 32, 22 TTYNAME_SIZE = 32,
23}; 23};
24 24
25static char full_tty[TTYNAME_SIZE]; 25static char* short_tty;
26static char* short_tty = full_tty;
27 26
28#if ENABLE_FEATURE_UTMP 27#if ENABLE_FEATURE_UTMP
29/* vv Taken from tinylogin utmp.c vv */ 28/* vv Taken from tinylogin utmp.c vv */
@@ -41,9 +40,7 @@ static char* short_tty = full_tty;
41 * command line flags. 40 * command line flags.
42 */ 41 */
43 42
44static struct utmp utent; 43static void read_or_build_utent(struct utmp *utptr, int picky)
45
46static void read_or_build_utent(int picky)
47{ 44{
48 struct utmp *ut; 45 struct utmp *ut;
49 pid_t pid = getpid(); 46 pid_t pid = getpid();
@@ -58,23 +55,23 @@ static void read_or_build_utent(int picky)
58 55
59 /* If there is one, just use it, otherwise create a new one. */ 56 /* If there is one, just use it, otherwise create a new one. */
60 if (ut) { 57 if (ut) {
61 utent = *ut; 58 *utptr = *ut;
62 } else { 59 } else {
63 if (picky) 60 if (picky)
64 bb_error_msg_and_die("no utmp entry found"); 61 bb_error_msg_and_die("no utmp entry found");
65 62
66 memset(&utent, 0, sizeof(utent)); 63 memset(utptr, 0, sizeof(*utptr));
67 utent.ut_type = LOGIN_PROCESS; 64 utptr->ut_type = LOGIN_PROCESS;
68 utent.ut_pid = pid; 65 utptr->ut_pid = pid;
69 strncpy(utent.ut_line, short_tty, sizeof(utent.ut_line)); 66 strncpy(utptr->ut_line, short_tty, sizeof(utptr->ut_line));
70 /* This one is only 4 chars wide. Try to fit something 67 /* This one is only 4 chars wide. Try to fit something
71 * remotely meaningful by skipping "tty"... */ 68 * remotely meaningful by skipping "tty"... */
72 strncpy(utent.ut_id, short_tty + 3, sizeof(utent.ut_id)); 69 strncpy(utptr->ut_id, short_tty + 3, sizeof(utptr->ut_id));
73 strncpy(utent.ut_user, "LOGIN", sizeof(utent.ut_user)); 70 strncpy(utptr->ut_user, "LOGIN", sizeof(utptr->ut_user));
74 utent.ut_time = time(NULL); 71 utptr->ut_time = time(NULL);
75 } 72 }
76 if (!picky) /* root login */ 73 if (!picky) /* root login */
77 memset(utent.ut_host, 0, sizeof(utent.ut_host)); 74 memset(utptr->ut_host, 0, sizeof(utptr->ut_host));
78} 75}
79 76
80/* 77/*
@@ -83,25 +80,25 @@ static void read_or_build_utent(int picky)
83 * write_utent changes the type of the current utmp entry to 80 * write_utent changes the type of the current utmp entry to
84 * USER_PROCESS. the wtmp file will be updated as well. 81 * USER_PROCESS. the wtmp file will be updated as well.
85 */ 82 */
86static void write_utent(const char *username) 83static void write_utent(struct utmp *utptr, const char *username)
87{ 84{
88 utent.ut_type = USER_PROCESS; 85 utptr->ut_type = USER_PROCESS;
89 strncpy(utent.ut_user, username, sizeof(utent.ut_user)); 86 strncpy(utptr->ut_user, username, sizeof(utptr->ut_user));
90 utent.ut_time = time(NULL); 87 utptr->ut_time = time(NULL);
91 /* other fields already filled in by read_or_build_utent above */ 88 /* other fields already filled in by read_or_build_utent above */
92 setutent(); 89 setutent();
93 pututline(&utent); 90 pututline(utptr);
94 endutent(); 91 endutent();
95#if ENABLE_FEATURE_WTMP 92#if ENABLE_FEATURE_WTMP
96 if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) { 93 if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {
97 close(creat(bb_path_wtmp_file, 0664)); 94 close(creat(bb_path_wtmp_file, 0664));
98 } 95 }
99 updwtmp(bb_path_wtmp_file, &utent); 96 updwtmp(bb_path_wtmp_file, utptr);
100#endif 97#endif
101} 98}
102#else /* !ENABLE_FEATURE_UTMP */ 99#else /* !ENABLE_FEATURE_UTMP */
103static inline void read_or_build_utent(int ATTRIBUTE_UNUSED picky) {} 100#define read_or_build_utent(utptr, picky) ((void)0)
104static inline void write_utent(const char ATTRIBUTE_UNUSED *username) {} 101#define write_utent(utptr, username) ((void)0)
105#endif /* !ENABLE_FEATURE_UTMP */ 102#endif /* !ENABLE_FEATURE_UTMP */
106 103
107static void die_if_nologin_and_non_root(int amroot) 104static void die_if_nologin_and_non_root(int amroot)
@@ -195,18 +192,13 @@ static void motd(void)
195 } 192 }
196} 193}
197 194
198static void nonblock(int fd)
199{
200 fcntl(fd, F_SETFL, O_NONBLOCK | fcntl(fd, F_GETFL));
201}
202
203static void alarm_handler(int sig ATTRIBUTE_UNUSED) 195static void alarm_handler(int sig ATTRIBUTE_UNUSED)
204{ 196{
205 /* This is the escape hatch! Poor serial line users and the like 197 /* This is the escape hatch! Poor serial line users and the like
206 * arrive here when their connection is broken. 198 * arrive here when their connection is broken.
207 * We don't want to block here */ 199 * We don't want to block here */
208 nonblock(1); 200 ndelay_on(1);
209 nonblock(2); 201 ndelay_on(2);
210 bb_info_msg("\r\nLogin timed out after %d seconds\r", TIMEOUT); 202 bb_info_msg("\r\nLogin timed out after %d seconds\r", TIMEOUT);
211 exit(EXIT_SUCCESS); 203 exit(EXIT_SUCCESS);
212} 204}
@@ -228,8 +220,11 @@ int login_main(int argc, char **argv)
228 struct passwd *pw; 220 struct passwd *pw;
229 char *opt_host = NULL; 221 char *opt_host = NULL;
230 char *opt_user = NULL; 222 char *opt_user = NULL;
223 char full_tty[TTYNAME_SIZE];
231 USE_SELINUX(security_context_t user_sid = NULL;) 224 USE_SELINUX(security_context_t user_sid = NULL;)
225 USE_FEATURE_UTMP(struct utmp utent;)
232 226
227 short_tty = full_tty;
233 username[0] = '\0'; 228 username[0] = '\0';
234 amroot = (getuid() == 0); 229 amroot = (getuid() == 0);
235 signal(SIGALRM, alarm_handler); 230 signal(SIGALRM, alarm_handler);
@@ -255,7 +250,7 @@ int login_main(int argc, char **argv)
255 short_tty = full_tty + 5; 250 short_tty = full_tty + 5;
256 } 251 }
257 252
258 read_or_build_utent(!amroot); 253 read_or_build_utent(&utent, !amroot);
259 254
260 if (opt_host) { 255 if (opt_host) {
261 USE_FEATURE_UTMP( 256 USE_FEATURE_UTMP(
@@ -263,8 +258,7 @@ int login_main(int argc, char **argv)
263 ) 258 )
264 snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s' from " 259 snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s' from "
265 "'%.200s'", short_tty, opt_host); 260 "'%.200s'", short_tty, opt_host);
266 } 261 } else
267 else
268 snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s'", short_tty); 262 snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s'", short_tty);
269 263
270 bb_setpgrp; 264 bb_setpgrp;
@@ -313,7 +307,7 @@ auth_failed:
313 alarm(0); 307 alarm(0);
314 die_if_nologin_and_non_root(pw->pw_uid == 0); 308 die_if_nologin_and_non_root(pw->pw_uid == 0);
315 309
316 write_utent(username); 310 write_utent(&utent, username);
317 311
318#ifdef CONFIG_SELINUX 312#ifdef CONFIG_SELINUX
319 if (is_selinux_enabled()) { 313 if (is_selinux_enabled()) {