~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/plugins/expire/doveadm-expire.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "module-dir.h"
33
33
        struct dict_transaction_context *trans;
34
34
        struct dict_iterate_context *iter;
35
35
 
36
 
        struct hash_table *users;
37
 
        ARRAY_DEFINE(queries, struct expire_query);
 
36
        /* username => enum expire_user_state */
 
37
        HASH_TABLE(char *, void *) user_states;
 
38
        ARRAY(struct expire_query) queries;
38
39
        time_t oldest_before_time;
39
40
        bool delete_nonexistent_users;
40
41
};
41
42
 
42
 
const char *doveadm_expire_plugin_version = DOVECOT_VERSION;
 
43
const char *doveadm_expire_plugin_version = DOVECOT_ABI_VERSION;
43
44
 
44
45
void doveadm_expire_plugin_init(struct module *module);
45
46
void doveadm_expire_plugin_deinit(void);
78
79
                DOVEADM_EXPIRE_MAIL_CMD_CONTEXT(ctx);
79
80
        const char *username, *mailbox;
80
81
        enum expire_user_state state;
81
 
        void *key, *value;
 
82
        char *orig_username;
 
83
        void *value;
82
84
 
83
85
        /* dict_key = DICT_EXPIRE_PREFIX<user>/<mailbox> */
84
86
        username = dict_key + strlen(DICT_EXPIRE_PREFIX);
90
92
        }
91
93
        username = t_strdup_until(username, mailbox++);
92
94
 
93
 
        if (!hash_table_lookup_full(ectx->users, username, &key, &value)) {
 
95
        if (!hash_table_lookup_full(ectx->user_states, username,
 
96
                                    &orig_username, &value)) {
94
97
                /* user no longer exists, delete the record */
95
98
                return -1;
96
99
        }
110
113
                /* this mailbox doesn't have any matching messages */
111
114
                return 0;
112
115
        }
113
 
        hash_table_update(ectx->users, key,
114
 
                          POINTER_CAST(EXPIRE_USER_STATE_SEEN));
115
 
        *username_r = key;
 
116
        state = EXPIRE_USER_STATE_SEEN;
 
117
        hash_table_update(ectx->user_states, orig_username,
 
118
                          POINTER_CAST(state));
 
119
        *username_r = orig_username;
116
120
        return 1;
117
121
}
118
122
 
166
170
{
167
171
        ARRAY_TYPE(const_string) patterns;
168
172
        const char *str;
169
 
        char set_name[20];
 
173
        char set_name[6+MAX_INT_STRLEN+1];
170
174
        unsigned int i;
171
175
 
172
176
        t_array_init(&patterns, 16);
174
178
        for (i = 2; str != NULL; i++) {
175
179
                array_append(&patterns, &str, 1);
176
180
 
177
 
                i_snprintf(set_name, sizeof(set_name), "expire%u", i);
 
181
                if (i_snprintf(set_name, sizeof(set_name), "expire%u", i) < 0)
 
182
                        i_unreached();
178
183
                str = doveadm_plugin_getenv(set_name);
179
184
        }
180
 
        (void)array_append_space(&patterns);
 
185
        array_append_zero(&patterns);
181
186
        return array_idx(&patterns, 0);
182
187
}
183
188
 
350
355
 
351
356
        if (ectx->iter != NULL) {
352
357
                if (dict_iterate_deinit(&ectx->iter) < 0)
353
 
                        i_error("Dictionary iteration failed");
 
358
                        i_error("expire: Dictionary iteration failed");
354
359
        }
355
 
        dict_transaction_commit(&ectx->trans);
 
360
        if (dict_transaction_commit(&ectx->trans) < 0)
 
361
                i_error("expire: Dictionary commit failed");
356
362
        dict_deinit(&ectx->dict);
357
 
        hash_table_destroy(&ectx->users);
 
363
        hash_table_destroy(&ectx->user_states);
358
364
 
359
365
        ectx->module_ctx.super.deinit(ctx);
360
366
}
364
370
        struct doveadm_expire_mail_cmd_context *ectx;
365
371
        struct dict *dict;
366
372
        const struct expire_query *query;
367
 
        const char *expire_dict, *username, *value;
 
373
        const char *expire_dict, *username, *value, *error;
368
374
        char *username_dup;
 
375
        enum expire_user_state state;
369
376
 
370
377
        if (ctx->search_args == NULL)
371
378
                return;
374
381
        if (expire_dict == NULL)
375
382
                return;
376
383
 
377
 
        if (ctx->iterate_single_user) {
 
384
        /* doveadm proxying uses expire database only locally. the remote
 
385
           doveadm handles each user one at a time (even though
 
386
           iterate_single_user=FALSE) */
 
387
        if (ctx->iterate_single_user || ctx->proxying) {
378
388
                if (doveadm_debug) {
379
389
                        i_debug("expire: Iterating only a single user, "
380
390
                                "ignoring expire database");
397
407
        if (doveadm_debug)
398
408
                i_debug("expire: Searching only users listed in expire database");
399
409
 
400
 
        dict = dict_init(expire_dict, DICT_DATA_TYPE_UINT32, "",
401
 
                         doveadm_settings->base_dir);
402
 
        if (dict == NULL) {
403
 
                i_error("dict_init(%s) failed, not using it", expire_dict);
 
410
        if (dict_init(expire_dict, DICT_DATA_TYPE_UINT32, "",
 
411
                      doveadm_settings->base_dir, &dict, &error) < 0) {
 
412
                i_error("dict_init(%s) failed, not using it: %s",
 
413
                        expire_dict, error);
404
414
                return;
405
415
        }
406
416
 
414
424
        ctx->v.deinit = doveadm_expire_mail_cmd_deinit;
415
425
        ctx->v.get_next_user = doveadm_expire_mail_cmd_get_next_user;
416
426
 
417
 
        ectx->users =
418
 
                hash_table_create(default_pool, ctx->pool, 0,
419
 
                                  str_hash, (hash_cmp_callback_t *)strcmp);
 
427
        hash_table_create(&ectx->user_states, ctx->pool, 0, str_hash, strcmp);
420
428
        while (mail_storage_service_all_next(ctx->storage_service, &username) > 0) {
421
429
                username_dup = p_strdup(ctx->pool, username);
422
 
                hash_table_insert(ectx->users, username_dup,
423
 
                                  POINTER_CAST(EXPIRE_USER_STATE_EXISTS));
 
430
                state = EXPIRE_USER_STATE_EXISTS;
 
431
                hash_table_insert(ectx->user_states, username_dup,
 
432
                                  POINTER_CAST(state));
424
433
        }
425
434
 
426
435
        ectx->dict = dict;