[BACK]Return to at.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / at

Diff for /src/usr.bin/at/at.c between version 1.75 and 1.76

version 1.75, 2015/11/13 21:34:06 version 1.76, 2015/11/13 21:35:34
Line 48 
Line 48 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <syslog.h>
 #include <time.h>  #include <time.h>
 #include <unistd.h>  #include <unistd.h>
   
Line 71 
Line 72 
   
 static int program = AT;        /* default program mode */  static int program = AT;        /* default program mode */
 static char atfile[PATH_MAX];   /* path to the at spool file */  static char atfile[PATH_MAX];   /* path to the at spool file */
   static char user_name[MAX_UNAME];/* invoking user name */
 static int fcreated;            /* whether or not we created the file yet */  static int fcreated;            /* whether or not we created the file yet */
 static char atqueue = 0;        /* which queue to examine for jobs (atq) */  static char atqueue = 0;        /* which queue to examine for jobs (atq) */
 static char vflag = 0;          /* show completed but unremoved jobs (atq) */  static char vflag = 0;          /* show completed but unremoved jobs (atq) */
Line 85 
Line 87 
 static void writefile(const char *, time_t, char);  static void writefile(const char *, time_t, char);
 static void list_jobs(int, char **, int, int);  static void list_jobs(int, char **, int, int);
 static time_t ttime(char *);  static time_t ttime(char *);
 static int check_permission(void);  
 static __dead void fatal(const char *, ...)  static __dead void fatal(const char *, ...)
     __attribute__((__format__ (printf, 1, 2)));      __attribute__((__format__ (printf, 1, 2)));
 static __dead void fatalx(const char *, ...)  static __dead void fatalx(const char *, ...)
Line 241 
Line 242 
   
         if ((mailname == NULL) || (mailname[0] == '\0') ||          if ((mailname == NULL) || (mailname[0] == '\0') ||
             (strlen(mailname) > MAX_UNAME) || (getpwnam(mailname) == NULL)) {              (strlen(mailname) > MAX_UNAME) || (getpwnam(mailname) == NULL)) {
                 pass_entry = getpwuid(user_uid);                  mailname = user_name;
                 if (pass_entry != NULL)  
                         mailname = pass_entry->pw_name;  
         }          }
   
         /*          /*
Line 373 
Line 372 
         (void)fprintf(stderr, "commands will be executed using %s\n", shell);          (void)fprintf(stderr, "commands will be executed using %s\n", shell);
         (void)fprintf(stderr, "job %s at %s\n", &atfile[sizeof(_PATH_AT_SPOOL)],          (void)fprintf(stderr, "job %s at %s\n", &atfile[sizeof(_PATH_AT_SPOOL)],
             timestr);              timestr);
   
           syslog(LOG_INFO, "(%s) CREATE (%s)", user_name,
               &atfile[sizeof(_PATH_AT_SPOOL)]);
 }  }
   
 /* Sort by creation time. */  /* Sort by creation time. */
Line 448 
Line 450 
         int dfd, i, shortformat;          int dfd, i, shortformat;
         size_t numjobs, maxjobs;          size_t numjobs, maxjobs;
   
           syslog(LOG_INFO, "(%s) LIST (%s)", user_name,
               user_uid ? user_name : "ALL");
   
         if (argc) {          if (argc) {
                 if ((uids = calloc(sizeof(uid_t), argc)) == NULL)                  if ((uids = calloc(sizeof(uid_t), argc)) == NULL)
                         fatal(NULL);                          fatal(NULL);
Line 669 
Line 674 
                         case ATRM:                          case ATRM:
                                 if (!interactive ||                                  if (!interactive ||
                                     (interactive && rmok(runtimer))) {                                      (interactive && rmok(runtimer))) {
                                         if (unlinkat(dfd, dirent->d_name, 0) == 0)                                          if (unlinkat(dfd, dirent->d_name, 0) == 0) {
                                                   syslog(LOG_INFO,
                                                       "(%s) DELETE (%s)",
                                                       user_name, dirent->d_name);
                                                 changed = 1;                                                  changed = 1;
                                         else if (!force)                                          } else if (!force)
                                                 fatal("%s", dirent->d_name);                                                  fatal("%s", dirent->d_name);
                                         if (!force && !interactive)                                          if (!force && !interactive)
                                                 warnx("%s removed",                                                  warnx("%s removed",
Line 684 
Line 692 
                                     O_RDONLY|O_NOFOLLOW);                                      O_RDONLY|O_NOFOLLOW);
                                 if (i == -1 || (fp = fdopen(i, "r")) == NULL)                                  if (i == -1 || (fp = fdopen(i, "r")) == NULL)
                                         fatal("%s", dirent->d_name);                                          fatal("%s", dirent->d_name);
                                   syslog(LOG_INFO, "(%s) CAT (%s)",
                                       user_name, dirent->d_name);
   
                                 while ((ch = getc(fp)) != EOF)                                  while ((ch = getc(fp)) != EOF)
                                         putchar(ch);                                          putchar(ch);
Line 799 
Line 809 
         return (then);          return (then);
 }  }
   
 static int  
 check_permission(void)  
 {  
         struct passwd *pw;  
   
         if ((pw = getpwuid(user_uid)) == NULL)  
                 fatalx("unknown uid %u", user_uid);  
   
         return (allowed(pw->pw_name, _PATH_AT_ALLOW, _PATH_AT_DENY));  
 }  
   
 static __dead void  static __dead void
 usage(void)  usage(void)
 {  {
Line 847 
Line 846 
         char queue_set = 0;          char queue_set = 0;
         char *options = "q:f:t:bcdlmrv";        /* default options for at */          char *options = "q:f:t:bcdlmrv";        /* default options for at */
         char cwd[PATH_MAX];          char cwd[PATH_MAX];
           struct passwd *pw;
         int ch;          int ch;
         int aflag = 0;          int aflag = 0;
         int cflag = 0;          int cflag = 0;
Line 855 
Line 855 
         if (pledge("stdio rpath wpath cpath fattr getpw unix id", NULL) == -1)          if (pledge("stdio rpath wpath cpath fattr getpw unix id", NULL) == -1)
                 fatal("pledge");                  fatal("pledge");
   
           openlog(__progname, LOG_PID, LOG_CRON);
   
         if (argc < 1)          if (argc < 1)
                 usage();                  usage();
   
Line 976 
Line 978 
                 ;                  ;
         }          }
   
           if ((pw = getpwuid(user_uid)) == NULL)
               fatalx("unknown uid %u", user_uid);
           if (strlcpy(user_name, pw->pw_name, sizeof(user_name)) >= sizeof(user_name))
               fatalx("username too long");
   
         if (getcwd(cwd, sizeof(cwd)) == NULL)          if (getcwd(cwd, sizeof(cwd)) == NULL)
                 fatal("unable to get current working directory");                  fatal("unable to get current working directory");
   
         if (!check_permission())          if (!allowed(pw->pw_name, _PATH_AT_ALLOW, _PATH_AT_DENY)) {
                   syslog(LOG_WARNING, "(%s) AUTH (at command not allowed)",
                       pw->pw_name);
                 fatalx("you do not have permission to use at.");                  fatalx("you do not have permission to use at.");
           }
   
         /* select our program */          /* select our program */
         switch (program) {          switch (program) {

Legend:
Removed from v.1.75  
changed lines
  Added in v.1.76