Deleted Added
full compact
crontab.c (135165) crontab.c (135174)
1/* Copyright 1988,1990,1993,1994 by Paul Vixie
2 * All rights reserved
3 *
4 * Distribute freely, except: don't remove my name from the source or
5 * documentation (don't take credit for my work), mark your changes (don't
6 * get me blamed for your possible bugs), don't alter or remove this
7 * notice. May be sold if buildable source is provided to buyer. No
8 * warrantee of any kind, express or implied, is included with this

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

13 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
14 * I'll try to keep a version up to date. I can be reached as follows:
15 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
16 * From Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp
17 */
18
19#if !defined(lint) && !defined(LINT)
20static const char rcsid[] =
1/* Copyright 1988,1990,1993,1994 by Paul Vixie
2 * All rights reserved
3 *
4 * Distribute freely, except: don't remove my name from the source or
5 * documentation (don't take credit for my work), mark your changes (don't
6 * get me blamed for your possible bugs), don't alter or remove this
7 * notice. May be sold if buildable source is provided to buyer. No
8 * warrantee of any kind, express or implied, is included with this

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

13 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
14 * I'll try to keep a version up to date. I can be reached as follows:
15 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
16 * From Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp
17 */
18
19#if !defined(lint) && !defined(LINT)
20static const char rcsid[] =
21 "$FreeBSD: head/usr.sbin/cron/crontab/crontab.c 135165 2004-09-13 18:39:04Z dds $";
21 "$FreeBSD: head/usr.sbin/cron/crontab/crontab.c 135174 2004-09-13 21:04:30Z dds $";
22#endif
23
24/* crontab - install and manage per-user crontab files
25 * vix 02may87 [RCS has the rest of the log]
26 * vix 26jan87 [original]
27 */
28
29#define MAIN_PROGRAM

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

216 err(ERROR_EXIT, "swapping uids back");
217 }
218 }
219
220 Debug(DMISC, ("user=%s, file=%s, option=%s\n",
221 User, Filename, Options[(int)Option]))
222}
223
22#endif
23
24/* crontab - install and manage per-user crontab files
25 * vix 02may87 [RCS has the rest of the log]
26 * vix 26jan87 [original]
27 */
28
29#define MAIN_PROGRAM

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

