This file is indexed.

/usr/share/perl5/EBox/Objects/Model/MemberTable.pm is in zentyal-objects 2.3.6+quantal1.

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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# Copyright (C) 2008-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, 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 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# Class:
#
#   EBox::Object::Model::ObjectTable
#
#   This class inherits from <EBox::Model::DataTable> and represents the
#   membembers beloging to an object
#
#
package EBox::Objects::Model::MemberTable;

use EBox::Objects::Members;
use EBox::Global;
use EBox::Gettext;
use EBox::Validate qw(:all);
use EBox::Sudo;
use EBox::Types::Text;
use EBox::Types::Union;
use EBox::Types::MACAddr;
use EBox::Types::IPAddr;
use EBox::Types::IPRange;


use EBox::Exceptions::External;

use Net::IP;

use strict;
use warnings;

use base 'EBox::Model::DataTable';

sub new
{
    my $class = shift;
    my %parms = @_;

    my $self = $class->SUPER::new(@_);
    bless($self, $class);

    return $self;
}

sub _table
{
    my @tableHead =
        (

            new EBox::Types::Text
                            (
                                'fieldName' => 'name',
                                'printableName' => __('Name'),
                                'unique' => 1,
                                'editable' => 1
                             ),
            new EBox::Types::Union(
                fieldName => 'address',
                printableName => __('IP address'),
                subtypes => [
                    new EBox::Types::IPAddr (
                        'fieldName' => 'ipaddr',
                        'printableName' => 'CIDR',
                        'editable' => 1,
                       ),
                    new EBox::Types::IPRange(
                        'fieldName' => 'iprange',
                        'printableName' => __('Range'),
                        'editable' => 1,
                       ),
                    ],
            ),
            new EBox::Types::MACAddr
                            (
                                'fieldName' => 'macaddr',
                                'printableName' => __('MAC address'),
                                'unique' => 1,
                                'editable' => 1,
                                'optional' => 1
                            ),


          );

    my $dataTable =
        {
            'tableName' => 'MemberTable',
            'printableTableName' => __('Members'),
            'automaticRemove' => 1,
            'defaultController' => '/Objects/Controller/MemberTable',
            'defaultActions' => ['add', 'del', 'editField', 'changeView', 'clone' ],
            'tableDescription' => \@tableHead,
            'class' => 'dataTable',
            'help' => __('For the IP addresses you can use CIDR notation (address/netmask) or specify the first and last addresses of a range that will also include all the IP addresses between them.'),
            'printableRowName' => __('member'),
            'sortedBy' => 'name',
        };

    return $dataTable;
}

sub validateTypedRow
{
    my ($self, $action, $params, $actual) = @_;
    my $id = $params->{id}; # XXX not sure
    my $address = exists $params->{address} ?
                         $params->{address} : $actual->{address};
    my $mac = exists $params->{macaddr} ?
                         $params->{macaddr}->value() : $actual->{macaddr}->value();
    my $addressType = $address->selectedType();
    my $printableValue;

    if ($addressType eq 'ipaddr') {
        my $ipaddr = $address->subtype();
        my $ip = $ipaddr->ip();
        my $mask = $ipaddr->mask();

        if ($mask eq '32') {
            if ($ip =~ /\.0+$/) {
                throw EBox::Exceptions::External(
                        __('Only network addresses can end with a zero'));
            }
        } else {
            if (defined ($mac)) {
                throw EBox::Exceptions::External(
                        __('You can only use MAC addresses with hosts'));
            }
        }

        $printableValue = $ipaddr->printableValue();
    } elsif ($addressType eq 'iprange') {
        if (defined $mac) {
            throw EBox::Exceptions::External(
            __('You cannot use MAC addresses with IP ranges'));
        }
        my $range = $address->subtype();
        $printableValue = $range->printableValue();
    }

    if ($self->_alreadyInSameObject($id, $printableValue)) {
        throw EBox::Exceptions::External(
            __x(
                    q{{ip} overlaps with the address or another object's member},
                    ip => $printableValue
                   )
           );
    }
}



# Method: alreadyInSameObject
#
#       Checks if a member (i.e: its ip and mask) overlaps with another object's member
#
# Parameters:
#
#           (POSITIONAL)
#
#       memberId - memberId
#       ip - IPv4 address
#       mask - network mask
#
# Returns:
#
#       boolean - true if it overlaps, otherwise false
sub _alreadyInSameObject
{
    my ($self, $memberId, $printableValue) = @_;

    my $new = new Net::IP($printableValue);

    foreach my $id (@{$self->ids()}) {
        next if ((defined $memberId) and ($id eq $memberId));

        my $row  = $self->row($id);
        my $memaddr = new Net::IP($row->printableValueByName('address'));

        if ($memaddr->overlaps($new) != $IP_NO_OVERLAP){
            return 1;
        }

    }

    return undef;
}

# Method: members
#
#       Return the members
#
# Parameters:
#
#       (POSITIONAL)
#
#       id - object's id
#
# Returns:
#       <EBox::Objects::Members>
#
# Exceptions:
#
#       <EBox::Exceptions::MissingArgument>
sub members
{
    my ($self) = @_;

    my @members;
    foreach my $id (@{$self->ids()}) {
        my $memberRow = $self->row($id);
        my $address = $memberRow->elementByName('address');
        my $type =  $address->selectedType();

        my %member = (
            name => $memberRow->valueByName('name'),
            type => $type,
           );

        if ($type eq 'ipaddr') {
            my $ipaddr = $address->subtype();
            $member{ipaddr} = $ipaddr->printableValue();
            $member{ip}     = $ipaddr->ip();
            $member{mask}   = $ipaddr->mask();
            $member{macaddr} = $memberRow->valueByName('macaddr');
        } elsif ($type eq 'iprange') {
            my $range = $address->subtype();
            $member{begin} = $range->begin();
            $member{end} = $range->end();
            # not sure if good idea to extract all ips now
            $member{addresses} = $range->addresses(),
            $member{mask} = 32,
        }

        push @members, \%member;
    }

    my $membersObject = \@members;
    bless $membersObject, 'EBox::Objects::Members';
    return $membersObject;
}


# addresses
#
#       Return the network addresses
#
# Parameters:
#
#       mask - return also addresses' mask (named optional, default false)
#
# Returns:
#
#       array ref - containing an ip addresses
#                   empty array if there are no addresses in the table
#
#       If mask parameter is on, the elements of the array would be [ip_without_mask, mask]
#
sub addresses
{
    my ($self, @params) = @_;

    my $members = $self->members();
    return $members->addresses(@params);
}


# Method: pageTitle
#
#   Overrides <EBox::Model::DataTable::pageTitle>
#   to show the name of the domain
sub pageTitle
{
    my ($self) = @_;

    return $self->parentRow()->printableValueByName('name');
}

1;