* Tue Aug 13 2024 Jean-Philippe Pialasse <jpp@koozali.org> 11.0.0-6.sme
- use esmith::util::ldap for machines LDAP account [SME: 12687]
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/perl -w
|
||||
#----------------------------------------------------------------------
|
||||
# copyright (C) 2001 Mitel Networks Corporation
|
||||
# Copyright (C) 2024 Koozali Foundation inc.
|
||||
#
|
||||
# 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
|
||||
@@ -26,6 +27,9 @@ use Errno;
|
||||
use esmith::ConfigDB;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::util;
|
||||
use utf8;
|
||||
use esmith::util::ldap;
|
||||
|
||||
|
||||
my $a = esmith::AccountsDB->open || die "Couldn't open accounts db\n";
|
||||
my $c = esmith::ConfigDB->open_ro || die "Could not open Config DB";
|
||||
@@ -33,8 +37,8 @@ my $c = esmith::ConfigDB->open_ro || die "Could not open Config DB";
|
||||
my $ldapauth = $c->get('ldap')->prop('Authentication') || 'disabled';
|
||||
my $x = 0; # exit value
|
||||
|
||||
my $domain = $c->get('DomainName')->value();
|
||||
my $base = esmith::util::ldapBase ($domain);
|
||||
# prepare LDAP bind
|
||||
my $ldap=esmith::util::ldap->new();
|
||||
|
||||
my $event = $ARGV [0];
|
||||
my $machineName = $ARGV [1];
|
||||
@@ -101,34 +105,16 @@ if ($ldapauth ne 'enabled')
|
||||
}
|
||||
|
||||
# Create the machine's unique group first (in ldap)
|
||||
system(
|
||||
"/usr/sbin/cpu", "-C/etc/cpu-system.conf", "groupadd",
|
||||
"-g", $gid,
|
||||
"-o",
|
||||
"$machineName"
|
||||
) == 0 or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to create (ldap) group $machineName.\n" );
|
||||
my $result = $ldap->ldapgroup($m);
|
||||
$result && ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to create (ldap) group $machineName.\n" );
|
||||
|
||||
# Now create the machine account (in ldap)
|
||||
system(
|
||||
"/usr/sbin/cpu", "-C/etc/cpu-system.conf", "useradd",
|
||||
"-u", $uid,
|
||||
"-g", $gid,
|
||||
"--userbase=ou=Computers,$base",
|
||||
"-c", "Hostname account for $machineName",
|
||||
"-o",
|
||||
"-d", "/noexistingpath",
|
||||
"-s", "/bin/false",
|
||||
"$machineName"
|
||||
) == 0 or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to create (ldap) account $machineName.\n" );
|
||||
# Now create the machine account (in ldap). samba related action script will add more
|
||||
$result = $ldap->ldapaddmachine($m);
|
||||
$result && ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to create (ldap) account $machineName.\n" );
|
||||
|
||||
warn "create-machine-account $machineName: Locking account\n";
|
||||
|
||||
system("/usr/sbin/cpu", "-C/etc/cpu-system.conf", "usermod",
|
||||
"--userbase=ou=Computers,$base",
|
||||
"-o",
|
||||
"-L",
|
||||
"$machineName"
|
||||
) == 0 or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed locking (ldap) password for $machineName\n" );
|
||||
# esmith::util::ldap ldapaddmachine already lock account on creation in LDAP
|
||||
|
||||
if ($ldapauth ne 'enabled')
|
||||
{
|
||||
|
Reference in New Issue
Block a user