Guest User

at-secprec

a guest
Mar 21st, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.84 KB | None | 0 0
  1. --- a/at.c  2015-12-06 16:45:10.000000000 +0100
  2. +++ b/at.c  2016-02-20 11:36:22.000000000 +0100
  3. @@ -122,7 +122,7 @@
  4.  extern char **environ;
  5.  int fcreated;
  6.  char *namep;
  7. -char atfile[] = ATJOB_DIR "/12345678901234";
  8. +char atfile[] = ATJOB_DIR "/12345678901234567";
  9.  
  10.  char *atinput = (char *) 0;    /* where to get input from */
  11.  char atqueue = 0;      /* which queue to examine for jobs (atq) */
  12. @@ -244,6 +244,7 @@
  13.      int kill_errno;
  14.      int rc;
  15.      int mailsize = 128;
  16. +    char *shell_path;
  17.  
  18.  /* Install the signal handler for SIGINT; terminate after removing the
  19.   * spool file if necessary
  20. @@ -299,7 +300,7 @@
  21.         perr("Cannot generate job number");
  22.  
  23.     (void)snprintf(ppos, sizeof(atfile) - (ppos - atfile),
  24. -              "%c%5lx%8lx", queue, jobno, (unsigned long) (runtimer / 60));
  25. +              "%c%5lx%8lx%2u", queue, jobno, (unsigned long) (runtimer / 60), (unsigned int) (runtimer % 60));
  26.  
  27.     for (ap = ppos; *ap != '\0'; ap++)
  28.         if (*ap == ' ')
  29. @@ -352,6 +353,19 @@
  30.      if ((fp = fdopen(fd, "w")) == NULL)
  31.     panic("Cannot reopen atjob file");
  32.  
  33. +   shell_path = getenv("SHELL");
  34. +   if(shell_path == NULL || shell_path[0] == '\0')
  35. +   {
  36. +   /* POSIX.2 allows the shell specified by the user's SHELL environment
  37. +      variable, the login shell from the user's password database entry,
  38. +      or /bin/sh to be the command interpreter that processes the at-job.
  39. +      It also alows a warning diagnostic to be printed.  Because of the
  40. +      possible variance, we always output the diagnostic. */
  41. +
  42. +       shell_path = "/bin/sh";
  43. +       fprintf(stderr, "warning: commands will be executed using %s\n", shell_path);
  44. +   }
  45. +
  46.      /* Get the userid to mail to, first by trying getlogin(), which reads
  47.       * /var/run/utmp, then from LOGNAME, finally from getpwuid().
  48.       */
  49. @@ -374,8 +388,8 @@
  50.         perr("Cannot open input file %.500s", atinput);
  51.      }
  52.  
  53. -    fprintf(fp, "#!/bin/sh\n# atrun uid=%d gid=%d\n# mail %s %d\n",
  54. -       real_uid, real_gid, mailname, send_mail);
  55. +    fprintf(fp, "#!%s\n# atrun uid=%d gid=%d\n# mail %s %d\n",
  56. +       shell_path, real_uid, real_gid, mailname, send_mail);
  57.  
  58.      /* Write out the umask at the time of invocation
  59.       */
  60. @@ -574,6 +588,7 @@
  61.      struct stat buf;
  62.      struct tm *runtime;
  63.      unsigned long ctm;
  64. +    unsigned int  ctmsec;
  65.      char queue;
  66.      long jobno;
  67.      time_t runtimer;
  68. @@ -600,21 +615,25 @@
  69.         || atverify)
  70.         continue;
  71.  
  72. -   if (sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm) != 3)
  73. -       continue;
  74. +   if (sscanf(dirent->d_name, "%c%5lx%8lx%2u", &queue, &jobno, &ctm, &ctmsec) != 4)
  75. +   {
  76. +       ctmsec = 0;
  77. +       if (sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm) != 3)
  78. +           continue;
  79. +   }
  80.  
  81.     if (atqueue && (queue != atqueue))
  82.         continue;
  83.  
  84. -   runtimer = 60 * (time_t) ctm;
  85. +   runtimer = (time_t) ctm * 60 + ctmsec;
  86.     runtime = localtime(&runtimer);
  87.  
  88.     strftime(timestr, TIMESIZE, TIMEFORMAT_POSIX, runtime);
  89.  
  90.     if ((pwd = getpwuid(buf.st_uid)))
  91. -     printf("%ld\t%s %c %s\n", jobno, timestr, queue, pwd->pw_name);
  92. +     printf("%ld\t%s\tqueue=%c user=%s\n", jobno, timestr, queue, pwd->pw_name);
  93.     else
  94. -     printf("%ld\t%s %c\n", jobno, timestr, queue);
  95. +     printf("%ld\t%s\tqueue=%c\n", jobno, timestr, queue);
  96.      }
  97.      PRIV_END
  98.  }
  99. @@ -857,8 +876,6 @@
  100.         fprintf(stderr, "invalid date format: %s\n", optarg);
  101.         exit(EXIT_FAILURE);
  102.         }
  103. -       /* drop seconds */
  104. -       timer -= timer % 60;
  105.         break;
  106.  
  107.     default:
  108. @@ -937,14 +954,6 @@
  109.         fprintf(stderr, "%s\n", asctime(tm));
  110.     }
  111.  
  112. -   /* POSIX.2 allows the shell specified by the user's SHELL environment
  113. -      variable, the login shell from the user's password database entry,
  114. -      or /bin/sh to be the command interpreter that processes the at-job.
  115. -      It also alows a warning diagnostic to be printed.  Because of the
  116. -      possible variance, we always output the diagnostic. */
  117. -
  118. -   fprintf(stderr, "warning: commands will be executed using /bin/sh\n");
  119. -
  120.     writefile(timer, queue);
  121.     break;
Advertisement
Add Comment
Please, Sign In to add comment