summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjkar8572 <jkar8572>2004-01-07 12:37:48 +0000
committerjkar8572 <jkar8572>2004-01-07 12:37:48 +0000
commitb8d851f6a89ed3ab64ca70cf2b71637478605db2 (patch)
treef38839764c1317187a1df81686823f8e2c0d580f
parent4a0ccd0b25a224a95c574b92e19c21eb65dfe103 (diff)
Fixed a few problems in mail-server checking. (Jan Kara)
-rw-r--r--README.mailserver7
-rw-r--r--warnquota.c50
-rw-r--r--warnquota.conf4
3 files changed, 42 insertions, 19 deletions
diff --git a/README.mailserver b/README.mailserver
index e3b51ce..9882435 100644
--- a/README.mailserver
+++ b/README.mailserver
@@ -3,11 +3,12 @@ Mail server support by James Bourne <jbourne@hardrock.org>
If you are running warnquota on a mail server you need to be able to tell
warnquota not to send mail when the users quota is either over the hard
limit or past the grace period. So, to do this add the value:
-MAILSERV = true
+MAILDEV = any
into /etc/warnquota.conf and warnquota will not send mail to those users.
If you have only a single partition you wish to apply this rule to, use the
device name as the argument to the MAILSERV configuration variable list
this:
-MAILSERV = /dev/sdb1
-
+MAILDEV = /dev/sdb1
+Please note that specifying checking of mail device may slow down things
+considerably...
diff --git a/warnquota.c b/warnquota.c
index 89df4f6..6a39ce1 100644
--- a/warnquota.c
+++ b/warnquota.c
@@ -10,7 +10,7 @@
*
* Author: Marco van Wieringen <mvw@planets.elm.net>
*
- * Version: $Id: warnquota.c,v 1.17 2004/01/06 12:19:31 jkar8572 Exp $
+ * Version: $Id: warnquota.c,v 1.18 2004/01/07 12:37:48 jkar8572 Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -137,7 +137,8 @@ struct adminstable {
};
int qtab_i = 0, fmt = -1, flags;
-char mailserv[CNF_BUFFER];
+char maildev[CNF_BUFFER];
+struct quota_handle *maildev_handle;
char *configfile = WARNQUOTA_CONF, *quotatabfile = QUOTATAB, *adminsfile = ADMINSFILE;
char *progname;
quotatable_t *quotatable;
@@ -231,20 +232,25 @@ void add_offence(struct dquot *dquot, char *name)
int deliverable(struct dquot *dquot)
{
time_t now;
+ struct dquot *mdquot;
- if((strlen(mailserv) == 0) || (strcasecmp(mailserv, "false") == 0))
- return(1);
+ if (!maildev[0])
+ return 1;
time(&now);
- if (((dquot->dq_dqb.dqb_bhardlimit && toqb(dquot->dq_dqb.dqb_curspace) >= dquot->dq_dqb.dqb_bhardlimit)
- || ((dquot->dq_dqb.dqb_bsoftlimit && toqb(dquot->dq_dqb.dqb_curspace) >= dquot->dq_dqb.dqb_bsoftlimit)
- && (dquot->dq_dqb.dqb_btime && dquot->dq_dqb.dqb_btime <= now)))
- && ((strcasecmp(mailserv, "true") == 0)
- || (strcasecmp(mailserv, dquot->dq_h->qh_quotadev) == 0)))
- return(0);
-
- return(1);
+ if (!strcasecmp(maildev, "any") &&
+ ((dquot->dq_dqb.dqb_bhardlimit && toqb(dquot->dq_dqb.dqb_curspace) >= dquot->dq_dqb.dqb_bhardlimit)
+ || ((dquot->dq_dqb.dqb_bsoftlimit && toqb(dquot->dq_dqb.dqb_curspace) >= dquot->dq_dqb.dqb_bsoftlimit)
+ && (dquot->dq_dqb.dqb_btime && dquot->dq_dqb.dqb_btime <= now))))
+ return 0;
+ mdquot = maildev_handle->qh_ops->read_dquot(maildev_handle, dquot->dq_id);
+ if (mdquot &&
+ ((mdquot->dq_dqb.dqb_bhardlimit && toqb(mdquot->dq_dqb.dqb_curspace) >= mdquot->dq_dqb.dqb_bhardlimit)
+ || ((mdquot->dq_dqb.dqb_bsoftlimit && toqb(mdquot->dq_dqb.dqb_curspace) >= mdquot->dq_dqb.dqb_bsoftlimit)
+ && (mdquot->dq_dqb.dqb_btime && mdquot->dq_dqb.dqb_btime <= now))))
+ return 0;
+ return 1;
}
int check_offence(struct dquot *dquot, char *name)
@@ -591,7 +597,7 @@ int readconfigfile(const char *filename, struct configparams *config)
sstrncpy(config->cc_to, CC_TO, CNF_BUFFER);
sstrncpy(config->support, SUPPORT, CNF_BUFFER);
sstrncpy(config->phone, PHONE, CNF_BUFFER);
- sstrncpy(mailserv, "false", CNF_BUFFER);
+ maildev[0] = 0;
config->user_signature = config->user_message = config->group_signature = config->group_message = NULL;
config->use_ldap_mail = 0;
@@ -655,7 +661,7 @@ int readconfigfile(const char *filename, struct configparams *config)
sstrncpy(config->phone, value, CNF_BUFFER);
else if (!strcmp(var, "MAILSERV")) {
/* set the global */
- sstrncpy(mailserv, value, CNF_BUFFER);
+ sstrncpy(maildev, value, CNF_BUFFER);
} else if (!strcmp(var, "MESSAGE")) {
config->user_message = sstrdup(value);
create_eoln(config->user_message);
@@ -771,6 +777,14 @@ int get_groupadmins(void)
return 0;
}
+struct quota_handle *find_handle_dev(char *dev, struct quota_handle **handles)
+{
+ int i;
+
+ for (i = 0; handles[i] && strcmp(dev, handles[i]->qh_quotadev); i++);
+ return handles[i];
+}
+
void warn_quota(void)
{
struct quota_handle **handles;
@@ -784,6 +798,10 @@ void warn_quota(void)
if (flags & FL_USER) {
handles = create_handle_list(0, NULL, USRQUOTA, -1, IOI_LOCALONLY | IOI_READONLY | IOI_OPENFILE, (flags & FL_NOAUTOFS ? MS_NO_AUTOFS : 0));
+ if (!maildev[0] || !strcasecmp(maildev, "any"))
+ maildev_handle = NULL;
+ else
+ maildev_handle = find_handle_dev(maildev, handles);
for (i = 0; handles[i]; i++)
handles[i]->qh_ops->scan_dquots(handles[i], check_offence);
dispose_handle_list(handles);
@@ -792,6 +810,10 @@ void warn_quota(void)
if (get_groupadmins() < 0)
wc_exit(1);
handles = create_handle_list(0, NULL, GRPQUOTA, -1, IOI_LOCALONLY | IOI_READONLY | IOI_OPENFILE, (flags & FL_NOAUTOFS ? MS_NO_AUTOFS : 0));
+ if (!maildev[0] || !strcasecmp(maildev, "any"))
+ maildev_handle = NULL;
+ else
+ maildev_handle = find_handle_dev(maildev, handles);
for (i = 0; handles[i]; i++)
handles[i]->qh_ops->scan_dquots(handles[i], check_offence);
dispose_handle_list(handles);
diff --git a/warnquota.conf b/warnquota.conf
index ee8a24d..44c2a64 100644
--- a/warnquota.conf
+++ b/warnquota.conf
@@ -28,12 +28,12 @@ I chose you to do the cleanup.|Delete group files on following filesystems:|
GROUP_SIGNATURE = See you!| Your admin|
#
#If you are running warnquota on a mail server, and don't want bounces
-#because clients can not receive mail setting this to true will cause
+#because clients can not receive mail setting this to "any" will cause
#warnquota to not send them mail for all devices. If you set this to the
#device name (for example /dev/hdb1) then they will not be sent mail if they
#are overquota on that device only, and will be sent mail for all other
#devices.
-#MAILSERV = "false"
+#MAILDEV =
#
# If you are using LDAP mail lookups.
# host, port, tls, binddn, and bindpw are straight forward.