* Sat May 18 2024 Jean-Philippe Pialasse <jpp@koozali.org> 11.0.0-7.sme

- edit LDAP entries using Net::LDAP rather than cpu [SME: 12687]
This commit is contained in:
2024-05-18 14:07:19 -04:00
parent 0e72a182b7
commit 1d67d9bd64
3 changed files with 169 additions and 59 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/sh
#!/usr/bin/perl
#----------------------------------------------------------------------
# copyright (C) 1999-2005 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
@@ -22,28 +22,76 @@
#------------------------------------------------------------
# Delete the Unix account and files for the ibay.
#------------------------------------------------------------
package esmith;
event=$1
ibay=$2
use strict;
use Errno;
use esmith::ConfigDB;
use esmith::util;
use Net::LDAP;
use esmith::AccountsDB;
if [ -z "$ibay" ]
then
echo ibayName argument missing
exit 1
fi
my $adb = esmith::AccountsDB->open_ro();
ldapauth=$(/sbin/e-smith/config getprop ldap Authentication || echo disabled)
x=0 # exit value
my $conf = esmith::ConfigDB->open_ro or die "Could not open config db";
/bin/rm -rf /home/e-smith/files/ibays/$ibay
if [ "$ldapauth" != "enabled" ]
then
/usr/sbin/userdel "$ibay" || x=1
/usr/sbin/cpu -C/etc/cpu-system.conf userdel "$ibay"
/usr/sbin/cpu -C/etc/cpu-system.conf groupdel "$ibay"
else
/usr/sbin/cpu userdel "$ibay" || x=1
/usr/sbin/cpu -C/etc/cpu-system.conf groupdel "$ibay" || x=1
fi
unless ($conf->get('ldap')->prop('status') eq "enabled" )
{
warn "Not running action script $0, LDAP service not enabled!\n";
exit(0);
}
my $domain = $conf->get('DomainName')
|| die("Couldn't determine domain name");
$domain = $domain->value;
# prepare LDAP bind
my $pw = esmith::util::LdapPassword();
my $base = esmith::util::ldapBase ($domain);
my $ldap = Net::LDAP->new('localhost')
or die "$@";
$ldap->bind(
dn => "cn=root,$base",
password => $pw
);
my $event = $ARGV [0];
my $ibay = $ARGV [1];
die "Username argument missing." unless defined ($ibay);
$a = $adb->get($ibay) || undef;
unless ( defined $a && $a->prop('type') eq "ibay-deleted" )
{
warn "$ibay is not an Ibay account\n";
exit (0);
}
my $ldapauth = $conf->get('ldap')->prop('Authentication') || 'disabled';
my $x = 0; # exit value
my $discard = `/bin/rm -rf /home/e-smith/files/ibays/$ibay`;
if ($? != 0)
{
( $x = 255, warn "Failed to delete content of ibay $ibay.\n" );
}
if ( "$ldapauth" ne "enabled" )
{
$discard = `/usr/sbin/userdel "$ibay"`;
if ($? != 0)
{
( $x = 255, warn "Failed to delete (unix) account $ibay.\n" );
}
}
my $result = $ldap->delete("uid=$ibay,ou=Users,$base");
$result->code && ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to delete (ldap) ibay account $ibay.\n" );
$result = $ldap->delete("cn=$ibay,ou=Groups,$base");
$result->code && ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to delete (ldap) group account $ibay.\n" );
exit $x