From c589fa01a4c608080c873e722ea785c591a9fa08 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 26 Jan 2016 14:33:41 +0100 Subject: [PATCH] Use a new user-expire-account event --- createlinks | 9 ++++++--- .../{expire-update-auto-reply => user-expire-account} | 18 ++++++++++++++++++ root/sbin/e-smith/expire-accounts | 12 +----------- 3 files changed, 25 insertions(+), 14 deletions(-) rename root/etc/e-smith/events/actions/{expire-update-auto-reply => user-expire-account} (69%) diff --git a/createlinks b/createlinks index 9996064..45ab1b0 100644 --- a/createlinks +++ b/createlinks @@ -2,6 +2,9 @@ use esmith::Build::CreateLinks qw(:all); -event_link("user-reset-expired", 'password-modify', "80"); -event_link("expire-update-auto-reply", "user-lock", "80"); -event_link("qmail-update-user", "user-lock", "20"); +event_link("user-reset-expired", "password-modify", "80"); +event_link("user-expire-account", "user-expire-account", "20"); +event_link("user-lock-passwd", "user-expire-account", "30"); +event_link("count-active-user-accounts", "user-expire-account", "40"); +event_link("ldap-update-simple", "user-expire-account", "50"); +event_link("qmail-update-user", "user-expire-account", "60"); diff --git a/root/etc/e-smith/events/actions/expire-update-auto-reply b/root/etc/e-smith/events/actions/user-expire-account similarity index 69% rename from root/etc/e-smith/events/actions/expire-update-auto-reply rename to root/etc/e-smith/events/actions/user-expire-account index b203698..3eee910 100644 --- a/root/etc/e-smith/events/actions/expire-update-auto-reply +++ b/root/etc/e-smith/events/actions/user-expire-account @@ -4,6 +4,7 @@ use strict; use esmith::ConfigDB; use esmith::AccountsDB; use esmith::templates; +use DateTime; use User::pwent; my $a = esmith::AccountsDB->open_ro or @@ -23,6 +24,8 @@ else{ @users = ( $a->users ); } +my $now = DateTime->now; + foreach my $user (@users){ my $userName = $user->key; @@ -32,6 +35,21 @@ foreach my $user (@users){ my $expired = $user->prop('ExpireLockedOn') || ''; next if $expired !~ /^\d{4}\-\d{1,2}\-\d{1,2}$/; + # Remove user from all its groups + my @groups = $a->user_group_list($u) || (); + $a->remove_user_from_groups($u, @groups); + event_signal('group-modify', @groups) if (scalar @groups); + + # Set forward if needed + my $fwd = $user->prop('ExpireForwardAfterLock') || ''; + if ($fwd ne ''){ + $rec->set_prop('ForwardAddress', $fwd); + $rec->set_prop('EmailForward', 'forward'); + } + # Remove expiration settings now that the account is locked + $user->delete_prop('ExpireLockOn'); + $user->delete_prop('ExpireLastNotifiedOn'); + my $home = getpwnam($userName)->dir; mkdir $home . '/.lock-auto-reply' unless -d $home . '/.lock-auto-reply'; esmith::templates::processTemplate ({ diff --git a/root/sbin/e-smith/expire-accounts b/root/sbin/e-smith/expire-accounts index e4fac6f..840bf27 100644 --- a/root/sbin/e-smith/expire-accounts +++ b/root/sbin/e-smith/expire-accounts @@ -70,17 +70,7 @@ foreach my $user ($a->users){ # Lock accounts which need to be locked now foreach my $u (@lock){ - event_signal('user-lock', $u); - $a = esmith::AccountsDB->open || die "Couldn't open the AccountsDB\n"; - my $rec = $a->get($u); - my $fwd = $rec->prop('ExpireForwardAfterLock') || ''; - if ($fwd ne ''){ - $rec->set_prop('ForwardAddress', $fwd); - $rec->set_prop('EmailForward', 'forward'); - } - $rec->delete_prop('ExpireLockOn'); - $rec->delete_prop('ExpireLastNotifiedOn'); - $rec->set_prop('ExpireLockedOn', $now->ymd); + event_signal('user-expire-account', $u); } # Send a warning for accounts which will be locked soon