This file is indexed.

/usr/share/perl5/EBox/UsersAndGroups/Setup.pm is in zentyal-users 2.3.4.

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
# Copyright (C) 2009-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::UsersAndGroups::Setup;

use strict;
use warnings;

use Error qw(:try);

use EBox;
use EBox::Config;
use EBox::Gettext;
use EBox::Global;
use EBox::Ldap;
use EBox::Module::Base;
use EBox::Sudo;
use EBox::Exceptions::Internal;
use EBox::Exceptions::Sudo::Command;
use EBox::Model::ModelManager;

use constant LDAPCONFDIR => '/etc/ldap/';

sub new_pass
{
    # Create a new LDAP password for our eBox admin
    my $LDAP_PWD_FILE = EBox::Config::conf() . 'ebox-ldap.passwd';

    my $pass;
    my $newpass = undef;
    if ( -s $LDAP_PWD_FILE ) {
        my $pwdfile;
        my $fd;
        unless (open ($fd, "<$LDAP_PWD_FILE")) {
            throw EBox::Exceptions::External("Can't open $LDAP_PWD_FILE");
        }
        $pass = <$fd>;
        close($fd)
    } else {
        $pass = '';
        my $letters = 'abcdefghijklmnopqrstuvwxyz';
        my @chars= split(//, $letters . uc($letters) .
            '-+/.0123456789');
        for my $i (1..16) {
            $pass .= $chars[int(rand (scalar(@chars)))];
        }
        $newpass = 1;
    }

    if ($newpass) {
        my $fd;
        unless (open ($fd, ">$LDAP_PWD_FILE")) {
                throw EBox::Exceptions::External("Can't open $LDAP_PWD_FILE");
        }
        print $fd $pass;
        close($fd);
        unless (chmod (0400, $LDAP_PWD_FILE)) {
                throw EBox::Exceptions::External("Can't chmod $LDAP_PWD_FILE");
        }
        my ($login,$pass,$uid,$gid) = getpwnam('ebox');
        unless (chown($uid, $gid, $LDAP_PWD_FILE)) {
                throw EBox::Exceptions::External("Can't chown $LDAP_PWD_FILE");
        }
    }
    return $pass;
}

# Function stolen from slapd.config in slapd package
sub GenRandom {
      my ($len) = @_;
      my $char;
      my $data;
      my @chars;;
      @chars = split(//, "abcdefghijklmnopqrstuvwxyz"
                       . "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

      open(RD, "</dev/urandom") or die "Failed to open random source";
      $data = "";
      while ($len--) {
        read(RD, $char, 1) == 1 or die "Failed to read random data";
        $data .= $chars[ord($char) % @chars];
      }
      close(RD);
      return $data;
}

# Setup a master
sub master
{
    my $model = EBox::Model::ModelManager->instance()->model('Mode');
    my $dn = $model->dnValue();

    my $pass = new_pass();
    my $tmp = EBox::Config::tmp();

    EBox::Module::Base::writeConfFileNoCheck(
        "$tmp/slapd-master.ldif",
        'users/slapd-master.ldif.mas',
        [
          'dn' => $dn,
          'password' => $pass
        ]);

    EBox::Module::Base::writeConfFileNoCheck(
        "$tmp/slapd-master-db.ldif",
        'users/slapd-master-db.ldif.mas',
        [
          'dn' => $dn,
          'password' => $pass
        ]);

    try {
        EBox::Sudo::root(
            #"ldapadd -H 'ldapi://' -Y EXTERNAL -c -f $tmp/slapd-master.ldif"
            'rm -rf /var/lib/ldap/*',
            'rm -rf /etc/ldap/slapd.d/cn=config*',
            "slapadd -b cn=config -F /etc/ldap/slapd.d/ -l $tmp/slapd-master.ldif",
            "slapadd -F /etc/ldap/slapd.d/ -l $tmp/slapd-master-db.ldif",
            'chown -R openldap:openldap /var/lib/ldap /etc/ldap/slapd.d'
        );
    } catch EBox::Exceptions::Sudo::Command with {
        my $exception = shift;
        EBox::warn('Trying to setup master ldap failed, exit value: ' .
            $exception->exitValue());
    };

    createDefaultGroupIfNeeded();

    createJournalsDirs();
}

sub createDefaultGroupIfNeeded
{
    my $users = EBox::Global->modInstance('users');
    my $defaultGroup = $users->defaultGroup();
    unless ($users->groupExists($defaultGroup)) {
        $users->addGroup($defaultGroup, 'All users', 1);
    }
}

# create parent dirs for slave's journals
sub createJournalsDirs
{
    my $users = EBox::Global->modInstance('users');
    my $journalDirs = $users->_journalsDir();

    unless (-d $journalDirs) {
        EBox::Sudo::root("mkdir -p $journalDirs");
    }
}

1;