Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] test for *other* write permissions



I'm running a script as root, I'm going to parse a file.  I can easily test that the file is owned by root.  I want to test if the group or other write bit is set.

If using "find" you can test that a file is writable by yourself - but not test if it's writable by anyone else.

If using "stat" you can get the perms in drwxrwxrws format.  But the number of characters sometimes varies, based on whether or not it's a character special device, directory, softlink, etc.  Also, the leading or trailing blank character ' ' space may or may not be present for different implementations of stat.  So although it's definitely possible to find the "w" bit in the "g" and "o" fields...  I am hesitant to do this.  Also, even if I want to do this, it's not immediately obvious to me, how to extract the nth character out of a string in a bash script.

If using "stat" you can also get the perms in 755 format.  From here, I can easily do a bitwise & with 2, and I can easily find the world write bit.  But bash arithmetic doesn't view the number "755" in octal...  It operates decimal.  So I can't bitwise & with 16, or with 020.  I have to strip off the last character, and then bitwise 75 with & 2.  So once again, given my previous comments about leading and trailing spaces and stuff, plus, not knowing how to get the nth character of a string, I'm not really sure there's a good solution here.

So far, my best idea is to check if the file is owned by root:root, and then just check the World write bit.

People have better suggestions?



BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org