This file is indexed.

/usr/lib/gdesklets/plugin/ControlRegistry.py is in gdesklets 0.36.1-5+b1.

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
from main import HOME, REGISTRY_PATH
from plugin.Interface import Interface
from utils.MetaDataRegistry import MetaDataRegistry
from utils import vfs

import commands
import os

_REGFILE = os.path.join(REGISTRY_PATH, "controls.reg")


class ControlRegistry:
    """
    Class for holding a registry of controls. The registry is saved to a
    'controls.reg' file in order to speed up the startup process, since cached
    information can be used.
    """


    def __init__(self, repos):

        self.__registry = {}

        self.__mdreg = MetaDataRegistry(_REGFILE, repos,
                                        self.__find_controls,
                                        self.__register_control)

        self.__search_for_controls()



    #
    # Returns whether the given path has a control.
    #
    def __is_control(self, path):

        # is this test sufficient?
        return os.path.exists(os.path.join(path, "__init__.py"))



    #
    # Returns a list of all controls in the given repository.
    #
    def __find_controls(self, path):

        out = []
        if (not os.path.isdir(path)): return out

        files = os.listdir(path)
        for f in files:
            fpath = os.path.join(path, f)
            if (os.path.isdir(fpath)):
                if (self.__is_control(fpath)): out.append(fpath)
                else:
                    out += self.__find_controls(fpath)

        return out


    #
    # Registers the given control. Registering a control requires us to
    # actually load the control, so this is a critical phase where we have to
    # be careful about malware.
    #
    def __register_control(self, ctrl):

        items = []

        # it's more secure to use a separate process here
        cmd = os.path.join(HOME, "ctrlinfo")
        fail, out = commands.getstatusoutput("%s %s" % (cmd, ctrl))

        if (fail):
            log("Warning: \"%s\" is an invalid control." % ctrl)
            return None

        else:
            log("Registering new control \"%s\"." % ctrl)

        # cut off initial crap; you never know what controls might do during
        # initialization...
        out = out[out.find("PATH:"):]

        for line in out.splitlines():
            if (":" in line):
                key, value = line.split(":")
                value = vfs.unescape_path(value)
            else:
                key = value = ""

            if (not value in self.__registry):
                self.__registry[value] = []

            items.append((key, value))

        return items


    #
    # Searches for new controls.
    #
    def __search_for_controls(self):

        self.__mdreg.scan_repositories()

        self.__registry = {}

        # for all items
        for item in self.__mdreg.get_item_list():
            # go through all key-value pairs
            for k, v in self.__mdreg.get_item(item):
                # being only interested in the IDs
                if (k in ("ID1", "ID2")):
                    # register every single ID
                    for iface in v.split(" "):
                        if (not iface in self.__registry):
                            self.__registry[iface] = []
                        self.__registry[iface].append(item)



    #
    # Returns a control matching the given interface.
    #
    def get_control(self, iface, second_try = False):

        candidates = self.__registry.get(iface, [])
        for i in candidates:
            if (os.path.isdir(i)): return i

        if (not second_try):
            # search for new controls and give it a second try
            self.__search_for_controls()
            return self.get_control(iface, True)

        else:
            return ""