* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: conf.c,v 1.17 2000-06-29 21:12:22 thib Exp $ */
+ /* $Id: conf.c,v 1.18 2000-08-22 18:01:30 thib Exp $ */
#include "fcron.h"
char buf[LINE_LEN];
time_t t_save = 0;
time_t slept = 0;
- char c;
- int i;
char *user = NULL;
- char *runas = NULL;
- struct passwd *pas = NULL;
/* open file */
slept = now - t_save;
- /* check if there is a mailto field in file */
- if ( (c = getc(ff)) == 'm' ) {
- /* there is one : read it */
-
- for (i = 0; i < sizeof(buf); i++)
- if ( (buf[i] = fgetc(ff)) == '\0')
- break;
- cf->cf_mailto = strdup2(buf);
-
- debug(" MailTo: '%s'", cf->cf_mailto);
- } else
- /* if there is no mailto field, the first letter is not a 'm',
- * but a 'e' : there is no need to lseek */
- ;
-
/* read env variables */
Alloc(env, env_t);
while( (env->e_name = read_str(ff, buf, sizeof(buf))) != NULL ) {
add_serial_job(cl);
}
- /* set the uid */
- if ( is_runas(cl->cl_option) ) {
- struct passwd *p = NULL;
- runas = read_str(ff, buf, sizeof(buf));
- if ( (p = getpwnam(runas)) == NULL )
- die_e("could not getpwnam() %s", runas);
- cl->cl_runas = p->pw_uid;
- }
- else {
- if ( pas == NULL && (pas = getpwnam(user)) == NULL )
- die_e("could not getpwnam() %s", user);
- cl->cl_runas = pas->pw_uid;
- }
-
/* check if the task has not been stopped during execution */
if (cl->cl_pid > 0) {
/* finally free file itself */
free(file->cf_user);
- free(file->cf_mailto);
free(file);
}
FILE *f = NULL;
CF *start = NULL;
env_t *env = NULL;
- struct passwd *pas = NULL;
if (file != NULL)
start = file;
* the system down time */
fprintf(f, "%ld", now);
- /* mailto, */
- if ( cf->cf_mailto != NULL ) {
- fprintf(f, "m");
- fprintf(f, "%s%c", cf->cf_mailto, '\0');
- } else
- fprintf(f, "e");
-
/* env variables, */
for (env = cf->cf_env_base; env; env = env->e_next) {
fprintf(f, "%s%c", env->e_name, '\0');
if ( fwrite(cl, sizeof(CL), 1, f) != 1 )
error_e("save");
fprintf(f, "%s%c", cl->cl_shell, '\0');
- if ( is_runas(cl->cl_option) ) {
- if ( (pas = getpwuid(cl->cl_runas)) == NULL )
- die_e("could not getpwuid() %d", cl->cl_runas);
- fprintf(f, "%s%c", pas->pw_name, '\0');
- }
}
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fcrontab.c,v 1.11 2000-06-25 20:02:32 thib Exp $ */
+ /* $Id: fcrontab.c,v 1.12 2000-08-22 18:01:32 thib Exp $ */
/*
* The goal of this program is simple : giving a user interface to fcron
#include "fcrontab.h"
-char rcs_info[] = "$Id: fcrontab.c,v 1.11 2000-06-25 20:02:32 thib Exp $";
+char rcs_info[] = "$Id: fcrontab.c,v 1.12 2000-08-22 18:01:32 thib Exp $";
void info(void);
void usage(void);
int file_opt = 0;
char debug_opt = DEBUG;
char *user = NULL;
+uid_t uid = 0 ;
char *cdir = FCRONTABS;
char need_sig = 0; /* do we need to signal fcron daemon */
}
}
else {
- if ( ! getpwnam(user) )
+ struct passwd *pass;
+ if ( ! (pass = getpwnam(user)) )
die("user '%s' is not in passwd file. Aborting.", user);
+ uid = pass->pw_uid;
}
if ( ! is_allowed(user) ) {
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fileconf.c,v 1.12 2000-06-29 21:12:44 thib Exp $ */
+ /* $Id: fileconf.c,v 1.13 2000-08-22 18:01:34 thib Exp $ */
#include "fcrontab.h"
char *file_name;
int line;
extern char *user;
+extern uid_t uid;
/* warning : all names must have the same length */
const char *dows_ary[] = {
Alloc(cf, CF);
default_line.cl_file = cf;
+ default_line.cl_runas = uid;
+ default_line.cl_mailto = uid;
if ( debug_opt )
fprintf(stderr, "FILE %s\n", file_name);
fclose(file);
- if ( cf->cf_mailto != NULL && cf->cf_mailto[0] == '\0' ) {
- CL *line;
-
- for (line = cf->cf_line_base; line; line = line->cl_next)
- clear_mail(line->cl_option);
- }
-
if ( ! need_correction )
return OK;
else
/* the MAILTO assignment is, in fact, an fcron option :
* we don't store it in the same way. */
if ( strcmp(name, "MAILTO") == 0 ) {
- if ( cf->cf_mailto != NULL )
- free(cf->cf_mailto);
- cf->cf_mailto = val;
+ if ( strcmp(val, "\0") == 0 )
+ clear_mail(default_line.cl_option);
+ else {
+ struct passwd *pass = NULL;
+ if ( (pass = getpwnam(val)) == 0 ) {
+ fprintf(stderr, "%s:%d: %s is not in passwd.\n",
+ file_name, line, val);
+ need_correction = 1;
+ } else
+ default_line.cl_mailto = pass->pw_uid;
+ }
+
}
else {
else if( strcmp(opt_name, "mailto") == 0) {
char buf[50];
+ struct passwd *pass = NULL;
bzero(buf, sizeof(buf));
if( ! in_brackets )
i = 0;
while ( isalnum(*ptr) )
buf[i++] = *ptr++;
- if ( cl->cl_file->cf_mailto != NULL )
- free(cl->cl_file->cf_mailto);
- cl->cl_file->cf_mailto = strdup2(buf);
+ if ( (pass = getpwnam(buf)) == NULL ) {
+ fprintf(stderr, "%s:%d: %s is not in passwd.\n",
+ file_name, line, buf);
+ need_correction = 1;
+ } else
+ cl->cl_mailto = pass->pw_uid;
if (debug_opt)
fprintf(stderr, " Opt : '%s' '%s'\n", opt_name, buf);
}
/* finally free file itself */
free(file->cf_user);
- free(file->cf_mailto);
free(file);
}
CL *line = NULL;
FILE *f = NULL;
env_t *env = NULL;
- struct passwd *pas = NULL;
if (debug_opt)
fprintf(stderr, "Saving ...\n");
* the system down time. As it is a new file, we set it to 0 */
fprintf(f, "%d", 0);
- /* mailto, */
- if ( file->cf_mailto != NULL ) {
- fprintf(f, "m");
- fprintf(f, "%s%c", file->cf_mailto, '\0');
- } else
- fprintf(f, "e");
-
/* env variables, */
for (env = file->cf_env_base; env; env = env->e_next) {
fprintf(f, "%s%c", env->e_name, '\0');
if ( fwrite(line, sizeof(CL), 1, f) != 1 )
perror("save");
fprintf(f, "%s%c", line->cl_shell, '\0');
- if ( is_runas(line->cl_option) ) {
- if ( (pas = getpwuid(line->cl_runas)) == NULL )
- die_e("could not getpwuid() %d", line->cl_runas);
- fprintf(f, "%s%c", pas->pw_name, '\0');
- }
}
// /* finally, write the number of lines to permit to check if the file
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: global.h,v 1.15 2000-06-29 21:12:51 thib Exp $ */
+ /* $Id: global.h,v 1.16 2000-08-22 18:01:37 thib Exp $ */
/*
#include "option.h"
-#define FILEVERSION "009" /* syntax's version of fcrontabs :
+#define FILEVERSION "010" /* syntax's version of fcrontabs :
* must have a length of 3 characters */
#define ERR -1
struct CF *cf_next;
struct CL *cf_line_base;
char *cf_user; /* user-name */
- char *cf_mailto; /* mail output's to mail_user */
struct env_t *cf_env_base; /* list of all env variables to set */
int cf_running; /* number of jobs running */
} CF;
char *cl_shell; /* shell command */
char cl_nice; /* nice value to control priority */
uid_t cl_runas; /* determine permissions of the job */
+ uid_t cl_mailto; /* mail output to cl_mailto */
pid_t cl_pid; /* running pid, 0, or armed (-1) */
time_t cl_nextexe; /* time and date of the next execution */
short int cl_remain; /* remaining until next execution */
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: job.c,v 1.18 2000-06-28 14:01:18 thib Exp $ */
+ /* $Id: job.c,v 1.19 2000-08-22 18:01:39 thib Exp $ */
#include "fcron.h"
launch_mailer(CL *line, int mailfd)
/* mail the output of a job to user */
{
- char *mailto = NULL;
+ struct passwd *pass;
foreground = 0;
xcloselog();
/* determine which will be the mail receiver */
- if ( (mailto = line->cl_file->cf_mailto) == NULL )
- mailto = line->cl_file->cf_user;
-
+ 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, mailto, NULL);
+ execl(SENDMAIL, SENDMAIL, SENDMAIL_ARGS, pass->pw_name, NULL);
die_e("Can't exec " SENDMAIL);
}