bijna werkende permissie check

This commit is contained in:
Ward Wouts 2004-01-19 22:23:46 +00:00
parent 118f0b1cab
commit e5776d052b

View file

@ -35,6 +35,7 @@ $cpcmd
$cvscmd $cvscmd
$mkdircmd $mkdircmd
$sudocmd $sudocmd
$permsfile
); );
$hostname = hostname(); $hostname = hostname();
@ -47,6 +48,10 @@ $sudocmd = "/usr/bin/sudo";
&readconfig; &readconfig;
unless ( $permsfile ) {
$permsfile = $cvspath ? "$cvspath/PERMS" : "";
}
my %option = (); my %option = ();
&cmdline; &cmdline;
@ -56,6 +61,7 @@ if ( $cvspath ) {
foreach ( @ARGV ) { foreach ( @ARGV ) {
if ( -f $_ ) { if ( -f $_ ) {
&incvs($_); # check if file exists in cvs else make it so &incvs($_); # check if file exists in cvs else make it so
&inperms($_); # check if file perms are registered or make it so
unless (&cmptocvs($_)) { # compare file to cvs unless (&cmptocvs($_)) { # compare file to cvs
print "$_ not in sync with cvs version\n"; print "$_ not in sync with cvs version\n";
print "please fix this\n"; print "please fix this\n";
@ -166,6 +172,45 @@ sub incvs($) {
} }
} }
sub inperms($) {
my $file = shift;
my $path = &fullpath($file);
my $fullname = "$path/" . basename($file);
my @stats = stat $fullname;
my $user = (getpwuid($stats[4]))[0];
my $group = (getgrgid($stats[5]))[0];
my $mode = sprintf "%lo", $stats[2];
$mode =~ s/.*(\d{4})$/$1/;
print "$mode:$user:$group:$fullname\n";
exit;
unless ( -f $permsfile ) {
print <<EOT;
# \$Id\$
# \$Source\$
EOT
system("$cvscmd add $permsfile");
system("$cvscmd ci -m initial $permsfile");
}
my $perms = &slurp($permsfile);
if ( $perms =~ /^(\d{4}):([^-:][^:]*):([^:]+?):$fullname$/o ) {
# check perms
# update als optie -p anders file skippen
} else {
open(FH, ">>$permsfile");
print FH "$mode:$user:$group:$fullname\n";
close FH;
system("$cvscmd ci -m \"adding $fullname\" $permsfile");
}
print "$path\n";
exit;
}
sub edit($) { sub edit($) {
if ( exists $ENV{'EDITOR'} ) { if ( exists $ENV{'EDITOR'} ) {
$editor = $ENV{'EDITOR'}; $editor = $ENV{'EDITOR'};
@ -307,6 +352,14 @@ sub fullpath($) {
} }
} }
sub slurp($) {
my $file = shift;
open(FH, "<$file") or die "Couldn't open $file: $!\n";
my $result = do { local $/; <FH>; };
close FH;
return $result;
}
sub help { sub help {
print <<EOT; print <<EOT;