#include "libbb.h"
-#ifndef CRONTABS
-#define CRONTABS "/var/spool/cron/crontabs"
-#endif
+#define CRONTABS CONFIG_FEATURE_CROND_DIR "/crontabs"
#ifndef CRONUPDATE
#define CRONUPDATE "cron.update"
#endif
-static void change_user(const struct passwd *pas)
-{
- xsetenv("USER", pas->pw_name);
- xsetenv("HOME", pas->pw_dir);
- xsetenv("SHELL", DEFAULT_SHELL);
-
- /* initgroups, setgid, setuid */
- change_identity(pas);
-
- if (chdir(pas->pw_dir) < 0) {
- bb_perror_msg("chdir(%s) by %s failed",
- pas->pw_dir, pas->pw_name);
- xchdir("/tmp");
- }
-}
-
static void edit_file(const struct passwd *pas, const char *file)
{
const char *ptr;
}
/* CHILD - change user and run editor */
- change_user(pas);
+ /* initgroups, setgid, setuid */
+ change_identity(pas);
+ setup_environment(DEFAULT_SHELL,
+ SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP,
+ pas);
ptr = getenv("VISUAL");
if (!ptr) {
ptr = getenv("EDITOR");
argv += optind;
if (sanitize_env_if_suid()) { /* Clears dangerous stuff, sets PATH */
- /* run by non-root? */
+ /* Run by non-root */
if (opt_ler & (OPT_u|OPT_c))
- bb_error_msg_and_die("only root can use -c or -u");
+ bb_error_msg_and_die(bb_msg_you_must_be_root);
}
if (opt_ler & OPT_u) {
- pas = getpwnam(user_name);
- if (!pas)
- bb_error_msg_and_die("user %s is not known", user_name);
+ pas = xgetpwnam(user_name);
} else {
-/* XXX: xgetpwuid */
- uid_t my_uid = getuid();
- pas = getpwuid(my_uid);
- if (!pas)
- bb_perror_msg_and_die("unknown uid %d", (int)my_uid);
+ pas = xgetpwuid(getuid());
}
#define user_name DONT_USE_ME_BEYOND_THIS_POINT
close(fd);
xrename(new_fname, pas->pw_name);
} else {
- bb_error_msg("cannot create %s/%s",
+ bb_error_msg("can't create %s/%s",
crontab_dir, new_fname);
}
if (tmp_fname)
/* loop */
}
if (fd < 0) {
- bb_error_msg("cannot append to %s/%s",
+ bb_error_msg("can't append to %s/%s",
crontab_dir, CRONUPDATE);
}
return 0;