This file is indexed.

/usr/lib/python2.7/dist-packages/VirtualMailManager/aliasdomain.py is in vmm 0.6.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: UTF-8 -*-
# Copyright (c) 2008 - 2014, Pascal Volk
# See COPYING for distribution information.
"""
    VirtualMailManager.aliasdomain
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Virtual Mail Manager's AliasDomain class to manage alias domains.
"""

from VirtualMailManager.domain import Domain, check_domainname
from VirtualMailManager.constants import \
     ALIASDOMAIN_EXISTS, ALIASDOMAIN_ISDOMAIN, ALIASDOMAIN_NO_DOMDEST, \
     NO_SUCH_ALIASDOMAIN, NO_SUCH_DOMAIN
from VirtualMailManager.errors import AliasDomainError as ADErr


_ = lambda msg: msg


class AliasDomain(object):
    """Class to manage e-mail alias domains."""
    __slots__ = ('_gid', '_name', '_domain', '_dbh')

    def __init__(self, dbh, domainname):
        """Creates a new AliasDomain instance.

        Arguments:

        `dbh` : pyPgSQL.PgSQL.Connection
          a database connection for the database access
        `domainname` : basestring
          the name of the AliasDomain"""
        self._dbh = dbh
        self._name = check_domainname(domainname)
        self._gid = 0
        self._domain = None
        self._load()

    def _load(self):
        """Loads the AliasDomain's GID from the database and checks if the
        domain name is marked as primary."""
        dbc = self._dbh.cursor()
        dbc.execute('SELECT gid, is_primary FROM domain_name WHERE '
                    'domainname = %s', (self._name,))
        result = dbc.fetchone()
        dbc.close()
        if result:
            if result[1]:
                raise ADErr(_(u"The domain '%s' is a primary domain.") %
                            self._name, ALIASDOMAIN_ISDOMAIN)
            self._gid = result[0]

    def set_destination(self, dest_domain):
        """Set the destination of a new AliasDomain or updates the
        destination of an existing AliasDomain.

        Argument:

        `dest_domain` : VirtualMailManager.Domain.Domain
          the AliasDomain's destination domain
        """
        assert isinstance(dest_domain, Domain)
        self._domain = dest_domain

    def save(self):
        """Stores information about the new AliasDomain in the database."""
        if self._gid > 0:
            raise ADErr(_(u"The alias domain '%s' already exists.") %
                        self._name, ALIASDOMAIN_EXISTS)
        if not self._domain:
            raise ADErr(_(u'No destination domain set for the alias domain.'),
                        ALIASDOMAIN_NO_DOMDEST)
        if self._domain.gid < 1:
            raise ADErr(_(u"The target domain '%s' does not exist.") %
                        self._domain.name, NO_SUCH_DOMAIN)
        dbc = self._dbh.cursor()
        dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary) '
                    'VALUES (%s, %s, FALSE)', (self._name, self._domain.gid))
        self._dbh.commit()
        dbc.close()
        self._gid = self._domain.gid

    def info(self):
        """Returns a dict (keys: "alias" and "domain") with the names of the
        AliasDomain and its primary domain."""
        if self._gid < 1:
            raise ADErr(_(u"The alias domain '%s' does not exist.") %
                        self._name, NO_SUCH_ALIASDOMAIN)
        dbc = self._dbh.cursor()
        dbc.execute('SELECT domainname FROM domain_name WHERE gid = %s AND '
                    'is_primary', (self._gid,))
        domain = dbc.fetchone()
        dbc.close()
        if domain:
            return {'alias': self._name, 'domain': domain[0]}
        else:  # an almost unlikely case, isn't it?
            raise ADErr(_(u'There is no primary domain for the alias domain '
                          u"'%s'.") % self._name, NO_SUCH_DOMAIN)

    def switch(self):
        """Switch the destination of the AliasDomain to the new destination,
        set with the method `set_destination()`.
        """
        if not self._domain:
            raise ADErr(_(u'No destination domain set for the alias domain.'),
                        ALIASDOMAIN_NO_DOMDEST)
        if self._domain.gid < 1:
            raise ADErr(_(u"The target domain '%s' does not exist.") %
                        self._domain.name, NO_SUCH_DOMAIN)
        if self._gid < 1:
            raise ADErr(_(u"The alias domain '%s' does not exist.") %
                        self._name, NO_SUCH_ALIASDOMAIN)
        if self._gid == self._domain.gid:
            raise ADErr(_(u"The alias domain '%(alias)s' is already assigned "
                          u"to the domain '%(domain)s'.") %
                        {'alias': self._name, 'domain': self._domain.name},
                        ALIASDOMAIN_EXISTS)
        dbc = self._dbh.cursor()
        dbc.execute('UPDATE domain_name SET gid = %s WHERE gid = %s AND '
                    'domainname = %s AND NOT is_primary', (self._domain.gid,
                    self._gid, self._name))
        self._dbh.commit()
        dbc.close()
        self._gid = self._domain.gid

    def delete(self):
        """Delete the AliasDomain's record form the database.

        Raises an AliasDomainError if the AliasDomain doesn't exist.
        """
        if self._gid < 1:
            raise ADErr(_(u"The alias domain '%s' does not exist.") %
                        self._name, NO_SUCH_ALIASDOMAIN)
        dbc = self._dbh.cursor()
        dbc.execute('DELETE FROM domain_name WHERE domainname = %s AND NOT '
                    'is_primary', (self._name,))
        if dbc.rowcount > 0:
            self._dbh.commit()
            self._gid = 0
        dbc.close()

del _