stux2000 / plan9front

Automatically exported from code.google.com/p/plan9front
0 stars 0 forks source link

test -w on directories #127

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
test -w on directories doesnt work. it always returns
false. problem is that test uses access(AWRITE) which
does an open(OWRITE) on the directory which will
always fail.

is this expected behaviour? some rc scripts seem to
suggest that it should work:

/rc/bin/lp
/rc/bin/juke

access() bug? test bug? are these scripts just buggy?

dont "FIX" it right away, wanna discuss this and see
our options.

suggestions? :)

Original issue reported on code.google.com by cinap_le...@felloff.net on 24 May 2012 at 6:38

GoogleCodeExporter commented 9 years ago
Some possible fixes (including ones that I think are awful and/or dangerous):

1. Make ‘test -w’ check whether its argument is a directory, and if it is, 
try creating a file in it.

2. Change those scripts to try creating a file in the directory, like 
$home/lib/profile does (on line /syscall create/).  Maybe delete the file 
afterward?  ($home/lib/profile doesn't delete the file, but at least the test 
still succeeds when the file already exists.)

3. Add a new option to test which tests that (a) its argument is a directory 
and (b) the directory allowed creation (then deletion) of at least one file 
with a semi-arbitrary name.  Change the scripts to use this option.

4. Add an option to test which tests that its argument has at least one mode 
bit in common with a specified mask.  (Can it know which set of mode bits 
(user/group/other) applies to the current process?)

5. Give up on testing directories for writability. Change lp to always mount 
its /tmp (is there a security risk from not doing this?); change juke to use 
‘test -e /mnt/juke’.

I think option 5 is best, and option 1 is horribly dangerous.

Original comment by rransom....@gmail.com on 10 Aug 2012 at 7:15

GoogleCodeExporter commented 9 years ago
yes, and 5 was exactly what i did to lp :)

Original comment by cinap_le...@felloff.net on 10 Aug 2012 at 9:03

GoogleCodeExporter commented 9 years ago
changed the scripts.

Original comment by cinap_le...@felloff.net on 9 Sep 2012 at 1:28