[BACK]Return to atrun.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / libexec / atrun

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/libexec/atrun/atrun.c between version 1.18 and 1.19

version 1.18, 2007/12/15 19:44:45 version 1.19, 2008/04/05 20:17:37
Line 160  run_file(const char *filename, uid_t uid
Line 160  run_file(const char *filename, uid_t uid
         gid_t ngid;          gid_t ngid;
         int serrno;          int serrno;
   
         PRIV_START          PRIV_START;
   
         if (chmod(filename, S_IRUSR) == -1)          if (chmod(filename, S_IRUSR) == -1)
                 perr("Cannot change file permissions to `%s'", filename);                  perr("Cannot change file permissions to `%s'", filename);
   
         PRIV_END          PRIV_END;
   
         pid = fork();          pid = fork();
         if (pid == -1)          if (pid == -1)
Line 184  run_file(const char *filename, uid_t uid
Line 184  run_file(const char *filename, uid_t uid
                 perrx("Userid %lu not found - aborting job `%s'",                  perrx("Userid %lu not found - aborting job `%s'",
                     (unsigned long)uid, filename);                      (unsigned long)uid, filename);
   
         PRIV_START          PRIV_START;
   
         stream = fopen(filename, "r");          stream = fopen(filename, "r");
         serrno = errno;          serrno = errno;
   
         PRIV_END          PRIV_END;
   
         if (stream == NULL) {          if (stream == NULL) {
                 errno = serrno;                  errno = serrno;
Line 206  run_file(const char *filename, uid_t uid
Line 206  run_file(const char *filename, uid_t uid
         if (fstat(fd_in, &buf) == -1)          if (fstat(fd_in, &buf) == -1)
                 perr("Error in fstat of input file descriptor");                  perr("Error in fstat of input file descriptor");
   
         PRIV_START          PRIV_START;
   
         if (lstat(filename, &lbuf) == -1)          if (lstat(filename, &lbuf) == -1)
                 perr("Error in lstat of `%s'", filename);                  perr("Error in lstat of `%s'", filename);
   
         PRIV_END          PRIV_END;
   
         if (S_ISLNK(lbuf.st_mode))          if (S_ISLNK(lbuf.st_mode))
                 perrx("Symbolic link encountered in job `%s' - aborting",                  perrx("Symbolic link encountered in job `%s' - aborting",
Line 253  run_file(const char *filename, uid_t uid
Line 253  run_file(const char *filename, uid_t uid
   
         (void)fclose(stream);          (void)fclose(stream);
   
         PRIV_START          PRIV_START;
   
         if (chdir(_PATH_ATSPOOL) == -1)          if (chdir(_PATH_ATSPOOL) == -1)
                 perr("Cannot chdir to `%s'", _PATH_ATSPOOL);                  perr("Cannot chdir to `%s'", _PATH_ATSPOOL);
Line 267  run_file(const char *filename, uid_t uid
Line 267  run_file(const char *filename, uid_t uid
                     O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1)                      O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1)
                 perr("Cannot create output file `%s'", filename);                  perr("Cannot create output file `%s'", filename);
   
         PRIV_END          PRIV_END;
   
         write_string(fd_out, "To: ");          write_string(fd_out, "To: ");
         write_string(fd_out, mailname);          write_string(fd_out, mailname);
Line 309  run_file(const char *filename, uid_t uid
Line 309  run_file(const char *filename, uid_t uid
                 (void)close(fd_in);                  (void)close(fd_in);
                 (void)close(fd_out);                  (void)close(fd_out);
   
                 PRIV_START                  PRIV_START;
   
                 if (chdir(_PATH_ATJOBS) == -1)                  if (chdir(_PATH_ATJOBS) == -1)
                         perr("Cannot chdir to `%s'", _PATH_ATJOBS);                          perr("Cannot chdir to `%s'", _PATH_ATJOBS);
Line 333  run_file(const char *filename, uid_t uid
Line 333  run_file(const char *filename, uid_t uid
          * Send mail.  Unlink the output file first, so it is deleted           * Send mail.  Unlink the output file first, so it is deleted
          * after the run.           * after the run.
          */           */
         PRIV_START          PRIV_START;
   
         if (stat(filename, &buf) == -1)          if (stat(filename, &buf) == -1)
                 perr("Error in stat of output file `%s'", filename);                  perr("Error in stat of output file `%s'", filename);
Line 342  run_file(const char *filename, uid_t uid
Line 342  run_file(const char *filename, uid_t uid
   
         (void)unlink(filename);          (void)unlink(filename);
   
         PRIV_END          PRIV_END;
   
         if ((buf.st_size != size) || send_mail) {          if ((buf.st_size != size) || send_mail) {
                 /* Fork off a child for sending mail */                  /* Fork off a child for sending mail */
   
                 PRIV_START                  PRIV_START;
   
                 become_user(pentry, uid);                  become_user(pentry, uid);
   
Line 355  run_file(const char *filename, uid_t uid
Line 355  run_file(const char *filename, uid_t uid
                     "-odi", "-oem", "-t", (char *) NULL);                      "-odi", "-oem", "-t", (char *) NULL);
                 perr("Exec failed for mail command `%s'", _PATH_SENDMAIL);                  perr("Exec failed for mail command `%s'", _PATH_SENDMAIL);
   
                 PRIV_END                  PRIV_END;
         }          }
         exit(EXIT_SUCCESS);          exit(EXIT_SUCCESS);
 }  }
Line 406  main(int argc, char *argv[])
Line 406  main(int argc, char *argv[])
          * We don't need root privileges all the time; running under uid           * We don't need root privileges all the time; running under uid
          * and gid nobody is fine except for privileged operations.           * and gid nobody is fine except for privileged operations.
          */           */
         RELINQUISH_PRIVS_ROOT(pwd->pw_uid, grp->gr_gid)          RELINQUISH_PRIVS_ROOT(pwd->pw_uid, grp->gr_gid);
   
         opterr = 0;          opterr = 0;
         errno = 0;          errno = 0;
Line 433  main(int argc, char *argv[])
Line 433  main(int argc, char *argv[])
                 }                  }
         }          }
   
         PRIV_START          PRIV_START;
   
         if (chdir(_PATH_ATJOBS) == -1)          if (chdir(_PATH_ATJOBS) == -1)
                 perr("Cannot change directory to `%s'", _PATH_ATJOBS);                  perr("Cannot change directory to `%s'", _PATH_ATJOBS);
Line 453  main(int argc, char *argv[])
Line 453  main(int argc, char *argv[])
         if ((spool = opendir(".")) == NULL)          if ((spool = opendir(".")) == NULL)
                 perr("Cannot open `%s'", _PATH_ATJOBS);                  perr("Cannot open `%s'", _PATH_ATJOBS);
   
         PRIV_END          PRIV_END;
   
         now = time(NULL);          now = time(NULL);
         run_batch = 0;          run_batch = 0;
Line 461  main(int argc, char *argv[])
Line 461  main(int argc, char *argv[])
         batch_gid = (gid_t) -1;          batch_gid = (gid_t) -1;
   
         while ((dirent = readdir(spool)) != NULL) {          while ((dirent = readdir(spool)) != NULL) {
                 PRIV_START                  PRIV_START;
   
                 if (stat(dirent->d_name, &buf) == -1)                  if (stat(dirent->d_name, &buf) == -1)
                         perr("Cannot stat `%s' in `%s'", dirent->d_name,                          perr("Cannot stat `%s' in `%s'", dirent->d_name,
                             _PATH_ATJOBS);                              _PATH_ATJOBS);
   
                 PRIV_END                  PRIV_END;
   
                 /* We don't want directories */                  /* We don't want directories */
                 if (!S_ISREG(buf.st_mode))                  if (!S_ISREG(buf.st_mode))
Line 498  main(int argc, char *argv[])
Line 498  main(int argc, char *argv[])
                 /* Delete older files */                  /* Delete older files */
                 if ((run_time < now) && !(S_IXUSR & buf.st_mode) &&                  if ((run_time < now) && !(S_IXUSR & buf.st_mode) &&
                     (S_IRUSR & buf.st_mode)) {                      (S_IRUSR & buf.st_mode)) {
                         PRIV_START                          PRIV_START;
   
                         (void)unlink(dirent->d_name);                          (void)unlink(dirent->d_name);
   
                         PRIV_END                          PRIV_END;
                 }                  }
         }          }
   

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

CVSweb <webmaster@jp.NetBSD.org>