[prev in list] [next in list] [prev in thread] [next in thread] 

List:       proftpd-committers
Subject:    [ProFTPD-committers] CVS: proftpd/contrib mod_quotatab.c, 1.49, 1.50
From:       "TJ Saunders" <castaglia () users ! sourceforge ! net>
Date:       2009-09-29 21:46:06
Message-ID: E1MskWM-0008FV-M7 () ddv4jf1 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Update of /cvsroot/proftp/proftpd/contrib
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31669/contrib

Modified Files:
	mod_quotatab.c 
Log Message:

Bug#3296 - mod_quotatab should reject an upload via APPE if the quota is
already exceeded.


Index: mod_quotatab.c
===================================================================
RCS file: /cvsroot/proftp/proftpd/contrib/mod_quotatab.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- mod_quotatab.c	7 Sep 2009 02:03:52 -0000	1.49
+++ mod_quotatab.c	29 Sep 2009 21:46:04 -0000	1.50
@@ -1480,6 +1480,8 @@
 MODRET quotatab_pre_appe(cmd_rec *cmd) {
   struct stat st;
 
+  have_err_response = FALSE;
+
   /* Sanity check */
   if (!use_quotas)
     return PR_DECLINED(cmd);
@@ -1487,6 +1489,32 @@
   /* Refresh the tally */
   QUOTATAB_TALLY_READ
 
+  /* Check quotas to see if bytes upload or total quota has been reached.
+   * Block command if so.
+   */
+  if (sess_limit.bytes_in_avail > 0.0 &&
+      sess_tally.bytes_in_used >= sess_limit.bytes_in_avail) {
+
+    /* Report the exceeding of the threshold. */
+    quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
+      DISPLAY_BYTES_IN(cmd));
+    pr_response_add_err(R_552, _("%s denied: quota exceeded: used %s"),
+      cmd->argv[0], DISPLAY_BYTES_IN(cmd));
+    have_err_response = TRUE;
+    return PR_ERROR(cmd);
+
+  } else if (sess_limit.bytes_xfer_avail > 0.0 &&
+      sess_tally.bytes_xfer_used >= sess_limit.bytes_xfer_avail) {
+
+    /* Report the exceeding of the threshold. */
+    quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
+      DISPLAY_BYTES_XFER(cmd));
+    pr_response_add_err(R_552, _("%s denied: quota exceeded: used %s"),
+      cmd->argv[0], DISPLAY_BYTES_XFER(cmd));
+    have_err_response = TRUE;
+    return PR_ERROR(cmd);
+  }
+
   /* Briefly cache the size (in bytes) of the file being appended to, so that
    * if successful, the byte counts can be adjusted correctly.
    */
@@ -1540,17 +1568,58 @@
    */
   if (sess_limit.bytes_in_avail > 0.0 &&
       sess_tally.bytes_in_used >= sess_limit.bytes_in_avail) {
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_BYTES_IN(cmd));
-    pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_BYTES_IN(cmd));
+
+    if (!have_err_response) {
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_BYTES_IN(cmd));
+      pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_BYTES_IN(cmd));
+    }
+
+    if (sess_tally.bytes_in_used > sess_limit.bytes_in_avail &&
+        sess_limit.quota_limit_type == HARD_LIMIT) {
+      if (pr_fsio_unlink(cmd->arg) < 0) {
+        quotatab_log("notice: unable to unlink '%s': %s", cmd->arg,
+          strerror(errno));
+
+      } else {
+        QUOTATAB_TALLY_WRITE(-append_bytes, 0, -session.xfer.total_bytes,
+          -1, 0, -1);
+
+        /* Report the removal of the file. */
+        quotatab_log("%s: quota reached: '%s' removed", cmd->argv[0], cmd->arg);
+        pr_response_add(R_DUP, _("%s: notice: quota reached: '%s' removed"),
+          cmd->argv[0], cmd->arg);
+      }
+    }
 
   } else if (sess_limit.bytes_xfer_avail > 0.0 &&
       sess_tally.bytes_xfer_used >= sess_limit.bytes_xfer_avail) {
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_BYTES_XFER(cmd));
-    pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_BYTES_XFER(cmd));
+
+    if (!have_err_response) {
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_BYTES_XFER(cmd));
+      pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_BYTES_XFER(cmd));
+    }
+
+    if (sess_tally.bytes_xfer_used > sess_limit.bytes_xfer_avail &&
+        sess_limit.quota_limit_type == HARD_LIMIT) {
+      if (pr_fsio_unlink(cmd->arg) < 0) {
+        quotatab_log("notice: unable to unlink '%s': %s", cmd->arg,
+          strerror(errno));
+
+      } else {
+        QUOTATAB_TALLY_WRITE(-append_bytes, 0, -session.xfer.total_bytes,
+          -1, 0, -1);
+
+        /* Report the removal of the file. */
+        quotatab_log("%s: quota reached: '%s' removed", cmd->argv[0], cmd->arg);
+        pr_response_add(R_DUP, _("%s: notice: quota reached: '%s' removed"),
+          cmd->argv[0], cmd->arg);
+      }
+    }
+
   }
 
   return PR_DECLINED(cmd);
