* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: conf.c,v 1.37 2001-01-27 15:41:09 thib Exp $ */
+ /* $Id: conf.c,v 1.38 2001-01-30 15:53:27 thib Exp $ */
#include "fcron.h"
char buf[LINE_LEN];
time_t t_save = 0;
time_t slept = 0;
- char zero[bitstr_size(60)];
uid_t runas = 0;
+ char *runas_str = NULL;
struct stat file_stat;
struct passwd *pass = NULL;
- bzero(zero, sizeof(zero));
-
/* open file */
if ( (ff = fopen(file_name, "r")) == NULL ) {
error_e("Could not read %s", file_name);
return 1;
}
/* set cf_user field */
- cf->cf_user = strdup2(pass->pw_name);
+ runas_str = cf->cf_user = strdup2(pass->pw_name);
}
}
else {
- if ( file_stat.st_uid == 0 ) {
+ if ( file_stat.st_uid == 0 )
/* file is owned by root : either this file has already been parsed
* at least once by fcron, either it is the root's fcrontab */
- if (strcmp(file_name,"root") == 0)
- /* this is root's fcrontab : set runas to 0 */
- runas = 0;
- else {
- /* this is a user's fcrontab : set the runas fields to the uid
- * corresponding to the name of the file, since the uid of the
- * user may have changed since last load */
- if ( (pass = getpwnam(file_name)) == NULL ) {
- error_e("Could not getpwnam(%s)", file_name);
- return 1;
- }
- runas = pass->pw_uid;
- }
- }
+ runas = 0;
else {
error("Non-new file %s owned by someone else than root",file_name);
return 1;
return 1;
}
- /* get the owner's name */
- if ( (cf->cf_user = read_str(ff, buf, sizeof(buf))) == NULL ) {
- error("Cannot read user's name : file ignored");
- return 1;
- }
+ if ( runas == 0 ) {
+ /* get the owner's name */
+ if ((cf->cf_user = read_str(ff, buf, sizeof(buf))) == NULL) {
+ error("Cannot read user's name : file ignored");
+ return 1;
+ }
+ }
+ else
+ /* read the user name but ignore it */
+ read_str(ff, buf, sizeof(buf));
/* get the time & date of the saving */
/* a new file generated by fcrontab has t_save set to 0 */
error("Line is not valid (empty shell command) : ignored");
continue;
}
+ if ((cl->cl_runas = read_str(ff, buf, sizeof(buf))) == NULL) {
+ error("Line is not valid (empty runas field) : ignored");
+ continue;
+ }
+ if ((cl->cl_mailto = read_str(ff, buf, sizeof(buf))) == NULL) {
+ error("Line is not valid (empty mailto field) : ignored");
+ continue;
+ }
/* set runas field if necessary (to improve security) */
if (runas > 0) {
- if (cl->cl_runas != runas)
- warn("warning: runas(%d) is not owner's uid(%d): overridden.",
- cl->cl_runas, runas);
- cl->cl_runas = runas;
+ if (strcmp(cl->cl_runas, runas_str) != 0)
+ warn("warning: runas(%s) is not owner (%s): overridden.",
+ cl->cl_runas, runas_str);
+ free(cl->cl_runas);
+ cl->cl_runas = strdup2(runas_str);
}
/* we need that here because the user's name (contained in the
set_next_exe(cl, STD);
}
else {
- if ( is_notice_notrun(cl->cl_option) )
- mail_notrun(cl, SYSDOWN, NULL);
- set_next_exe(cl, NO_GOTO);
+ if ( is_notice_notrun(cl->cl_option) ) {
+ struct tm *since2 = localtime(&cl->cl_nextexe), since;
+ memcpy(&since, since2, sizeof(since));
+ set_next_exe(cl, NO_GOTO);
+ mail_notrun(cl, SYSDOWN, &since);
+ }
+ else
+ set_next_exe(cl, NO_GOTO);
}
}
else
/* free line itself */
free(line->cl_shell);
+ free(line->cl_runas);
+ free(line->cl_mailto);
free(line);
}
/* delete_file() MUST remove only the first occurrence :
if ( fwrite(cl, sizeof(CL), 1, f) != 1 )
error_e("save");
fprintf(f, "%s%c", cl->cl_shell, '\0');
-
+ fprintf(f, "%s%c", cl->cl_runas, '\0');
+ fprintf(f, "%s%c", cl->cl_mailto, '\0');
}
fclose(f);
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: job.c,v 1.30 2001-01-27 15:43:06 thib Exp $ */
+ /* $Id: job.c,v 1.31 2001-01-30 15:54:01 thib Exp $ */
#include "fcron.h"
int temp_file(void);
void launch_mailer(CL *line, int mailfd);
-int change_user(uid_t uid);
void sig_dfl(void);
void end_job(CL *line, int status, int mailfd, short mailpos);
void end_mailer(CL *line, int status);
int
-change_user(uid_t uid)
+change_user(char *user_name)
{
struct passwd *pas;
-
/* Obtain password entry and change privileges */
- if ((pas = getpwuid(uid)) == NULL)
- die("failed to get passwd fields for user's uid %d", uid);
+ if ((pas = getpwnam(user_name)) == NULL)
+ die("failed to get passwd fields for user \"%s\"", user_name);
#ifdef HAVE_SETENV
setenv("USER", pas->pw_name, 1);
strcat( strcpy(buf, "HOME"), "=");
putenv( strncat(buf, pas->pw_dir, sizeof(buf)-5) );
strcat( strcpy(buf, "SHELL"), "=");
- putenv( strncat(buf, pas->pw_name, sizeof(buf)-6) );
+ putenv( strncat(buf, pas->pw_shell, sizeof(buf)-6) );
}
#endif /* HAVE_SETENV */
launch_mailer(CL *line, int mailfd)
/* mail the output of a job to user */
{
- struct passwd *pass;
-
foreground = 0;
/* set stdin to the job's output */
xcloselog();
- /* determine which will be the mail receiver */
- if ( (pass = getpwuid(line->cl_mailto)) == NULL )
- die("uid unknown: %d : no mail will be sent");
-
/* run sendmail with mail file as standard input */
- execl(SENDMAIL, SENDMAIL, SENDMAIL_ARGS, pass->pw_name, NULL);
- debug("launch_mailer4");
+ execl(SENDMAIL, SENDMAIL, SENDMAIL_ARGS, line->cl_mailto, NULL);
error_e("Can't find \""SENDMAIL"\". Trying a execlp(\"sendmail\")");
- execlp("sendmail", "sendmail", SENDMAIL_ARGS, pass->pw_name, NULL);
- debug("launch_mailer5");
+ execlp("sendmail", "sendmail", SENDMAIL_ARGS, line->cl_mailto, NULL);
die_e("Can't exec " SENDMAIL);
}