Index: /LATMOS-Accounts/MANIFEST
===================================================================
--- /LATMOS-Accounts/MANIFEST	(revision 866)
+++ /LATMOS-Accounts/MANIFEST	(revision 867)
@@ -31,9 +31,9 @@
 bin/la-sql-loadatt
 bin/la-sql-regatt
+bin/la-sql-sanity
 bin/la-sync
 bin/la-sync-list
 bin/la-sync-manager
 bin/la-warn-expire
-bin/la-web-directory
 etc/cron.d/latmos-accounts
 etc/init.d/la-sync-manager
Index: /LATMOS-Accounts/Makefile.PL
===================================================================
--- /LATMOS-Accounts/Makefile.PL	(revision 866)
+++ /LATMOS-Accounts/Makefile.PL	(revision 867)
@@ -22,4 +22,6 @@
         'Crypt::Cracklib' => undef,
         'Net::IP' => undef,
+        'Net::IPv4Addr' => undef,
+        'Net::IPv6Addr' => undef,
     }, # e.g., Module::Name => 1.1
     ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
Index: /LATMOS-Accounts/bin/la-sql-sanity
===================================================================
--- /LATMOS-Accounts/bin/la-sql-sanity	(revision 867)
+++ /LATMOS-Accounts/bin/la-sql-sanity	(revision 867)
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use LATMOS::Accounts::Maintenance;
+use LATMOS::Accounts::Log;
+use Getopt::Long;
+use Pod::Usage;
+
+=head1 NAME
+
+    la-expired-reminder - Notify manager about expired account needing deletion
+
+=head1 SYNOPSIS
+
+    la-expired-reminder [options]
+
+=cut
+
+GetOptions(
+    'c|config=s' => \my $config,
+#    'b|base=s'   => \my $base,
+    'm|mail'     => \my $mail,
+    'help'       => sub { pod2usage(0) },
+    'users|u=s'  => \my @users,
+    'to=s'       => \my $to,
+    'test'       => \my $test,
+) or pod2usage();
+
+=head1 OPTIONS
+
+=over 4
+
+=item -c|--config configdir
+
+Use this configuration directory instead of the default one.
+
+=item -m|mail
+
+Send a mail to user(s) concerned by the future expiration of his/her/their account(s).
+
+=item u|user USER
+
+Send email only to this user if his/her account will expire. Usefull for
+testing and not sending hundred of mails.
+
+Multiple users can be specified by using -u several times
+
+=item --to MAIL
+
+Instead sending email to user(s) and eventually his/her/their manager(s), send the mail to
+only this email address.
+
+=item --test
+
+With -m, do not send mail but tell to who the mail would have been sent
+
+=back
+
+=head1 CONFIGURATION
+
+Some variables are taken from configuration directory:
+
+=over 4
+
+=item mailFrom
+
+Specify the From address to use in mail
+
+=item smtp
+
+The smtp server to use to send mail
+
+=item alwayscc
+
+In normal mode (without --to), the mail is also sent this email address.
+
+=back
+
+=head1 USERS EMAIL ADDRESSES
+
+The mail use to send warning to users and manager is taken from 'mail'
+attributes. If the attributes is unset, the user will not receive the mail.
+
+=cut
+
+if (!$test) {
+    la_set_log(
+        syslog => [],
+        console => undef,
+    );
+}
+
+my $LA = LATMOS::Accounts->new($config, noacl => 1);
+my $labase = $LA->default_base;
+$labase && $labase->load or die "Cannot load base";
+$labase->wexported(1);
+
+
+foreach (qw(check_user_manager check_group_manager check_nethost_owner)) {
+    my %res = $labase->$_;
+    if (%res) {
+        warn "\n$_:\n";
+        foreach (sort keys %res) {
+            warn "  $_ $res{$_}\n";
+        }
+    }
+}
+# $labase->check_user_manager;
+# $labase->check_group_manager;
+# $labase->check_nethost_owner;
Index: /LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
===================================================================
--- /LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm	(revision 866)
+++ /LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm	(revision 867)
@@ -317,4 +317,36 @@
 }
 
+sub check_user_manager {
+    $_[0]->_handle_by_unexported('user', 'manager', 'active');
+}
+
+sub check_group_manager {
+    $_[0]->_handle_by_unexported('group', 'managedBy');
+}
+
+sub check_nethost_owner {
+    $_[0]->_handle_by_unexported('nethost', 'owner', 'active');
+}
+
+sub _handle_by_unexported {
+    my ($self, $otype, $refattr, $chkattr) = @_;
+
+    my $ptrotype = $self->attribute($otype, $refattr)->reference();
+
+    my %unhandle;
+    foreach my $objname ($self->search_objects($otype, 'active=1', 'exported=1', "$refattr=*")) {
+        my $obj = $self->get_object($otype, $objname) or next;
+        my $val = $obj->get_attributes($refattr) or next;
+        if (my $refobj = $self->get_object($ptrotype, $val)) {
+            if (!$refobj->get_attributes($chkattr || 'exported')) {
+                $unhandle{$objname} = $val;
+            }
+        } else {
+            $unhandle{$objname} = $val;
+        }
+    }
+    %unhandle;
+}
+
 1;
 