@@ -1595,17 +1664,57 @@
    */
   if (sess_limit.bytes_in_avail > 0.0 &&
       sess_tally.bytes_in_used >= sess_limit.bytes_in_avail) {
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_BYTES_IN(cmd));
-    pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_BYTES_IN(cmd));
+
+    if (!have_err_response) {
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_BYTES_IN(cmd));
+      pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_BYTES_IN(cmd));
+    }
+
+    if (sess_tally.bytes_in_used > sess_limit.bytes_in_avail &&
+        sess_limit.quota_limit_type == HARD_LIMIT) {
+      if (pr_fsio_unlink(cmd->arg) < 0) {
+        quotatab_log("notice: unable to unlink '%s': %s", cmd->arg,
+          strerror(errno));
+
+      } else {
+        QUOTATAB_TALLY_WRITE(-append_bytes, 0, -session.xfer.total_bytes,
+          -1, 0, -1);
+
+        /* Report the removal of the file. */
+        quotatab_log("%s: quota reached: '%s' removed", cmd->argv[0], cmd->arg);
+        pr_response_add(R_DUP, _("%s: notice: quota reached: '%s' removed"),
+          cmd->argv[0], cmd->arg);
+      }
+    }
 
   } else if (sess_limit.bytes_xfer_avail > 0.0 &&
       sess_tally.bytes_xfer_used >= sess_limit.bytes_xfer_avail) {
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_BYTES_XFER(cmd));
-    pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_BYTES_XFER(cmd));
+
+    if (!have_err_response) {
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_BYTES_XFER(cmd));
+      pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_BYTES_XFER(cmd));
+    }
+
+    if (sess_tally.bytes_xfer_used > sess_limit.bytes_xfer_avail &&
+        sess_limit.quota_limit_type == HARD_LIMIT) {
+      if (pr_fsio_unlink(cmd->arg) < 0) {
+        quotatab_log("notice: unable to unlink '%s': %s", cmd->arg,
+          strerror(errno));
+
+      } else {
+        QUOTATAB_TALLY_WRITE(-append_bytes, 0, -session.xfer.total_bytes,
+          -1, 0, -1);
+
+        /* Report the removal of the file. */
+        quotatab_log("%s: quota reached: '%s' removed", cmd->argv[0], cmd->arg);
+        pr_response_add(R_DUP, _("%s: notice: quota reached: '%s' removed"),
+          cmd->argv[0], cmd->arg);
+      }
+    }
   }
 
   return PR_DECLINED(cmd);
