quota.c revision 89adb28d8f041e8c0b9c5156f089bb2f8f478ee3
/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "mailbox-list-private.h"
#include "maildir-storage.h"
#include "quota-private.h"
#include "quota-fs.h"
#include <ctype.h>
#include <stdlib.h>
#define DEFAULT_QUOTA_EXCEEDED_MSG \
"Quota exceeded (mailbox for user is full)"
#define RULE_NAME_DEFAULT_FORCE "*"
#define RULE_NAME_DEFAULT_NONFORCE "?"
struct quota_root_iter {
unsigned int i;
};
unsigned int quota_module_id = 0;
extern struct quota_backend quota_backend_dict;
extern struct quota_backend quota_backend_dirsize;
extern struct quota_backend quota_backend_fs;
extern struct quota_backend quota_backend_maildir;
static const struct quota_backend *quota_backends[] = {
#ifdef HAVE_FS_QUOTA
#endif
};
struct quota_settings *quota_settings_init(void)
{
struct quota_settings *quota_set;
return quota_set;
}
{
*_quota_set = NULL;
}
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(quota_backends); i++) {
return quota_backends[i];
}
return NULL;
}
struct quota_root_settings *
{
struct quota_root_settings *root_set;
const struct quota_backend *backend;
const char *p, *args, *backend_name;
/* <backend>[:<quota root name>[:<backend args>]] */
if (p == NULL) {
} else {
args = p + 1;
}
return NULL;
}
/* save root's name */
if (p == NULL) {
} else {
args = p + 1;
}
} else {
}
i_info("Quota root: name=%s backend=%s args=%s",
}
return root_set;
}
static struct quota_root *
{
struct quota_root *root;
const char *const *tmp;
sizeof(void *), 10);
else
break;
}
i_fatal("Quota root %s backend %s: "
"Unknown parameter: %s",
}
}
return root;
}
{
pool_unref(&pool);
}
{
struct quota_root *root;
struct quota_root_settings *const *root_sets;
unsigned int i, count;
for (i = 0; i < count; i++) {
}
return quota;
}
{
struct quota_root *const *roots;
unsigned int i, count;
for (i = 0; i < count; i++)
quota_root_deinit(roots[i]);
}
struct quota_rule *
{
struct quota_rule *rules;
unsigned int i, count;
for (i = 0; i < count; i++) {
return &rules[i];
}
return NULL;
}
static int
struct quota_rule *rule,
{
"Invalid rule percentage: %lld", (long long)percentage);
return -1;
}
*error_r = "Default rule can't be a percentage";
return -1;
}
else
i_unreached();
return 0;
}
static void
const struct quota_rule *default_rule)
{
if (rule->bytes_percent > 0) {
}
if (rule->count_percent > 0) {
}
}
{
struct quota_rule *rules;
struct quota_warning_rule *warning_rules;
unsigned int i, count;
for (i = 0; i < count; i++) {
&root_set->default_rule);
}
for (i = 0; i < count; i++) {
&root_set->default_rule);
}
}
static int
bool allow_negative, const char **error_r)
{
const char **args;
char *p;
multiply = 1;
multiply = 1024;
} else {
"Unknown rule limit name: %s", *args);
return -1;
}
switch (i_toupper(*p)) {
case '\0':
/* default */
break;
case 'B':
multiply = 1;
break;
case 'K':
multiply = 1024;
break;
case 'M':
break;
case 'G':
break;
case 'T':
break;
case '%':
multiply = 0;
error_r) < 0)
return -1;
break;
default:
"Invalid rule limit value: %s", *args);
return -1;
}
}
if (!allow_negative) {
if (rule->bytes_limit < 0) {
*error_r = "Bytes limit can't be negative";
return -1;
}
if (rule->count_limit < 0) {
*error_r = "Count limit can't be negative";
return -1;
}
}
return 0;
}
{
struct quota_rule *rule;
const char *p, *mailbox_name;
int ret = 0;
if (p == NULL) {
*error_r = "Invalid rule";
return -1;
}
/* <mailbox name>:<quota limits> */
} else {
rule->mailbox_name =
}
}
if (strcmp(p, "ignore") == 0) {
i_info("Quota rule: root=%s mailbox=%s ignored",
}
return 0;
}
p + 8, error_r))
ret = -1;
} else {
allow_negative, error_r) < 0)
ret = -1;
}
i_info("Quota rule: root=%s mailbox=%s "
}
return ret;
}
const char *mailbox_name,
{
struct quota_rule *rule;
bool found;
/* if default rule limits are 0, this rule applies only to specific
mailboxes */
} else {
bytes_limit = 0;
count_limit = 0;
}
}
return found;
}
{
/* FIXME: a bit ugly location for this code. */
/* For newly generated filenames add ,S=size. */
struct maildir_storage *mstorage =
(struct maildir_storage *)storage;
}
}
{
struct quota_root *const *roots;
struct mail_storage *const *storages;
struct quota_backend **backends;
unsigned int i, j, count;
bool is_file;
/* first check if there already exists a storage with the exact same
path. we don't want to count them twice. */
for (i = 0; i < count; i++) {
&is_file);
/* duplicate */
return;
}
}
}
/* @UNSAFE: get different backends into one array */
for (i = 0; i < count; i++) {
break;
}
}
}
}
{
struct mail_storage *const *storages;
unsigned int i, count;
/* no quota for this storage */
return;
}
for (i = 0; i < count; i++) {
break;
}
}
}
{
struct quota_warning_rule *warning;
struct quota_rule rule;
const char *p;
int ret;
if (p == NULL) {
*error_r = "No command specified";
return -1;
}
t_strdup_until(rule_def, p),
if (ret < 0)
return -1;
i_info("Quota warning: bytes=%llu (%u%%) "
"messages=%llu (%u%%) command=%s",
}
return 0;
}
struct quota_root_iter *
{
struct quota_root_iter *iter;
return iter;
}
static bool
bool enforce)
{
/* we don't want to include this root in quota enforcing */
return FALSE;
}
/* a single quota root: don't bother checking further */
return TRUE;
}
}
{
unsigned int count;
int ret;
return NULL;
continue;
if (ret == -1) {
}
if (ret == 0) {
}
if (ret > 0) {
break;
}
}
iter->i++;
return root;
}
{
}
{
struct quota_root *const *roots;
unsigned int i, count;
for (i = 0; i < count; i++) {
return roots[i];
}
return NULL;
}
{
}
{
}
{
int ret;
}
/* Get the value first. This call may also update quota limits if
they're defined externally. */
if (ret <= 0)
return ret;
&bytes_limit, &count_limit);
*limit_r = bytes_limit;
*limit_r = count_limit;
else
*limit_r = 0;
if (kilobytes) {
*value_r /= 1024;
*limit_r /= 1024;
}
return *limit_r == 0 ? 0 : 1;
}
const char *name ATTR_UNUSED,
{
/* the quota information comes from userdb (or even config file),
so there's really no way to support this until some major changes
are done */
return -1;
}
{
struct quota_transaction_context *ctx;
return ctx;
}
{
struct quota_root *const *roots;
const char *mailbox_name;
unsigned int i, count;
int ret;
/* find the lowest quota limits from all roots and use them */
for (i = 0; i < count; i++) {
continue;
&bytes_limit, &count_limit);
if (bytes_limit > 0) {
if (ret > 0) {
} else if (ret < 0) {
return -1;
}
}
if (count_limit > 0) {
if (ret > 0) {
} else if (ret < 0) {
return -1;
}
}
}
return 0;
}
{
int ret;
if (ret < 0) {
} else if (WIFSIGNALED(ret)) {
i_error("system(%s) exited with status %d",
}
}
struct quota_root *root)
{
struct quota_warning_rule *warnings;
unsigned int i, count;
if (count == 0)
return;
&bytes_current, &bytes_limit) < 0)
return;
&count_current, &count_limit) < 0)
return;
for (i = 0; i < count; i++) {
break;
}
}
}
{
struct quota_rule *rule;
struct quota_root *const *roots;
unsigned int i, count;
const char *mailbox_name;
int ret = 0;
ret = -1;
ctx->recalculate) {
for (i = 0; i < count; i++) {
continue;
/* mailbox not included in quota */
continue;
}
ret = -1;
}
/* execute quota warnings after all updates. this makes it
work correctly regardless of whether backend.get_resource()
returns updated values before backend.update() or not */
for (i = 0; i < count; i++)
}
return ret;
}
{
}
{
int ret;
return -1;
if (ret <= 0)
return ret;
return 1;
}
{
return -1;
if (!ctx->limits_set) {
if (quota_transaction_set_limits(ctx) < 0)
return -1;
}
}
{
struct quota_root *const *roots;
unsigned int i, count;
*too_large_r = FALSE;
return 1;
for (i = 0; i < count; i++) {
continue;
if (!quota_root_get_rule_limits(roots[i],
&bytes_limit, &count_limit))
continue;
/* if size is bigger than any limit, then
it is bigger than the lowest limit */
if (size > bytes_limit) {
*too_large_r = TRUE;
break;
}
}
return 0;
}
{
ctx->count_used++;
}
{
else
}
{
ctx->count_used--;
}
{
}