This file is indexed.

/usr/share/perl5/EBox/SambaLdapUser.pm is in zentyal-samba 2.3.12+quantal1ubuntu1.

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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# Copyright (C) 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

package EBox::SambaLdapUser;

use strict;
use warnings;

use MIME::Base64;
use Encode;
use Error qw(:try);

use EBox::Sudo;
use EBox::Samba;
use EBox::Samba::User;
use EBox::Samba::Group;
use EBox::UsersAndGroups::User;
use EBox::UsersAndGroups::Group;

use base qw(EBox::LdapUserBase);

sub new
{
    my $class = shift;
    my $self  = {};
    $self->{samba} = EBox::Global->modInstance('samba');
    $self->{ldb} = $self->{samba}->ldb();
    bless($self, $class);

    return $self;
}

# Method: _addUser
#
#   This method adds the user to samba LDAP
#   TODO Support multiples OU
#
sub _addUser
{
    my ($self, $zentyalUser, $zentyalPassword) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $dn = $zentyalUser->dn();
    EBox::debug("Adding user '$dn' to samba");
    my $params = {
        clearPassword => $zentyalPassword,
        uidNumber     => scalar ($zentyalUser->get('uidNumber')),
        description   => scalar ($zentyalUser->get('description')),
        givenName     => scalar ($zentyalUser->get('givenName')),
        sn            => scalar ($zentyalUser->get('sn')),
    };
    EBox::Samba::User->create($zentyalUser->get('uid'), $params);
}

sub _modifyUser
{
    my ($self, $zentyalUser, $zentyalPwd) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $dn = $zentyalUser->dn();
    EBox::debug("Updating user '$dn'");
    try {
        my $sambaUser = new EBox::Samba::User(samAccountName => $zentyalUser->get('uid'));
        return unless $sambaUser->exists();

        my $gn = $zentyalUser->get('givenName');
        my $sn = $zentyalUser->get('sn');
        my $desc = $zentyalUser->get('description');
        $sambaUser->set('givenName', $gn, 1);
        $sambaUser->set('sn', $sn, 1);
        $sambaUser->set('description', $desc, 1);
        $sambaUser->changePassword($zentyalPwd, 1) if defined $zentyalPwd;
        $sambaUser->save();
    } otherwise {
        my ($error) = @_;
        EBox::error("Error modifying user: $error");
    };
}

sub _delUser
{
    my ($self, $zentyalUser) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $dn = $zentyalUser->dn();
    EBox::debug("Deleting user '$dn' from samba");
    try {
        my $sambaUser = new EBox::Samba::User(samAccountName => $zentyalUser->get('uid'));
        return unless $sambaUser->exists();
        $sambaUser->deleteObject();
    } otherwise {
        my ($error) = @_;
        EBox::error("Error deleting user: $error");
    };
}

# Method: _addGroup
#
#   This method adds the group to samba LDAP
#   TODO Support multiples OU
#
sub _addGroup
{
    my ($self, $zentyalGroup) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $dn = $zentyalGroup->dn();
    EBox::debug("Adding group '$dn' to samba");
    my $params = {
        gidNumber     => scalar ($zentyalGroup->get('gidNumber')),
        description   => scalar ($zentyalGroup->get('description')),
    };
    EBox::Samba::Group->create($zentyalGroup->get('cn'), $params);
}

sub _modifyGroup
{
    my ($self, $zentyalGroup) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $dn = $zentyalGroup->dn();
    EBox::debug("Modifying group '$dn'");
    try {
        my $sambaGroup = new EBox::Samba::Group(samAccountName => $zentyalGroup->get('cn'));
        return unless $sambaGroup->exists();

        my $sambaMembersDNs = [];
        my $zentyalMembers = $zentyalGroup->users();
        foreach my $zentyalMember (@{$zentyalMembers}) {
            my $sambaUser = new EBox::Samba::User(samAccountName => $zentyalMember->get('uid'));
            push (@{$sambaMembersDNs}, $sambaUser->dn());
        }
        $sambaGroup->set('member', $sambaMembersDNs, 1);
        $sambaGroup->set('description', scalar ($zentyalGroup->get('description')), 1);
        $sambaGroup->save();
    } otherwise {
        my ($error) = @_;
        EBox::error("Error modifying group: $error");
    };
}