@@ -2236,6 +2345,7 @@
 }
 
 MODRET quotatab_pre_retr(cmd_rec *cmd) {
+  have_err_response = FALSE;
 
   /* Sanity check */
   if (!use_quotas)
@@ -2256,7 +2366,7 @@
   if (sess_limit.bytes_out_avail > 0.0 &&
       sess_tally.bytes_out_used >= sess_limit.bytes_out_avail) {
 
-    /* Report the exceeding of the threshhold. */
+    /* Report the exceeding of the threshold. */
     quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_BYTES_OUT(cmd));
     pr_response_add_err(R_451, _("%s denied: quota exceeded: used %s"),
@@ -2267,7 +2377,7 @@
   } else if (sess_limit.bytes_xfer_avail > 0.0 &&
       sess_tally.bytes_xfer_used >= sess_limit.bytes_xfer_avail) {
 
-    /* Report the exceeding of the threshhold. */
+    /* Report the exceeding of the threshold. */
     quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_BYTES_XFER(cmd));
     pr_response_add_err(R_451, _("%s denied: quota exceeded: used %s"),
@@ -2282,7 +2392,7 @@
   if (sess_limit.files_out_avail != 0 &&
       sess_tally.files_out_used >= sess_limit.files_out_avail) {
 
-    /* Report the exceeding of the threshhold. */
+    /* Report the exceeding of the threshold. */
     quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_FILES_OUT(cmd));
     pr_response_add_err(R_451, _("%s denied: quota exceeded: used %s"),
@@ -2293,7 +2403,7 @@
   } else if (sess_limit.files_xfer_avail != 0 &&
       sess_tally.files_xfer_used >= sess_limit.files_xfer_avail) {
 
-    /* Report the exceeding of the threshhold. */
+    /* Report the exceeding of the threshold. */
     quotatab_log("%s: denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_FILES_XFER(cmd));
     pr_response_add(R_451, _("%s denied: quota exceeded: used %s"),
@@ -2328,7 +2438,7 @@
   if (sess_limit.bytes_out_avail > 0.0 &&
       sess_tally.bytes_out_used >= sess_limit.bytes_out_avail) {
 
-    /* Report the reaching of the threshhold. */
+    /* Report the reaching of the threshold. */
     quotatab_log("%s: quota reached: used %s", cmd->argv[0],
       DISPLAY_BYTES_OUT(cmd));
     pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2337,7 +2447,7 @@
   } else if (sess_limit.bytes_xfer_avail > 0.0 &&
       sess_tally.bytes_xfer_used >= sess_limit.bytes_xfer_avail) {
 
-    /* Report the reaching of the threshhold. */
+    /* Report the reaching of the threshold. */
     quotatab_log("%s: quota reached: used %s", cmd->argv[0],
       DISPLAY_BYTES_XFER(cmd));
     pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2350,7 +2460,7 @@
   if (sess_limit.files_out_avail != 0 && 
       sess_tally.files_out_used >= sess_limit.files_out_avail) {
 
-    /* Report the reaching of the threshhold. */
+    /* Report the reaching of the threshold. */
     quotatab_log("%s: quota reached: used %s", cmd->argv[0],
       DISPLAY_FILES_OUT(cmd));
     pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2359,7 +2469,7 @@
   } else if (sess_limit.files_xfer_avail != 0 &&
     sess_tally.files_xfer_used >= sess_limit.files_xfer_avail) {
 
-    /* Report the reaching of the threshhold. */
+    /* Report the reaching of the threshold. */
     quotatab_log("%s: quota reached: used %s", cmd->argv[0],
       DISPLAY_FILES_XFER(cmd));
     pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2393,7 +2503,7 @@
 
     if (!have_err_response) {
 
-      /* Report the reaching of the threshhold. */
+      /* Report the reaching of the threshold. */
       quotatab_log("%s: quota reached: used %s", cmd->argv[0],
         DISPLAY_BYTES_OUT(cmd));
       pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2405,7 +2515,7 @@
 
     if (!have_err_response) {
 
-      /* Report the reaching of the threshhold. */
+      /* Report the reaching of the threshold. */
       quotatab_log("%s: quota reached: used %s", cmd->argv[0],
         DISPLAY_BYTES_XFER(cmd));
       pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2421,7 +2531,7 @@
 
     if (!have_err_response) {
 
-      /* Report the reaching of the treshhold. */
+      /* Report the reaching of the treshold. */
       quotatab_log("%s: quota reached: used %s", cmd->argv[0],
         DISPLAY_FILES_OUT(cmd));
       pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2433,7 +2543,7 @@
 
     if (!have_err_response) {
 
-      /* Report the reaching of the treshhold. */
+      /* Report the reaching of the treshold. */
       quotatab_log("%s: quota reached: used %s", cmd->argv[0],
         DISPLAY_FILES_XFER(cmd));
       pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2536,6 +2646,8 @@
 MODRET quotatab_pre_stor(cmd_rec *cmd) {
   struct stat st;
  
+  have_err_response = FALSE;
+
   /* Sanity check */
   if (!use_quotas)
     return PR_DECLINED(cmd);
@@ -2555,7 +2667,7 @@
   if (sess_limit.bytes_in_avail > 0.0 &&
       sess_tally.bytes_in_used >= sess_limit.bytes_in_avail) {
 
-    /* Report the exceeding of the threshhold. */
+    /* Report the exceeding of the threshold. */
     quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_BYTES_IN(cmd));
     pr_response_add_err(R_552, _("%s denied: quota exceeded: used %s"),
@@ -2566,7 +2678,7 @@
   } else if (sess_limit.bytes_xfer_avail > 0.0 &&
       sess_tally.bytes_xfer_used >= sess_limit.bytes_xfer_avail) {
 
-    /* Report the exceeding of the threshhold. */
+    /* Report the exceeding of the threshold. */
     quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_BYTES_XFER(cmd));
     pr_response_add_err(R_552, _("%s denied: quota exceeded: used %s"),
@@ -2581,7 +2693,7 @@
   if (sess_limit.files_in_avail != 0 &&
       sess_tally.files_in_used >= sess_limit.files_in_avail) {
 
-    /* Repor the exceeding of the threshhold. */
+    /* Repor the exceeding of the threshold. */
     quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_FILES_IN(cmd));
     pr_response_add_err(R_552, _("%s denied: quota exceeded: used %s"),
@@ -2592,7 +2704,7 @@
   } else if (sess_limit.files_xfer_avail != 0 &&
       sess_tally.files_xfer_used >= sess_limit.files_xfer_avail) {
 
-    /* Report the exceeding of the threshhold. */
+    /* Report the exceeding of the threshold. */
     quotatab_log("%s denied: quota exceeded: used %s", cmd->argv[0],
       DISPLAY_FILES_XFER(cmd));
     pr_response_add_err(R_552, _("%s denied: quota exceeded: used %s"),
@@ -2662,11 +2774,13 @@
   if (sess_limit.bytes_in_avail > 0.0 &&
       sess_tally.bytes_in_used >= sess_limit.bytes_in_avail) {
 
-    /* Report the reaching of the threshhold. */
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_BYTES_IN(cmd));
-    pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_BYTES_IN(cmd));
+    if (!have_err_response) {
+      /* Report the reaching of the threshold. */
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_BYTES_IN(cmd));
+      pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_BYTES_IN(cmd));
+    }
 
     if (sess_tally.bytes_in_used > sess_limit.bytes_in_avail &&
         sess_limit.quota_limit_type == HARD_LIMIT) {
@@ -2688,11 +2802,13 @@
   } else if (sess_limit.bytes_xfer_avail > 0.0 &&
       sess_tally.bytes_xfer_used >= sess_limit.bytes_xfer_avail) {
 
-    /* Report the reaching of the threshhold. */ 
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_BYTES_XFER(cmd));
-    pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_BYTES_XFER(cmd));
+    if (!have_err_response) {
+      /* Report the reaching of the threshold. */ 
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_BYTES_XFER(cmd));
+      pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_BYTES_XFER(cmd));
+    }
 
     if (sess_tally.bytes_xfer_used > sess_limit.bytes_xfer_avail &&
         sess_limit.quota_limit_type == HARD_LIMIT) {
@@ -2718,20 +2834,24 @@
   if (sess_limit.files_in_avail != 0 &&
       sess_tally.files_in_used >= sess_limit.files_in_avail) {
 
-    /* Report the reaching of the treshhold. */
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_FILES_IN(cmd));
-    pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_FILES_IN(cmd));
+    if (!have_err_response) {
+      /* Report the reaching of the threshold. */
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_FILES_IN(cmd));
+      pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_FILES_IN(cmd));
+    }
 
   } else if (sess_limit.files_xfer_avail != 0 &&
       sess_tally.files_xfer_used >= sess_limit.files_xfer_avail) {
 
-    /* Report the reaching of the threshhold. */
-    quotatab_log("%s: quota reached: used %s", cmd->argv[0],
-      DISPLAY_FILES_XFER(cmd));
-    pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
-      cmd->argv[0], DISPLAY_FILES_XFER(cmd));
+    if (!have_err_response) {
+      /* Report the reaching of the threshold. */
+      quotatab_log("%s: quota reached: used %s", cmd->argv[0],
+        DISPLAY_FILES_XFER(cmd));
+      pr_response_add(R_DUP, _("%s: notice: quota reached: used %s"),
+        cmd->argv[0], DISPLAY_FILES_XFER(cmd));
+    }
   }
 
   return PR_DECLINED(cmd);
@@ -2780,7 +2900,7 @@
 
     if (!have_err_response) {
 
-      /* Report the reaching of the threshhold. */
+      /* Report the reaching of the threshold. */
       quotatab_log("%s: quota reached: used %s", cmd->argv[0],
         DISPLAY_BYTES_IN(cmd));
       pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2812,7 +2932,7 @@
 
     if (!have_err_response) {
 
-      /* Report the reaching of the threshhold. */
+      /* Report the reaching of the threshold. */
       quotatab_log("%s: quota reached: used %s", cmd->argv[0],
         DISPLAY_BYTES_XFER(cmd));
       pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2846,7 +2966,7 @@
   if (sess_limit.files_in_avail != 0 &&
       sess_tally.files_in_used >= sess_limit.files_in_avail) {
 
-    /* Report the reaching of the threshhold. */
+    /* Report the reaching of the threshold. */
     quotatab_log("%s: quota reached: used %s", cmd->argv[0],
       DISPLAY_FILES_IN(cmd));
     pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),
@@ -2855,7 +2975,7 @@
   } else if (sess_limit.files_xfer_avail != 0 &&
       sess_tally.files_xfer_used >= sess_limit.files_xfer_avail) {
 
-    /* Report the reaching of the threshhold. */
+    /* Report the reaching of the threshold. */
     quotatab_log("%s: quota reached: used %s", cmd->argv[0],
       DISPLAY_FILES_XFER(cmd));
     pr_response_add_err(R_DUP, _("%s: notice: quota reached: used %s"),


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
ProFTPD Committers Mailing List
proftpd-committers@proftpd.org
https://lists.sourceforge.net/lists/listinfo/proftp-committers
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic