mirror of
https://github.com/sheumann/hush.git
synced 2025-02-28 20:31:33 +00:00
crontab: clear env if run by non-root, so that we can use PATH now
crontab: make "-c /tmp/ -e" work
This commit is contained in:
parent
3718832a15
commit
7fc294cdfe
@ -15,9 +15,6 @@
|
|||||||
#ifndef CRONTABS
|
#ifndef CRONTABS
|
||||||
#define CRONTABS "/var/spool/cron/crontabs"
|
#define CRONTABS "/var/spool/cron/crontabs"
|
||||||
#endif
|
#endif
|
||||||
#ifndef TMPDIR
|
|
||||||
#define TMPDIR "/var/spool/cron"
|
|
||||||
#endif
|
|
||||||
#ifndef CRONUPDATE
|
#ifndef CRONUPDATE
|
||||||
#define CRONUPDATE "cron.update"
|
#define CRONUPDATE "cron.update"
|
||||||
#endif
|
#endif
|
||||||
@ -37,7 +34,7 @@ static void change_user(const struct passwd *pas)
|
|||||||
if (chdir(pas->pw_dir) < 0) {
|
if (chdir(pas->pw_dir) < 0) {
|
||||||
bb_perror_msg("chdir(%s) by %s failed",
|
bb_perror_msg("chdir(%s) by %s failed",
|
||||||
pas->pw_dir, pas->pw_name);
|
pas->pw_dir, pas->pw_name);
|
||||||
xchdir(TMPDIR);
|
xchdir("/tmp");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,9 +59,7 @@ static void edit_file(const struct passwd *pas, const char *file)
|
|||||||
ptr = PATH_VI;
|
ptr = PATH_VI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: clean up the environment!!! */
|
BB_EXECLP(ptr, ptr, file, NULL);
|
||||||
/* not execlp - we won't use PATH */
|
|
||||||
execl(ptr, ptr, file, NULL);
|
|
||||||
bb_perror_msg_and_die("exec %s", ptr);
|
bb_perror_msg_and_die("exec %s", ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,9 +131,12 @@ int crontab_main(int argc, char **argv)
|
|||||||
opt_ler = getopt32(argv, "u:c:lerd", &user_name, &crontab_dir);
|
opt_ler = getopt32(argv, "u:c:lerd", &user_name, &crontab_dir);
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
if (opt_ler & (OPT_u|OPT_c))
|
if (my_uid != geteuid()) { /* run by non-root? */
|
||||||
if (my_uid != geteuid())
|
if (opt_ler & (OPT_u|OPT_c))
|
||||||
bb_error_msg_and_die("only root can use -c or -u");
|
bb_error_msg_and_die("only root can use -c or -u");
|
||||||
|
/* Clear dangerous stuff, set PATH */
|
||||||
|
sanitize_env_for_suid();
|
||||||
|
}
|
||||||
|
|
||||||
if (opt_ler & OPT_u) {
|
if (opt_ler & OPT_u) {
|
||||||
pas = getpwnam(user_name);
|
pas = getpwnam(user_name);
|
||||||
@ -194,7 +192,7 @@ int crontab_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case OPT_e: /* Edit */
|
case OPT_e: /* Edit */
|
||||||
tmp_fname = xasprintf(TMPDIR "/crontab.%u", (unsigned)getpid());
|
tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid());
|
||||||
fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
|
fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
|
||||||
xmove_fd(fd, STDIN_FILENO);
|
xmove_fd(fd, STDIN_FILENO);
|
||||||
fd = open(pas->pw_name, O_RDONLY);
|
fd = open(pas->pw_name, O_RDONLY);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user