so the process is not killable by the user.
case 0:
Debug(DPROC, ("[%ld] grandchild process fork()'ed\n", (long) getpid()))
- if (cron_change_user_permanently(e->pwd, env_get("HOME", jobenv)) < 0)
- _exit(ERROR_EXIT);
-
/* write a log message. we've waited this long to do it
* because it was not until now that we knew the PID that
* the actual user command shell was going to get and the
free(x);
}
- /* that's the last thing we'll log. close the log files.
- */
- log_close();
+ if (cron_change_user_permanently(e->pwd, env_get("HOME", jobenv)) < 0)
+ _exit(ERROR_EXIT);
/* get new pgrp, void tty, etc.
*/
gethostname(hostname, MAXHOSTNAMELEN);
if (MailCmd[0] == '\0') {
- if (strlens(MAILFMT, MAILARG, mailfrom, NULL) + 1
+ if (snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG, mailfrom)
>= sizeof mailcmd) {
fprintf(stderr, "mailcmd too long\n");
(void) _exit(ERROR_EXIT);
}
- (void) sprintf(mailcmd, MAILFMT, MAILARG, mailfrom);
}
else {
strncpy(mailcmd, MailCmd, MAX_COMMAND);
void cron_close_security_session( void );
-int cron_change_user( struct passwd *pw );
+int cron_change_groups( struct passwd *pw );
int cron_change_user_permanently( struct passwd *pw, char *homedir );
sa.sa_handler = SIG_DFL;
sigaction(SIGPIPE, &sa, NULL);
+ if (cron_change_user_permanently(pw, pw->pw_dir) != 0)
+ _exit(2);
+
if (execvp(argv[0], argv) < 0) {
int save_errno = errno;
}
#endif
- if (cron_change_user(e->pwd) != 0) {
- log_it(e->pwd->pw_name, getpid(), "ERROR", "failed to change user", 0);
+ if (cron_change_groups(e->pwd) != 0) {
return -1;
}
- log_close();
-
time_t job_run_time = time(0L);
if ((minutely_time > 0) && ((job_run_time / 60) != (minutely_time / 60))) {
#endif
}
-int cron_change_user(struct passwd *pw) {
+int cron_change_groups(struct passwd *pw) {
pid_t pid = getpid();
- /* set our directory, uid and gid. Set gid first, since once
- * we set uid, we've lost root privledges.
- */
+
if (setgid(pw->pw_gid) != 0) {
log_it("CRON", pid, "ERROR", "setgid failed", errno);
return -1;
return -1;
}
- if (setreuid(pw->pw_uid, -1) != 0) {
- log_it("CRON", pid, "ERROR", "setreuid failed", errno);
- return -1;
- }
+#if defined(WITH_PAM)
+ /* credentials may take form of supplementary groups so reinitialize
+ * them here */
+ pam_setcred(pamh, PAM_REINITIALIZE_CRED | PAM_SILENT);
+#endif
return 0;
}
log_it("CRON", getpid(), "ERROR", "setreuid failed", errno);
return -1;
}
+
if (chdir(homedir) == -1) {
log_it("CRON", getpid(), "ERROR chdir failed", homedir, errno);
return -1;
}
+ log_close();
+
return 0;
}