Abid Khwaja wrote: > Thanks for the pointers. Here's what I did: > > 1. stat the file to see the mode set by the system > > demerzel:~/etc abid$ ls -l > total 16 > -rw-rw---- 1 root uucp 311 Nov 14 15:20 slist.conf > demerzel:~/etc abid$ stat -s slist.conf > st_dev=234881026 st_ino=6858828 st_mode=0100660 st_nlink=1 st_uid=0 > st_gid=66 st_rdev=0 st_size=311 st_atime=1132939903 st_mtime=1131999637 > st_ctime=1132948249 st_blksize=4096 st_blocks=8 st_flags=0 > > 2. check for root:uucp and 660 > > use Fcntl; > use File::stat; > > my $etcgroup = "/etc/group"; > my $conffile = "/Users/abid/etc/slist.conf"; > my $shouldbegroup = "uucp"; > my $shouldbeuid = 0; > my $shouldbemode = 0100660; # -rw-rw---- perms > > my $shouldbegid; > > sysopen(GROUP, $etcgroup, O_RDONLY) > || die "can't find/open $etcgroup: $!\n"; > > while (<GROUP>) { > if (/^$shouldbegroup/ && /\d+/) { > $shouldbegid = $&; > last; > } > }
You could use perl's built-in getgrnam function to do that: $ perl -le' $shouldbegid = getgrnam "uucp"; print $shouldbegid' 14 > close(GROUP) > || die "can't close $etcgroup: $!\n"; > > # get config file permissions > my $perms = stat($conffile) > || die "can't find $conffile: $!\n"; > > # are permissions set correctly? > unless (($perms->uid == $shouldbeuid) && > ($perms->gid == $shouldbegid) && > (($perms->mode & $shouldbemode) == $shouldbemode)) { I think you may misunderstand how the & operator works. You are telling it to turn off bits in $perms->mode that are not turned on in both $perms->mode and $shouldbemode. For example: $ perl -e' $x = 0777; $y = 0660; printf "%#o\n", $x & $y' 0660 $ perl -e' $x = 0; $y = 0660; printf "%#o\n", $x & $y' 0 > print "Aborting! Incorrect config file perms!\n"; > exit 1 > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>