sub _delGroup
{
    my ($self, $zentyalGroup) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $dn = $zentyalGroup->dn();
    EBox::debug("Deleting group '$dn' from samba");
    try {
        my $sambaGroup = new EBox::Samba::Group(samAccountName => $zentyalGroup->get('cn'));
        return unless $sambaGroup->exists();
        $sambaGroup->deleteObject();
    } otherwise {
        my ($error) = @_;
        EBox::error("Error deleting user: $error");
    };
}

# User and group addons

sub _userAddOns
{
    my ($self, $zentyalUser) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $sambaUser = new EBox::Samba::User(samAccountName => $zentyalUser->get('uid'));
    return undef unless $sambaUser->exists();

    my $serviceEnabled = $self->{samba}->isEnabled();
    my $accountEnabled = $sambaUser->isAccountEnabled();

    my $args = {
        'username'       => $zentyalUser->dn(),
        'accountEnabled' => $accountEnabled,
        'service'        => $serviceEnabled,
    };

    return { path => '/samba/samba.mas', params => $args };
}

# Method: _groupShareEnabled
#
#   Check if there is a share configured for the group
#
# Returns:
#
#   The share name or undef if it is not configured
#
sub _groupShareEnabled
{
    my ($self, $zentyalGroup) = @_;

    my $groupName = $zentyalGroup->get('cn');
    my $sharesModel = $self->{samba}->model('SambaShares');
    foreach my $id (@{$sharesModel->ids()}) {
        my $row = $sharesModel->row($id);
        my $shareName  = $row->valueByName('share');
        my $groupShare = $row->valueByName('groupShare');
        return $shareName if $groupShare eq $groupName;
    }

    return undef;
}

sub setGroupShare
{
    my ($self, $group, $shareName) = @_;

    if ((not defined $shareName) or ( $shareName =~ /^\s*$/)) {
        throw EBox::Exceptions::External(__("A name should be provided for the share."));
    }

    my $oldName = $self->_groupShareEnabled($group);
    return if ($oldName and $oldName eq $shareName);

    my $groupName = $group->get('cn');
    my $sharesModel = $self->{samba}->model('SambaShares');

    # Create or rename the share for the group
    my $row = $sharesModel->findValue(groupShare => $groupName);
    if ($row) {
        # Rename the share
        EBox::debug("Renaming the share for group '$groupName' from '$oldName' to '$shareName'");
        $row->elementByName('share')->setValue($shareName);
        $row->store();
    } else {
        # Add the share
        my %params = ( share => $shareName,
                       path_selected => 'zentyal',
                       zentyal => $shareName,
                       comment => "Share for group $groupName",
                       guest => 0,
                       groupShare => $groupName );
        EBox::debug("Adding share named '$shareName' for group '$groupName'");
        my $shareRowId = $sharesModel->addRow(%params, readOnly => 1, enabled => 1);
        my $shareRow = $sharesModel->row($shareRowId);
        # And set the access control
        my $accessModel = $shareRow->subModel('access');
        %params = ( user_group_selected => 'group',
                    group => $groupName,
                    permissions => 'readWrite' );
        $accessModel->addRow(%params);
    }
}

sub removeGroupShare
{
    my ($self, $zentyalGroup) = @_;

    my $groupName = $zentyalGroup->get('cn');
    my $sharesModel = $self->{samba}->model('SambaShares');
    my $row = $sharesModel->findValue(groupShare => $groupName);
    $sharesModel->removeRow($row->id()) if $row;
}

sub _groupAddOns
{
    my ($self, $zentyalGroup) = @_;

    return unless ($self->{samba}->configured() and
                   $self->{samba}->isEnabled() and
                   $self->{samba}->isProvisioned());

    my $share = $self->_groupShareEnabled($zentyalGroup);
    my $args =  {
        'groupname' => $zentyalGroup->dn(),
        'share'     => $share,
        'service'   => $self->{samba}->isEnabled(),
    };

    return { path => '/samba/samba.mas', params => $args };
}

1;