216 err(ERROR_EXIT, "swapping uids back");
217 }
218 }
219
220 Debug(DMISC, ("user=%s, file=%s, option=%s\n",
221 User, Filename, Options[(int)Option]))
222}
223
224
225static void
224static void
226list_cmd() {
227 char n[MAX_FNAME];
228 FILE *f;
229 int ch, x;
225copy_file(FILE *in, FILE *out) {
226 int x, ch;
230
227
231 log_it(RealUser, Pid, "LIST", User);
232 (void) sprintf(n, CRON_TAB(User));
233 if (!(f = fopen(n, "r"))) {
234 if (errno == ENOENT)
235 errx(ERROR_EXIT, "no crontab for %s", User);
236 else
237 err(ERROR_EXIT, "%s", n);
238 }
239
240 /* file is open. copy to stdout, close.
241 */
242 Set_LineNum(1)
228 Set_LineNum(1)
243
244 /* ignore the top few comments since we probably put them there.
245 */
246 for (x = 0; x < NHEADER_LINES; x++) {
229 /* ignore the top few comments since we probably put them there.
230 */
231 for (x = 0; x < NHEADER_LINES; x++) {
247 ch = get_char(f);
232 ch = get_char(in);
248 if (EOF == ch)
249 break;
250 if ('#' != ch) {
233 if (EOF == ch)
234 break;
235 if ('#' != ch) {
251 putchar(ch);
236 putc(ch, out);
252 break;
253 }
237 break;
238 }
254 while (EOF != (ch = get_char(f)))
239 while (EOF != (ch = get_char(in)))
255 if (ch == '\n')
256 break;
257 if (EOF == ch)
258 break;
259 }
260
240 if (ch == '\n')
241 break;
242 if (EOF == ch)
243 break;
244 }
245
261 while (EOF != (ch = get_char(f)))
262 putchar(ch);
246 /* copy the rest of the crontab (if any) to the output file.
247 */
248 if (EOF != ch)
249 while (EOF != (ch = get_char(in)))
250 putc(ch, out);
251}
252
253static void
254list_cmd() {
255 char n[MAX_FNAME];
256 FILE *f;
257
258 log_it(RealUser, Pid, "LIST", User);
259 (void) sprintf(n, CRON_TAB(User));
260 if (!(f = fopen(n, "r"))) {
261 if (errno == ENOENT)
262 errx(ERROR_EXIT, "no crontab for %s", User);
263 else
264 err(ERROR_EXIT, "%s", n);
265 }
266
267 /* file is open. copy to stdout, close.
268 */
269 copy_file(f, stdout);
263 fclose(f);
264}
265
266
267static void
268delete_cmd() {
269 char n[MAX_FNAME];
270 int ch, first;

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

298 fprintf(stderr, "\"%s\":%d: %s\n", Filename, LineNumber-1, msg);
299}
300
301
302static void
303edit_cmd() {
304 char n[MAX_FNAME], q[MAX_TEMPSTR], *editor;
305 FILE *f;
270 fclose(f);
271}
272
273
274static void
275delete_cmd() {
276 char n[MAX_FNAME];
277 int ch, first;

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

305 fprintf(stderr, "\"%s\":%d: %s\n", Filename, LineNumber-1, msg);
306}
307
308
309static void
310edit_cmd() {
311 char n[MAX_FNAME], q[MAX_TEMPSTR], *editor;
312 FILE *f;
306 int ch, t, x;
313 int t;
307 struct stat statbuf, fsbuf;
308 time_t mtime;
309 WAIT_T waiter;
310 PID_T pid, xpid;
311 mode_t um;
312 int syntax_error = 0;
313
314 log_it(RealUser, Pid, "BEGIN EDIT", User);

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

337 warn("fchown");
338 goto fatal;
339 }
340 if (!(NewCrontab = fdopen(t, "r+"))) {
341 warn("fdopen");
342 goto fatal;
343 }
344
314 struct stat statbuf, fsbuf;
315 time_t mtime;
316 WAIT_T waiter;
317 PID_T pid, xpid;
318 mode_t um;
319 int syntax_error = 0;
320
321 log_it(RealUser, Pid, "BEGIN EDIT", User);

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

344 warn("fchown");
345 goto fatal;
346 }
347 if (!(NewCrontab = fdopen(t, "r+"))) {
348 warn("fdopen");
349 goto fatal;
350 }
351
345 Set_LineNum(1)
346
347 /* ignore the top few comments since we probably put them there.
348 */
349 for (x = 0; x < NHEADER_LINES; x++) {
350 ch = get_char(f);
351 if (EOF == ch)
352 break;
353 if ('#' != ch) {
354 putc(ch, NewCrontab);
355 break;
356 }
357 while (EOF != (ch = get_char(f)))
358 if (ch == '\n')
359 break;
360 if (EOF == ch)
361 break;
362 }
363
364 /* copy the rest of the crontab (if any) to the temp file.
365 */
366 if (EOF != ch)
367 while (EOF != (ch = get_char(f)))
368 putc(ch, NewCrontab);
352 copy_file(f, NewCrontab);
369 fclose(f);
370 if (fflush(NewCrontab))
371 err(ERROR_EXIT, "%s", Filename);
372 if (fstat(t, &fsbuf) < 0) {
373 warn("unable to fstat temp file");
374 goto fatal;
375 }
376 again:

--- 252 unchanged lines hidden ---
353 fclose(f);
354 if (fflush(NewCrontab))
355 err(ERROR_EXIT, "%s", Filename);
356 if (fstat(t, &fsbuf) < 0) {
357 warn("unable to fstat temp file");
358 goto fatal;
359 }
360 again:

--- 252 unchanged lines hidden ---