Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-perm doesn't accept some valid symbolic modes #26

Closed
tavianator opened this issue Jun 14, 2017 · 6 comments · Fixed by #154
Closed

-perm doesn't accept some valid symbolic modes #26

tavianator opened this issue Jun 14, 2017 · 6 comments · Fixed by #154
Labels

Comments

@tavianator
Copy link
Contributor

$ ./target/debug/find -perm +rwx
Error: invalid mode '+rwx'
$ ./target/debug/find -perm u+rwX
Error: invalid mode 'u+rwX'
$ ./target/debug/find -perm u=g
Error: invalid mode 'u=g'
@mcharsley
Copy link
Contributor

mcharsley commented Jun 15, 2017 via email

@tavianator
Copy link
Contributor Author

tavianator commented Jun 15, 2017

Luckily in this case we have the POSIX documentation:

The mode argument is used to represent file mode bits. It shall be identical in format to the symbolic_mode operand described in chmod, and shall be interpreted as follows. To start, a template shall be assumed with all file mode bits cleared. An op symbol of '+' shall set the appropriate mode bits in the template; '-' shall clear the appropriate bits; '=' shall set the appropriate mode bits, without regard to the contents of the file mode creation mask of the process. The op symbol of '-' cannot be the first character of mode; this avoids ambiguity with the optional leading <hyphen-minus>. Since the initial mode is all bits off, there are not any symbolic modes that need to use '-' as the first character.

In other words, the syntax is exactly the same as chmod. Since chmod symbolic modes actually specify a change to some existing permissions, you should interpret them as starting from 0000.

The linked chmod docs go on to describe the exact grammar.

I'm assuming +rwx is the equivalent of ugo+rwx

Yes, +rwx == a+rwx == ugo+rwx. See the lines starting with "If who is not specified, ..." in the chmod docs.

and u=g means "where user permissions = group permissions"

Not exactly, u=g means "set the user permissions to the same as the group permissions." These are normally 0 because that's what we're starting from, but something like u=rw,g=u-w is the same as u=rw,g=r.

@e12e
Copy link

e12e commented Jul 18, 2017

Just a hint, while you can't just look at the GNU sources (without risking having to change the license), you could probably look at bsd find for help?

https://github.com/freebsd/freebsd/blob/f5d95e1f8d32db4ccccfd5ad9cecb21ed07a695d/usr.bin/find/function.c#L1277

On a similar note, I saw that the maintainer of GNU coreutils mentioned on a reddit[r] discussion of a similar project in go[g] (no find port, though) - that the GNU coreutils have an extensive test suite. The same seems to hold true for Gnu findutils as well:

http://git.savannah.gnu.org/gitweb/?p=findutils.git;a=tree;f=find/testsuite;h=b3f19586ab00fcc897be2ee17a8966cf445983f2;hb=HEAD

A set of tests written with Dejagnu[d].

While there's probably no license problems running this project through GNU tests (but care would have to be taken re-distributing Gnu tests) -- I see that the FreeBSD project has a test suite[w] using kyua[k] and ATF[a] - apparently inspired by the NetBSD test-suite. But FreeBSD doesn't have any tests for find (that I can see), but there are a handful for NetBSD (but not for symbolic permissions):

https://github.com/IIJ-NetBSD/netbsd-src/blob/master/tests/usr.bin/find/t_find.sh

NetBSD find handling of permissions:

https://github.com/IIJ-NetBSD/netbsd-src/blob/0bcc2a01826fc41bf3f1b6d9fb95f157b3db607d/usr.bin/find/function.c#L1513

All in all, I'd say there'd be a use for a project dedicated to making a POSIX test-suite as a form of executable specification/documentation for this stuff - but that's at least a separate issue, probably a separate project.

The Open Group apparently has such a test suite available, and as far as I can tell it's free for open source projects - but presumably not Free/redistributable (every developer/contributor would need to acquire a personal license?):

http://www.opengroup.org/testing/testsuites/vscpcts2016.htm

Apologies if this "drive-by essay" is a bit out of scope, but it appeared that at least looking at Net/FreeBSD might be of some help on some of these thornier syntax/behaviors. It would probably also be great to reach some consensus on test suites - both for BSD in particular and Free nix-likes in general.

From a cursory look, I'd probably start with the NetBSD/FreeBSD tests - the GNU tests are quite extensive, but would appear to benefit from some modernization.

[a] https://github.com/jmmv/atf/
[d] https://www.gnu.org/software/dejagnu/
[g] https://github.com/aisola/go-coreutils
[k] https://github.com/jmmv/kyua/
[r] https://www.reddit.com/r/golang/comments/27ggqy/a_go_language_implementation_of_the_gnu_coreutils/
[w] https://wiki.freebsd.org/TestSuite

@tavianator
Copy link
Contributor Author

tavianator commented Jul 19, 2017

@e12e thanks for all those links!

I've also written what I believe is a correct implementation as part of a find-compatible tool: https://github.com/tavianator/bfs/blob/1.1/parse.c#L1416

I also have a test suite for it that you can run against other tools with ./tests.sh --bfs=/path/to/find (pass --gnu or just --posix to run only those parts of the test suite). In fact that's how I found most of the bugs I've reported :) https://github.com/tavianator/bfs/blob/1.1/tests.sh

@mcharsley
Copy link
Contributor

mcharsley commented Jul 19, 2017 via email

@tavianator
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants