[Discuss] test for *other* write permissions

Tom Metro tmetro+blu at gmail.com
Thu Nov 15 21:41:59 EST 2012


Derek Martin wrote:
> I'd use Python or C (or <shudder> Perl for this).
> 
>>>> import stat, os
>>>> mode = os.stat(".bashrc")
>>>> print ((mode.st_mode | stat.S_IWGRP) and mode.st_gid == 0)
> False

Shudder yourself. This operation is perfectly legible in Perl:

use File::stat;
use Fcntl qw(S_IWGRP S_IWOTH); # import fcntl.h symbols
my $fs = stat($filename);
print "$filename is group or other writable\n"
  if $fs && $fs->mode & (S_IWGRP | S_IWOTH);

(Are you sure your code tests that the file is group or other writable?
You seem to be only testing for group write and that the group owner is
root.)

 -Tom

-- 
Tom Metro
Venture Logic, Newton, MA, USA
"Enterprise solutions through open source."
Professional Profile: http://tmetro.venturelogic.com/



More information about the Discuss mailing list