RocHack / bb

Command line Blackboard client
MIT License
72 stars 8 forks source link

Fix find -perm syntax #12

Closed jthurst3 closed 9 years ago

jthurst3 commented 9 years ago

find $1 -perm /066 gives an error with find on OSX. Changed to find $1 -perm 066.

clehner commented 9 years ago

From man page for find (GNU findutils) 4.4.2

-perm mode: File's permission bits are exactly mode -perm -mode: All of the permission bits mode are set for the file -perm /mode: Any of the permission bits mode are set for the file -perm +mode: Deprecated, old way of searching for files with any of the permission bits in mode set

find $1 -perm /066 checks for any of the bits 066 (group/other read/write) being set for the file. If we use -perm 066 it checks for all of the bits being set, i.e. the file is group readable, group writable, other writable, and other readable, which is too specific.

bb used to use +mode but that gives an warning on CSUG machines because it is deprecated for /mode (since findutils-4.2.21). OS X and BSD find don't support /mode. I suggest we go back to using +mode, which was used in bb until 84cc3f5702af267a806824ac9021ad0aaa1ddcdc. Then the warning can be suppressed with 2>&- and if it is removed in later versions of GNU find we change it to something else.

jthurst3 commented 9 years ago

Okay. I don't think going back to +mode will work though, since Linux gives an error and quits when using +mode, and OSX gives an error and quits when using /mode. Without checking the operating system or the version of find, the simplest solution is probably:

insecure_file() {
        [[ -n `find $1 -perm +066 2>&-; find $1 -perm /066 2>&-` ]]
} 
clehner commented 9 years ago

I had forgotten the error was fatal instead of just a warning. This should work well now. I'll merge it.