[Toybox] [PATCH] chown/chgrp with unknown numeric ids

darken darken at darken.eu
Sun Aug 14 10:54:48 PDT 2016


The issue is that chown/chgrp would error exit if it was passed an unknown
numeric uid/gid.
https://github.com/landley/toybox/issues/45

This all happens in the `xgetpwnamid` function (also applies to `
xgetgrnamid`)
https://github.com/landley/toybox/blob/5b360d8da327b38daf0c5b8874fbe55406b70ced/lib/xwrap.c#L593

The function tries to resolve the text input to a uid, if it fails it takes
the input and turns it into a uid, if that works it returns the `struct
passwd`, otherwise it errors out.
Because it wants to return the looked up struct it fails if the uid/gid is
unknown.

When looking at the uses of `xgetpwnamid`:
https://github.com/landley/toybox/search?utf8=%E2%9C%93&q=xgetgrnamid
It's used in:
- chgrp
- makedevs
- cp
- find
In each case the code wants to turn user-input into a uid/gid to further
work with it.
In each case only the uid/gid wanted, not the whole passwd or group struct!
So `xgetgrnamid` could actually return just `uid_t` and as far as I looked
it up, for the 4 cases where it's used, an unknown uid/gid is fine.
(I think the function name also makes more sense if it returns an id).

So now we only error out if we have input that is neither a resolvable
user/group and the input can't be turned into a number via `estrtol` either.

Find can now search for unknown uid/gid too :)!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20160814/2c6108eb/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Allow-processing-of-unknown-uid-gid.patch
Type: application/octet-stream
Size: 4551 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20160814/2c6108eb/attachment-0003.obj>


More information about the Toybox mailing list