]> git.ipfire.org Git - thirdparty/fcron.git/commitdiff
runas and mailto are now strings, not uid (to handle a change of the
authorThibault Godouet <yo8192@users.noreply.github.com>
Tue, 30 Jan 2001 15:53:27 +0000 (15:53 +0000)
committerThibault Godouet <yo8192@users.noreply.github.com>
Tue, 30 Jan 2001 15:53:27 +0000 (15:53 +0000)
uid of a user.

conf.c
job.c

diff --git a/conf.c b/conf.c
index 4044921fd30c24acb567b069954048a660a49b50..ec0d414545bae7717c85fc942b579f5d4b529358 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.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"
 
@@ -374,13 +374,11 @@ read_file(const char *file_name, CF *cf)
     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);
@@ -407,27 +405,14 @@ read_file(const char *file_name, CF *cf)
                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;
@@ -452,11 +437,16 @@ read_file(const char *file_name, CF *cf)
        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 */
@@ -486,13 +476,22 @@ read_file(const char *file_name, CF *cf)
            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
@@ -545,9 +544,14 @@ read_file(const char *file_name, CF *cf)
                    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
@@ -704,6 +708,8 @@ delete_file(const char *user_name)
 
            /* 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 :
@@ -792,7 +798,8 @@ save_file(CF *file)
            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);
diff --git a/job.c b/job.c
index a243eac55827a2a70aede67880a1adc5db400ab7..8210ac8e73ecbf0c7fa0369e08703bedcc015b55 100644 (file)
--- a/job.c
+++ b/job.c
  *  `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);
@@ -57,7 +55,7 @@ change_user(uid_t uid)
        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 */
 
@@ -309,8 +307,6 @@ void
 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 */
@@ -319,16 +315,10 @@ launch_mailer(CL *line, int mailfd)
 
     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);
 
 }