Quota checking during reception. Bug 163
[exim.git] / src / src / exim.c
index 905ef0a7008bbe12078dac39137f823a11e6ff72..4e7aae69a0f7143edd3e510ef9b07a2372eeda96 100644 (file)
@@ -1618,6 +1618,7 @@ BOOL removed_privilege = FALSE;
 BOOL usage_wanted = FALSE;
 BOOL verify_address_mode = FALSE;
 BOOL verify_as_sender = FALSE;
+BOOL rcpt_verify_quota = FALSE;
 BOOL version_printed = FALSE;
 uschar *alias_arg = NULL;
 uschar *called_as = US"";
@@ -2790,6 +2791,13 @@ on the second character (the one after '-'), to save some effort. */
                  else badarg = TRUE;
                  break;
 
+    /* -MCq: do a quota check on the given recipient for the given size
+    of message.  Separate from -MC. */
+       case 'q': rcpt_verify_quota = TRUE;
+                 if (++i < argc) message_size = Uatoi(argv[i]);
+                 else badarg = TRUE;
+                 break;
+
     /* -MCS: set the smtp_use_size flag; this is useful only when it
     precedes -MC (see above) */
 
@@ -4296,6 +4304,7 @@ if (  !unprivileged                               /* originally had root AND */
             || msg_action != MSG_DELIVER       /* not delivering          */
            )                                   /*       and               */
          && (!checking || !f.address_test_mode)        /* not address checking    */
+        && !rcpt_verify_quota                  /* and not quota checking  */
    )  )  )
   exim_setugid(exim_uid, exim_gid, TRUE, US"privilege not needed");
 
@@ -4414,6 +4423,18 @@ needed in transports so we lost the optimisation. */
 #endif
   }
 
+/* Handle a request to check quota */
+if (rcpt_verify_quota)
+  if (real_uid != root_uid && real_uid != exim_uid)
+    exim_fail("exim: Permission denied\n");
+  else if (recipients_arg >= argc)
+    exim_fail("exim: missing recipient for quota check\n");
+  else
+    {
+    verify_quota(argv[recipients_arg]);
+    exim_exit(EXIT_SUCCESS);
+    }
+
 /* Handle the -brt option. This is for checking out retry configurations.
 The next three arguments are a domain name or a complete address, and
 optionally two error numbers. All it does is to call the function that