2023-10-26 12:24:52 +02:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# copyright (C) 1999-2005 Mitel Networks Corporation
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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 esmith;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Errno;
|
|
|
|
use esmith::AccountsDB;
|
|
|
|
use esmith::ConfigDB;
|
|
|
|
use esmith::util;
|
2024-08-13 22:55:04 +02:00
|
|
|
use utf8;
|
|
|
|
use esmith::util::ldap;
|
2023-10-26 12:24:52 +02:00
|
|
|
|
|
|
|
my $conf = esmith::ConfigDB->open or die "Could not open configuration db";
|
|
|
|
|
|
|
|
my $ldapauth = $conf->get('ldap')->prop('Authentication') || 'disabled';
|
|
|
|
my $x = 0; # exit value
|
|
|
|
|
|
|
|
# prepare LDAP bind
|
2024-08-13 22:55:04 +02:00
|
|
|
my $ldap=esmith::util::ldap->new();
|
2023-10-26 12:24:52 +02:00
|
|
|
|
|
|
|
my $event = $ARGV [0];
|
|
|
|
my $userName = $ARGV [1];
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# Check the Unix account
|
|
|
|
#------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
my $a = esmith::AccountsDB->open or die "Could not open accounts db";
|
|
|
|
|
|
|
|
my @users;
|
|
|
|
if ($event eq 'bootstrap-ldap-save')
|
|
|
|
{
|
|
|
|
@users = $a->users;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die "Username argument missing." unless defined ($userName);
|
|
|
|
my $u = $a->get($userName) or die "No account db record found for user $userName";
|
|
|
|
@users = ($u);
|
|
|
|
}
|
|
|
|
foreach my $u (@users)
|
|
|
|
{
|
|
|
|
my $type = $u->prop('type');
|
|
|
|
my $userName = $u->key;
|
|
|
|
|
|
|
|
die "Account $userName is not a user account; modify user failed.\n"
|
|
|
|
unless ( ($userName eq 'admin') or ($type eq 'user') );
|
|
|
|
|
|
|
|
setpwent;
|
|
|
|
my ($comment, $shell) = (getpwnam($userName))[6,8];
|
|
|
|
endpwent;
|
|
|
|
my $new_shell = $u->prop('Shell')
|
2024-03-14 21:00:28 +01:00
|
|
|
|| (($shell eq "/bin/sshell") ? "/usr/bin/false" : $shell);
|
2023-10-26 12:24:52 +02:00
|
|
|
|
2024-03-14 21:00:28 +01:00
|
|
|
$u->set_prop('Shell', $new_shell) unless (not defined $u->prop('Shell') && $new_shell eq "/usr/bin/false" ) ;
|
2023-10-26 12:24:52 +02:00
|
|
|
|
|
|
|
my $result;
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# Modify user's shell, if required, in /etc/passwd using "usermod"
|
|
|
|
#------------------------------------------------------------
|
|
|
|
unless ($shell eq $new_shell)
|
|
|
|
{
|
|
|
|
if ($ldapauth ne 'enabled')
|
|
|
|
{
|
|
|
|
system("/usr/sbin/usermod", '-s', "$new_shell", $userName) == 0
|
|
|
|
or ( $x = 255, warn "Failed to modify shell of (unix) account $userName.\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# Modify user's first name and last name if required,
|
|
|
|
# in /etc/passwd using "usermod"
|
|
|
|
#------------------------------------------------------------
|
2024-08-13 22:55:04 +02:00
|
|
|
my $first = stringToASCII($u->prop('FirstName') || "");
|
|
|
|
my $last = stringToASCII($u->prop('LastName') || "");
|
2023-10-26 12:24:52 +02:00
|
|
|
my $new_comment = "$first $last";
|
|
|
|
|
|
|
|
unless ($comment eq $new_comment)
|
|
|
|
{
|
|
|
|
if ($ldapauth ne 'enabled')
|
|
|
|
{
|
|
|
|
system("/usr/sbin/usermod", "-c", "$first $last", $userName) == 0
|
|
|
|
or ( $x = 255, warn "Failed to modify comment of (unix) account $userName.\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-13 22:55:04 +02:00
|
|
|
# we do all the test in ldap pm to avoid 3 differents write access, which are costly.
|
|
|
|
$result = $ldap->ldapuser($u);
|
|
|
|
$result && ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to modify email of (ldap) account $userName.\n" );
|
2023-10-26 12:24:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$ldap->unbind;
|
|
|
|
exit ($x);
|