~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101901

« back to all changes in this revision

Viewing changes to src/deliver/auth-client.c

  • Committer: Chuck Short
  • Date: 2010-01-21 20:21:25 UTC
  • mfrom: (4.1.11 squeeze)
  • Revision ID: zulcss@ubuntu.com-20100121202125-pme73o491kfwj5nc
* Merge from debian testing, remaining changes:
  + Add new binary pkg dovecot-postfix that integrates postfix and dovecot
    automatically: (LP: #164837)
  + debian/control:
    - add new binary with short description
    - set Architecture all for dovecot-postfix (LP: #329878)
  + debian/dovecot-postfix.postinst:
    - create initial certificate symlinks to snakeoil.
    - set up postfix with postconf to:
      - use Maildir/ as the default mailbox.
      - use dovecot as the sasl authentication server.
      - use dovecot LDA (deliver).
      - use tls for smtp{d} services.
    - fix certificates paths in postfix' main.cf
    - add reject_unauth_destination to postfix' recipient restrictions
    - add reject_unknown_sender_domain to postfix' sender restriction
    - rename configuration name on remove, delete on purge
    - restart dovecot after linking certificates
    - handle use case when postfix is unconfigurated
  + debian/dovecot-postfix.dirs: create backup directory for postfix's config
    configuration
  + restart postfix and dovecot.
  + debian/dovecot-postfix.postrm:
    - remove all dovecot related configuration from postfix.
    - restart postfix and dovecot.
  + debian/dovecot-common.init:
    - check if /etc/dovecot/dovecot-postfix.conf exists and use it
      as the configuration file if so.
  + debian/patches/warning-ubuntu-postfix.dpatch
    - add warning about dovecot-postfix.conf in dovecot default
      configuration file
  + debian/patches/dovecot-postfix.conf.diff:
    - Ubuntu server custom changes to the default dovecot configuration for
      better interfation with postfix.
    - enable sieve plugin.
    - Ubuntu server custom changes to the default dovecot configuration for
      better integration with postfix:
      - enable imap, pop3, imaps, pop3s and managesieve by default.
      - enable dovecot LDA (deliver).
      - enable SASL auth socket in postfix private directory
   + debian/rules:
     - copy, patch and install dovecot-postfix.conf in /etc/dovecot/.
     - build architecure independent packages too
   + Use Snakeoil SSL certificates by default.
     - debian/control: Depend on ssl-cert.
     - debian/patches/ssl-cert-snakeoil.dpatch: Change default SSL cert
       paths to snakeoil.
     - debian/dovecot-common.postinst: Relax grep for SSL_* a bit.
   + Add autopkgtest to debian/tests/*.
   + Fast TearDown: Update the lsb init header to not stop in level 6.
   + Add ufw integration:
     - Created debian/dovecot-common.ufw.profile.
     - debian/rules: install profile.
     - debian/control: suggest ufw.
   + debian/{control,rules}: enable PIE hardening.
   + dovecot-imapd, dovecot-pop3: Replaces dovecot-common (<< 1:1.1). (LP: #254721)
   + debian/control: Update Vcs-* headers.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
* New upstream release.
* debian/patches/gold-fix.patch: Removed. Fixed upstream.
* Moved libexec to lib corrections in dovecot-managesieve.patch and
  dovecot-managesieve-dist.patch to dovecot-example.patch
* debian/patches/dovecot-mboxlocking.patch: Regenerated to avoid FTBFS
  when quilt isn't installed.
* debian/patches/quota-mountpoint.patch: Removed. Not needed anymore.
* debian/patches/dovecot-quota.patch: Removed. Quotas aren't properly
  enabled unless mail_plugins = quota imap_quota.
* debian/patches/gold-fix.patch: Fixed configure script to build even
  with binutils-gold or --no-add-needed linker flag (Closes: #554306)
* debian/dovecot-common.init: fixed LSB headers. Thanks to Pascal Volk.
  (Closes: #558040)
* debian/changelog: added CVE references to previous changelog entry.
* debian/rules: checked up the build system. It's not fragile anymore.
  (Closes: 493803)
* debian/dovecot-common.postinst: Now invoking dpkg-reconfigure
  on dovecot-common is enough to generate new certificates
  if the previous ones were removed. (Closes: #545582)
* debian/rules: No longer install convert-tool in /usr/bin.
  It isn't an user utility and it should stay in /usr/lib/dovecot
  like all other similar tool.
* New upstream release. (Closes: #557601)
* [SECURITY] Fixes local information disclosure and denial of service.
  (see: http://www.dovecot.org/list/dovecot-news/2009-November/000143.html
  and CVE-2009-3897)
* Added myself to uploaders.
* Switched to the new source format "3.0 (quilt)":
  - removed dpatch from build-depends
  - removed debian/README.source because now we use only standard
    dpkg features
  - regenerated all patches
* Prepared to switch to multi-origin source:
  - recreated dovecot-libsieve.patch and dovecot-managesieve-dist.patch
    starting from the upstream tarball
  - removed all autotools related build-depends and build-conflict
  - renamed dovecot-libsieve and dovecot-managesieve directories
    to libsieve and managesieve.
* debian/rules: Moved the configuration of libsieve and managesieve from
  the build phase to the configuration phase
* Added dovecot-dbg package  with debugging symbols.  Thanks Stephan Bosch.
  (Closes: #554710)
* Fixed some stray libexec'isms in the default configuration.
* New upstream release.
* debian/dovecot-common.init:
  - use $CONF when starting the daemon. (Closes: #549944)
  - always output start/stop messages. (Closes: #523810)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
2
 
 
3
 
#include "lib.h"
4
 
#include "array.h"
5
 
#include "ioloop.h"
6
 
#include "network.h"
7
 
#include "istream.h"
8
 
#include "ostream.h"
9
 
#include "env-util.h"
10
 
#include "restrict-access.h"
11
 
#include "auth-client.h"
12
 
#include "auth-master.h"
13
 
 
14
 
#include <stdlib.h>
15
 
#include <unistd.h>
16
 
#include <pwd.h>
17
 
#include <grp.h>
18
 
#include <sysexits.h>
19
 
 
20
 
static bool parse_uid(const char *str, uid_t *uid_r)
21
 
{
22
 
        struct passwd *pw;
23
 
        char *p;
24
 
 
25
 
        if (*str >= '0' && *str <= '9') {
26
 
                *uid_r = (uid_t)strtoul(str, &p, 10);
27
 
                if (*p == '\0')
28
 
                        return TRUE;
29
 
        }
30
 
 
31
 
        pw = getpwnam(str);
32
 
        if (pw == NULL)
33
 
                return FALSE;
34
 
 
35
 
        *uid_r = pw->pw_uid;
36
 
        return TRUE;
37
 
}
38
 
 
39
 
static bool parse_gid(const char *str, gid_t *gid_r)
40
 
{
41
 
        struct group *gr;
42
 
        char *p;
43
 
 
44
 
        if (*str >= '0' && *str <= '9') {
45
 
                *gid_r = (gid_t)strtoul(str, &p, 10);
46
 
                if (*p == '\0')
47
 
                        return TRUE;
48
 
        }
49
 
 
50
 
        gr = getgrnam(str);
51
 
        if (gr == NULL)
52
 
                return FALSE;
53
 
 
54
 
        *gid_r = gr->gr_gid;
55
 
        return TRUE;
56
 
}
57
 
 
58
 
static int set_env(struct auth_user_reply *reply,
59
 
                   const char *user, uid_t euid)
60
 
{
61
 
        const char *extra_groups;
62
 
        unsigned int len;
63
 
 
64
 
        if (reply->uid == 0) {
65
 
                i_error("userdb(%s) returned 0 as uid", user);
66
 
                return -1;
67
 
        } else if (reply->uid == (uid_t)-1) {
68
 
                if (getenv("MAIL_UID") != NULL) {
69
 
                        if (!parse_uid(getenv("MAIL_UID"), &reply->uid) ||
70
 
                            reply->uid == 0) {
71
 
                                i_error("mail_uid setting is invalid");
72
 
                                return -1;
73
 
                        }
74
 
                } else {
75
 
                        i_error("User %s is missing UID (set mail_uid)", user);
76
 
                        return -1;
77
 
                }
78
 
        }
79
 
        if (reply->gid == 0) {
80
 
                i_error("userdb(%s) returned 0 as gid", user);
81
 
                return -1;
82
 
        } else if (reply->gid == (gid_t)-1) {
83
 
                if (getenv("MAIL_GID") != NULL) {
84
 
                        if (!parse_gid(getenv("MAIL_GID"), &reply->gid) ||
85
 
                            reply->gid == 0) {
86
 
                                i_error("mail_gid setting is invalid");
87
 
                                return -1;
88
 
                        }
89
 
                } else {
90
 
                        i_error("User %s is missing GID (set mail_gid)", user);
91
 
                        return -1;
92
 
                }
93
 
        }
94
 
 
95
 
        if (euid != reply->uid) {
96
 
                env_put(t_strconcat("RESTRICT_SETUID=",
97
 
                                    dec2str(reply->uid), NULL));
98
 
        }
99
 
        if (euid == 0 || getegid() != reply->gid) {
100
 
                env_put(t_strconcat("RESTRICT_SETGID=",
101
 
                                    dec2str(reply->gid), NULL));
102
 
        }
103
 
 
104
 
        if (reply->chroot == NULL)
105
 
                reply->chroot = getenv("MAIL_CHROOT");
106
 
        if (reply->chroot != NULL) {
107
 
                len = strlen(reply->chroot);
108
 
                if (len > 2 && strcmp(reply->chroot + len - 2, "/.") == 0 &&
109
 
                    reply->home != NULL &&
110
 
                    strncmp(reply->home, reply->chroot, len - 2) == 0) {
111
 
                        /* strip chroot dir from home dir */
112
 
                        reply->home += len - 2;
113
 
                }
114
 
                env_put(t_strconcat("RESTRICT_CHROOT=", reply->chroot, NULL));
115
 
        }
