Deleted Added
full compact
atrun.c (24349) atrun.c (24829)
1/*
2 * atrun.c - run jobs queued by at; run with root privileges.
3 * Copyright (C) 1993, 1994 Thomas Koenig
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 */
25
26/* System Headers */
27
28#include <sys/fcntl.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <sys/wait.h>
1/*
2 * atrun.c - run jobs queued by at; run with root privileges.
3 * Copyright (C) 1993, 1994 Thomas Koenig
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 */
25
26/* System Headers */
27
28#include <sys/fcntl.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <sys/wait.h>
32#include <sys/param.h>
32#include <ctype.h>
33#include <dirent.h>
34#include <errno.h>
35#include <pwd.h>
36#include <grp.h>
37#include <signal.h>
38#include <stddef.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <time.h>
43#include <unistd.h>
44#include <syslog.h>
33#include <ctype.h>
34#include <dirent.h>
35#include <errno.h>
36#include <pwd.h>
37#include <grp.h>
38#include <signal.h>
39#include <stddef.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <time.h>
44#include <unistd.h>
45#include <syslog.h>
46#include <utmp.h>
45#ifdef __FreeBSD__
46#include <paths.h>
47#else
48#include <getopt.h>
49#endif
50
47#ifdef __FreeBSD__
48#include <paths.h>
49#else
50#include <getopt.h>
51#endif
52
53#if (MAXLOGNAME-1) > UT_NAMESIZE
54#define LOGNAMESIZE UT_NAMESIZE
55#else
56#define LOGNAMESIZE (MAXLOGNAME-1)
57#endif
58
51/* Local headers */
52
53#include "gloadavg.h"
54#define MAIN
55#include "privs.h"
56
57/* Macros */
58

--- 7 unchanged lines hidden (view full) ---

66
67#ifndef LOADAVG_MX
68#define LOADAVG_MX 1.5
69#endif
70
71/* File scope variables */
72
73static char *namep;
59/* Local headers */
60
61#include "gloadavg.h"
62#define MAIN
63#include "privs.h"
64
65/* Macros */
66

--- 7 unchanged lines hidden (view full) ---

74
75#ifndef LOADAVG_MX
76#define LOADAVG_MX 1.5
77#endif
78
79/* File scope variables */
80
81static char *namep;
74static char rcsid[] = "$Id: atrun.c,v 1.8 1997/02/22 14:20:54 peter Exp $";
82static char rcsid[] = "$Id: atrun.c,v 1.9 1997/03/28 15:48:03 imp Exp $";
75static debug = 0;
76
77void perr(const char *a);
78
79/* Local functions */
80static int
81write_string(int fd, const char* a)
82{

--- 20 unchanged lines hidden (view full) ---

103{
104/* Run a file by by spawning off a process which redirects I/O,
105 * spawns a subshell, then waits for it to complete and sends
106 * mail to the user.
107 */
108 pid_t pid;
109 int fd_out, fd_in;
110 int queue;
83static debug = 0;
84
85void perr(const char *a);
86
87/* Local functions */
88static int
89write_string(int fd, const char* a)
90{

--- 20 unchanged lines hidden (view full) ---

111{
112/* Run a file by by spawning off a process which redirects I/O,
113 * spawns a subshell, then waits for it to complete and sends
114 * mail to the user.
115 */
116 pid_t pid;
117 int fd_out, fd_in;
118 int queue;
111 char mailbuf[9];
119 char mailbuf[LOGNAMESIZE + 1], fmt[49];
112 char *mailname = NULL;
113 FILE *stream;
114 int send_mail = 0;
115 struct stat buf, lbuf;
116 off_t size;
117 struct passwd *pentry;
118 int fflags;
119 long nuid;

--- 72 unchanged lines hidden (view full) ---

192 filename);
193 exit(EXIT_FAILURE);
194 }
195 if ((fflags = fcntl(fd_in, F_GETFD)) <0)
196 perr("Error in fcntl");
197
198 fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC);
199
120 char *mailname = NULL;
121 FILE *stream;
122 int send_mail = 0;
123 struct stat buf, lbuf;
124 off_t size;
125 struct passwd *pentry;
126 int fflags;
127 long nuid;

--- 72 unchanged lines hidden (view full) ---

200 filename);
201 exit(EXIT_FAILURE);
202 }
203 if ((fflags = fcntl(fd_in, F_GETFD)) <0)
204 perr("Error in fcntl");
205
206 fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC);
207
200 if (fscanf(stream, "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %8s %d",
201 &nuid, &ngid, mailbuf, &send_mail) != 4)
202 {
203 syslog(LOG_ERR,"File %s is in wrong format - aborting",
204 filename);
208 snprintf(fmt, 49, "#!/bin/sh\n# atrun uid=%%ld gid=%%ld\n# mail %%%ds %%d",
209 LOGNAMESIZE);
210 if (fscanf(stream, fmt, &nuid, &ngid, mailbuf, &send_mail) != 4) {
211 syslog(LOG_ERR,"File %s is in wrong format - aborting", filename);
205 exit(EXIT_FAILURE);
206 }
207 if (mailbuf[0] == '-') {
208 syslog(LOG_ERR,"illegal mail name %s in %s",mailbuf,filename);
209 exit(EXIT_FAILURE);
210 }
211 mailname = mailbuf;
212 if (nuid != uid) {

--- 267 unchanged lines hidden ---
212 exit(EXIT_FAILURE);
213 }
214 if (mailbuf[0] == '-') {
215 syslog(LOG_ERR,"illegal mail name %s in %s",mailbuf,filename);
216 exit(EXIT_FAILURE);
217 }
218 mailname = mailbuf;
219 if (nuid != uid) {

--- 267 unchanged lines hidden ---