diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-16 13:47:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-16 13:47:57 +0000 |
commit | 7fc294cdfe1e7f4a12c44f984a698b0c0f609075 (patch) | |
tree | 95fa6ff18d8894af201b3f341962c97956330252 | |
parent | 3718832a1542f7bf786a1678741b8566ad3a35c6 (diff) | |
download | busybox-w32-7fc294cdfe1e7f4a12c44f984a698b0c0f609075.tar.gz busybox-w32-7fc294cdfe1e7f4a12c44f984a698b0c0f609075.tar.bz2 busybox-w32-7fc294cdfe1e7f4a12c44f984a698b0c0f609075.zip |
crontab: clear env if run by non-root, so that we can use PATH now
crontab: make "-c /tmp/ -e" work
-rw-r--r-- | miscutils/crontab.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index b292535b1..a1fe2c5a5 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -15,9 +15,6 @@ | |||
15 | #ifndef CRONTABS | 15 | #ifndef CRONTABS |
16 | #define CRONTABS "/var/spool/cron/crontabs" | 16 | #define CRONTABS "/var/spool/cron/crontabs" |
17 | #endif | 17 | #endif |
18 | #ifndef TMPDIR | ||
19 | #define TMPDIR "/var/spool/cron" | ||
20 | #endif | ||
21 | #ifndef CRONUPDATE | 18 | #ifndef CRONUPDATE |
22 | #define CRONUPDATE "cron.update" | 19 | #define CRONUPDATE "cron.update" |
23 | #endif | 20 | #endif |
@@ -37,7 +34,7 @@ static void change_user(const struct passwd *pas) | |||
37 | if (chdir(pas->pw_dir) < 0) { | 34 | if (chdir(pas->pw_dir) < 0) { |
38 | bb_perror_msg("chdir(%s) by %s failed", | 35 | bb_perror_msg("chdir(%s) by %s failed", |
39 | pas->pw_dir, pas->pw_name); | 36 | pas->pw_dir, pas->pw_name); |
40 | xchdir(TMPDIR); | 37 | xchdir("/tmp"); |
41 | } | 38 | } |
42 | } | 39 | } |
43 | 40 | ||
@@ -62,9 +59,7 @@ static void edit_file(const struct passwd *pas, const char *file) | |||
62 | ptr = PATH_VI; | 59 | ptr = PATH_VI; |
63 | } | 60 | } |
64 | 61 | ||
65 | /* TODO: clean up the environment!!! */ | 62 | BB_EXECLP(ptr, ptr, file, NULL); |
66 | /* not execlp - we won't use PATH */ | ||
67 | execl(ptr, ptr, file, NULL); | ||
68 | bb_perror_msg_and_die("exec %s", ptr); | 63 | bb_perror_msg_and_die("exec %s", ptr); |
69 | } | 64 | } |
70 | 65 | ||
@@ -136,9 +131,12 @@ int crontab_main(int argc, char **argv) | |||
136 | opt_ler = getopt32(argv, "u:c:lerd", &user_name, &crontab_dir); | 131 | opt_ler = getopt32(argv, "u:c:lerd", &user_name, &crontab_dir); |
137 | argv += optind; | 132 | argv += optind; |
138 | 133 | ||
139 | if (opt_ler & (OPT_u|OPT_c)) | 134 | if (my_uid != geteuid()) { /* run by non-root? */ |
140 | if (my_uid != geteuid()) | 135 | if (opt_ler & (OPT_u|OPT_c)) |
141 | bb_error_msg_and_die("only root can use -c or -u"); | 136 | bb_error_msg_and_die("only root can use -c or -u"); |
137 | /* Clear dangerous stuff, set PATH */ | ||
138 | sanitize_env_for_suid(); | ||
139 | } | ||
142 | 140 | ||
143 | if (opt_ler & OPT_u) { | 141 | if (opt_ler & OPT_u) { |
144 | pas = getpwnam(user_name); | 142 | pas = getpwnam(user_name); |
@@ -194,7 +192,7 @@ int crontab_main(int argc, char **argv) | |||
194 | } | 192 | } |
195 | 193 | ||
196 | case OPT_e: /* Edit */ | 194 | case OPT_e: /* Edit */ |
197 | tmp_fname = xasprintf(TMPDIR "/crontab.%u", (unsigned)getpid()); | 195 | tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid()); |
198 | fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); | 196 | fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); |
199 | xmove_fd(fd, STDIN_FILENO); | 197 | xmove_fd(fd, STDIN_FILENO); |
200 | fd = open(pas->pw_name, O_RDONLY); | 198 | fd = open(pas->pw_name, O_RDONLY); |