~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/indexer/indexer-worker.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-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/{control,rules}: enable PIE hardening.
  + 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.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2011-2012 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "restrict-access.h"
 
5
#include "mail-storage-service.h"
 
6
#include "mail-storage-settings.h"
 
7
#include "master-service.h"
 
8
#include "master-service-settings.h"
 
9
#include "master-connection.h"
 
10
 
 
11
static struct master_connection *master_conn;
 
12
static struct mail_storage_service_ctx *storage_service;
 
13
 
 
14
static void client_connected(struct master_service_connection *conn)
 
15
{
 
16
        if (master_conn != NULL) {
 
17
                i_error("indexer-worker must be configured with client_limit=1");
 
18
                return;
 
19
        }
 
20
 
 
21
        master_service_client_connection_accept(conn);
 
22
        master_conn = master_connection_create(conn->fd, storage_service);
 
23
}
 
24
 
 
25
static void drop_privileges(void)
 
26
{
 
27
        struct restrict_access_settings set;
 
28
        const char *error;
 
29
 
 
30
        /* by default we don't drop any privileges, but keep running as root. */
 
31
        restrict_access_get_env(&set);
 
32
        if (set.uid != 0) {
 
33
                /* open config connection before dropping privileges */
 
34
                struct master_service_settings_input input;
 
35
                struct master_service_settings_output output;
 
36
 
 
37
                memset(&input, 0, sizeof(input));
 
38
                input.module = "mail";
 
39
                input.service = "indexer-worker";
 
40
                (void)master_service_settings_read(master_service,
 
41
                                                   &input, &output, &error);
 
42
        }
 
43
        restrict_access_by_env(NULL, FALSE);
 
44
}
 
45
 
 
46
int main(int argc, char *argv[])
 
47
{
 
48
        enum mail_storage_service_flags storage_service_flags =
 
49
                MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT |
 
50
                MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP |
 
51
                MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP |
 
52
                MAIL_STORAGE_SERVICE_FLAG_NO_IDLE_TIMEOUT;
 
53
        int c;
 
54
 
 
55
        master_service = master_service_init("indexer-worker", 0,
 
56
                                             &argc, &argv, "D");
 
57
        while ((c = master_getopt(master_service)) > 0) {
 
58
                switch (c) {
 
59
                case 'D':
 
60
                        storage_service_flags |=
 
61
                                MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS;
 
62
                        break;
 
63
                default:
 
64
                        return FATAL_DEFAULT;
 
65
                }
 
66
        }
 
67
 
 
68
        drop_privileges();
 
69
        master_service_init_log(master_service, "indexer-worker: ");
 
70
        master_service_init_finish(master_service);
 
71
 
 
72
        storage_service = mail_storage_service_init(master_service, NULL,
 
73
                                                    storage_service_flags);
 
74
        restrict_access_allow_coredumps(TRUE);
 
75
 
 
76
        master_service_run(master_service, client_connected);
 
77
 
 
78
        if (master_conn != NULL)
 
79
                master_connection_destroy(&master_conn);
 
80
        mail_storage_service_deinit(&storage_service);
 
81
        master_service_deinit(&master_service);
 
82
        return 0;
 
83
}