This file is indexed.

/usr/bin/indicator-cpufreq-selector is in indicator-cpufreq 0.2.2-0ubuntu1.

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
#! /usr/bin/python3
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright (C) 2010 Artem Popov <artfwo@gmail.com>
# Copyright (C) 2008 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it 
# under the terms of the GNU General Public License version 3, as published 
# by the Free Software Foundation.
# 
# This program is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranties of 
# MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.

from gi.repository import GLib

import dbus.service
import dbus.mainloop.glib

from indicator_cpufreq import cpufreq

class PermissionDeniedByPolicy(dbus.DBusException):
    _dbus_error_name = 'com.ubuntu.DeviceDriver.PermissionDeniedByPolicy'

class IndicatorCpufreqSelector(dbus.service.Object):

    DBUS_INTERFACE_NAME = 'com.ubuntu.IndicatorCpufreqSelector'

    def __init__(self, bus, path):
        dbus.service.Object.__init__(self, bus, path)

        # cached D-BUS interfaces for _check_polkit_privilege()
        self.dbus_info = None
        self.polkit = None
        self.main_loop = None

        self.enforce_polkit = True
        self._package_operation_in_progress = False

    @dbus.service.method(dbus_interface='com.ubuntu.IndicatorCpufreqSelector',
        in_signature='auu',
        out_signature='',
        sender_keyword='sender',
        connection_keyword='conn')
    def SetFrequency(self, cpus, frequency, sender=None, conn=None):
        self._check_polkit_privilege(sender, conn, 'com.ubuntu.indicatorcpufreqselector.setfrequencyscaling')
        for cpu in cpus:
            error = cpufreq.set_frequency(cpu, frequency)

    @dbus.service.method(dbus_interface='com.ubuntu.IndicatorCpufreqSelector',
        in_signature='aus',
        out_signature='',
        sender_keyword='sender',
        connection_keyword='conn')
    def SetGovernor(self, cpus, governor, sender=None, conn=None):
        self._check_polkit_privilege(sender, conn, 'com.ubuntu.indicatorcpufreqselector.setfrequencyscaling')
        for cpu in cpus:
            error = cpufreq.modify_policy_governor(cpu, governor)

    def _check_polkit_privilege(self, sender, conn, privilege):
        '''Verify that sender has a given PolicyKit privilege.

        sender is the sender's (private) D-BUS name, such as ":1:42"
        (sender_keyword in @dbus.service.methods). conn is
        the dbus.Connection object (connection_keyword in
        @dbus.service.methods). privilege is the PolicyKit privilege string.

        This method returns if the caller is privileged, and otherwise throws a
        PermissionDeniedByPolicy exception.
        '''
        if sender is None and conn is None:
            # called locally, not through D-BUS
            return
        if not self.enforce_polkit:
            # that happens for testing purposes when running on the session
            # bus, and it does not make sense to restrict operations here
            return

        # get peer PID
        if self.dbus_info is None:
            self.dbus_info = dbus.Interface(conn.get_object('org.freedesktop.DBus',
                '/org/freedesktop/DBus/Bus', False), 'org.freedesktop.DBus')
        pid = self.dbus_info.GetConnectionUnixProcessID(sender)

        # query PolicyKit
        if self.polkit is None:
            self.polkit = dbus.Interface(dbus.SystemBus().get_object(
                'org.freedesktop.PolicyKit1',
                '/org/freedesktop/PolicyKit1/Authority', False),
                'org.freedesktop.PolicyKit1.Authority')
        try:
            # we don't need is_challenge return here, since we call with AllowUserInteraction
            (is_auth, _, details) = self.polkit.CheckAuthorization(
                    ('unix-process', {'pid': dbus.UInt32(pid, variant_level=1),
                        'start-time': dbus.UInt64(0, variant_level=1)}), 
                    privilege, {'': ''}, dbus.UInt32(1), '', timeout=600)
        except dbus.DBusException as e:
            if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown':
                # polkitd timed out, connect again
                self.polkit = None
                return self._check_polkit_privilege(sender, conn, privilege)
            else:
                raise

        if not is_auth:
            #logging.debug('_check_polkit_privilege: sender %s on connection %s pid %i is not authorized for %s: %s' %
            #        (sender, conn, pid, privilege, str(details)))
            raise PermissionDeniedByPolicy(privilege)

if __name__ == '__main__':
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    bus = dbus.SystemBus()
    name = dbus.service.BusName("com.ubuntu.IndicatorCpufreqSelector", bus)
    object = IndicatorCpufreqSelector(bus, '/Selector')
    #object.enforce_polkit = False

    mainloop = GLib.MainLoop()
    mainloop.run()