]> git.ipfire.org Git - thirdparty/fcron.git/commitdiff
support of the mailto option for each line
authorThibault Godouet <yo8192@users.noreply.github.com>
Tue, 22 Aug 2000 18:01:30 +0000 (18:01 +0000)
committerThibault Godouet <yo8192@users.noreply.github.com>
Tue, 22 Aug 2000 18:01:30 +0000 (18:01 +0000)
conf.c
fcrontab.c
fileconf.c
global.h
job.c

diff --git a/conf.c b/conf.c
index ae05e6b0d88d03525bb452ada9a185bd835a8c48..2abbbcc77c26291449878c4e4d8c6e7716ad2968 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -22,7 +22,7 @@
  *  `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"
 
@@ -386,11 +386,7 @@ read_file(const char *file_name, CF *cf)
     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 */
@@ -429,21 +425,6 @@ read_file(const char *file_name, CF *cf)
     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 ) {
@@ -491,20 +472,6 @@ read_file(const char *file_name, CF *cf)
            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) {
@@ -621,7 +588,6 @@ delete_file(const char *user_name)
 
     /* finally free file itself */
     free(file->cf_user);
-    free(file->cf_mailto);
     free(file);
 
 }
@@ -637,7 +603,6 @@ save_file(CF *file, char *path)
     FILE *f = NULL;
     CF *start = NULL;
     env_t *env = NULL;
-    struct passwd *pas = NULL;
 
     if (file != NULL)
        start = file;
@@ -673,13 +638,6 @@ save_file(CF *file, char *path)
         * 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');
@@ -692,11 +650,6 @@ save_file(CF *file, char *path)
            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');
-           }
 
        }
     
index 0f54cb9d4f155cf9c80846fb3a4ffa1ff7f88494..34529db18ff58cd437d7430b307ec1ba601aa471 100644 (file)
@@ -22,7 +22,7 @@
  *  `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
@@ -42,7 +42,7 @@
 
 #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);
@@ -59,6 +59,7 @@ char ignore_prev = 0;
 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 */
@@ -663,8 +664,10 @@ parseopt(int argc, char *argv[])
        }
     }
     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) ) {
index 7b0ac59b61d4e84f445435d2c776a7b94dc56f11..e7aded5878536cbb12313edf86417b9547159540 100644 (file)
@@ -22,7 +22,7 @@
  *  `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"
 
@@ -45,6 +45,7 @@ CL default_line;    /* default options for a line */
 char *file_name;
 int line;
 extern char *user;
+extern uid_t uid;
 
 /* warning : all names must have the same length */
 const char *dows_ary[] = {
@@ -173,6 +174,8 @@ read_file(char *filename, char *user)
 
     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);
@@ -250,13 +253,6 @@ read_file(char *filename, char *user)
 
     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
@@ -317,9 +313,18 @@ read_env(char *ptr, CF *cf)
     /* 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 {
 
@@ -532,6 +537,7 @@ read_opt(char *ptr, CL *cl)
 
        else if( strcmp(opt_name, "mailto") == 0) {
            char buf[50];
+           struct passwd *pass = NULL;
            bzero(buf, sizeof(buf));
 
            if( ! in_brackets )
@@ -540,9 +546,12 @@ read_opt(char *ptr, CL *cl)
            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);
        }
@@ -1077,7 +1086,6 @@ delete_file(const char *user_name)
 
     /* finally free file itself */
     free(file->cf_user);
-    free(file->cf_mailto);
     free(file);
 
 }
@@ -1093,7 +1101,6 @@ save_file(char *path)
     CL *line = NULL;
     FILE *f = NULL;
     env_t *env = NULL;
-    struct passwd *pas = NULL;
 
     if (debug_opt)
        fprintf(stderr, "Saving ...\n");
@@ -1119,13 +1126,6 @@ save_file(char *path)
         * 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');
@@ -1138,11 +1138,6 @@ save_file(char *path)
            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
index d6b066fa5c3f940655916d8bf3c1d46584ce9453..bdba9334f768456b8f6fa62f4e0f170357a902c6 100644 (file)
--- a/global.h
+++ b/global.h
@@ -21,7 +21,7 @@
  *  `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 $ */
 
 
 /* 
@@ -57,7 +57,7 @@
 #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           
@@ -81,7 +81,6 @@ typedef struct CF {
     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;
@@ -95,6 +94,7 @@ typedef struct CL {
     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       */
diff --git a/job.c b/job.c
index 6a7b53d2d89fc8d9890fa0682666344e9ca309d9..6e8965e26557e5c2001d8728a3ffa7ffb969f39f 100644 (file)
--- a/job.c
+++ b/job.c
@@ -22,7 +22,7 @@
  *  `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"
 
@@ -252,7 +252,7 @@ void
 launch_mailer(CL *line, int mailfd)
     /* mail the output of a job to user */
 {
-    char *mailto = NULL;
+    struct passwd *pass;
 
     foreground = 0;
 
@@ -263,11 +263,11 @@ launch_mailer(CL *line, int mailfd)
     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);
 
 }