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

« back to all changes in this revision

Viewing changes to .pc/split-protocols.patch/src/master/master-settings.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 "common.h"
4
4
#include "array.h"
5
5
#include "env-util.h"
6
6
#include "istream.h"
7
 
#include "network.h"
 
7
#include "net.h"
8
8
#include "str.h"
9
9
#include "ipwd.h"
10
10
#include "mkdir-parents.h"
64
64
        DEF(SET_STR, address),
65
65
        DEF(SET_UINT, port),
66
66
        DEF(SET_BOOL, ssl),
 
67
        DEF(SET_BOOL, reuse_port),
67
68
 
68
69
        SETTING_DEFINE_LIST_END
69
70
};
72
73
        .name = "",
73
74
        .address = "",
74
75
        .port = 0,
75
 
        .ssl = FALSE
 
76
        .ssl = FALSE,
 
77
        .reuse_port = FALSE
76
78
};
77
79
 
78
80
static const struct setting_parser_info inet_listener_setting_parser_info = {
171
173
 
172
174
static const struct setting_define master_setting_defines[] = {
173
175
        DEF(SET_STR, base_dir),
 
176
        DEF(SET_STR, state_dir),
174
177
        DEF(SET_STR, libexec_dir),
175
178
        DEF(SET_STR, instance_name),
176
179
        DEF(SET_STR, import_environment),
211
214
 
212
215
static const struct master_settings master_default_settings = {
213
216
        .base_dir = PKG_RUNDIR,
 
217
        .state_dir = PKG_STATEDIR,
214
218
        .libexec_dir = PKG_LIBEXECDIR,
215
219
        .instance_name = PACKAGE,
216
 
        .import_environment = "TZ" ENV_SYSTEMD ENV_GDB,
 
220
        .import_environment = "TZ DEBUG_OUTOFMEM" ENV_SYSTEMD ENV_GDB,
217
221
        .protocols = "imap pop3 lmtp",
218
222
        .listen = "*, ::",
219
223
        .ssl = "yes:no:required",
415
419
        const struct service_settings *default_service;
416
420
#else
417
421
        rlim_t fd_limit;
418
 
        const char *max_client_limit_source = "default_client_count";
 
422
        const char *max_client_limit_source = "default_client_limit";
419
423
        unsigned int max_client_limit = set->default_client_limit;
420
424
#endif
421
425
 
496
500
        for (i = 0; i < count; i++) {
497
501
                struct service_settings *service = services[i];
498
502
 
499
 
                if (*service->executable == '\0') {
500
 
                        *error_r = t_strdup_printf("service(%s): "
501
 
                                "executable is empty", service->name);
502
 
                        return FALSE;
 
503
                if (*service->protocol != '\0' &&
 
504
                    !str_array_find((const char **)set->protocols_split,
 
505
                                    service->protocol)) {
 
506
                        /* protocol not enabled, ignore its settings */
 
507
                        continue;
503
508
                }
504
 
                if (*service->executable != '/') {
 
509
 
 
510
                if (*service->executable != '/' &&
 
511
                    *service->executable != '\0') {
505
512
                        service->executable =
506
513
                                p_strconcat(pool, set->libexec_dir, "/",
507
514
                                            service->executable, NULL);
550
557
                }
551
558
#endif
552
559
 
553
 
                if (*service->protocol != '\0' &&
554
 
                    str_array_find((const char **)set->protocols_split,
555
 
                                   service->protocol)) {
 
560
                if (*service->protocol != '\0') {
556
561
                        /* each imap/pop3/lmtp process can use up a connection,
557
562
                           although if service_count=1 it's only temporary */
558
563
                        if (service->service_count != 1 ||
708
713
        (void)closedir(dirp);
709
714
}
710
715
 
711
 
bool master_settings_do_fixes(const struct master_settings *set)
 
716
static void
 
717
mkdir_login_dir(const struct master_settings *set, const char *login_dir)
712
718
{
713
 
        const char *login_dir, *empty_dir;
714
 
        struct stat st;
 
719
        mode_t mode;
715
720
        gid_t gid;
716
721
 
717
 
        /* since base dir is under /var/run by default, it may have been
718
 
           deleted. */
719
 
        if (mkdir_parents(set->base_dir, 0755) < 0 && errno != EEXIST) {
720
 
                i_error("mkdir(%s) failed: %m", set->base_dir);
721
 
                return FALSE;
722
 
        }
723
 
        /* allow base_dir to be a symlink, so don't use lstat() */
724
 
        if (stat(set->base_dir, &st) < 0) {
725
 
                i_error("stat(%s) failed: %m", set->base_dir);
726
 
                return FALSE;
727
 
        }
728
 
        if (!S_ISDIR(st.st_mode)) {
729
 
                i_error("%s is not a directory", set->base_dir);
730
 
                return FALSE;
731
 
        }
732
 
        if ((st.st_mode & 0755) != 0755) {
733
 
                i_warning("Fixing permissions of %s to be world-readable",
734
 
                          set->base_dir);
735
 
                if (chmod(set->base_dir, 0755) < 0)
736
 
                        i_error("chmod(%s) failed: %m", set->base_dir);
737
 
        }
738
 
 
739
 
        /* Make sure our permanent state directory exists */
740
 
        if (mkdir_parents(PKG_STATEDIR, 0750) < 0 && errno != EEXIST) {
741
 
                i_error("mkdir(%s) failed: %m", PKG_STATEDIR);
742
 
                return FALSE;
743
 
        }
744
 
 
745
 
        login_dir = t_strconcat(set->base_dir, "/login", NULL);
746
722
        if (settings_have_auth_unix_listeners_in(set, login_dir)) {
747
723
                /* we are not using external authentication, so make sure the
748
724
                   login directory exists with correct permissions and it's
749
725
                   empty. with external auth we wouldn't want to delete
750
726
                   existing sockets or break the permissions required by the
751
727
                   auth server. */
752
 
                mode_t mode = login_want_core_dumps(set, &gid) ? 0770 : 0750;
 
728
                mode = login_want_core_dumps(set, &gid) ? 0770 : 0750;
753
729
                if (safe_mkdir(login_dir, mode, master_uid, gid) == 0) {
754
730
                        i_warning("Corrected permissions for login directory "
755
731
                                  "%s", login_dir);
758
734
                unlink_sockets(login_dir, "");
759
735
        } else {
760
736
                /* still make sure that login directory exists */
761
 
                if (mkdir(login_dir, 0755) < 0 && errno != EEXIST) {
762
 
                        i_error("mkdir(%s) failed: %m", login_dir);
763
 
                        return FALSE;
764
 
                }
765
 
        }
 
737
                if (mkdir(login_dir, 0755) < 0 && errno != EEXIST)
 
738
                        i_fatal("mkdir(%s) failed: %m", login_dir);
 
739
        }
 
740
}
 
741
 
 
742
void master_settings_do_fixes(const struct master_settings *set)
 
743
{
 
744
        const char *empty_dir;
 
745
        struct stat st;
 
746
 
 
747
        /* since base dir is under /var/run by default, it may have been
 
748
           deleted. */
 
749
        if (mkdir_parents(set->base_dir, 0755) < 0 && errno != EEXIST)
 
750
                i_fatal("mkdir(%s) failed: %m", set->base_dir);
 
751
        /* allow base_dir to be a symlink, so don't use lstat() */
 
752
        if (stat(set->base_dir, &st) < 0)
 
753
                i_fatal("stat(%s) failed: %m", set->base_dir);
 
754
        if (!S_ISDIR(st.st_mode))
 
755
                i_fatal("%s is not a directory", set->base_dir);
 
756
        if ((st.st_mode & 0755) != 0755) {
 
757
                i_warning("Fixing permissions of %s to be world-readable",
 
758
                          set->base_dir);
 
759
                if (chmod(set->base_dir, 0755) < 0)
 
760
                        i_error("chmod(%s) failed: %m", set->base_dir);
 
761
        }
 
762
 
 
763
        /* Make sure our permanent state directory exists */
 
764
        if (mkdir_parents(set->state_dir, 0755) < 0 && errno != EEXIST)
 
765
                i_fatal("mkdir(%s) failed: %m", set->state_dir);
 
766
 
 
767
        mkdir_login_dir(set, t_strconcat(set->base_dir, "/login", NULL));
 
768
        mkdir_login_dir(set, t_strconcat(set->base_dir, "/token-login", NULL));
766
769
 
767
770
        empty_dir = t_strconcat(set->base_dir, "/empty", NULL);
768
771
        if (safe_mkdir(empty_dir, 0755, master_uid, getegid()) == 0) {
769
772
                i_warning("Corrected permissions for empty directory "
770
773
                          "%s", empty_dir);
771
774
        }
772
 
        return TRUE;
773
775
}