This file is indexed.

/usr/lib/python2.7/dist-packages/ipaplatform/debian/services.py is in python-ipalib 4.7.0~pre1+git20180411-2ubuntu2.

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
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
#
# Copyright (C) 2017  FreeIPA Contributors see COPYING for license
#

"""
Contains Debian-specific service class implementations.
"""

from ipaplatform.base import services as base_services
from ipaplatform.redhat import services as redhat_services
from ipapython import ipautil
from ipaplatform.paths import paths

# Mappings from service names as FreeIPA code references to these services
# to their actual systemd service names
debian_system_units = redhat_services.redhat_system_units.copy()

# For beginning just remap names to add .service
# As more services will migrate to systemd, unit names will deviate and
# mapping will be kept in this dictionary
debian_system_units['httpd'] = 'apache2.service'
debian_system_units['kadmin'] = 'krb5-admin-server.service'
debian_system_units['krb5kdc'] = 'krb5-kdc.service'
debian_system_units['named-regular'] = 'bind9.service'
debian_system_units['named-pkcs11'] = 'bind9-pkcs11.service'
debian_system_units['named'] = debian_system_units['named-pkcs11']
debian_system_units['pki-tomcatd'] = 'pki-tomcatd.service'
debian_system_units['pki_tomcatd'] = debian_system_units['pki-tomcatd']
debian_system_units['ods-enforcerd'] = 'opendnssec-enforcer.service'
debian_system_units['ods_enforcerd'] = debian_system_units['ods-enforcerd']
debian_system_units['ods-signerd'] = 'opendnssec-signer.service'
debian_system_units['ods_signerd'] = debian_system_units['ods-signerd']
debian_system_units['rpcgssd'] = 'rpc-gssd.service'
debian_system_units['rpcidmapd'] = 'nfs-idmapd.service'
debian_system_units['smb'] = 'smbd.service'

# Service classes that implement Debian family-specific behaviour

class DebianService(redhat_services.RedHatService):
    system_units = debian_system_units


class DebianSysvService(base_services.PlatformService):
    def __wait_for_open_ports(self, instance_name=""):
        """
        If this is a service we need to wait for do so.
        """
        ports = None
        if instance_name in base_services.wellknownports:
            ports = base_services.wellknownports[instance_name]
        else:
            if self.service_name in base_services.wellknownports:
                ports = base_services.wellknownports[self.service_name]
        if ports:
            ipautil.wait_for_open_ports('localhost', ports, self.api.env.startup_timeout)

    def stop(self, instance_name='', capture_output=True):
        ipautil.run([paths.SBIN_SERVICE, self.service_name, "stop",
                     instance_name], capture_output=capture_output)
        super(DebianSysvService, self).stop(instance_name)

    def start(self, instance_name='', capture_output=True, wait=True):
        ipautil.run([paths.SBIN_SERVICE, self.service_name, "start",
                     instance_name], capture_output=capture_output)
        if wait and self.is_running(instance_name):
            self.__wait_for_open_ports(instance_name)
        super(DebianSysvService, self).start(instance_name)

    def restart(self, instance_name='', capture_output=True, wait=True):
        ipautil.run([paths.SBIN_SERVICE, self.service_name, "restart",
                     instance_name], capture_output=capture_output)
        if wait and self.is_running(instance_name):
            self.__wait_for_open_ports(instance_name)

    def is_running(self, instance_name="", wait=True):
        ret = True
        try:
            result = ipautil.run([paths.SBIN_SERVICE,
                                  self.service_name, "status",
                                  instance_name],
                                  capture_output=True)
            sout = result.output
            if sout.find("NOT running") >= 0:
                ret = False
            if sout.find("stop") >= 0:
                ret = False
            if sout.find("inactive") >= 0:
                ret = False
        except ipautil.CalledProcessError:
                ret = False
        return ret

    def is_installed(self):
        installed = True
        try:
            ipautil.run([paths.SBIN_SERVICE, self.service_name, "status"])
        except ipautil.CalledProcessError as e:
            if e.returncode == 1:
                # service is not installed or there is other serious issue
                installed = False
        return installed

    @staticmethod
    def is_enabled(instance_name=""):
        # Services are always assumed to be enabled when installed
        return True

    @staticmethod
    def enable():
        return True

    @staticmethod
    def disable():
        return True

    @staticmethod
    def install():
        return True

    @staticmethod
    def remove():
        return True


# For services which have no Debian counterpart
class DebianNoService(base_services.PlatformService):
    @staticmethod
    def start():
        return True

    @staticmethod
    def stop():
        return True

    @staticmethod
    def restart():
        return True

    @staticmethod
    def disable():
        return True


# Function that constructs proper Debian-specific server classes for services
# of specified name

def debian_service_class_factory(name, api=None):
    if name == 'dirsrv':
        return redhat_services.RedHatDirectoryService(name, api)
    if name == 'domainname':
        return DebianNoService(name, api)
    if name == 'ipa':
        return redhat_services.RedHatIPAService(name, api)
    if name == 'messagebus':
        return DebianNoService(name, api)
    if name == 'ntpd':
        return DebianSysvService("ntp", api)
    return DebianService(name, api)


# Magicdict containing DebianService instances.

class DebianServices(base_services.KnownServices):
    def __init__(self):
        # pylint: disable=ipa-forbidden-import
        import ipalib  # FixMe: break import cycle
        # pylint: enable=ipa-forbidden-import
        services = dict()
        for s in base_services.wellknownservices:
            services[s] = self.service_class_factory(s, ipalib.api)
        # Call base class constructor. This will lock services to read-only
        super(DebianServices, self).__init__(services)

    @staticmethod
    def service_class_factory(name, api=None):
        return debian_service_class_factory(name, api)

# Objects below are expected to be exported by platform module

timedate_services = base_services.timedate_services
service = debian_service_class_factory
knownservices = DebianServices()