Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/cron Reduce default crontab size limit to 32K. Use ...



details:   https://anonhg.NetBSD.org/src/rev/4418ebe26057
branches:  trunk
changeset: 471717:4418ebe26057
user:      cjs <cjs%NetBSD.org@localhost>
date:      Fri Apr 09 02:47:03 1999 +0000

description:
Reduce default crontab size limit to 32K. Use the limit in
/var/cron/maxtabsize, if that file exists.

diffstat:

 usr.sbin/cron/config.h    |   9 ++++++++-
 usr.sbin/cron/crontab.1   |   9 ++++++++-
 usr.sbin/cron/crontab.c   |  40 +++++++++++++++++++++++++++++++---------
 usr.sbin/cron/pathnames.h |   5 ++++-
 4 files changed, 51 insertions(+), 12 deletions(-)

diffs (161 lines):

diff -r 546a094e615e -r 4418ebe26057 usr.sbin/cron/config.h
--- a/usr.sbin/cron/config.h    Fri Apr 09 00:38:10 1999 +0000
+++ b/usr.sbin/cron/config.h    Fri Apr 09 02:47:03 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.h,v 1.5 1998/01/31 14:40:17 christos Exp $      */
+/*     $NetBSD: config.h,v 1.6 1999/04/09 02:47:03 cjs Exp $   */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -73,6 +73,11 @@
                         */
 /*#define ALLOW_ONLY_ROOT                      */
 
+                       /* The maximum size of a crontab, in bytes, if
+                          MAXTABSIZE_FILE doesn't exist.
+                        */
+#define MAXTABSIZE_DEFAULT     (1024*32)
+
                        /* if you want to use syslog(3) instead of appending
                         * to CRONDIR/LOG_FILE (/var/cron/log, e.g.), define
                         * SYSLOG here.  Note that quite a bit of logging
@@ -87,3 +92,5 @@
                         * places.
                         */
 #define SYSLOG                         /*-*/
+
+
diff -r 546a094e615e -r 4418ebe26057 usr.sbin/cron/crontab.1
--- a/usr.sbin/cron/crontab.1   Fri Apr 09 00:38:10 1999 +0000
+++ b/usr.sbin/cron/crontab.1   Fri Apr 09 02:47:03 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: crontab.1,v 1.3 1997/03/13 06:19:13 mikel Exp $
+.\"    $NetBSD: crontab.1,v 1.4 1999/04/09 02:47:03 cjs Exp $
 .\"
 .\"/* Copyright 1988,1990,1993 by Paul Vixie
 .\" * All rights reserved
@@ -49,6 +49,12 @@
 will be allowed to use this command, or all users will be able to use this
 command.
 .PP
+The default maximum size for a crontab is 32768 bytes, but this may be
+changed for all users on the system by putting the desired maximum size
+(in bytes) in the
+.I maxtabsize
+file.
+.PP
 If the
 .I -u
 option is given, it specifies the name of the user whose crontab is to be
@@ -87,6 +93,7 @@
 .nf
 /var/cron/allow
 /var/cron/deny
+/var/cron/maxtabsize
 .fi
 .SH STANDARDS
 The
diff -r 546a094e615e -r 4418ebe26057 usr.sbin/cron/crontab.c
--- a/usr.sbin/cron/crontab.c   Fri Apr 09 00:38:10 1999 +0000
+++ b/usr.sbin/cron/crontab.c   Fri Apr 09 02:47:03 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crontab.c,v 1.13 1999/04/08 21:30:02 cjs Exp $ */
+/*     $NetBSD: crontab.c,v 1.14 1999/04/09 02:47:03 cjs Exp $ */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -22,7 +22,7 @@
 #if 0
 static char rcsid[] = "Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp";
 #else
-__RCSID("$NetBSD: crontab.c,v 1.13 1999/04/08 21:30:02 cjs Exp $");
+__RCSID("$NetBSD: crontab.c,v 1.14 1999/04/09 02:47:03 cjs Exp $");
 #endif
 #endif
 
@@ -512,12 +512,13 @@
  */
 static int
 replace_cmd() {
-       char    n[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME];
-       FILE    *tmp;
+       char    n[MAX_FNAME], n2[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME];
+       FILE    *tmp, *fmaxtabsize;
        int     ch, eof;
        entry   *e;
        time_t  now = time(NULL);
        char    **envp = env_init();
+       size_t  maxtabsize;
        struct  stat statbuf;
 
        (void) snprintf(n, sizeof(n), "tmp.%d", Pid);
@@ -527,16 +528,37 @@
                return (-2);
        }
 
-       /* make sure that the crontab is not an unreasonable size
-        * XXX this is subject to a race condition--fix it if you like.
+       /* Make sure that the crontab is not an unreasonable size.
+        *
+        * XXX This is subject to a race condition--the user could
+        * add stuff to the file after we've checked the size but
+        * before we slurp it in and write it out. We can't just move
+        * the test to test the temp file we later create, because by
+        * that time we've already filled up the crontab disk. Probably
+        * the right thing to do is to do a bytecount in the copy loop
+        * rather than stating the file we're about to read.
         */
+       (void) snprintf(n2, sizeof(n), "%s/%s", CRONDIR, MAXTABSIZE_FILE);
+       if ((fmaxtabsize = fopen(n2, "r")))  {
+           if (fgets(n2, sizeof(n2), fmaxtabsize) == NULL)  {
+               maxtabsize = 0;
+           } else {
+               maxtabsize = atoi(n2);
+           }
+           fclose(fmaxtabsize);
+       } else {
+           maxtabsize = MAXTABSIZE_DEFAULT;
+       }
+
        if (fstat(fileno(NewCrontab), &statbuf))  {
            fprintf(stderr, "%s: error stat'ing crontab input: %s\n",
                ProgramName, strerror(errno));
            return(-2);
        }
-       if (statbuf.st_size > MAXCRONTABSIZE)  {
-           fprintf(stderr, "%s: crontab too large\n", ProgramName);
+       if (statbuf.st_size > maxtabsize)  {
+           fprintf(stderr,
+               "%s: %ld bytes is larger than the maximum size of %ld bytes\n",
+               ProgramName, (long) statbuf.st_size, (long) maxtabsize);
            return(-1);
        }
 
@@ -547,7 +569,7 @@
        fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n");
        fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
        fprintf(tmp, "# (Cron version -- %s)\n",
-           "$NetBSD: crontab.c,v 1.13 1999/04/08 21:30:02 cjs Exp $");
+           "$NetBSD: crontab.c,v 1.14 1999/04/09 02:47:03 cjs Exp $");
 
        /* copy the crontab to the tmp
         */
diff -r 546a094e615e -r 4418ebe26057 usr.sbin/cron/pathnames.h
--- a/usr.sbin/cron/pathnames.h Fri Apr 09 00:38:10 1999 +0000
+++ b/usr.sbin/cron/pathnames.h Fri Apr 09 02:47:03 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pathnames.h,v 1.4 1998/01/31 14:40:40 christos Exp $   */
+/*     $NetBSD: pathnames.h,v 1.5 1999/04/09 02:47:03 cjs Exp $        */
 
 /* Copyright 1993,1994 by Paul Vixie
  * All rights reserved
@@ -43,6 +43,9 @@
                         */
 #define SPOOL_DIR      "tabs"
 
+                       /* File containing maximum crontab size, in bytes. */
+#define MAXTABSIZE_FILE        "maxtabsize"
+
                        /* undefining these turns off their features.  note
                         * that ALLOW_FILE and DENY_FILE must both be defined
                         * in order to enable the allow/deny code.  If neither



Home | Main Index | Thread Index | Old Index