File:  [LON-CAPA] / loncom / build / verifymodown.pl
Revision 1.1: download - view: text, annotated - select for diffs
Sat Nov 17 22:46:00 2001 UTC (22 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: stable_2001_fall, HEAD
needed tool for monitoring and enforcing file ownership and permissions -Scott

    1: #!/usr/bin/perl
    2: 
    3: # The LearningOnline Network with CAPA
    4: #
    5: # verifymodown.pl - script to enforce file mode and ownership
    6: #
    7: # YEAR=2001
    8: # 11/17 Scott Harrison
    9: #
   10: # $Id: verifymodown.pl,v 1.1 2001/11/17 22:46:00 harris41 Exp $
   11: ###
   12: 
   13: my $filename=shift @ARGV;
   14: my $arguments=shift @ARGV;
   15: 
   16: #print "Filename: $filename\n";
   17: #print "Arguments: $arguments\n";
   18: 
   19: my ($user)=($arguments=~/\-o (\S+)/);
   20: my ($group)=($arguments=~/\-g (\S+)/);
   21: my ($mode)=($arguments=~/\-m (\S+)/);
   22: 
   23: my $currentmode=(stat($filename))[2];
   24: my $currentuser=getpwuid((stat($filename))[4]);
   25: my $currentgroup=getgrgid((stat($filename))[5]);
   26: 
   27: my $cflag='';
   28: 
   29: unless (-l $filename) {
   30:     $currentmode=sprintf("%.4o",($currentmode&07777));
   31:     $cflag.="[MODE IS $currentmode SHOULD BE $mode]" if $mode ne $currentmode;
   32: }
   33: 
   34:     $cflag.="[USER IS $currentuser SHOULD BE $user]" if $user ne $currentuser;
   35:     $cflag.="[GROUP IS $currentgroup SHOULD BE $group]" 
   36:         if $group ne $currentgroup;
   37: 
   38: if ($cflag) {
   39:     `chmod $mode $filename`;
   40:     `chown $user:$group $filename`;
   41: }
   42: 
   43: print <<END if $cflag;
   44: **** WARNING (how did this happen?!) ****
   45: Fixing $filename ownership/permissions mismatch. $cflag\n";
   46: END

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>