diff options
author | jkar8572 <jkar8572> | 2004-03-12 18:08:52 +0000 |
---|---|---|
committer | jkar8572 <jkar8572> | 2004-03-12 18:08:52 +0000 |
commit | e690fa51db6769773ed8d44807a371d66389505e (patch) | |
tree | 4b78ed06a95d0e85da3290df64e73933b68c7bb5 | |
parent | 1aee062af4f7fef4a40b275c198e2c75605ce409 (diff) |
Added CC_BEFORE config option to warnquota(8)
-rw-r--r-- | Changelog | 2 | ||||
-rw-r--r-- | warnquota.c | 37 | ||||
-rw-r--r-- | warnquota.conf | 6 |
3 files changed, 42 insertions, 3 deletions
@@ -5,6 +5,8 @@ Changes in quota-tools from 3.11 to 3.12 * fixed compiler warning in quotacheck.c (Peter Breitenlohner) * added config option for putting some important binaries to /sbin regardless $(prefix) (Jan Kara) +* added config option to warnquota(8) for CCing admin only specified amount of + time before grace time runs out (Jan Kara) Changes in quota-tools from 3.10 to 3.11 * quota-tools should again use old RPC protocol when needed (Jan Kara) diff --git a/warnquota.c b/warnquota.c index b1a4eb7..bc4eacb 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.19 2004/01/09 11:27:45 jkar8572 Exp $ + * Version: $Id: warnquota.c,v 1.20 2004/03/12 18:08:52 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 @@ -105,6 +105,7 @@ struct configparams { char *group_message; char *group_signature; int use_ldap_mail; /* 0 */ + time_t cc_before; #ifdef USE_LDAP_MAIL_LOOKUP int ldap_is_setup; /* 0 */ char ldap_host[CNF_BUFFER]; @@ -304,6 +305,25 @@ int admin_name_cmp(const void *key, const void *mem) return strcmp(key, ((struct adminstable *)mem)->grpname); } +int should_cc(struct offenderlist *offender, struct configparams *config) +{ + struct usage *lptr; + struct util_dqblk *dqb; + time_t atime; + + if (config->cc_before == -1) + return 1; + time(&atime); + for (lptr = offender->usage; lptr; lptr = lptr->next) { + dqb = &lptr->dq_dqb; + if (dqb->dqb_bsoftlimit && dqb->dqb_bsoftlimit <= toqb(dqb->dqb_curspace) && dqb->dqb_btime-config->cc_before <= atime) + return 1; + if (dqb->dqb_isoftlimit && dqb->dqb_isoftlimit <= dqb->dqb_curinodes && dqb->dqb_itime-config->cc_before <= atime) + return 1; + } + return 0; +} + int mail_user(struct offenderlist *offender, struct configparams *config) { struct usage *lptr; @@ -414,7 +434,8 @@ int mail_user(struct offenderlist *offender, struct configparams *config) fprintf(fp, "Reply-To: %s\n", config->support); fprintf(fp, "Subject: %s\n", config->subject); fprintf(fp, "To: %s\n", to); - fprintf(fp, "Cc: %s\n", config->cc_to); + if (should_cc(offender, config)) + fprintf(fp, "Cc: %s\n", config->cc_to); fprintf(fp, "\n"); free(to); @@ -605,6 +626,7 @@ int readconfigfile(const char *filename, struct configparams *config) maildev[0] = 0; config->user_signature = config->user_message = config->group_signature = config->group_message = NULL; config->use_ldap_mail = 0; + config->cc_before = -1; #ifdef USE_LDAP_MAIL_LOOKUP config->ldap_port = config->ldap_is_setup = 0; @@ -689,6 +711,17 @@ int readconfigfile(const char *filename, struct configparams *config) else config->use_ldap_mail = 0; } + else if (!strcmp(var, "CC_BEFORE")) { + int num; + char unit[10]; + + if (sscanf(value, "%d%s", &num, unit) != 2) + goto cc_parse_err; + if (str2timeunits(num, unit, &config->cc_before) < 0) { +cc_parse_err: + errstr(_("Cannot parse time at CC_BEFORE variable (line %d).\n"), line); + } + } #ifdef USE_LDAP_MAIL_LOOKUP else if (!strcmp(var, "LDAP_HOST")) sstrncpy(config->ldap_host, value, CNF_BUFFER); diff --git a/warnquota.conf b/warnquota.conf index 44c2a64..653f92c 100644 --- a/warnquota.conf +++ b/warnquota.conf @@ -9,6 +9,10 @@ FROM = "bas@localhost" # but they don't have to be: SUBJECT = Hey, user, clean up your account! CC_TO = "sysadm@localhost" +# If you set this variable CC will be used only when user has less than +# specified grace time left (examples of possible times: 5 seconds, 1 minute, +# 12 hours, 5 days) +# CC_BEFORE = 2 days SUPPORT = "support@myhost.com" PHONE = "(123) 456-1111 or (222) 333-4444" # Text in the beginning of the mail (if not specified, default text is used) @@ -28,7 +32,7 @@ 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 "any" will cause +#because clients cannot 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 |