[Chicago-talk] CGI umask

Steven Lembark lembark at wrkhors.com
Wed Mar 3 22:35:03 CST 2004

-- "Randal L. Schwartz" <merlyn at stonehenge.com>

>>>>>> "Steven" == Steven Lembark <lembark at wrkhors.com> writes:
> Steven> -- jason scott gessner <jason at multiply.org>
> Steven> perldoc the stat call, one of the return values are the
> Steven> mods in octal.
> stat() returns numbers.  Numbers are neither decimal nor octal.
> What are you talking about?

The bit groupings for the mods use three values for
each of settings, user, group, other. These are normally
represented in octal with the u/g/o taken as octal digits
for each of the triplets.

So far as I know the internal representation used by
Perl for integers provided in hex, octal, or decimal is
an internally consistent integer for the local processor.
That should leave me able to compare stat's mod's
return with values converted from octal strings, no?

For example, user has write is 0200 so (stat)[2] & 0200
can be used in a test for user-writable files. More common
are group writeable checks, (stat)[2] & 070.

So, if you chmod-ed something using $mode then:

	(stat)[2] & $mode == $mode

is one quick test for the proper modes. Given the
way mods work, most people write them in octal,
e.g., "02775" for sgid + all access for user + group
and r + x for other.

Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 888 359 3508

More information about the Chicago-talk mailing list