diff options
-rw-r--r-- | miscutils/crontab.c | 27 | ||||
-rw-r--r-- | miscutils/wall.c | 6 |
2 files changed, 2 insertions, 31 deletions
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 4731d8da6..aad242fd8 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -55,28 +55,6 @@ static void edit_file(const struct passwd *pas, const char *file) | |||
55 | bb_perror_msg_and_die("can't execute '%s'", ptr); | 55 | bb_perror_msg_and_die("can't execute '%s'", ptr); |
56 | } | 56 | } |
57 | 57 | ||
58 | static int open_as_user(const struct passwd *pas, const char *file) | ||
59 | { | ||
60 | pid_t pid; | ||
61 | char c; | ||
62 | |||
63 | pid = xvfork(); | ||
64 | if (pid) { /* PARENT */ | ||
65 | if (wait4pid(pid) == 0) { | ||
66 | /* exitcode 0: child says it can read */ | ||
67 | return open(file, O_RDONLY); | ||
68 | } | ||
69 | return -1; | ||
70 | } | ||
71 | |||
72 | /* CHILD */ | ||
73 | /* initgroups, setgid, setuid */ | ||
74 | change_identity(pas); | ||
75 | /* We just try to read one byte. If it works, file is readable | ||
76 | * under this user. We signal that by exiting with 0. */ | ||
77 | _exit(safe_read(xopen(file, O_RDONLY), &c, 1) < 0); | ||
78 | } | ||
79 | |||
80 | int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 58 | int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
81 | int crontab_main(int argc UNUSED_PARAM, char **argv) | 59 | int crontab_main(int argc UNUSED_PARAM, char **argv) |
82 | { | 60 | { |
@@ -137,10 +115,7 @@ int crontab_main(int argc UNUSED_PARAM, char **argv) | |||
137 | if (!argv[0]) | 115 | if (!argv[0]) |
138 | bb_show_usage(); | 116 | bb_show_usage(); |
139 | if (NOT_LONE_DASH(argv[0])) { | 117 | if (NOT_LONE_DASH(argv[0])) { |
140 | src_fd = open_as_user(pas, argv[0]); | 118 | src_fd = xopen_as_uid_gid(argv[0], O_RDONLY, pas->pw_uid, pas->pw_gid); |
141 | if (src_fd < 0) | ||
142 | bb_error_msg_and_die("user %s cannot read %s", | ||
143 | pas->pw_name, argv[0]); | ||
144 | } | 119 | } |
145 | } | 120 | } |
146 | 121 | ||
diff --git a/miscutils/wall.c b/miscutils/wall.c index c74f4f27b..bb709ee39 100644 --- a/miscutils/wall.c +++ b/miscutils/wall.c | |||
@@ -41,11 +41,7 @@ int wall_main(int argc UNUSED_PARAM, char **argv) | |||
41 | /* The applet is setuid. | 41 | /* The applet is setuid. |
42 | * Access to the file must be under user's uid/gid. | 42 | * Access to the file must be under user's uid/gid. |
43 | */ | 43 | */ |
44 | setfsuid(getuid()); | 44 | fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid()); |
45 | setfsgid(getgid()); | ||
46 | fd = xopen(argv[1], O_RDONLY); | ||
47 | setfsuid(geteuid()); | ||
48 | setfsgid(getegid()); | ||
49 | } | 45 | } |
50 | msg = xmalloc_read(fd, NULL); | 46 | msg = xmalloc_read(fd, NULL); |
51 | if (ENABLE_FEATURE_CLEAN_UP && argv[1]) | 47 | if (ENABLE_FEATURE_CLEAN_UP && argv[1]) |