This file is indexed.

/usr/share/php/Horde/Share/Object/Sqlng.php is in php-horde-share 2.0.4-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
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
216
217
218
219
220
221
222
<?php
/**
 * Extension of the Horde_Share_Object class for storing share information in
 * the Sqlng driver.
 *
 * @author  Jan Schneider <jan@horde.org>
 * @package Share
 */
class Horde_Share_Object_Sqlng extends Horde_Share_Object_Sql
{
    /**
     * Serializable version.
     */
    const VERSION = 1;

    /**
     * A list of available permission.
     *
     * This is necessary to unset certain permission when updating existing
     * share objects.
     *
     * @param array
     */
    public $availablePermissions = array();

    /**
     * Constructor.
     *
     * @param array $data Share data array.
     */
    public function __construct($data)
    {
        parent::__construct($data);
        $this->_setAvailablePermissions();
    }

    /**
     * Serialize this object.
     *
     * @return string  The serialized data.
     */
    public function serialize()
    {
        return serialize(array(
            self::VERSION,
            $this->data,
            $this->_shareCallback,
            $this->availablePermissions,
        ));
    }

    /**
     * Reconstruct the object from serialized data.
     *
     * @param string $data  The serialized data.
     */
    public function unserialize($data)
    {
        $data = @unserialize($data);
        if (!is_array($data) ||
            !isset($data[0]) ||
            ($data[0] != self::VERSION)) {
            throw new Exception('Cache version change');
        }

        $this->data = $data[1];
        if (empty($data[2])) {
            throw new Exception('Missing callback for Horde_Share_Object unserializing');
        }
        $this->_shareCallback = $data[2];
        $this->availablePermissions = $data[3];
    }

    /**
     * Saves the current attribute values.
     */
    protected function _save()
    {
        $db = $this->getShareOb()->getStorage();
        $table = $this->getShareOb()->getTable();

        // Build the parameter arrays for the sql statement.
        $fields = $params = array();
        foreach ($this->getShareOb()->toDriverCharset($this->data) as $key => $value) {
            if ($key != 'share_id' && $key != 'perm' && $key != 'share_flags') {
                $fields[] = $key;
                $params[] = $value;
            }
        }

        $fields[] = 'share_flags';
        $flags = 0;
        if (!empty($this->data['perm']['users'])) {
            $flags |= Horde_Share_Sql::SQL_FLAG_USERS;
        }
        if (!empty($this->data['perm']['groups'])) {
            $flags |= Horde_Share_Sql::SQL_FLAG_GROUPS;
        }
        $params[] = $flags;

        // Insert new share record, or update existing
        if (empty($this->data['share_id'])) {
            foreach ($this->data['perm'] as $base => $perms) {
                if ($base == 'type' || $base == 'users' || $base == 'groups') {
                    continue;
                }
                foreach (Horde_Share_Sqlng::convertBitmaskToArray($perms) as $perm) {
                    $fields[] = 'perm_' . $base . '_' . $perm;
                    $params[] = true;
                }
            }
            $sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (?' . str_repeat(', ?', count($fields) - 1) . ')';
            try {
                $this->data['share_id'] = $db->insert($sql, $params);
            } catch (Horde_Db_Exception $e) {
                throw new Horde_Share_Exception($e);
            }
        } else {
            foreach ($this->data['perm'] as $base => $perms) {
                if ($base == 'type' || $base == 'users' || $base == 'groups') {
                    continue;
                }
                $perms = array_flip(Horde_Share_Sqlng::convertBitmaskToArray($perms));
                foreach ($this->availablePermissions as $perm) {
                    $fields[] = 'perm_' . $base . '_' . $perm;
                    $params[] = isset($perms[$perm]) ? true : false;
                }
            }
            $sql = 'UPDATE ' . $table . ' SET ' . implode(' = ?, ', $fields) . ' = ? WHERE share_id = ?';
            $params[] = $this->data['share_id'];
            try {
                $db->update($sql, $params);
            } catch (Horde_Db_Exception $e) {
                throw new Horde_Share_Exception($e);
            }
        }

        // Update the share's user permissions
        $db->delete('DELETE FROM ' . $table . '_users WHERE share_id = ?', array($this->data['share_id']));
        if (!empty($this->data['perm']['users'])) {
            $data = array();
            foreach ($this->data['perm']['users'] as $user => $perms) {
                $fields = $params = array();
                foreach (Horde_Share_Sqlng::convertBitmaskToArray($perms) as $perm) {
                    $fields[] = 'perm_' . $perm;
                    $params[] = true;
                }
                if (!$fields) {
                    continue;
                }
                array_unshift($params, $user);
                array_unshift($params, $this->data['share_id']);
                $db->insert('INSERT INTO ' . $table . '_users (share_id, user_uid, ' . implode(', ', $fields) . ') VALUES (?, ?' . str_repeat(', ?', count($fields)) . ')', $params);
            }
        }

        // Update the share's group permissions
        $db->delete('DELETE FROM ' . $table . '_groups WHERE share_id = ?', array($this->data['share_id']));
        if (!empty($this->data['perm']['groups'])) {
            $data = array();
            foreach ($this->data['perm']['groups'] as $group => $perms) {
                $fields = $params = array();
                foreach (Horde_Share_Sqlng::convertBitmaskToArray($perms) as $perm) {
                    $fields[] = 'perm_' . $perm;
                    $params[] = true;
                }
                if (!$fields) {
                    continue;
                }
                array_unshift($params, $group);
                array_unshift($params, $this->data['share_id']);
                $db->insert('INSERT INTO ' . $table . '_groups (share_id, group_uid, ' . implode(', ', $fields) . ') VALUES (?, ?' . str_repeat(', ?', count($fields)) . ')', $params);
            }
        }

        return true;
    }

    /**
     * Sets the permission of this share.
     *
     * @param Horde_Perms_Permission $perm  Permission object.
     * @param boolean $update               Should the share be saved
     *                                      after this operation?
     */
    public function setPermission($perm, $update = true)
    {
        parent::setPermission($perm, false);
        $this->_setAvailablePermissions();
        if ($update) {
            $this->save();
        }
    }

    /**
     * Populates the $availablePermissions property with all seen permissions.
     *
     * This is necessary because the share tables might be extended with
     * arbitrary permissions.
     */
    protected function _setAvailablePermissions()
    {
        $available = array();
        foreach ($this->availablePermissions as $perm) {
            $available[$perm] = true;
        }
        foreach ($this->data['perm'] as $base => $perms) {
            if ($base == 'type') {
                continue;
            }
            if ($base != 'users' && $base != 'groups') {
                $perms = array($perms);
            }
            foreach ($perms as $subperms) {
                foreach (Horde_Share_Sqlng::convertBitmaskToArray($subperms) as $perm) {
                    $available[$perm] = true;
                }
            }
        }
        $this->availablePermissions = array_keys($available);
    }
}