This file is indexed.

/usr/lib/ipa/ipa-httpd-kdcproxy is in freeipa-server 4.7.0~pre1+git20180411-2ubuntu2.

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

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/python
# Authors:
#   Christian Heimes <cheimes@redhat.com>
#
# Copyright (C) 2015  Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
"""ipa-httpd-kdproxy

This script creates or removes the symlink from /etc/ipa/ipa-kdc-proxy.conf
to /etc/httpd/conf.d/. It's called from ExecStartPre hook in httpd.service.
"""
import logging
import os
import socket
import sys

from ipalib import api, errors
from ipapython.ipa_log_manager import standard_logging_setup
from ipapython.ipaldap import LDAPClient
from ipapython.dn import DN
from ipaplatform.paths import paths

logger = logging.getLogger(os.path.basename(__file__))


DEBUG = False
TIME_LIMIT = 2


class Error(Exception):
    """Base error class"""


class ConfigFileError(Error):
    """Something is wrong with the config file"""


class CheckError(Error):
    """An unrecoverable error has occured

    The exit code is 0.
    """


class FatalError(Error):
    """A fatal error has occured

    Fatal errors cause the command to exit with a non-null exit code.
    """


class KDCProxyConfig(object):
    ipaconfig_flag = 'ipaKDCProxyEnabled'

    def __init__(self, time_limit=TIME_LIMIT):
        self.time_limit = time_limit
        self.con = None
        self.ldap_uri = api.env.ldap_uri
        self.kdc_dn = DN(('cn', 'KDC'), ('cn', api.env.host),
                         ('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
                         api.env.basedn)
        self.conf = paths.HTTPD_IPA_KDCPROXY_CONF
        self.conflink = paths.HTTPD_IPA_KDCPROXY_CONF_SYMLINK

    def _ldap_con(self):
        """Establish LDAP connection"""
        logger.debug('ldap_uri: %s', self.ldap_uri)
        try:
            self.con = LDAPClient(self.ldap_uri)
            self.con.external_bind()
        except (errors.NetworkError, socket.timeout) as e:
            msg = 'Unable to connect to dirsrv: %s' % e
            raise CheckError(msg)
        except errors.AuthorizationError as e:
            msg = 'Authorization error: %s' % e
            raise CheckError(msg)
        except Exception as e:
            msg = ('Unknown error while retrieving setting from %s: %s' %
                   (self.ldap_uri, e))
            logger.exception('%s', msg)
            raise FatalError(msg)

    def _find_entry(self, dn, attrs, filter, scope=LDAPClient.SCOPE_BASE):
        """Find an LDAP entry, handles NotFound and Limit"""
        try:
            entries = self.con.get_entries(
                dn, scope, filter, attrs, time_limit=self.time_limit)
        except errors.NotFound:
            logger.debug('Entry not found: %s', dn)
            return None
        except Exception as e:
            msg = ('Unknown error while retrieving setting from %s: %s' %
                   (self.ldap_uri, e))
            logger.exception('%s', msg)
            raise FatalError(msg)
        return entries[0]

    def is_host_enabled(self):
        """Check replica specific flag"""
        logger.debug('Read settings from dn: %s', self.kdc_dn)
        srcfilter = self.con.make_filter(
            {'ipaConfigString': u'kdcProxyEnabled'}
        )
        entry = self._find_entry(self.kdc_dn, ['cn'], srcfilter)
        logger.debug('%s ipaConfigString: %s', self.kdc_dn, entry)
        return entry is not None

    def validate_symlink(self):
        """Validate symlink in Apache conf.d"""
        if not os.path.exists(self.conflink):
            return False
        if not os.path.islink(self.conflink):
            raise ConfigFileError(
                "'%s' already exists, but it is not a symlink"
                % self.conflink)
        dest = os.readlink(self.conflink)
        if dest != self.conf:
            raise ConfigFileError(
                "'%s' points to '%s', expected '%s'"
                % (self.conflink, dest, self.conf))
        return True

    def create_symlink(self):
        """Create symlink to enable KDC proxy support"""
        try:
            valid = self.validate_symlink()
        except ConfigFileError as e:
            logger.warning("Cannot enable KDC proxy: %s ", e)
            return False

        if valid:
            logger.debug("Symlink exists and is valid")
            return True

        if not os.path.isfile(self.conf):
            logger.warning("'%s' does not exist", self.conf)
            return False

        # create the symbolic link
        logger.debug("Creating symlink from '%s' to '%s'",
                     self.conf, self.conflink)
        os.symlink(self.conf, self.conflink)
        return True

    def remove_symlink(self):
        """Delete symlink to disable KDC proxy support"""
        try:
            valid = self.validate_symlink()
        except CheckError as e:
            logger.warning("Cannot disable KDC proxy: %s ", e)
            return False

        if valid:
            logger.debug("Removing symlink '%s'", self.conflink)
            os.unlink(self.conflink)
        else:
            logger.debug("Symlink '%s' has already been removed.",
                         self.conflink)

        return True

    def __enter__(self):
        self._ldap_con()
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        if self.con is not None:
            self.con.unbind()
            self.con = None


def main(debug=DEBUG, time_limit=TIME_LIMIT):
    # initialize API without file logging
    if not api.isdone('bootstrap'):
        api.bootstrap(context='server', confdir=paths.ETC_IPA,
                      log=None, debug=debug)
        standard_logging_setup(verbose=True, debug=debug)

    try:
        cfg = KDCProxyConfig(time_limit)
        with cfg:
            if cfg.is_host_enabled():
                if cfg.create_symlink():
                    logger.info('KDC proxy enabled')
                    return 0
            else:
                if cfg.remove_symlink():
                    logger.info('KDC proxy disabled')
                    return 0
    except CheckError as e:
        logger.warning('%s', str(e))
        logger.warning('Disabling KDC proxy')
        cfg.remove_symlink()
        return 0
    except Exception as e:
        logger.error('%s', str(e))
        return 1


if __name__ == '__main__':
    sys.exit(main())