diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-12 12:31:02 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-12 12:31:02 +0000 |
commit | 74cd3ed86d968ecf247f749dcd48ec5a408c9d74 (patch) | |
tree | cf080409fa9b904793fb19d397e7f0d9fb17a936 | |
parent | 5ce9987c2025ffb8eb0b57fed05744f9d94e9111 (diff) | |
download | busybox-w32-74cd3ed86d968ecf247f749dcd48ec5a408c9d74.tar.gz busybox-w32-74cd3ed86d968ecf247f749dcd48ec5a408c9d74.tar.bz2 busybox-w32-74cd3ed86d968ecf247f749dcd48ec5a408c9d74.zip |
login: remove setpgrp call (makes it work from shell prompt again).
login: sanitize stdio descriptors (we are suid, need to be careful!)
shrink login and set_environment by ~100 bytes.
git-svn-id: svn://busybox.net/trunk/busybox@18416 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | include/platform.h | 6 | ||||
-rw-r--r-- | libbb/info_msg.c | 4 | ||||
-rw-r--r-- | libbb/setup_environment.c | 15 | ||||
-rw-r--r-- | loginutils/login.c | 45 |
4 files changed, 32 insertions, 38 deletions
diff --git a/include/platform.h b/include/platform.h index d7389f1aa..4ed5fe624 100644 --- a/include/platform.h +++ b/include/platform.h | |||
@@ -259,8 +259,8 @@ static ATTRIBUTE_ALWAYS_INLINE char* strchrnul(const char *s, char c) { | |||
259 | #define HAVE_INTTYPES_H | 259 | #define HAVE_INTTYPES_H |
260 | #define PRIu32 "u" | 260 | #define PRIu32 "u" |
261 | 261 | ||
262 | /* use legacy setpgrp(pidt_,pid_t) for now. move to platform.c */ | 262 | /* use legacy setpgrp(pid_t,pid_t) for now. move to platform.c */ |
263 | #define bb_setpgrp do { pid_t __me = getpid(); setpgrp(__me,__me); } while (0) | 263 | #define bb_setpgrp() do { pid_t __me = getpid(); setpgrp(__me,__me); } while (0) |
264 | 264 | ||
265 | #if !defined ADJ_OFFSET_SINGLESHOT && defined MOD_CLKA && defined MOD_OFFSET | 265 | #if !defined ADJ_OFFSET_SINGLESHOT && defined MOD_CLKA && defined MOD_OFFSET |
266 | #define ADJ_OFFSET_SINGLESHOT (MOD_CLKA | MOD_OFFSET) | 266 | #define ADJ_OFFSET_SINGLESHOT (MOD_CLKA | MOD_OFFSET) |
@@ -276,7 +276,7 @@ static ATTRIBUTE_ALWAYS_INLINE char* strchrnul(const char *s, char c) { | |||
276 | #endif | 276 | #endif |
277 | 277 | ||
278 | #else | 278 | #else |
279 | #define bb_setpgrp setpgrp() | 279 | #define bb_setpgrp() setpgrp() |
280 | #endif | 280 | #endif |
281 | 281 | ||
282 | #if defined(__linux__) | 282 | #if defined(__linux__) |
diff --git a/libbb/info_msg.c b/libbb/info_msg.c index 78d5c8f32..c763ce60c 100644 --- a/libbb/info_msg.c +++ b/libbb/info_msg.c | |||
@@ -7,10 +7,6 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdio.h> | ||
11 | #include <errno.h> | ||
12 | #include <string.h> | ||
13 | #include <stdlib.h> | ||
14 | #include "libbb.h" | 10 | #include "libbb.h" |
15 | 11 | ||
16 | void bb_info_msg(const char *s, ...) | 12 | void bb_info_msg(const char *s, ...) |
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 874a58efa..18d5a0610 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
@@ -28,19 +28,12 @@ | |||
28 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <stdio.h> | ||
32 | #include <errno.h> | ||
33 | #include <unistd.h> | ||
34 | #include <string.h> | ||
35 | #include <stdlib.h> | ||
36 | #include <syslog.h> | ||
37 | #include <ctype.h> | ||
38 | #include "libbb.h" | 31 | #include "libbb.h" |
39 | 32 | ||
40 | 33 | /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, | |
41 | 34 | * but I want to save a few bytes here */ | |
42 | #define DEFAULT_LOGIN_PATH "/bin:/usr/bin" | 35 | static const char DEFAULT_ROOT_LOGIN_PATH[] = "/sbin:/usr/sbin:/bin:/usr/bin"; |
43 | #define DEFAULT_ROOT_LOGIN_PATH "/usr/sbin:/bin:/usr/bin:/sbin" | 36 | #define DEFAULT_LOGIN_PATH (DEFAULT_ROOT_LOGIN_PATH + sizeof("/sbin:/usr/sbin")) |
44 | 37 | ||
45 | void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw) | 38 | void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw) |
46 | { | 39 | { |
diff --git a/loginutils/login.c b/loginutils/login.c index 3d8b8e540..6a829986e 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -181,14 +181,13 @@ prompt: | |||
181 | 181 | ||
182 | static void motd(void) | 182 | static void motd(void) |
183 | { | 183 | { |
184 | FILE *fp; | 184 | int fd; |
185 | int c; | ||
186 | 185 | ||
187 | fp = fopen(bb_path_motd_file, "r"); | 186 | fd = open(bb_path_motd_file, O_RDONLY); |
188 | if (fp) { | 187 | if (fd) { |
189 | while ((c = getc(fp)) != EOF) | 188 | fflush(stdout); |
190 | putchar(c); | 189 | bb_copyfd_eof(fd, STDOUT_FILENO); |
191 | fclose(fp); | 190 | close(fd); |
192 | } | 191 | } |
193 | } | 192 | } |
194 | 193 | ||
@@ -199,7 +198,7 @@ static void alarm_handler(int sig ATTRIBUTE_UNUSED) | |||
199 | * We don't want to block here */ | 198 | * We don't want to block here */ |
200 | ndelay_on(1); | 199 | ndelay_on(1); |
201 | ndelay_on(2); | 200 | ndelay_on(2); |
202 | bb_info_msg("\r\nLogin timed out after %d seconds\r", TIMEOUT); | 201 | printf("\r\nLogin timed out after %d seconds\r\n", TIMEOUT); |
203 | exit(EXIT_SUCCESS); | 202 | exit(EXIT_SUCCESS); |
204 | } | 203 | } |
205 | 204 | ||
@@ -230,6 +229,12 @@ int login_main(int argc, char **argv) | |||
230 | signal(SIGALRM, alarm_handler); | 229 | signal(SIGALRM, alarm_handler); |
231 | alarm(TIMEOUT); | 230 | alarm(TIMEOUT); |
232 | 231 | ||
232 | /* Mandatory paranoia for suid applet: | ||
233 | * ensure that fd# 0,1,2 are opened (at least to /dev/null) | ||
234 | * and any extra open fd's are closed. | ||
235 | * (The name of the function is misleading. Not daemonizing here.) */ | ||
236 | bb_daemonize_or_rexec(DAEMON_ONLY_SANITIZE | DAEMON_CLOSE_EXTRA_FDS, NULL); | ||
237 | |||
233 | opt = getopt32(argc, argv, "f:h:p", &opt_user, &opt_host); | 238 | opt = getopt32(argc, argv, "f:h:p", &opt_user, &opt_host); |
234 | if (opt & LOGIN_OPT_f) { | 239 | if (opt & LOGIN_OPT_f) { |
235 | if (!amroot) | 240 | if (!amroot) |
@@ -261,7 +266,8 @@ int login_main(int argc, char **argv) | |||
261 | } else | 266 | } else |
262 | snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s'", short_tty); | 267 | snprintf(fromhost, sizeof(fromhost)-1, " on '%.100s'", short_tty); |
263 | 268 | ||
264 | bb_setpgrp; | 269 | // Was breaking "login <username>" from shell command line: |
270 | // bb_setpgrp(); | ||
265 | 271 | ||
266 | openlog(applet_name, LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH); | 272 | openlog(applet_name, LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH); |
267 | 273 | ||
@@ -292,7 +298,7 @@ int login_main(int argc, char **argv) | |||
292 | if (correct_password(pw)) | 298 | if (correct_password(pw)) |
293 | break; | 299 | break; |
294 | 300 | ||
295 | auth_failed: | 301 | auth_failed: |
296 | opt &= ~LOGIN_OPT_f; | 302 | opt &= ~LOGIN_OPT_f; |
297 | bb_do_delay(FAIL_DELAY); | 303 | bb_do_delay(FAIL_DELAY); |
298 | puts("Login incorrect"); | 304 | puts("Login incorrect"); |
@@ -343,17 +349,13 @@ auth_failed: | |||
343 | t_argv[0] = getenv("LOGIN_PRE_SUID_SCRIPT"); | 349 | t_argv[0] = getenv("LOGIN_PRE_SUID_SCRIPT"); |
344 | if (t_argv[0]) { | 350 | if (t_argv[0]) { |
345 | t_argv[1] = NULL; | 351 | t_argv[1] = NULL; |
346 | setenv("LOGIN_TTY", full_tty, 1); | 352 | xsetenv("LOGIN_TTY", full_tty); |
347 | setenv("LOGIN_USER", pw->pw_name, 1); | 353 | xsetenv("LOGIN_USER", pw->pw_name); |
348 | setenv("LOGIN_UID", utoa(pw->pw_uid), 1); | 354 | xsetenv("LOGIN_UID", utoa(pw->pw_uid)); |
349 | setenv("LOGIN_GID", utoa(pw->pw_gid), 1); | 355 | xsetenv("LOGIN_GID", utoa(pw->pw_gid)); |
350 | setenv("LOGIN_SHELL", pw->pw_shell, 1); | 356 | xsetenv("LOGIN_SHELL", pw->pw_shell); |
351 | xspawn(argv); /* NOMMU-friendly */ | 357 | xspawn(argv); /* NOMMU-friendly */ |
352 | unsetenv("LOGIN_TTY"); | 358 | /* All variables are unset by setup_environment */ |
353 | unsetenv("LOGIN_USER"); | ||
354 | unsetenv("LOGIN_UID"); | ||
355 | unsetenv("LOGIN_GID"); | ||
356 | unsetenv("LOGIN_SHELL"); | ||
357 | wait(NULL); | 359 | wait(NULL); |
358 | } | 360 | } |
359 | } | 361 | } |
@@ -379,6 +381,9 @@ auth_failed: | |||
379 | // setsid(); | 381 | // setsid(); |
380 | // /* TIOCSCTTY: steal tty from other process group */ | 382 | // /* TIOCSCTTY: steal tty from other process group */ |
381 | // if (ioctl(0, TIOCSCTTY, 1)) error_msg... | 383 | // if (ioctl(0, TIOCSCTTY, 1)) error_msg... |
384 | // BBox login used to do this (see above): | ||
385 | // bb_setpgrp(); | ||
386 | // If this stuff is really needed, add it and explain why! | ||
382 | 387 | ||
383 | /* set signals to defaults */ | 388 | /* set signals to defaults */ |
384 | signal(SIGALRM, SIG_DFL); | 389 | signal(SIGALRM, SIG_DFL); |