# script to generate a playfile for subinacl
#
# Copyright (C) 2007  GONICUS GmbH  info@GONICUS.de
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#!/usr/bin/perl -W
#
# Erstellen einer 'playlist' für das Windows-Tool 'subinacl'.
# Aufruf unter Windows: 'subinacl /playlist playfile.txt'
#
# Die Benutzerliste wird unter dem Namen 'piloten.txt' erwartet, diese enthält
# pro Zeile genau einen Benutzer, für den die nachfolgenden Änderungen
# durchgeführt werden.
#
# Es werden folgende Rechte-Änderungen durchgeführt:
#  + Besitzer wird auf den Benutzer gesetzt
#  + Volle Berechtigung für den Benutzer
#  + Volle Berechtigung für smbadmin.kult
#
# Diese Änderungen werden auf folgende Shares angewandt:
# e:\homes\BENUTZER
# e:\mail\BENUTZER
# d:\profiles\BENUTZER
#

use strict;
use Data::Dumper;

my $infilename=  'piloten.txt';
my $outfilename= 'playfile.txt';

my @users;

my $template_text='
+file e:\homes\%USER%
/perm
/setowner=KULREF\%USER%
/grant=KULREF\%USER%=F
/grant=KULREF\smbadmin.kult=F

+subdirec e:\homes\%USER%\*
/perm
/setowner=KULREF\%USER%
/grant=KULREF\%USER%=F
/grant=KULREF\smbadmin.kult=F

+file e:\mail\%USER%
/perm
/setowner=KULREF\%USER%
/grant=KULREF\%USER%=F
/grant=KULREF\smbadmin.kult=F

+subdirec e:\mail\%USER%\*
/perm
/setowner=KULREF\%USER%
/grant=KULREF\%USER%=F
/grant=KULREF\smbadmin.kult=F

+file d:\profiles\%USER%
/perm
/setowner=KULREF\%USER%
/grant=KULREF\%USER%=F
/grant=KULREF\smbadmin.kult=F

+subdirec d:\profiles\%USER%\*
/perm
/setowner=KULREF\%USER%
/grant=KULREF\%USER%=F
/grant=KULREF\smbadmin.kult=F
';

open(FILE, $infilename) or die "Could not open input file $infilename\n";
while(<FILE>) {
	chomp $_;
	push @users, $_;
}
close FILE or die "Could not close input file $infilename\n";

open(FILE, ">$outfilename") or die "Could not open input file $outfilename\n";
foreach my $username (@users) {
	my $user_template= $template_text;
	$user_template =~ s/%USER%/$username/g;
	print FILE $user_template;
}
close FILE or die "Could not close input file $outfilename\n";

# Convert to DOS Format
system('perl -pi -e \' s/\n/\r\n/;\' '.$outfilename);
