|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
package esmith;
|
|
|
|
use File::Path qw(mkpath rmtree);
|
|
|
|
use esmith::AccountsDB;
|
|
|
|
|
|
|
|
my $a = esmith::AccountsDB->open_ro();
|
|
|
|
|
|
|
|
$ENV{'PATH'} = "/bin";
|
|
|
|
my $setfacl = "/usr/bin/setfacl";
|
|
|
|
|
|
|
|
my $event = $ARGV [0];
|
|
|
|
my $name = $ARGV [1];
|
|
|
|
|
|
|
|
die "Event name missing\n" unless (defined $event);
|
|
|
|
|
|
|
|
if ($event eq 'user-create'){
|
|
|
|
mkpath "/home/e-smith/files/scan/$name";
|
|
|
|
system ("$setfacl",
|
|
|
|
'-m',
|
|
|
|
"u:scanner:wX,u:$name:rwX,g:admins:rwX,d:u:$name:rwX,d:g:admins,rwX",
|
|
|
|
'--',
|
|
|
|
"/home/e-smith/files/scan/$name");
|
|
|
|
}
|
|
|
|
elsif ($event eq 'user-delete'){
|
|
|
|
rmtree "/home/e-smith/files/scan/$name";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
system ("$setfacl",
|
|
|
|
'-R',
|
|
|
|
'--remove-all',
|
|
|
|
'--remove-default',
|
|
|
|
'--',
|
|
|
|
"/home/e-smith/files/scan/");
|
|
|
|
|
|
|
|
foreach ($a->users,$a->get('admin')){
|
|
|
|
$name = $_->key;
|
|
|
|
if (-d "/home/e-smith/files/scan/$name"){
|
|
|
|
chmod 0700, "/home/e-smith/files/scan/$name";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mkdir "/home/e-smith/files/scan/$name", 0700;
|
|
|
|
}
|
|
|
|
system ("$setfacl",
|
|
|
|
'-R',
|
|
|
|
'-m',
|
|
|
|
"u:scanner:wX,u:$name:rwX,d:u:$name:rwX",
|
|
|
|
'--',
|
|
|
|
"/home/e-smith/files/scan/$name");
|
|
|
|
}
|
|
|
|
chmod 0755, "/home/e-smith/files/scan/";
|
|
|
|
system ("$setfacl", "-R", "-m", "g:admins:rwX,d:g:admins:rwX", "/home/e-smith/files/scan/");
|
|
|
|
}
|
|
|
|
|
|
|
|
exit (0);
|