diff options
Diffstat (limited to 'mda/lib/mailquota.c')
-rw-r--r-- | mda/lib/mailquota.c | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/mda/lib/mailquota.c b/mda/lib/mailquota.c index 33fb5509b..8c7cf250f 100644 --- a/mda/lib/mailquota.c +++ b/mda/lib/mailquota.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2024 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,32 +51,29 @@ struct mu_cfg_param mda_mailquota_cfg[] = { mu_off_t groupquota = 5*1024*1024UL; static int -get_size (char *str, mu_off_t *size, char **endp) +get_quota (mu_off_t *pquota, const char *str) { - mu_off_t s; - - s = strtol (str, &str, 0); - switch (*str) + size_t n; + char *p; + int rc = mu_strtosize (str, &p, &n); + switch (rc) { case 0: + *pquota = n; break; - case 'k': - case 'K': - s *= 1024; + case ERANGE: + mu_error (_("quota value is out of allowed range: %s"), str); break; - - case 'm': - case 'M': - s *= 1024*1024; + + case MU_ERR_PARSE: + mu_error (_("bad quota value: %s, stopped at %s"), str, p); break; - + default: - *endp = str; - return -1; + mu_diag_funcall (MU_DIAG_ERROR, "mu_strtosize", str, rc); } - *size = s; - return 0; + return rc; } enum { @@ -164,12 +161,10 @@ dbm_retrieve_quota (char *name, mu_off_t *quota) strncpy (buffer, contentd.mu_dptr, contentd.mu_dsize); buffer[contentd.mu_dsize] = 0; + *quota = strtoul (buffer, &p, 0); - if (get_size (buffer, quota, &p)) - { - mu_error (_("bogus mailbox quota for `%s' (near `%s')"), name, p); - *quota = groupquota; - } + if (get_quota (quota, buffer)) + *quota = groupquota; } mu_dbm_datum_free (&contentd); @@ -211,7 +206,8 @@ sql_retrieve_quota (char *name, mu_off_t *quota) mu_sql_module_config.port, mu_sql_module_config.user, mu_sql_module_config.passwd, - mu_sql_module_config.db); + mu_sql_module_config.db, + mu_sql_module_config.param); if (status) { @@ -275,16 +271,10 @@ sql_retrieve_quota (char *name, mu_off_t *quota) } else if (tmp == NULL || tmp[0] == 0 || mu_c_strcasecmp (tmp, "none") == 0) rc = RETR_UNLIMITED; - else + else if (get_quota (quota, tmp)) { - char *p; - - if (get_size (tmp, quota, &p)) - { - mu_error (_("bogus mailbox quota for `%s' (near `%s')"), - name, p); - *quota = groupquota; - } + *quota = groupquota; + rc = RETR_OK; } } |