at.c (96216) | at.c (96701) |
---|---|
1/* 2 * at.c : Put file into atrun queue 3 * Copyright (C) 1993, 1994 Thomas Koenig 4 * 5 * Atrun & Atq modifications 6 * Copyright (C) 1993 David Parsons 7 * 8 * Redistribution and use in source and binary forms, with or without --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/* 2 * at.c : Put file into atrun queue 3 * Copyright (C) 1993, 1994 Thomas Koenig 4 * 5 * Atrun & Atq modifications 6 * Copyright (C) 1993 David Parsons 7 * 8 * Redistribution and use in source and binary forms, with or without --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/usr.bin/at/at.c 96216 2002-05-08 11:23:45Z kuriyama $"); | 30__FBSDID("$FreeBSD: head/usr.bin/at/at.c 96701 2002-05-16 00:47:14Z tjr $"); |
31 32#define _USE_BSD 1 33 34/* System Headers */ 35 36#include <sys/param.h> 37#include <sys/stat.h> 38#include <sys/time.h> --- 76 unchanged lines hidden (view full) --- 115char *namep; 116 117/* Function declarations */ 118 119static void sigc(int signo); 120static void alarmc(int signo); 121static char *cwdname(void); 122static void writefile(time_t runtimer, char queue); | 31 32#define _USE_BSD 1 33 34/* System Headers */ 35 36#include <sys/param.h> 37#include <sys/stat.h> 38#include <sys/time.h> --- 76 unchanged lines hidden (view full) --- 115char *namep; 116 117/* Function declarations */ 118 119static void sigc(int signo); 120static void alarmc(int signo); 121static char *cwdname(void); 122static void writefile(time_t runtimer, char queue); |
123static void list_jobs(void); | 123static void list_jobs(long *, int); |
124static long nextjob(void); 125static time_t ttime(const char *arg); | 124static long nextjob(void); 125static time_t ttime(const char *arg); |
126static int in_job_list(long, long *, int); 127static long *get_job_list(int, char *[], int *); |
|
126 127/* Signal catching functions */ 128 129static void sigc(int signo __unused) 130{ 131/* If the user presses ^C, remove the spool file and exit 132 */ 133 if (fcreated) --- 306 unchanged lines hidden (view full) --- 440 441 if (fchmod(fd2, S_IRUSR | S_IWUSR | S_IXUSR) < 0) 442 perr("cannot give away file"); 443 444 close(fd2); 445 fprintf(stderr, "Job %ld will be executed using /bin/sh\n", jobno); 446} 447 | 128 129/* Signal catching functions */ 130 131static void sigc(int signo __unused) 132{ 133/* If the user presses ^C, remove the spool file and exit 134 */ 135 if (fcreated) --- 306 unchanged lines hidden (view full) --- 442 443 if (fchmod(fd2, S_IRUSR | S_IWUSR | S_IXUSR) < 0) 444 perr("cannot give away file"); 445 446 close(fd2); 447 fprintf(stderr, "Job %ld will be executed using /bin/sh\n", jobno); 448} 449 |
450static int 451in_job_list(long job, long *joblist, int len) 452{ 453 int i; 454 455 for (i = 0; i < len; i++) 456 if (job == joblist[i]) 457 return 1; 458 459 return 0; 460} 461 |
|
448static void | 462static void |
449list_jobs() | 463list_jobs(long *joblist, int len) |
450{ 451 /* List all a user's jobs in the queue, by looping through ATJOB_DIR, 452 * or everybody's if we are root 453 */ 454 struct passwd *pw; 455 DIR *spool; 456 struct dirent *dirent; 457 struct stat buf; --- 29 unchanged lines hidden (view full) --- 487 if (!S_ISREG(buf.st_mode) 488 || ((buf.st_uid != real_uid) && ! (real_uid == 0)) 489 || !(S_IXUSR & buf.st_mode || atverify)) 490 continue; 491 492 if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3) 493 continue; 494 | 464{ 465 /* List all a user's jobs in the queue, by looping through ATJOB_DIR, 466 * or everybody's if we are root 467 */ 468 struct passwd *pw; 469 DIR *spool; 470 struct dirent *dirent; 471 struct stat buf; --- 29 unchanged lines hidden (view full) --- 501 if (!S_ISREG(buf.st_mode) 502 || ((buf.st_uid != real_uid) && ! (real_uid == 0)) 503 || !(S_IXUSR & buf.st_mode || atverify)) 504 continue; 505 506 if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3) 507 continue; 508 |
509 /* If jobs are given, only list those jobs */ 510 if (joblist && !in_job_list(jobno, joblist, len)) 511 continue; 512 |
|
495 if (atqueue && (queue != atqueue)) 496 continue; 497 498 runtimer = 60*(time_t) ctm; 499 runtime = *localtime(&runtimer); 500 strftime(timestr, TIMESIZE, "%+", &runtime); 501 if (first) { 502 printf("Date\t\t\t\tOwner\t\tQueue\tJob#\n"); --- 157 unchanged lines hidden (view full) --- 660 if (tv[0].tv_sec != -1) 661 return tv[0].tv_sec; 662 else 663terr: 664 panic( 665 "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); 666} 667 | 513 if (atqueue && (queue != atqueue)) 514 continue; 515 516 runtimer = 60*(time_t) ctm; 517 runtime = *localtime(&runtimer); 518 strftime(timestr, TIMESIZE, "%+", &runtime); 519 if (first) { 520 printf("Date\t\t\t\tOwner\t\tQueue\tJob#\n"); --- 157 unchanged lines hidden (view full) --- 678 if (tv[0].tv_sec != -1) 679 return tv[0].tv_sec; 680 else 681terr: 682 panic( 683 "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); 684} 685 |
686static long * 687get_job_list(int argc, char *argv[], int *joblen) 688{ 689 int i, len; 690 long *joblist; 691 char *ep; 692 693 joblist = NULL; 694 len = argc; 695 if (len > 0) { 696 if ((joblist = malloc(len * sizeof(*joblist))) == NULL) 697 panic("out of memory"); 698 699 for (i = 0; i < argc; i++) { 700 errno = 0; 701 if ((joblist[i] = strtol(argv[i], &ep, 10)) < 0 || 702 ep == argv[i] || *ep != '\0' || errno) 703 panic("invalid job number"); 704 } 705 } 706 707 *joblen = len; 708 return joblist; 709} 710 |
|
668int 669main(int argc, char **argv) 670{ 671 int c; 672 char queue = DEFAULT_AT_QUEUE; 673 char queue_set = 0; 674 char *pgm; 675 676 int program = AT; /* our default program */ 677 const char *options = "q:f:t:rmvldbc"; /* default options for at */ 678 time_t timer; | 711int 712main(int argc, char **argv) 713{ 714 int c; 715 char queue = DEFAULT_AT_QUEUE; 716 char queue_set = 0; 717 char *pgm; 718 719 int program = AT; /* our default program */ 720 const char *options = "q:f:t:rmvldbc"; /* default options for at */ 721 time_t timer; |
722 long *joblist; 723 int joblen; |
|
679 | 724 |
725 joblist = NULL; 726 joblen = 0; |
|
680 timer = -1; 681 RELINQUISH_PRIVS 682 683 /* Eat any leading paths 684 */ 685 if ((pgm = strrchr(argv[0], '/')) == NULL) 686 pgm = argv[0]; 687 else --- 62 unchanged lines hidden (view full) --- 750 timer = ttime(optarg); 751 break; 752 753 case 'l': 754 if (program != AT) 755 usage(); 756 757 program = ATQ; | 727 timer = -1; 728 RELINQUISH_PRIVS 729 730 /* Eat any leading paths 731 */ 732 if ((pgm = strrchr(argv[0], '/')) == NULL) 733 pgm = argv[0]; 734 else --- 62 unchanged lines hidden (view full) --- 797 timer = ttime(optarg); 798 break; 799 800 case 'l': 801 if (program != AT) 802 usage(); 803 804 program = ATQ; |
758 options = "q:v"; | 805 options = "q:"; |
759 break; 760 761 case 'b': 762 if (program != AT) 763 usage(); 764 765 program = BATCH; 766 options = "f:q:mv"; --- 15 unchanged lines hidden (view full) --- 782 */ 783 if(!check_permission()) 784 errx(EXIT_FAILURE, "you do not have permission to use this program"); 785 switch (program) { 786 case ATQ: 787 788 REDUCE_PRIV(DAEMON_UID, DAEMON_GID) 789 | 806 break; 807 808 case 'b': 809 if (program != AT) 810 usage(); 811 812 program = BATCH; 813 options = "f:q:mv"; --- 15 unchanged lines hidden (view full) --- 829 */ 830 if(!check_permission()) 831 errx(EXIT_FAILURE, "you do not have permission to use this program"); 832 switch (program) { 833 case ATQ: 834 835 REDUCE_PRIV(DAEMON_UID, DAEMON_GID) 836 |
790 list_jobs(); | 837 if (queue_set == 0) 838 joblist = get_job_list(argc - optind, argv + optind, &joblen); 839 list_jobs(joblist, joblen); |
791 break; 792 793 case ATRM: 794 795 REDUCE_PRIV(DAEMON_UID, DAEMON_GID) 796 797 process_jobs(argc, argv, ATRM); 798 break; --- 48 unchanged lines hidden --- | 840 break; 841 842 case ATRM: 843 844 REDUCE_PRIV(DAEMON_UID, DAEMON_GID) 845 846 process_jobs(argc, argv, ATRM); 847 break; --- 48 unchanged lines hidden --- |