116
 
        if (reply->home != NULL)
117
 
                env_put(t_strconcat("HOME=", reply->home, NULL));
118
 
 
119
 
        extra_groups = getenv("MAIL_ACCESS_GROUPS");
120
 
        if (extra_groups != NULL) {
121
 
                env_put(t_strconcat("RESTRICT_SETEXTRAGROUPS=",
122
 
                                    extra_groups, NULL));
123
 
        }
124
 
        return 0;
125
 
}
126
 
 
127
 
int auth_client_lookup_and_restrict(const char *auth_socket,
128
 
                                    const char **user, uid_t euid, pool_t pool,
129
 
                                    ARRAY_TYPE(const_string) *extra_fields_r)
130
 
{
131
 
        struct auth_master_connection *conn;
132
 
        struct auth_user_reply reply;
133
 
        bool debug = getenv("DEBUG") != NULL;
134
 
        int ret = EX_TEMPFAIL;
135
 
 
136
 
        conn = auth_master_init(auth_socket, debug);
137
 
        switch (auth_master_user_lookup(conn, *user, "deliver", pool, &reply)) {
138
 
        case 0:
139
 
                ret = EX_NOUSER;
140
 
                break;
141
 
        case 1:
142
 
                if (set_env(&reply, *user, euid) == 0) {
143
 
                        *user = p_strdup(pool, reply.user);
144
 
                        restrict_access_by_env(TRUE);
145
 
                        ret = EX_OK;
146
 
                }
147
 
                break;
148
 
        }
149
 
 
150
 
        *extra_fields_r = reply.extra_fields;
151
 
        auth_master_deinit(&conn);
152
 
        return ret;
153
 
}